From 820638694d6056cad2456e9f57b3afbeb03e6bf6 Mon Sep 17 00:00:00 2001 From: mst Date: Fri, 28 Feb 2025 07:16:38 +0300 Subject: [PATCH] theme store implementation --- app.py | 172 +++++++++++++ templates/admin/categories/customize.html | 281 +++++++++++++++++++++- 2 files changed, 441 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 07ba5fe..8f52076 100644 --- a/app.py +++ b/app.py @@ -391,6 +391,164 @@ def pwaManifest(): "background_color": "" }) +@api_bp.route('/ts/download///', methods=['GET']) +@loginRequired +def downloadTheme(author, theme): + return send_file( + requests.get(f"{ cfg['themeStoreUrl'] }/api/v1/dl/{author}/{theme}/"), + download_name=f"{ theme }.css") + +@api_bp.route('/ts/card_row/', methods=['GET']) +@loginRequired +def themeStore_themes(): + cfg = func.loadJSON(const.configFile) + url = f"{ cfg['themeStoreUrl'] }/api/v1/themes/" + themes = requests.get(url).json() + cards = "" + i = 0 + for theme in themes: + i += 1 + cards += f""" +
+
+
+ +
+
+

{ _("Updated") } { func.formatRelativeTime(theme['updated_at']) }

+
+

+ { _("by") } + { theme['author'] } +

+
+
+
+ """ + html = f""" +
+ {cards} +
+ """ + return html + +@api_bp.route('/ts/modals/', methods=['GET']) +@loginRequired +def themeStore_themeModals(): + cfg = func.loadJSON(const.configFile) + url = f"{cfg['themeStoreUrl']}/api/v1/themes/" + themes = requests.get(url).json() + i = 0 + modals = "" + + for theme in themes: + i += 1 + theme_name = theme['name'] + singleton = f"data-bs-toggle='modal' data-bs-target='#theme-modal-confirm-{i}'" if cfg['style']['customCss'] != "" else f"""data-bs-dismiss='modal' onclick='useTheme({i}, "{ theme_name }")'""" + modals += f""" + + + """ + return modals + +@api_bp.route("/change_language/", methods=['POST']) +def changeLanguage(): + if cfg['languages']['allowChanging']: + lang = request.form.get('lang') + if lang not in app.config['available_languages'].keys(): + # fallback to en_US on malformed request + session['language'] == 'en_US' + flash("400 Bad Request: The browser (or proxy) sent a request that this server could not understand.", "danger") + return redirect(request.referrer) + session['language'] = lang + return redirect(request.referrer) + else: + return abort(404) + # wip, scheduled for 1.8.0 release # @api_bp.route('/hyper/widget/', methods=['GET']) # def widget(): @@ -399,6 +557,20 @@ def pwaManifest(): # metadata = func_val[1] # return render_template('widget.html', combined=combined, urllib=urllib, trimContent=func.trimContent, metadata=metadata, getRandomWord=func.getRandomWord, formatRelativeTime=func.formatRelativeTime) +@api_bp.route('/hyper/load_more_questions/', methods=['GET']) +def load_more_questions(): + page = request.args.get('page', default=1, type=int) + per_page = 25 + offset = (page - 1) * per_page + + func_val = func.getAllQuestions(limit=per_page, offset=offset) + combined = func_val[0] + + if not combined: + return "" + + return render_template('snippets/layout/load_more_questions.html', combined=combined, page=page, per_page=per_page, formatRelativeTime=func.formatRelativeTime, trimContent=func.trimContent, urllib=urllib) + # -- question routes -- @api_bp.route('/add_question/', methods=['POST']) diff --git a/templates/admin/categories/customize.html b/templates/admin/categories/customize.html index 3b9307e..d7f3ffa 100644 --- a/templates/admin/categories/customize.html +++ b/templates/admin/categories/customize.html @@ -143,33 +143,290 @@ Retrospring -

Info box layout

+

{{ _('Info box layout') }}

-

Trimmed content

+

{{ _('Trimmed content') }}

- + -

Maximum length of content before it gets trimmed (used in sharing options); set to 0 to disable

+

{{ _('Maximum length of content before it gets trimmed (used in sharing options); set to 0 to disable') }}

-
- + +

{{ _('Advanced') }}

+

{{ _('Custom CSS') }}

+ +
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+
+
+ +
+
+
+ + +
+ + +
+
+ + +
+ + {% include 'snippets/admin/saveBtn.html' %} {% endblock %} {% block _scripts %} + +