diff --git a/froide_govplan/forms.py b/froide_govplan/forms.py index dc6e8a3..8854cce 100644 --- a/froide_govplan/forms.py +++ b/froide_govplan/forms.py @@ -1,11 +1,13 @@ from django import forms +from django.utils import timezone from django.utils.safestring import mark_safe +from django.utils.translation import gettext_lazy as _ import bleach from bleach.linkifier import Linker from tinymce.widgets import TinyMCE -from .models import GovernmentPlan, GovernmentPlanUpdate +from .models import GovernmentPlan, GovernmentPlanUpdate, PlanRating, PlanStatus BLEACH_OPTIONS = { "tags": [ @@ -47,7 +49,9 @@ class BleachField(forms.CharField): class GovernmentPlanForm(forms.ModelForm): - description = BleachField(required=False, widget=TinyMCE(attrs={"cols": 80, "rows": 30})) + description = BleachField( + required=False, widget=TinyMCE(attrs={"cols": 80, "rows": 30}) + ) class Meta: model = GovernmentPlan @@ -55,8 +59,74 @@ class GovernmentPlanForm(forms.ModelForm): class GovernmentPlanUpdateForm(forms.ModelForm): - content = BleachField(required=False, widget=TinyMCE(attrs={"cols": 80, "rows": 30})) + content = BleachField( + required=False, widget=TinyMCE(attrs={"cols": 80, "rows": 30}) + ) class Meta: model = GovernmentPlanUpdate fields = "__all__" + + +class GovernmentPlanUpdateProposalForm(forms.ModelForm): + title = forms.CharField( + label=_("title"), + help_text=_("Summarize the update in a title."), + widget=forms.TextInput( + attrs={ + "class": "form-control", + } + ), + ) + content = forms.CharField( + required=False, + label=_("details"), + help_text=_("Optionally give more details."), + widget=forms.Textarea(attrs={"class": "form-control", "rows": "3"}), + ) + url = forms.URLField( + label=_("source URL"), + help_text=_("Please give provide a link."), + widget=forms.URLInput( + attrs={"class": "form-control", "placeholder": "https://"} + ), + ) + status = forms.ChoiceField( + label=_("status"), + help_text=_("Has the status of the plan changed?"), + choices=[("", "---")] + PlanStatus.choices, + required=False, + ) + rating = forms.ChoiceField( + label=_("rating"), + help_text=_("What's your rating of the current implementation?"), + choices=[("", "---")] + PlanRating.choices, + required=False, + ) + + class Meta: + model = GovernmentPlanUpdate + fields = ( + "title", + "content", + "url", + "status", + "rating", + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def save(self, plan, user): + """ + This doesn't save instance, but saves + the change proposal. + """ + data = self.cleaned_data + plan.proposals = plan.proposals or {} + plan.proposals[user.id] = { + "data": data, + "timestamp": timezone.now().isoformat(), + } + plan.save() + return plan diff --git a/froide_govplan/templates/froide_govplan/detail.html b/froide_govplan/templates/froide_govplan/detail.html index 8eb064a..ed84cdf 100644 --- a/froide_govplan/templates/froide_govplan/detail.html +++ b/froide_govplan/templates/froide_govplan/detail.html @@ -6,6 +6,8 @@ {% load follow_tags %} {% load govplan %} {% load fds_ogimage %} +{% load form_helper %} +{% load content_helper %} {% block title %}{{ object.title }}{% endblock %} @@ -190,6 +192,51 @@ {% endfor %} +