diff --git a/app/admin/forms.py b/app/admin/forms.py index 9a9dbd47..ed9a9c8f 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -29,6 +29,9 @@ class SiteMiscForm(FlaskForm): registration_mode = SelectField(_l('Registration mode'), choices=types, default=1, coerce=str) application_question = TextAreaField(_l('Question to ask people applying for an account')) log_activitypub_json = BooleanField(_l('Log ActivityPub JSON for debugging')) + themes = [('', _l('PieFed')), + ('high_contrast', _l('High contrast'))] + default_theme = SelectField(_l('Default theme'), choices=themes, coerce=str) submit = SubmitField(_l('Save')) diff --git a/app/admin/routes.py b/app/admin/routes.py index 0e2ca625..4d8c19f3 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -80,6 +80,7 @@ def admin_misc(): site.application_question = form.application_question.data site.log_activitypub_json = form.log_activitypub_json.data site.updated = utcnow() + site.default_theme = form.default_theme.data if site.id is None: db.session.add(site) db.session.commit() @@ -95,6 +96,7 @@ def admin_misc(): form.registration_mode.data = site.registration_mode form.application_question.data = site.application_question form.log_activitypub_json.data = site.log_activitypub_json + form.default_theme.data = site.default_theme if site.default_theme is not None else '' return render_template('admin/misc.html', title=_('Misc settings'), form=form, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), diff --git a/app/models.py b/app/models.py index 903b6dbe..821edd90 100644 --- a/app/models.py +++ b/app/models.py @@ -352,6 +352,7 @@ class User(UserMixin, db.Model): instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True) reports = db.Column(db.Integer, default=0) # how many times this user has been reported. default_sort = db.Column(db.String(25), default='hot') + theme = db.Column(db.String(20), default='') avatar = db.relationship('File', lazy='joined', foreign_keys=[avatar_id], single_parent=True, cascade="all, delete-orphan") cover = db.relationship('File', lazy='joined', foreign_keys=[cover_id], single_parent=True, cascade="all, delete-orphan") @@ -1021,6 +1022,7 @@ class Site(db.Model): updated = db.Column(db.DateTime, default=utcnow) last_active = db.Column(db.DateTime, default=utcnow) log_activitypub_json = db.Column(db.Boolean, default=False) + default_theme = db.Column(db.String(20), default='') @staticmethod def admins() -> List[User]: diff --git a/app/static/themes b/app/static/themes new file mode 120000 index 00000000..3112f93b --- /dev/null +++ b/app/static/themes @@ -0,0 +1 @@ +../templates/themes \ No newline at end of file diff --git a/app/templates/admin/activities.html b/app/templates/admin/activities.html index 8f1c1372..a8f86d4b 100644 --- a/app/templates/admin/activities.html +++ b/app/templates/admin/activities.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/activity_json.html b/app/templates/admin/activity_json.html index 5a2f8b7e..8b300a19 100644 --- a/app/templates/admin/activity_json.html +++ b/app/templates/admin/activity_json.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/approve_registrations.html b/app/templates/admin/approve_registrations.html index 0b86f2eb..454b99f6 100644 --- a/app/templates/admin/approve_registrations.html +++ b/app/templates/admin/approve_registrations.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/communities.html b/app/templates/admin/communities.html index 411659f2..548ed408 100644 --- a/app/templates/admin/communities.html +++ b/app/templates/admin/communities.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/edit_community.html b/app/templates/admin/edit_community.html index c800ba89..2c5ca385 100644 --- a/app/templates/admin/edit_community.html +++ b/app/templates/admin/edit_community.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_field %} {% block app_content %} diff --git a/app/templates/admin/edit_topic.html b/app/templates/admin/edit_topic.html index db53cdc7..0a65d554 100644 --- a/app/templates/admin/edit_topic.html +++ b/app/templates/admin/edit_topic.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html index 17fd7cff..f71b478b 100644 --- a/app/templates/admin/edit_user.html +++ b/app/templates/admin/edit_user.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_field %} {% block app_content %} diff --git a/app/templates/admin/federation.html b/app/templates/admin/federation.html index b2a82362..96bd0ca2 100644 --- a/app/templates/admin/federation.html +++ b/app/templates/admin/federation.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/home.html b/app/templates/admin/home.html index 4c47482f..db0363db 100644 --- a/app/templates/admin/home.html +++ b/app/templates/admin/home.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/misc.html b/app/templates/admin/misc.html index 0fe862c2..73db60b2 100644 --- a/app/templates/admin/misc.html +++ b/app/templates/admin/misc.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/reports.html b/app/templates/admin/reports.html index 97827f29..67af4e06 100644 --- a/app/templates/admin/reports.html +++ b/app/templates/admin/reports.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/site.html b/app/templates/admin/site.html index c12dcd50..53478d98 100644 --- a/app/templates/admin/site.html +++ b/app/templates/admin/site.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_field %} {% block app_content %} diff --git a/app/templates/admin/topics.html b/app/templates/admin/topics.html index bede4c1e..7bba2707 100644 --- a/app/templates/admin/topics.html +++ b/app/templates/admin/topics.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index 881816f7..c73eee35 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/auth/register.html b/app/templates/auth/register.html index 4e99578d..891643ee 100644 --- a/app/templates/auth/register.html +++ b/app/templates/auth/register.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block scripts %} diff --git a/app/templates/auth/reset_password.html b/app/templates/auth/reset_password.html index 2b83b4b8..1af5d3b3 100644 --- a/app/templates/auth/reset_password.html +++ b/app/templates/auth/reset_password.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/auth/reset_password_request.html b/app/templates/auth/reset_password_request.html index 2b83b4b8..1af5d3b3 100644 --- a/app/templates/auth/reset_password_request.html +++ b/app/templates/auth/reset_password_request.html @@ -1,4 +1,8 @@ -{% extends "base.html" %} +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} {% from 'bootstrap/form.html' import render_form %} {% block app_content %} diff --git a/app/templates/base.html b/app/templates/base.html index ece3cbdd..5498a990 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -43,6 +43,9 @@ {% if markdown_editor %} {% endif %} + {% if theme() %} + + {% endif %} {% endblock %}