diff --git a/Dockerfile b/Dockerfile index 3b9eb9d..6d964ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,9 @@ FROM python:3.12.7 # Image Labels. Update values for each build LABEL Name="Skill-Forge" -LABEL Version="1.4.5" +LABEL Version="1.4.6" LABEL Release="public" -LABEL ReleaseDate="13.10.2024" +LABEL ReleaseDate="20.10.2024" LABEL Description="Skill Forge is a open-source platform for learning and practicing programming languages." LABEL Maintainer="Aleksandar Karastoyanov " LABEL License="GNU GPL v3.0 license" diff --git a/app/models.py b/app/models.py index 36e2477..93f215c 100644 --- a/app/models.py +++ b/app/models.py @@ -10,7 +10,7 @@ from app.database.db_init import db script_dir = os.path.dirname(os.path.abspath(__file__)) -default_avatar_path = os.path.join(script_dir, 'static', 'images', 'anvil.png') + ########### Define the User model ########### class User(UserMixin, db.Model): @@ -62,9 +62,7 @@ def __init__(self, username, first_name, last_name, password, email, avatar=None self.last_name = last_name self.email = email self.password = password - self.date_registered = datetime.now() - with open(default_avatar_path, 'rb') as f: - self.avatar = base64.b64encode(f.read()) + self.date_registered = datetime.now() self.generate_user_id() # Generate random UserID diff --git a/app/routes/user_routes.py b/app/routes/user_routes.py index ca57033..dbfccc0 100644 --- a/app/routes/user_routes.py +++ b/app/routes/user_routes.py @@ -1,7 +1,7 @@ import base64, json, random, string, io from datetime import datetime from bson import ObjectId -from flask import Blueprint, redirect, url_for, request, flash, render_template, abort, send_file, jsonify +from flask import Blueprint, redirect, url_for, request, flash, render_template, abort, send_file from flask_login import login_required, current_user from sqlalchemy import func from sqlalchemy.orm import joinedload @@ -12,7 +12,7 @@ from app.database.db_init import db # Import MongoDB transactions functions from app.database.mongodb_transactions import mongo_transaction -from app.database.mongodb_init import mongo1_db, mongo1_client +from app.database.mongodb_init import mongo1_client # Import admin_required decorator @@ -105,15 +105,21 @@ def open_user_profile(): form.discord_id.data = user.discord_id form.linked_in.data = user.linked_in + # Get the user's submited quests user_submited_quests = SubmitedQuest.query.filter(SubmitedQuest.quest_author_id == user_id).all() - user_solved_quests = SubmitedSolution.query.options( - joinedload(SubmitedSolution.coding_quest) - ).filter_by(user_id=user_id).all() + # Get the user's solved quests in descending order + user_solved_quests = SubmitedSolution.query.options(joinedload(SubmitedSolution.coding_quest)).filter_by(user_id=user_id).all() + # Get the user's achievements user_achievements = UserAchievement.query.filter(UserAchievement.user_id == user_id).all() - avatar_base64 = base64.b64encode(user.avatar).decode('utf-8') if user.avatar else None + # Get the user's avatar + if user.avatar: + avatar_base64 = base64.b64encode(user.avatar).decode('utf-8') + else: + avatar_base64 = None + # Get the user's status and last logged date user_status = user.user_online_status last_logged_date = user.last_status_update - + # Get the xp points for the level rank with open('app/static/configs/levels.json', 'r') as file: levels_data = json.load(file) diff --git a/app/routes/user_submit_quest_routes.py b/app/routes/user_submit_quest_routes.py index da1004d..4613aec 100644 --- a/app/routes/user_submit_quest_routes.py +++ b/app/routes/user_submit_quest_routes.py @@ -32,7 +32,7 @@ def open_user_submit_quest(): @login_required @admin_required def open_submited_quest(quest_id): - submited_quest = SubmitedQuest.query.filter_by(quest_id=quest_id).first() + submited_quest = SubmitedQuest.query.filter_by(quest_id=quest_id).first_or_404() user_avatar = base64.b64encode(current_user.avatar).decode('utf-8') form = QuestApprovalForm() form.submited_quest_id.data = quest_id @@ -276,7 +276,7 @@ def post_comment(): @bp_usq.route('/edit_submited_quest/', methods=['GET']) @login_required def open_submited_quest_as_user(quest_id): - submited_quest = SubmitedQuest.query.filter_by(quest_id=quest_id).first() + submited_quest = SubmitedQuest.query.filter_by(quest_id=quest_id).first_or_404() # Throw 404 error if the user is not the author of the quest OR the user is not an admin if current_user.username != submited_quest.quest_author and current_user.user_role != 'Admin': diff --git a/app/static/css/curr_task_template.css b/app/static/css/curr_task_template.css index f88fb5c..55be318 100644 --- a/app/static/css/curr_task_template.css +++ b/app/static/css/curr_task_template.css @@ -372,4 +372,4 @@ form { .user-feed { font-size: 14px; margin-top: 12px -} \ No newline at end of file +} diff --git a/app/static/js/questsTable.js b/app/static/js/questsTable.js index 4e5606f..bbd21c2 100644 --- a/app/static/js/questsTable.js +++ b/app/static/js/questsTable.js @@ -32,7 +32,6 @@ $(function () { }); }); - // Table for quests $(function () { $(document).ready(function () { @@ -44,14 +43,18 @@ $(function () { // Table for user submited quests in the user profile $(function () { $(document).ready(function () { - $('#user_submited_quests').DataTable(); + $('#user_submited_quests').DataTable({ + "order": [[ 4, "desc" ]] + }); }); }); // Table for user solved quests $(function () { $(document).ready(function () { - $('#user_solved_quests').DataTable(); + $('#user_solved_quests').DataTable({ + "order": [[ 5, "desc" ]] + }); }); }); diff --git a/app/templates/navbar.html b/app/templates/navbar.html index e4665f6..2036ef2 100644 --- a/app/templates/navbar.html +++ b/app/templates/navbar.html @@ -21,6 +21,9 @@ Submit Quest + + Skill Forge Hub + diff --git a/app/templates/open_quest.html b/app/templates/open_quest.html index a57007f..d357150 100644 --- a/app/templates/open_quest.html +++ b/app/templates/open_quest.html @@ -103,15 +103,15 @@

Zero Test Output

{{ form.csrf_token() }} -
-
-
-
+
+
+
+
Comments
- + {{ form.comment(class_="form-control", placeholder="Enter your comment...") }}
@@ -121,7 +121,7 @@
Comments
- +
diff --git a/app/templates/user_profile.html b/app/templates/user_profile.html index 2e09ff5..896b0f6 100644 --- a/app/templates/user_profile.html +++ b/app/templates/user_profile.html @@ -41,8 +41,8 @@