Skip to content

Commit

Permalink
Merge pull request #292 from Skill-Forge-Project/development
Browse files Browse the repository at this point in the history
Skill Forge v1.4.6 patch release
  • Loading branch information
karastoyanov authored Oct 20, 2024
2 parents 51115fe + da51948 commit 0b6538d
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
LABEL License="GNU GPL v3.0 license"
Expand Down
6 changes: 2 additions & 4 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions app/routes/user_routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions app/routes/user_submit_quest_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -276,7 +276,7 @@ def post_comment():
@bp_usq.route('/edit_submited_quest/<quest_id>', 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':
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/curr_task_template.css
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,4 @@ form {
.user-feed {
font-size: 14px;
margin-top: 12px
}
}
9 changes: 6 additions & 3 deletions app/static/js/questsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ $(function () {
});
});


// Table for quests
$(function () {
$(document).ready(function () {
Expand All @@ -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" ]]
});
});
});

Expand Down
3 changes: 3 additions & 0 deletions app/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<span class="px-1 hover:text-gray-700 nav-btn">
<span class="mx-1 cursor-pointer" onclick=location.href="{{ url_for('usq.open_user_submit_quest') }}">Submit Quest</span>
</span>
<span class="px-1 hover:text-gray-700 nav-btn">
<span class="mx-1 cursor-pointer" onclick="window.open('https://skill-forge-hub.stratios.net/', '_blank')">Skill Forge Hub</span>
</span>

<!-- Sign Out Icon -->
<span class="icon-wrapper sign-out-icon cursor-pointer float-right hover:text-gray-700">
Expand Down
12 changes: 6 additions & 6 deletions app/templates/open_quest.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ <h2 class="test-results-label">Zero Test Output</h2>
<!-- Bootstrap Comments Section -->
<form action="{{ url_for('quests.quest_post_comment', quest_id=quest_id) }}" method="post">
{{ form.csrf_token() }}
<div class="container mt-5 mb-5">
<div class="row height d-flex justify-content-center align-items-center">
<div class="col-md-7">
<div class="card">
<div class="container w-full">
<div class="row justify-content-center align-items-center">
<div class=" w-full">
<div class="card w-full">
<div class="p-3">
<h6>Comments</h6>
</div>
<div class="mt-3 d-flex flex-row align-items-center p-3 form-color">
<img src="{{ user_avatar }}" width="50" height="50" class="rounded-circle mr-2">
<img src="{{ user_avatar }}" class="inline-block rounded-full w-20 h-20 mr-2">
{{ form.comment(class_="form-control", placeholder="Enter your comment...") }}
</div>
<div class="submit-comment-btn-area">
Expand All @@ -121,7 +121,7 @@ <h6>Comments</h6>
<div class="mt-2">
<div class="d-flex flex-row p-3">
<a href="{{ url_for('usr.open_user_profile_view', username=comment.user.username) }}">
<img src="data:image/jpeg;base64,{{ comment.user.avatar_data }}" width="40" height="40" class="rounded-circle mr-3">
<img src="data:image/jpeg;base64,{{ comment.user.avatar_data }}" class="inline-block rounded-full w-20 h-20 mr-4">
</a>
<div class="w-100">
<div class="d-flex justify-content-between align-items-center">
Expand Down
5 changes: 2 additions & 3 deletions app/templates/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<div class="col-span-4 sm:col-span-3">
<div class="shadow rounded-lg p-6 user_profile_info left_pane">
<div class="flex flex-col items-center">
<img class="inline-block w-48 rounded-full user_avatar"
src="{{ user.avatar and 'data:image/jpeg;base64,' + avatar_base64 or url_for('static', filename='images/anvil.png') }}"
<img class="inline-block w-48 h-48 rounded-full user_avatar"
src="{{ user.avatar and 'data:image/jpeg;base64,' + avatar_base64 or url_for('static', filename='../static/images/achievements-icons/General/quest_approved.png') }}"
id="avatarPreview" alt="Avatar">
<h1 class="text-xl font-bold user_profile_info username">{{user.username}}</h1>
<p class="text-l user_profile_info name">{{user.first_name}} {{user.last_name}}</p>
Expand Down Expand Up @@ -336,7 +336,6 @@ <h1 class="text-xl font-bold mb-0 mt-5 pl-12 user_profile_info title">My Submite
alt="Failed" width="15" height="15">
{% endif %}
</td>

</tr>
{% endfor %}
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/user_profile_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<div class="flex flex-col items-center">
<div>
{% if avatar %}
<img src="data:image/jpeg;base64,{{ avatar }}" alt="Avatar" class="user_avatar">
<img src="data:image/jpeg;base64,{{ avatar }}" alt="Avatar" class="inline-block w-48 h-48 rounded-full user_avatar">
{% else %}
<img src="../static/images/anvil.png" alt="Default Avatar" class="user_avatar">
<img src="../static/images/anvil.png" alt="Default Avatar" class="inline-block w-48 h-48 rounded-full user_avatar">
{% endif %}
</div>
<h1 class="text-xl font-bold user_profile_info username">{{user.username}}</h1>
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = Skill-Forge
version = 1.4.5
release_date = 13.10.2024
version = 1.4.6
release_date = 20.10.2024
description = Skill Forge is a open-source platform for learning and practicing programming languages.
author = Aleksandar Karastoyanov
author_email = [email protected]
Expand Down

0 comments on commit 0b6538d

Please sign in to comment.