theme engine and high contrast theme fixes #27 fixes #19

This commit is contained in:
rimu 2024-02-07 17:31:12 +13:00
parent 6aa0d51bcc
commit 9874727eea
64 changed files with 419 additions and 55 deletions

View file

@ -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'))

View file

@ -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()),

View file

@ -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]:

1
app/static/themes Symbolic link
View file

@ -0,0 +1 @@
../templates/themes

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -43,6 +43,9 @@
{% if markdown_editor %}
<link href="{{ url_for('static', filename='js/markdown/downarea.css') }}" type="text/css" rel="stylesheet" />
{% endif %}
{% if theme() %}
<link href="{{ url_for('static', filename='themes/' + theme() + '/styles.css') }}" type="text/css" rel="stylesheet" />
{% endif %}
{% endblock %}
<title>{% if title %}{{ title }}{% else %}{{ _('PieFed') }}{% endif %}</title>
<link rel="apple-touch-icon" sizes="152x152" href="/static/images/apple-touch-icon.png">

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %} %}
{% block app_content %}
<div class="row">

View file

@ -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 %} %}
{% block app_content %}
<div class="row">

View file

@ -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 %} %}
{% block app_content %}
<div class="row">

View file

@ -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 'bootstrap5/form.html' import render_form %}
{% block app_content %}

View file

@ -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 %} %}
{% block app_content %}
<div class="row">

View file

@ -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 'bootstrap5/form.html' import render_form %}
{% block app_content %}

View file

@ -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 'bootstrap5/form.html' import render_form %}
{% block app_content %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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, render_field %}
{% block app_content %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %} %}
{% block app_content %}
<div class="row">

View file

@ -0,0 +1,3 @@
{
"name": "High Contrast"
}

View file

@ -0,0 +1,86 @@
:root {
--bs-link-color: black;
--bs-link-color-rgb: black;
--bs-link-hover-color-rgb: #333;
}
[data-bs-theme="dark"] {
--bs-body-bg: black;
--bs-link-color: white;
--bs-link-color-rgb: white;
--bs-link-hover-color-rgb: #eee;
--bs-heading-color: white;
--bs-body-color: white;
--bs-body-color-rgb: white;
}
.btn-primary {
--bs-btn-bg: black;
--bs-btn-border-color: black;
--bs-btn-hover-bg: #333;
}
[data-bs-theme="dark"] .btn-primary {
--bs-btn-bg: white;
--bs-btn-border-color: white;
--bs-btn-hover-bg: white;
--bs-btn-color: black;
}
[data-bs-theme="dark"] .btn-primary:hover {
--bs-btn-hover-color: black;
}
.btn-outline-secondary {
--bs-btn-color: black;
}
[data-bs-theme="dark"] .btn-outline-secondary {
--bs-btn-color: white;
}
.post_list .post_teaser {
border-bottom: solid 1px black;
}
[data-bs-theme="dark"] .post_list .post_teaser {
border-bottom: solid 1px white;
}
.domain_link, .domain_link a {
color: black;
}
[data-bs-theme="dark"] .domain_link, [data-bs-theme="dark"] .domain_link a {
color: ghostwhite;
}
.main_pane, .voting_buttons div {
border: solid 1px #333;
}
[data-bs-theme="dark"] .main_pane, [data-bs-theme="dark"] .voting_buttons div {
border: solid 1px #eee;
}
div.navbar {
border-bottom: solid 1px #333;
}
[data-bs-theme="dark"] div.navbar {
border-bottom: solid 1px #fff;
}
.nav-link {
color: black;
}
[data-bs-theme="dark"] .nav-link {
color: white;
}
.card {
--bs-card-border-color: #333;
}
[data-bs-theme="dark"] .card {
--bs-card-border-color: #fff;
}
.coolfieldset.collapsed legend, .coolfieldset legend, .coolfieldset.expanded legend {
background-color: white;
}
[data-bs-theme="dark"] .coolfieldset.collapsed legend, [data-bs-theme="dark"] .coolfieldset legend, [data-bs-theme="dark"] .coolfieldset.expanded legend {
background-color: black;
}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}
@ -22,6 +26,7 @@
{{ render_field(form.indexable) }}
{{ render_field(form.default_sort) }}
{{ render_field(form.import_file) }}
{{ render_field(form.theme) }}
{{ render_field(form.submit) }}
&nbsp;&nbsp;<a href="{{ url_for('user.user_settings_filters') }}">{{ _('Manage content filters') }}</a>
</form>

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -45,6 +45,9 @@ class SettingsForm(FlaskForm):
('active', _l('Active')),
]
default_sort = SelectField(_l('By default, sort posts by'), choices=sorts, validators=[DataRequired()], coerce=str)
themes = [('', _l('PieFed')),
('high_contrast', _l('High contrast'))]
theme = SelectField(_l('Theme'), choices=themes, coerce=str)
submit = SubmitField(_l('Save settings'))

View file

@ -160,6 +160,7 @@ def change_settings():
current_user.searchable = form.searchable.data
current_user.indexable = form.indexable.data
current_user.default_sort = form.default_sort.data
current_user.theme = form.theme.data
import_file = request.files['import_file']
if import_file and import_file.filename != '':
file_ext = os.path.splitext(import_file.filename)[1]
@ -190,6 +191,7 @@ def change_settings():
form.searchable.data = current_user.searchable
form.indexable.data = current_user.indexable
form.default_sort.data = current_user.default_sort
form.theme.data = current_user.theme
return render_template('user/edit_settings.html', title=_('Edit profile'), form=form, user=current_user,
moderating_communities=moderating_communities(current_user.get_id()),

View file

@ -29,8 +29,8 @@ from app.models import Settings, Domain, Instance, BannedInstances, User, Commun
# Flask's render_template function, with support for themes added
def render_template(template_name: str, **context) -> Response:
theme = get_setting('theme', '')
if theme != '':
theme = current_theme()
if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'):
content = flask.render_template(f'themes/{theme}/{template_name}', **context)
else:
content = flask.render_template(template_name, **context)
@ -672,3 +672,13 @@ def parse_page(page_url, tags_to_search = KNOWN_OPENGRAPH_TAGS, fallback_tags =
found_tags[og_tag] = soup.find(fallback_tags[og_tag]).text
return found_tags
def current_theme():
if current_user.is_authenticated:
if current_user.theme is not None and current_user.theme != '':
return current_user.theme
else:
return g.site.default_theme if g.site.default_theme is not None else ''
else:
return g.site.default_theme if g.site.default_theme is not None else ''

View file

@ -0,0 +1,38 @@
"""themes
Revision ID: f19d761c216d
Revises: 3fb833e34c75
Create Date: 2024-02-07 16:13:47.846365
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f19d761c216d'
down_revision = '3fb833e34c75'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('site', schema=None) as batch_op:
batch_op.add_column(sa.Column('default_theme', sa.String(length=20), nullable=True))
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('theme', sa.String(length=20), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('theme')
with op.batch_alter_table('site', schema=None) as batch_op:
batch_op.drop_column('default_theme')
# ### end Alembic commands ###

View file

@ -8,7 +8,7 @@ from flask import session, g, json, request
from app.constants import POST_TYPE_LINK, POST_TYPE_IMAGE, POST_TYPE_ARTICLE
from app.models import Site
from app.utils import getmtime, gibberish, shorten_string, shorten_url, digits, user_access, community_membership, \
can_create, can_upvote, can_downvote, shorten_number, ap_datetime
can_create, can_upvote, can_downvote, shorten_number, ap_datetime, current_theme
app = create_app()
cli.register(app)
@ -39,6 +39,8 @@ with app.app_context():
app.jinja_env.globals['can_create'] = can_create
app.jinja_env.globals['can_upvote'] = can_upvote
app.jinja_env.globals['can_downvote'] = can_downvote
app.jinja_env.globals['theme'] = current_theme
app.jinja_env.globals['file_exists'] = os.path.exists
app.jinja_env.filters['shorten'] = shorten_string
app.jinja_env.filters['shorten_url'] = shorten_url