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"]
|
||||
|
||||
|
||||
class CheckboxSelectMultipleHorizontal(widgets.CheckboxSelectMultiple):
|
||||
template_name = "widgets/checkbox_select_horizontal.html"
|
||||
option_template_name = "widgets/checkbox_select_horizontal_option.html"
|
||||
|
||||
|
||||
class FeedStatusTypes(CustomForm):
|
||||
class FeedStatusTypesForm(CustomForm):
|
||||
class Meta:
|
||||
model = models.User
|
||||
fields = ["feed_status_types"]
|
||||
help_texts = {f: None for f in fields}
|
||||
labels = {"feed_status_types": ""}
|
||||
widgets = {
|
||||
"feed_status_types": CheckboxSelectMultipleHorizontal(
|
||||
"feed_status_types": widgets.CheckboxSelectMultiple(
|
||||
choices=[
|
||||
("review", _("Reviews")),
|
||||
("comment", _("Comments")),
|
||||
|
|
|
@ -16,22 +16,35 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{# feed settings #}
|
||||
<details class="mb-5" {% if settings_saved %}open{% endif %}>
|
||||
<summary>
|
||||
<span class="has-text-weight-bold">What to display?</span>
|
||||
<span class="has-text-weight-bold">
|
||||
{{ _("Feed settings") }}
|
||||
</span>
|
||||
{% 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 %}
|
||||
</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 %}
|
||||
|
||||
<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 class="level-right">
|
||||
<button class="button is-small is-primary is-outlined" type="submit">
|
||||
Submit
|
||||
{{ _("Save settings") }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -56,7 +69,7 @@
|
|||
{# activity feed #}
|
||||
{% if not activities %}
|
||||
<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 %}
|
||||
{# 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.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm import activitystreams, forms, models
|
||||
|
@ -25,7 +26,7 @@ class Feed(View):
|
|||
def post(self, request, tab):
|
||||
"""save feed settings form, with a silent validation fail"""
|
||||
settings_saved = False
|
||||
form = forms.FeedStatusTypes(request.POST, instance=request.user)
|
||||
form = forms.FeedStatusTypesForm(request.POST, instance=request.user)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
settings_saved = True
|
||||
|
@ -57,9 +58,12 @@ class Feed(View):
|
|||
"tab": tab,
|
||||
"streams": STREAMS,
|
||||
"goal_form": forms.GoalForm(),
|
||||
"feed_status_types_form": forms.FeedStatusTypes(
|
||||
instance=request.user,
|
||||
),
|
||||
"feed_status_types_options": [
|
||||
("review", _("Reviews")),
|
||||
("comment", _("Comments")),
|
||||
("quotation", _("Quotations")),
|
||||
("everything", _("Everything else")),
|
||||
],
|
||||
"settings_saved": settings_saved,
|
||||
"path": f"/{tab['key']}",
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue