Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add avatars #331

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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/*
orronai marked this conversation as resolved.
Show resolved Hide resolved
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)
orronai marked this conversation as resolved.
Show resolved Hide resolved

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)),
orronai marked this conversation as resolved.
Show resolved Hide resolved
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,
orronai marked this conversation as resolved.
Show resolved Hide resolved
),
),
],
)
Loading