Merge 543a83cb81
into 00e35409ef
This commit is contained in:
commit
cb9ce12228
|
@ -28,19 +28,7 @@ class OAuthLoginForm(forms.Form):
|
|||
class PreferencesForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Preference
|
||||
fields = [
|
||||
"theme",
|
||||
"filter_replies",
|
||||
"filter_boosts",
|
||||
"timezone",
|
||||
"no_javascript",
|
||||
"notifications",
|
||||
"click_to_load",
|
||||
"lightbox",
|
||||
"filter_notifications",
|
||||
"bundle_notifications",
|
||||
"poll_frequency",
|
||||
]
|
||||
fields = Preference._fields
|
||||
|
||||
|
||||
class PostForm(forms.Form):
|
||||
|
|
|
@ -29,7 +29,20 @@ class Theme(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
from django.db.models.fields.related_descriptors import ForeignKeyDeferredAttribute
|
||||
def set_fields(klass):
|
||||
fields = []
|
||||
for n in dir(klass):
|
||||
assert n != "_fields"
|
||||
v = getattr(klass, n)
|
||||
if not hasattr(v, 'field'): continue
|
||||
if not isinstance(v.field, models.Field): continue
|
||||
if isinstance(v, ForeignKeyDeferredAttribute): continue
|
||||
fields.append(n)
|
||||
setattr(klass, '_fields', fields)
|
||||
return klass
|
||||
|
||||
@set_fields
|
||||
class Preference(models.Model):
|
||||
theme = models.ForeignKey(Theme, models.CASCADE, null=False, default=1)
|
||||
filter_replies = models.BooleanField(default=False)
|
||||
|
@ -37,6 +50,14 @@ class Preference(models.Model):
|
|||
timezone = models.CharField(
|
||||
max_length=80, blank=True, null=True, choices=timezones, default="UTC"
|
||||
)
|
||||
preview_sensitive = models.BooleanField(
|
||||
default=False,
|
||||
help_text=_(
|
||||
'Show preview for media marked as "sensitive"'))
|
||||
open_detail = models.BooleanField(
|
||||
default=False,
|
||||
help_text=_(
|
||||
'Open details (posts with subjects) by default'))
|
||||
no_javascript = models.BooleanField(
|
||||
default=False,
|
||||
help_text=_(
|
||||
|
|
|
@ -41,7 +41,11 @@
|
|||
{% endif %}
|
||||
</p>
|
||||
{% if toot.spoiler_text %}
|
||||
<details class="toot">
|
||||
<details class="toot"
|
||||
{% if preferences.open_detail %}
|
||||
open=""
|
||||
{% endif %}
|
||||
>
|
||||
<summary><strong>{{ toot.spoiler_text }} </strong></summary>
|
||||
<div class="toot">
|
||||
{{ toot.content | relink_toot | fix_emojos:toot.emojis | strip_html | safe }}
|
||||
|
@ -101,7 +105,7 @@
|
|||
<figure class="column attachment-image">
|
||||
<a href="{{ media.url }}">
|
||||
<noscript class="loading-lazy">
|
||||
{% if toot.sensitive %}
|
||||
{% if toot.sensitive and not preferences.preview_sensitive %}
|
||||
<img loading="lazy" src="{% static "images/sensitive.png" %}"
|
||||
{% else %}
|
||||
<img loading="lazy" src="{{ media.preview_url }}"
|
||||
|
@ -127,7 +131,7 @@
|
|||
<source src="{{ media.url }}" type="video/mp4">
|
||||
<a href="{{ media.url }}">
|
||||
<noscript class="loading-lazy">
|
||||
{% if toot.sensitive %}
|
||||
{% if toot.sensitive and not preferences.preview_sensitive %}
|
||||
<img loading="lazy" src="{% static "images/sensitive.png" %}"
|
||||
{% else %}
|
||||
<img loading="lazy" src="{{ media.preview_url }}"
|
||||
|
|
|
@ -30,6 +30,33 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<h2 class="subtitle">Options</h2>
|
||||
<div class="columns">
|
||||
<div class="column is-quarter">
|
||||
<label class="label checkbox" for="id_preview_sensitive">
|
||||
{% render_field form.preview_sensitive class+="checkbox" %}
|
||||
{{ form.preview_sensitive.label }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="column is-quarter">
|
||||
<p class="notification is-info preferences-help">
|
||||
{{ form.preview_sensitive.help_text }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="columns">
|
||||
<div class="column is-quarter">
|
||||
<label class="label checkbox" for="id_open_details">
|
||||
{% render_field form.open_detail class+="checkbox" %}
|
||||
{{ form.open_detail.label }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="column is-quarter">
|
||||
<p class="notification is-info preferences-help">
|
||||
{{ form.open_detail.help_text }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<h2 class="subtitle">Timeline Options</h2>
|
||||
<div class="field">
|
||||
<label class="label checkbox">
|
||||
|
|
|
@ -767,21 +767,10 @@ def settings(request):
|
|||
if request.method == "POST":
|
||||
form = PreferencesForm(request.POST)
|
||||
if form.is_valid():
|
||||
account.preferences.theme = form.cleaned_data["theme"]
|
||||
account.preferences.filter_replies = form.cleaned_data["filter_replies"]
|
||||
account.preferences.filter_boosts = form.cleaned_data["filter_boosts"]
|
||||
account.preferences.timezone = form.cleaned_data["timezone"]
|
||||
account.preferences.no_javascript = form.cleaned_data["no_javascript"]
|
||||
account.preferences.notifications = form.cleaned_data["notifications"]
|
||||
account.preferences.click_to_load = form.cleaned_data["click_to_load"]
|
||||
account.preferences.lightbox = form.cleaned_data["lightbox"]
|
||||
account.preferences.filter_notifications = form.cleaned_data[
|
||||
"filter_notifications"
|
||||
]
|
||||
account.preferences.bundle_notifications = form.cleaned_data[
|
||||
"bundle_notifications"
|
||||
]
|
||||
account.preferences.poll_frequency = form.cleaned_data["poll_frequency"]
|
||||
for field in account.preferences._fields:
|
||||
if field in form.cleaned_data:
|
||||
setattr(account.preferences, field,
|
||||
form.cleaned_data[field])
|
||||
request.session["timezone"] = account.preferences.timezone
|
||||
account.preferences.save()
|
||||
account.save()
|
||||
|
|
Loading…
Reference in New Issue