Skip to content

Commit

Permalink
User badge prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
x10102 committed Dec 22, 2024
1 parent 1b858e5 commit 3a7fec6
Show file tree
Hide file tree
Showing 8 changed files with 853 additions and 461 deletions.
11 changes: 10 additions & 1 deletion blueprints/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ def delete_user(uid: int):
info(f"User {name} deleted by {current_user.nickname} (ID: {current_user.uid})")
flash(f'Uživatel {name} smazán')

return redirect(url_for('index'))
return redirect(url_for('index'))

# TODO: Move this to separate Blueprint
# TODO: Don't forget to add type parameter for forwards compatibility
@UserController.route('/user/<int:uid>/embed', methods=["GET"])
def user_badge(uid: int):
user = dbs.get_user(uid) or abort(404)
stats = dbs.get_user_stats(uid)
last = dbs.get_last_translation(uid)
return render_template("partials/translator_badge.j2", user=user, stats=stats, last=last)
8 changes: 8 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ def get_global_stats(self) -> StatisticsRow:
query = "SELECT * FROM Statistics"
data = self.__tryexec(query).fetchone()
return StatisticsRow(*data)

def get_last_translation(self, uid: int) -> t.Optional[Article]:
query = "SELECT * FROM Article WHERE idauthor=? AND is_original=FALSE ORDER BY added DESC, id DESC LIMIT 1"
data = (uid,)
row = self.__tryexec(query, data).fetchone()
if not row:
return None
return self.__make_article(row)

def add_article(self, a: Article) -> int:
query = "INSERT INTO Article (name, words, bonus, added, link, idauthor, is_original) VALUES (?, ?, ?, ?, ?, ?, ?)"
Expand Down
1 change: 1 addition & 0 deletions scripts/build_badge_css.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx tailwindcss -c ./tailwind_badge_config.js -i ../static/css/src/badge.css -o ../static/css/badge.css --watch
8 changes: 8 additions & 0 deletions scripts/tailwind_badge_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["../templates/partials/translator_badge.j2", "../models/user.py"],
corePlugins: {
preflight: false, // Disable the preflight / reset so that we don't break WikiDot's (or other sites) CSS
},
plugins: [],
}
Loading

0 comments on commit 3a7fec6

Please sign in to comment.