Include whole context to pass csrf_token to form.html & set category on widget
This commit is contained in:
parent
c732fdc96e
commit
af8403f7ce
7 changed files with 17 additions and 11 deletions
|
|
@ -5,6 +5,6 @@
|
|||
{% block content %}
|
||||
<main id="import--page" class="main">
|
||||
{% url "news:collection:rules" as cancel_url %}
|
||||
{% include "form.html" with form=form title="Import an OPML file" cancel_url=cancel_url only %}
|
||||
{% include "form.html" with form=form title="Import an OPML file" cancel_url=cancel_url %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@
|
|||
{% block content %}
|
||||
<main id="rule--page" class="main">
|
||||
{% url "news:collection:rules" as cancel_url %}
|
||||
{% include "form/form.html" with form=form title="Create rule" cancel_url=cancel_url only %}
|
||||
{% include "form/form.html" with form=form title="Create rule" cancel_url=cancel_url %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@
|
|||
{% block content %}
|
||||
<main id="rule--page" class="main">
|
||||
{% url "news:collection:rules" as cancel_url %}
|
||||
{% include "form/form.html" with form=form title="Update rule" cancel_url=cancel_url only %}
|
||||
{% include "form/form.html" with form=form title="Update rule" cancel_url=cancel_url %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from newsreader.news.core.widgets import RulesWidget
|
|||
|
||||
class CategoryForm(forms.ModelForm):
|
||||
rules = forms.ModelMultipleChoiceField(
|
||||
required=False, queryset=CollectionRule.objects.all(), widget=RulesWidget
|
||||
required=False, queryset=CollectionRule.objects.none(), widget=RulesWidget
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
@ -17,6 +17,8 @@ class CategoryForm(forms.ModelForm):
|
|||
|
||||
self.fields["rules"].queryset = CollectionRule.objects.filter(user=self.user)
|
||||
|
||||
self.fields["rules"].widget.category = self.instance
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super().save(commit=False)
|
||||
instance.user = self.user
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@
|
|||
{% block content %}
|
||||
<main id="category--page" class="main">
|
||||
{% url "news:core:categories" as cancel_url %}
|
||||
{% include "form/form.html" with form=form title="Create category" cancel_url=cancel_url only %}
|
||||
{% include "form/form.html" with form=form title="Create category" cancel_url=cancel_url %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
{% extends "news/core/views/category.html" %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block form-header %}
|
||||
<h1 class="h1 form__title">Update category</h1>
|
||||
{% endblock %}
|
||||
{% load static %}
|
||||
|
||||
{% block confirm-button %}
|
||||
<button class="button button--confirm">Save category</button>
|
||||
{% block content %}
|
||||
<main id="category--page" class="main">
|
||||
{% url "news:core:categories" as cancel_url %}
|
||||
{% include "form/form.html" with form=form title="Update category" cancel_url=cancel_url %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,7 @@ class RulesWidget(CheckboxSelectMultiple):
|
|||
def create_option(self, *args, **kwargs):
|
||||
option = super().create_option(*args, **kwargs)
|
||||
instance = self.choices.queryset.get(pk=option["value"])
|
||||
|
||||
if self.category and instance.category:
|
||||
option["selected"] = self.category.pk == instance.category.pk
|
||||
return {**option, "instance": instance}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue