diff --git a/src/newsreader/news/collection/templates/collection/widgets/rule.html b/src/newsreader/news/collection/templates/collection/widgets/rule.html
new file mode 100644
index 0000000..fac5e13
--- /dev/null
+++ b/src/newsreader/news/collection/templates/collection/widgets/rule.html
@@ -0,0 +1,10 @@
+
+
+{% if rule.favicon %}
+
+{% else %}
+
+{% endif %}
+
+{{ rule.name }}
diff --git a/src/newsreader/news/collection/templates/collection/widgets/rules.html b/src/newsreader/news/collection/templates/collection/widgets/rules.html
new file mode 100644
index 0000000..d554ece
--- /dev/null
+++ b/src/newsreader/news/collection/templates/collection/widgets/rules.html
@@ -0,0 +1,7 @@
+
+ {% for rule in rules %}
+ -
+ {% include "collection/widgets/rule.html" %}
+
+ {% endfor %}
+
diff --git a/src/newsreader/news/collection/widgets.py b/src/newsreader/news/collection/widgets.py
new file mode 100644
index 0000000..ff65e1d
--- /dev/null
+++ b/src/newsreader/news/collection/widgets.py
@@ -0,0 +1,6 @@
+from django.forms.widgets import CheckboxSelectMultiple
+
+
+class RulesWidget(CheckboxSelectMultiple):
+ template_name = "collection/widgets/rules.html"
+ option_template_name = "collection/widgets/rule.html"
diff --git a/src/newsreader/news/core/forms.py b/src/newsreader/news/core/forms.py
index a86e2b2..97f7fd0 100644
--- a/src/newsreader/news/core/forms.py
+++ b/src/newsreader/news/core/forms.py
@@ -1,20 +1,13 @@
from django import forms
-from newsreader.accounts.models import User
from newsreader.news.collection.models import CollectionRule
+from newsreader.news.collection.widgets import RulesWidget
from newsreader.news.core.models import Category
class CategoryForm(forms.ModelForm):
rules = forms.ModelMultipleChoiceField(
- required=False,
- queryset=CollectionRule.objects.all(),
- widget=forms.widgets.CheckboxSelectMultiple,
- )
-
- user = forms.ModelChoiceField(
- queryset=User.objects.none(),
- widget=forms.widgets.HiddenInput(attrs={"readonly": True}),
+ required=False, queryset=CollectionRule.objects.all(), widget=RulesWidget
)
def __init__(self, *args, **kwargs):
@@ -23,12 +16,10 @@ class CategoryForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.fields["rules"].queryset = CollectionRule.objects.filter(user=self.user)
- self.fields["user"].queryset = User.objects.filter(pk=self.user.pk)
-
- self.initial["user"] = self.user
def save(self, commit=True):
instance = super().save(commit=False)
+ instance.user = self.user
if commit:
instance.save()
@@ -41,4 +32,4 @@ class CategoryForm(forms.ModelForm):
class Meta:
model = Category
- fields = ("name", "rules", "user")
+ fields = ("name", "rules")
diff --git a/src/newsreader/news/core/templates/core/category-create.html b/src/newsreader/news/core/templates/core/category-create.html
index 73d05b5..e145760 100644
--- a/src/newsreader/news/core/templates/core/category-create.html
+++ b/src/newsreader/news/core/templates/core/category-create.html
@@ -1,9 +1,10 @@
-{% extends "core/category.html" %}
+{% extends "base.html" %}
-{% block form-header %}
-
-{% endblock %}
+{% load static %}
-{% block confirm-button %}
-
+{% block content %}
+
+ {% url "news:core:categories" as cancel_url %}
+ {% include "form/form.html" with form=form title="Create category" cancel_url=cancel_url only %}
+
{% endblock %}
diff --git a/src/newsreader/news/core/templates/core/category.html b/src/newsreader/news/core/templates/core/category.html
deleted file mode 100644
index bee0585..0000000
--- a/src/newsreader/news/core/templates/core/category.html
+++ /dev/null
@@ -1,62 +0,0 @@
-{% extends "base.html" %}
-
-{% load static %}
-
-{% block content %}
-
-
-
-{% endblock %}