Skip to content

Commit c3e3d66

Browse files
committed
feat: Add avatars
- Added avatars to users tables - Added a template in order to change or delete avatar - Added the form and validators for the picture file - Added tests - Added translations - Added to the navbar near the username the avatar (if the user has one) - Added to gitignore the avatars
1 parent f3ed156 commit c3e3d66

File tree

17 files changed

+259
-56
lines changed

17 files changed

+259
-56
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,6 @@ lms/lmsweb/config.py
136136
db.sqlite
137137
vim.session
138138
devops/rabbitmq.cookie
139+
140+
# Avatars
141+
lms/static/avatars/*

lms/lmsdb/bootstrap.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ def _assessment_migration() -> bool:
315315
return True
316316

317317

318+
def _avatar_migration() -> bool:
319+
User = models.User
320+
_migrate_column_in_table_if_needed(User, User.avatar)
321+
return True
322+
323+
318324
def main():
319325
with models.database.connection_context():
320326
if models.database.table_exists(models.Exercise.__name__.lower()):
@@ -328,6 +334,7 @@ def main():
328334
_api_keys_migration()
329335
_last_course_viewed_migration()
330336
_uuid_migration()
337+
_avatar_migration()
331338

332339
if models.database.table_exists(models.UserCourse.__name__.lower()):
333340
_add_user_course_constaint()

lms/lmsdb/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class User(UserMixin, BaseModel):
172172
api_key = CharField()
173173
last_course_viewed = ForeignKeyField(Course, null=True)
174174
uuid = UUIDField(default=uuid4, unique=True)
175+
avatar = CharField(null=True)
175176

176177
def get_id(self):
177178
return str(self.uuid)

lms/lmsweb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
static_dir = project_dir / 'static'
1919
config_file = web_dir / 'config.py'
2020
config_example_file = web_dir / 'config.py.example'
21+
avatars_path = static_dir / 'avatars'
2122

2223

2324
if debug.is_enabled():

lms/lmsweb/forms/update_avatar.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from flask_babel import gettext as _ # type: ignore
2+
from flask_wtf import FlaskForm
3+
from flask_wtf.file import FileAllowed, FileField, FileRequired, FileSize
4+
5+
from lms.lmsweb.config import MAX_UPLOAD_SIZE
6+
from lms.utils.files import ALLOWED_IMAGES_EXTENSIONS
7+
8+
9+
class UpdateAvatarForm(FlaskForm):
10+
avatar = FileField(
11+
'Avatar', validators=[
12+
FileAllowed(list(ALLOWED_IMAGES_EXTENSIONS)),
13+
FileRequired(message=_('No file added')),
14+
FileSize(
15+
max_size=MAX_UPLOAD_SIZE, message=_(
16+
'File size is too big - %(size)dMB allowed',
17+
size=MAX_UPLOAD_SIZE // 1000000,
18+
),
19+
),
20+
],
21+
)

lms/lmsweb/translations/he/LC_MESSAGES/messages.po

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: 1.0\n"
99
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10-
"POT-Creation-Date: 2021-10-03 22:01+0300\n"
10+
"POT-Creation-Date: 2021-10-10 18:00+0300\n"
1111
"PO-Revision-Date: 2021-09-29 11:30+0300\n"
1212
"Last-Translator: Or Ronai\n"
1313
"Language: he\n"
@@ -18,7 +18,7 @@ msgstr ""
1818
"Content-Transfer-Encoding: 8bit\n"
1919
"Generated-By: Babel 2.9.1\n"
2020

21-
#: lmsdb/models.py:879
21+
#: lmsdb/models.py:918
2222
msgid "Fatal error"
2323
msgstr "כישלון חמור"
2424

@@ -47,31 +47,31 @@ msgstr "הבודק האוטומטי נכשל ב־ %(number)d דוגמאות בת
4747
msgid "Bro, did you check your code?"
4848
msgstr "אחי, בדקת את הקוד שלך?"
4949

50-
#: lmsweb/views.py:129
50+
#: lmsweb/views.py:133
5151
msgid "Can not register now"
5252
msgstr "לא ניתן להירשם כעת"
5353

54-
#: lmsweb/views.py:146
54+
#: lmsweb/views.py:150
5555
msgid "Registration successfully"
5656
msgstr "ההרשמה בוצעה בהצלחה"
5757

58-
#: lmsweb/views.py:169
58+
#: lmsweb/views.py:173
5959
msgid "The confirmation link is expired, new link has been sent to your email"
6060
msgstr "קישור האימות פג תוקף, קישור חדש נשלח אל תיבת המייל שלך"
6161

62-
#: lmsweb/views.py:185
62+
#: lmsweb/views.py:189
6363
msgid "Your user has been successfully confirmed, you can now login"
6464
msgstr "המשתמש שלך אומת בהצלחה, כעת אתה יכול להתחבר למערכת"
6565

66-
#: lmsweb/views.py:208 lmsweb/views.py:265
66+
#: lmsweb/views.py:212 lmsweb/views.py:293
6767
msgid "Your password has successfully changed"
6868
msgstr "הסיסמה שלך שונתה בהצלחה"
6969

70-
#: lmsweb/views.py:224
70+
#: lmsweb/views.py:252
7171
msgid "Password reset link has successfully sent"
7272
msgstr "קישור לאיפוס הסיסמה נשלח בהצלחה"
7373

74-
#: lmsweb/views.py:245
74+
#: lmsweb/views.py:273
7575
msgid "Reset password link is expired"
7676
msgstr "קישור איפוס הסיסמה פג תוקף"
7777

@@ -93,6 +93,15 @@ msgstr "הסיסמה הנוכחית שהוזנה שגויה"
9393
msgid "Invalid email"
9494
msgstr "אימייל לא תקין"
9595

96+
#: lmsweb/forms/update_avatar.py:13
97+
msgid "No file added"
98+
msgstr "לא צורף קובץ"
99+
100+
#: lmsweb/forms/update_avatar.py:15
101+
#, python-format
102+
msgid "File size is too big - %(size)dMB allowed"
103+
msgstr "הקובץ גדול מידי - גודל הקובץ המקסימלי הוא עד %(size)dMB"
104+
96105
#: lmsweb/tools/validators.py:13
97106
msgid "The username is already in use"
98107
msgstr "שם המשתמש כבר נמצא בשימוש"
@@ -116,11 +125,11 @@ msgstr "%(checker)s הגיב לך על תרגיל \"%(subject)s\"."
116125
msgid "Your solution for the \"%(subject)s\" exercise has been checked."
117126
msgstr "הפתרון שלך לתרגיל \"%(subject)s\" נבדק."
118127

119-
#: models/users.py:28
128+
#: models/users.py:32
120129
msgid "Invalid username or password"
121130
msgstr "שם המשתמש או הסיסמה שהוזנו לא תקינים"
122131

123-
#: models/users.py:31
132+
#: models/users.py:35
124133
msgid "You have to confirm your registration with the link sent to your email"
125134
msgstr "עליך לאשר את מייל האימות"
126135

@@ -143,7 +152,7 @@ msgid "Exercise submission system for the Python Course"
143152
msgstr "מערכת הגשת תרגילים לקורס פייתון"
144153

145154
#: templates/change-password.html:8 templates/change-password.html:17
146-
#: templates/user.html:19
155+
#: templates/user.html:22
147156
msgid "Change Password"
148157
msgstr "שנה סיסמה"
149158

@@ -170,7 +179,7 @@ msgstr "אימות סיסמה"
170179
msgid "Exercises"
171180
msgstr "תרגילים"
172181

173-
#: templates/exercises.html:21 templates/view.html:113
182+
#: templates/exercises.html:21 templates/view.html:126
174183
msgid "Comments for the solution"
175184
msgstr "הערות על התרגיל"
176185

@@ -203,7 +212,7 @@ msgid "Insert your username and password:"
203212
msgstr "הזינו את שם המשתמש והסיסמה שלכם:"
204213

205214
#: templates/login.html:22 templates/login.html:24 templates/signup.html:16
206-
#: templates/user.html:11
215+
#: templates/user.html:14
207216
msgid "Username"
208217
msgstr "שם משתמש"
209218

@@ -215,35 +224,35 @@ msgstr "שכחת את הסיסמה?"
215224
msgid "Register"
216225
msgstr "הירשם"
217226

218-
#: templates/navbar.html:21
227+
#: templates/navbar.html:25
219228
msgid "Messages"
220229
msgstr "הודעות"
221230

222-
#: templates/navbar.html:37
231+
#: templates/navbar.html:41
223232
msgid "Mark all as read"
224233
msgstr "סמן הכל כנקרא"
225234

226-
#: templates/navbar.html:45
235+
#: templates/navbar.html:49
227236
msgid "Courses List"
228237
msgstr "רשימת הקורסים"
229238

230-
#: templates/navbar.html:65
239+
#: templates/navbar.html:69
231240
msgid "Upload Exercises"
232241
msgstr "העלאת תרגילים"
233242

234-
#: templates/navbar.html:73
243+
#: templates/navbar.html:77
235244
msgid "Exercises List"
236245
msgstr "רשימת התרגילים"
237246

238-
#: templates/navbar.html:81
247+
#: templates/navbar.html:85
239248
msgid "Exercises Archive"
240249
msgstr "ארכיון התרגילים"
241250

242-
#: templates/navbar.html:91
251+
#: templates/navbar.html:95
243252
msgid "Check Exercises"
244253
msgstr "בדוק תרגילים"
245254

246-
#: templates/navbar.html:98
255+
#: templates/navbar.html:102
247256
msgid "Logout"
248257
msgstr "התנתקות"
249258

@@ -261,7 +270,7 @@ msgid "Insert your email for getting link to reset it:"
261270
msgstr "הזינו אימייל לצורך שליחת קישור לאיפוס הסיסמה:"
262271

263272
#: templates/reset-password.html:14 templates/signup.html:15
264-
#: templates/user.html:12
273+
#: templates/user.html:15
265274
msgid "Email Address"
266275
msgstr "כתובת אימייל"
267276

@@ -293,7 +302,7 @@ msgstr "חמ\"ל תרגילים"
293302
msgid "Name"
294303
msgstr "שם"
295304

296-
#: templates/status.html:13 templates/user.html:44
305+
#: templates/status.html:13 templates/user.html:48
297306
msgid "Checked"
298307
msgstr "נבדק/ו"
299308

@@ -313,6 +322,19 @@ msgstr "מדד"
313322
msgid "Archive"
314323
msgstr "ארכיון"
315324

325+
#: templates/update-avatar.html:11
326+
msgid "Change Avatar"
327+
msgstr "שנה תמונת פרופיל"
328+
329+
#: templates/update-avatar.html:14
330+
msgid "Update"
331+
msgstr "עדכן"
332+
333+
#: templates/update-avatar.html:16
334+
#, fuzzy
335+
msgid "Delete Avatar"
336+
msgstr "מחק תמונת פרופיל"
337+
316338
#: templates/upload.html:7
317339
msgid "Upload Notebooks"
318340
msgstr "העלאת מחברות"
@@ -337,63 +359,67 @@ msgstr "נכשלו"
337359
msgid "User details"
338360
msgstr "פרטי משתמש"
339361

340-
#: templates/user.html:16
362+
#: templates/user.html:19
341363
msgid "Actions"
342364
msgstr "פעולות"
343365

344-
#: templates/user.html:24
366+
#: templates/user.html:23
367+
msgid "Update Avatar"
368+
msgstr "עדכן תמונת פרופיל"
369+
370+
#: templates/user.html:28
345371
msgid "Exercises Submitted"
346372
msgstr "תרגילים שהוגשו"
347373

348-
#: templates/user.html:29
374+
#: templates/user.html:33
349375
msgid "Course name"
350376
msgstr "שם קורס"
351377

352-
#: templates/user.html:30
378+
#: templates/user.html:34
353379
msgid "Exercise name"
354380
msgstr "שם תרגיל"
355381

356-
#: templates/user.html:31
382+
#: templates/user.html:35
357383
msgid "Submission status"
358384
msgstr "מצב הגשה"
359385

360-
#: templates/user.html:32
386+
#: templates/user.html:36
361387
msgid "Submission"
362388
msgstr "הגשה"
363389

364-
#: templates/user.html:33
390+
#: templates/user.html:37
365391
msgid "Checker"
366392
msgstr "בודק"
367393

368-
#: templates/user.html:34 templates/view.html:21 templates/view.html:104
369-
msgid "Verbal note"
394+
#: templates/user.html:38 templates/view.html:25 templates/view.html:112
395+
msgid "Assessment"
370396
msgstr "הערה מילולית"
371397

372-
#: templates/user.html:44
398+
#: templates/user.html:48
373399
msgid "Submitted"
374400
msgstr "הוגש"
375401

376-
#: templates/user.html:44
402+
#: templates/user.html:48
377403
msgid "Not submitted"
378404
msgstr "לא הוגש"
379405

380-
#: templates/user.html:56
406+
#: templates/user.html:60
381407
msgid "Notes"
382408
msgstr "פתקיות"
383409

384-
#: templates/user.html:61 templates/user.html:63
410+
#: templates/user.html:65 templates/user.html:67
385411
msgid "New Note"
386412
msgstr "פתקית חדשה"
387413

388-
#: templates/user.html:67
414+
#: templates/user.html:71
389415
msgid "Related Exercise"
390416
msgstr "תרגיל משויך"
391417

392-
#: templates/user.html:76
418+
#: templates/user.html:80
393419
msgid "Privacy Level"
394420
msgstr "רמת פרטיות"
395421

396-
#: templates/user.html:82
422+
#: templates/user.html:86
397423
msgid "Add Note"
398424
msgstr "הוסף פתקית"
399425

@@ -425,43 +451,43 @@ msgstr "הפתרון שלך עדיין לא נבדק."
425451
msgid "It's important for us that all exercises will be checked by human eye."
426452
msgstr "חשוב לנו שכל תרגיל יעבור בדיקה של עין אנושית."
427453

428-
#: templates/view.html:18
454+
#: templates/view.html:19
429455
msgid "Solver"
430456
msgstr "מגיש"
431457

432-
#: templates/view.html:24
458+
#: templates/view.html:32
433459
msgid "Navigate in solution versions"
434460
msgstr "ניווט בגרסאות ההגשה"
435461

436-
#: templates/view.html:30
462+
#: templates/view.html:38
437463
msgid "Current page"
438464
msgstr "סיסמה נוכחית"
439465

440-
#: templates/view.html:38
466+
#: templates/view.html:46
441467
msgid "Finish Checking"
442468
msgstr "סיום בדיקה"
443469

444-
#: templates/view.html:78
470+
#: templates/view.html:86
445471
msgid "Automatic Checking"
446472
msgstr "בדיקות אוטומטיות"
447473

448-
#: templates/view.html:85
474+
#: templates/view.html:93
449475
msgid "Error"
450476
msgstr "כישלון חמור"
451477

452-
#: templates/view.html:90
478+
#: templates/view.html:98
453479
msgid "Staff Error"
454480
msgstr "כישלון חמור"
455481

456-
#: templates/view.html:121
482+
#: templates/view.html:134
457483
msgid "General comments"
458484
msgstr "הערות כלליות"
459485

460-
#: templates/view.html:129
486+
#: templates/view.html:142
461487
msgid "Checker comments"
462488
msgstr "הערות בודק"
463489

464-
#: templates/view.html:139
490+
#: templates/view.html:152
465491
msgid "Done Checking"
466492
msgstr "סיום בדיקה"
467493

0 commit comments

Comments
 (0)