Skip to content

Commit

Permalink
add settings page for usage stats config
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrf committed Oct 22, 2023
1 parent 92d7fe5 commit 119acb4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/settings/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ class EmailSettings(FlaskForm):
username = StringField("User name:")
password = PasswordField("Password:")
submit = SubmitField("Save changes and send test email")


class UsageStatsSettings(FlaskForm):
key = StringField("Key:", validators=[DataRequired()], render_kw={"readonly": True})
site = StringField("Site name:", validators=[DataRequired()])
submit = SubmitField("Save changes")
23 changes: 22 additions & 1 deletion app/settings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask_login import current_user, login_required

from . import settings
from .forms import NewSMBResourceForm, NewUserForm, EmailSettings
from .forms import NewSMBResourceForm, NewUserForm, EmailSettings, UsageStatsSettings
from .. import db
from ..decorators import admin_required
from ..emailing import send_mail, read_mailconfig, write_mailconfig
Expand Down Expand Up @@ -110,6 +110,27 @@ def email():
return render_template("settings/email.html", form=form)


@settings.route("/stats", methods=["GET", "POST"])
@login_required
@admin_required
def stats():
form = UsageStatsSettings()
if form.validate_on_submit():
with open("data/usage_stats_site", "w") as f:
f.write(form.site.data)
flash("Saved changes")

try:
with open("data/usage_stats_key") as f:
form.key.data = f.read()
with open("data/usage_stats_site") as f:
form.site.data = f.read()
except Exception:
pass

return render_template("settings/stats.html", form=form)


# ----- two helper functions for the settings/uploads page
def handle_img(loc, src, refdlist):
if src[:15] == "/browser/ulimg/":
Expand Down
1 change: 1 addition & 0 deletions app/templates/settings/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{{ me.menu_entry("uploads", "Uploads", active) }}
{% endif %}
{{ me.menu_entry("email", "Email", active) }}
{{ me.menu_entry("stats", "Usage stats", active) }}
{{ me.menu_entry("log", "Log", active) }}
</ul>
</div>
Expand Down
13 changes: 13 additions & 0 deletions app/templates/settings/stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% set active = "stats" %}
{% extends "settings/base.html" %}
{% import "util/wtf.html" as wtf %}

{% block page_content %}
<h3 class="page-header">Usage stats</h3>
<form method="POST">
{{ form.hidden_tag() }}
{{ wtf.form_field(form.key) }}
{{ wtf.form_field(form.site) }}
{{ wtf.form_field(form.submit) }}
</form>
{% endblock %}

0 comments on commit 119acb4

Please sign in to comment.