Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ lms/lmsweb/config.py
db.sqlite
vim.session
devops/rabbitmq.cookie

# Avatars
lms/static/avatars/*
7 changes: 7 additions & 0 deletions lms/lmsdb/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ def _assessment_migration() -> bool:
return True


def _avatar_migration() -> bool:
User = models.User
_migrate_column_in_table_if_needed(User, User.avatar)
return True


def main():
with models.database.connection_context():
if models.database.table_exists(models.Exercise.__name__.lower()):
Expand All @@ -328,6 +334,7 @@ def main():
_api_keys_migration()
_last_course_viewed_migration()
_uuid_migration()
_avatar_migration()

if models.database.table_exists(models.UserCourse.__name__.lower()):
_add_user_course_constaint()
Expand Down
1 change: 1 addition & 0 deletions lms/lmsdb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class User(UserMixin, BaseModel):
api_key = CharField()
last_course_viewed = ForeignKeyField(Course, null=True)
uuid = UUIDField(default=uuid4, unique=True)
avatar = CharField(null=True)

def get_id(self):
return str(self.uuid)
Expand Down
2 changes: 2 additions & 0 deletions lms/lmsweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
static_dir = project_dir / 'static'
config_file = web_dir / 'config.py'
config_example_file = web_dir / 'config.py.example'
avatars_path = static_dir / 'avatars'


if debug.is_enabled():
Expand All @@ -38,6 +39,7 @@
if not config_file.exists():
shutil.copy(str(config_example_file), str(config_file))
config_migrator.migrate(config_file, config_example_file)
avatars_path.mkdir(parents=True)

webapp.config.from_pyfile(str(config_file))

Expand Down
21 changes: 21 additions & 0 deletions lms/lmsweb/forms/update_avatar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flask_babel import gettext as _ # type: ignore
from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed, FileField, FileRequired, FileSize

from lms.lmsweb.config import MAX_UPLOAD_SIZE
from lms.utils.files import ALLOWED_IMAGES_EXTENSIONS


class UpdateAvatarForm(FlaskForm):
avatar = FileField(
'Avatar', validators=[
FileAllowed(list(ALLOWED_IMAGES_EXTENSIONS)),
FileRequired(message=_('No file added')),
FileSize(
max_size=MAX_UPLOAD_SIZE, message=_(
'File size is too big - %(size)dMB allowed',
size=MAX_UPLOAD_SIZE // 1000000,
),
),
],
)
Loading