Skip to content

Commit f8c6d9f

Browse files
committed
Add docstring comments to the code
1 parent 77d1eb3 commit f8c6d9f

File tree

2 files changed

+124
-5
lines changed

2 files changed

+124
-5
lines changed

My_path_team9/auth/routes.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@
44
from .forms import LoginForm, RegisterForm
55
from .models import User
66
from .. import login_manager, db
7-
login_manager.login_view = 'auth.login'
87

8+
# Set the login view for the login manager
9+
login_manager.login_view = 'auth.login'
910

1011
@login_manager.user_loader
1112
def load_user(user_id):
13+
"""
14+
Loads a user from the database by ID for Flask-Login.
15+
Args:
16+
user_id (str): The ID of the user to load.
17+
Returns:
18+
User: The user object if found, otherwise None.
19+
"""
1220
return User.query.get(int(user_id))
1321

14-
1522
@auth_bp.route('/login', methods=['GET', 'POST'])
1623
def login():
24+
"""
25+
Handles user login requests. Renders the login form and processes form submissions.
26+
27+
Returns:
28+
Response: A redirect to the appropriate dashboard if login is successful,
29+
or a re-rendered login page with an error message on failure.
30+
"""
1731
form = LoginForm()
1832

1933
if form.validate_on_submit():
@@ -36,6 +50,12 @@ def login():
3650

3751
@auth_bp.route('/register', methods=['GET', 'POST'])
3852
def register():
53+
"""
54+
Handles user registration requests. Renders the registration form and processes user data.
55+
56+
Returns:
57+
Response: Redirects to login on success or re-renders the form with messages on failure.
58+
"""
3959
form = RegisterForm()
4060

4161
if form.validate_on_submit():
@@ -68,9 +88,16 @@ def register():
6888

6989
return render_template("register.html", form=form, current_user=current_user)
7090

91+
7192
@auth_bp.route('/logout')
7293
@login_required
7394
def logout():
95+
"""
96+
Logs the current user out and redirects to the home page.
97+
98+
Returns:
99+
Response: A redirect to the main home page after logging out.
100+
"""
74101
logout_user()
75102
print('Logged out successfully.')
76-
return redirect(url_for("main.home"))
103+
return redirect(url_for("main.home"))

My_path_team9/student/routes.py

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
from .forms import VideoSubmissionForm
99
from .models import VideoSubmission
1010
import numpy as np
11-
from sklearn.linear_model import LogisticRegression
12-
from sklearn.preprocessing import OneHotEncoder
11+
1312

1413
@student_bp.route('/settings', methods=['GET', 'POST'])
1514
@login_required
1615
def settings():
16+
"""
17+
Allows students to update their profile settings including username, email, and password.
18+
19+
Returns:
20+
Renders the settings form or redirects with success/error messages.
21+
"""
1722
if not current_user.is_authenticated or current_user.role != 'student':
1823
return "Access denied", 403
1924

@@ -55,6 +60,12 @@ def settings():
5560
@student_bp.route('/survey', methods=['GET', 'POST'])
5661
@login_required
5762
def survey():
63+
"""
64+
Allows students to submit a learning preference and study habits survey.
65+
66+
Returns:
67+
Renders the survey form or redirects to the recommendation page.
68+
"""
5869
if current_user.role != 'student':
5970
return "Access denied", 403
6071

@@ -93,12 +104,24 @@ def survey():
93104
@student_bp.route('/dashboard')
94105
@login_required
95106
def dashboard():
107+
"""
108+
Renders the student dashboard.
109+
110+
Returns:
111+
The student dashboard page.
112+
"""
96113
return render_template('student_dashboard.html')
97114

98115

99116
@student_bp.route('/submit', methods=['GET', 'POST'])
100117
@login_required
101118
def submit():
119+
"""
120+
Allows students to submit educational video links.
121+
122+
Returns:
123+
Renders the submission form or refreshes the page with submission list.
124+
"""
102125
if current_user.role != 'student':
103126
return "Access denied", 403
104127

@@ -120,21 +143,48 @@ def submit():
120143
@student_bp.route('/tips')
121144
@login_required
122145
def tips():
146+
"""
147+
Displays academic tips for students.
148+
149+
Returns:
150+
Tips HTML page.
151+
"""
123152
return render_template('tips.html')
124153

125154
@student_bp.route('/classes')
126155
@login_required
127156
def classes():
157+
"""
158+
Displays available classes to students.
159+
160+
Returns:
161+
Classes HTML page.
162+
"""
128163
return render_template('classes.html')
129164

130165
@student_bp.route('/find_friends')
131166
def find_friends():
167+
"""
168+
Displays all student profiles for social interaction.
169+
170+
Returns:
171+
Find friends page with a list of students.
172+
"""
132173
all_students = User.query.all()
133174
return render_template('find_friends.html', students=all_students)
134175

135176
@student_bp.route('/profile/<int:user_id>')
136177
@login_required
137178
def profile(user_id):
179+
"""
180+
Displays a specific user's profile including their posts and like status.
181+
182+
Args:
183+
user_id (int): The ID of the user to view.
184+
185+
Returns:
186+
Profile page for the selected user.
187+
"""
138188
user = User.query.get_or_404(user_id)
139189

140190
# Map: post.id -> whether the current user liked it
@@ -146,6 +196,12 @@ def profile(user_id):
146196
@student_bp.route('/my_posts', methods=['GET', 'POST'])
147197
@login_required
148198
def my_posts():
199+
"""
200+
Allows students to view and add their own posts.
201+
202+
Returns:
203+
The user's posts page or refresh after adding a new post.
204+
"""
149205
if request.method == 'POST':
150206
content = request.form.get('content')
151207
if not content.strip():
@@ -163,6 +219,15 @@ def my_posts():
163219
@student_bp.route('/edit_post/<int:post_id>', methods=['GET', 'POST'])
164220
@login_required
165221
def edit_post(post_id):
222+
"""
223+
Allows students to edit their existing post.
224+
225+
Args:
226+
post_id (int): The ID of the post to edit.
227+
228+
Returns:
229+
Post editing page or redirect after update.
230+
"""
166231
post = Post.query.get_or_404(post_id)
167232
if post.user_id != current_user.id:
168233
abort(403)
@@ -180,6 +245,15 @@ def edit_post(post_id):
180245
@student_bp.route('/delete_post/<int:post_id>', methods=['POST'])
181246
@login_required
182247
def delete_post(post_id):
248+
"""
249+
Deletes a student's post.
250+
251+
Args:
252+
post_id (int): The ID of the post to delete.
253+
254+
Returns:
255+
Redirect to the posts page after deletion.
256+
"""
183257
post = Post.query.get_or_404(post_id)
184258
if post.user_id != current_user.id:
185259
abort(403)
@@ -193,6 +267,15 @@ def delete_post(post_id):
193267
@student_bp.route('/like/<int:post_id>', methods=['POST'])
194268
@login_required
195269
def like_post(post_id):
270+
"""
271+
Toggles like status on a post for the current user.
272+
273+
Args:
274+
post_id (int): The ID of the post to like/unlike.
275+
276+
Returns:
277+
Redirects to the referring page or student profile.
278+
"""
196279
post = Post.query.get_or_404(post_id)
197280
existing_like = Like.query.filter_by(user_id=current_user.id, post_id=post.id).first()
198281

@@ -210,6 +293,15 @@ def like_post(post_id):
210293
@student_bp.route('/recommendations/<int:survey_id>')
211294
@login_required
212295
def recommendations(survey_id):
296+
"""
297+
Recommends videos to students based on their survey data using a heuristic model.
298+
299+
Args:
300+
survey_id (int): The ID of the submitted survey.
301+
302+
Returns:
303+
Renders a recommendation page with up to 5 recommended videos.
304+
"""
213305
if current_user.role != 'student':
214306
return "Access denied", 403
215307

0 commit comments

Comments
 (0)