forked from mirrors/bookwyrm
Hardcode form
This commit is contained in:
parent
0b46db49a3
commit
47cfc2f157
5 changed files with 30 additions and 33 deletions
|
@ -174,19 +174,14 @@ class UserGroupForm(CustomForm):
|
||||||
fields = ["groups"]
|
fields = ["groups"]
|
||||||
|
|
||||||
|
|
||||||
class CheckboxSelectMultipleHorizontal(widgets.CheckboxSelectMultiple):
|
class FeedStatusTypesForm(CustomForm):
|
||||||
template_name = "widgets/checkbox_select_horizontal.html"
|
|
||||||
option_template_name = "widgets/checkbox_select_horizontal_option.html"
|
|
||||||
|
|
||||||
|
|
||||||
class FeedStatusTypes(CustomForm):
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.User
|
model = models.User
|
||||||
fields = ["feed_status_types"]
|
fields = ["feed_status_types"]
|
||||||
help_texts = {f: None for f in fields}
|
help_texts = {f: None for f in fields}
|
||||||
labels = {"feed_status_types": ""}
|
labels = {"feed_status_types": ""}
|
||||||
widgets = {
|
widgets = {
|
||||||
"feed_status_types": CheckboxSelectMultipleHorizontal(
|
"feed_status_types": widgets.CheckboxSelectMultiple(
|
||||||
choices=[
|
choices=[
|
||||||
("review", _("Reviews")),
|
("review", _("Reviews")),
|
||||||
("comment", _("Comments")),
|
("comment", _("Comments")),
|
||||||
|
|
|
@ -16,22 +16,35 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{# feed settings #}
|
||||||
<details class="mb-5" {% if settings_saved %}open{% endif %}>
|
<details class="mb-5" {% if settings_saved %}open{% endif %}>
|
||||||
<summary>
|
<summary>
|
||||||
<span class="has-text-weight-bold">What to display?</span>
|
<span class="has-text-weight-bold">
|
||||||
|
{{ _("Feed settings") }}
|
||||||
|
</span>
|
||||||
{% if settings_saved %}
|
{% if settings_saved %}
|
||||||
<span class="tag is-success is-light ml-2">Saved!</span>
|
<span class="tag is-success is-light ml-2">{{ _("Saved!") }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</summary>
|
</summary>
|
||||||
<form class="level" method="post" action="/{{ tab.key }}">
|
<form class="level is-align-items-flex-end" method="post" action="/{{ tab.key }}#feed">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="level-left">
|
<div class="level-left">
|
||||||
{{ feed_status_types_form }}
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<label class="label mt-2 mb-1">Status types</label>
|
||||||
|
{% for name, value in feed_status_types_options %}
|
||||||
|
<label class="mr-2">
|
||||||
|
<input type="checkbox" name="feed_status_types" value="{{ name }}" {% if name in user.feed_status_types %}checked=""{% endif %}/>
|
||||||
|
{{ value }}
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="level-right">
|
<div class="level-right">
|
||||||
<button class="button is-small is-primary is-outlined" type="submit">
|
<button class="button is-small is-primary is-outlined" type="submit">
|
||||||
Submit
|
{{ _("Save settings") }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -56,7 +69,7 @@
|
||||||
{# activity feed #}
|
{# activity feed #}
|
||||||
{% if not activities %}
|
{% if not activities %}
|
||||||
<div class="block content">
|
<div class="block content">
|
||||||
<p>{% trans "There aren't any activities right now! Try following a user to get started" %}</p>
|
<p>{% trans "There aren't any activities right now! Try following a user to get started" %}{% if user.feed_status_types|length < 4 %}{% trans ", or enable more status types" %}{% endif %}</p>
|
||||||
|
|
||||||
{% if request.user.show_suggested_users and suggested_users %}
|
{% if request.user.show_suggested_users and suggested_users %}
|
||||||
{# suggested users for when things are very lonely #}
|
{# suggested users for when things are very lonely #}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
{% with id=widget.attrs.id %}
|
|
||||||
<div{% if id %} id="{{ id }}"{% endif %} class="field">
|
|
||||||
<div class="control">
|
|
||||||
{% for group, options, index in widget.optgroups %}
|
|
||||||
{% for option in options %}
|
|
||||||
{% include option.template_name with widget=option %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endwith %}
|
|
|
@ -1,4 +0,0 @@
|
||||||
<label{% if widget.attrs.id %} for="{{ widget.attrs.id }}"{% endif %}>
|
|
||||||
{% include "django/forms/widgets/input.html" %}
|
|
||||||
{{ widget.label }}
|
|
||||||
</label>
|
|
|
@ -7,6 +7,7 @@ from django.shortcuts import get_object_or_404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import activitystreams, forms, models
|
from bookwyrm import activitystreams, forms, models
|
||||||
|
@ -25,7 +26,7 @@ class Feed(View):
|
||||||
def post(self, request, tab):
|
def post(self, request, tab):
|
||||||
"""save feed settings form, with a silent validation fail"""
|
"""save feed settings form, with a silent validation fail"""
|
||||||
settings_saved = False
|
settings_saved = False
|
||||||
form = forms.FeedStatusTypes(request.POST, instance=request.user)
|
form = forms.FeedStatusTypesForm(request.POST, instance=request.user)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
settings_saved = True
|
settings_saved = True
|
||||||
|
@ -57,9 +58,12 @@ class Feed(View):
|
||||||
"tab": tab,
|
"tab": tab,
|
||||||
"streams": STREAMS,
|
"streams": STREAMS,
|
||||||
"goal_form": forms.GoalForm(),
|
"goal_form": forms.GoalForm(),
|
||||||
"feed_status_types_form": forms.FeedStatusTypes(
|
"feed_status_types_options": [
|
||||||
instance=request.user,
|
("review", _("Reviews")),
|
||||||
),
|
("comment", _("Comments")),
|
||||||
|
("quotation", _("Quotations")),
|
||||||
|
("everything", _("Everything else")),
|
||||||
|
],
|
||||||
"settings_saved": settings_saved,
|
"settings_saved": settings_saved,
|
||||||
"path": f"/{tab['key']}",
|
"path": f"/{tab['key']}",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue