Skip to content

Commit

Permalink
Merge pull request #497 from maykinmedia/feature/1161-add-goal-descri…
Browse files Browse the repository at this point in the history
…ption-to-plans

[#1161] Added 'description' to Plan model, 'goal' and 'description' to Plan forms & views
  • Loading branch information
alextreme authored Feb 27, 2023
2 parents dd8ecd8 + 0953e69 commit 0162e4b
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 13 deletions.
38 changes: 34 additions & 4 deletions src/open_inwoner/plans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class PlanForm(forms.ModelForm):

class Meta:
model = Plan
fields = ("title", "end_date", "plan_contacts", "template")
fields = (
"title",
"goal",
"description",
"end_date",
"plan_contacts",
"template",
)

def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -41,6 +48,18 @@ def __init__(self, user, *args, **kwargs):

if self.instance.pk:
del self.fields["template"]
else:
# not always required (if we have a template)
self.fields["goal"].required = False

def clean(self):
cleaned_data = super().clean()
goal = cleaned_data.get("goal")
template = cleaned_data.get("template")
if not template and not goal:
self.add_error(
"goal", _("This field is required when not using a template")
)

def clean_plan_contacts(self):
# Make sure current user exists in plan_contacts when editing form
Expand All @@ -57,7 +76,12 @@ def save(self, user, commit=True):

template = self.cleaned_data.get("template")
if template:
self.instance.goal = template.goal
# apply template fields if not already set on new instance
if not self.instance.goal:
self.instance.goal = template.goal
if not self.instance.description:
self.instance.description = template.description

self.instance.save()

if template.file:
Expand Down Expand Up @@ -90,7 +114,10 @@ def save(self, user, commit=True):
class PlanGoalForm(forms.ModelForm):
class Meta:
model = Plan
fields = ("goal",)
fields = (
"goal",
"description",
)

def save(self, commit=True):
return super().save(commit=commit)
Expand All @@ -111,7 +138,10 @@ class PlanListFilterForm(forms.ModelForm):

class Meta:
model = Plan
fields = ("plan_contacts", "status")
fields = (
"plan_contacts",
"status",
)

def __init__(self, available_contacts, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
33 changes: 33 additions & 0 deletions src/open_inwoner/plans/migrations/0013_auto_20230223_1115.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.15 on 2023-02-23 10:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("plans", "0012_remove_actiontemplate_goal"),
]

operations = [
migrations.AddField(
model_name="plan",
name="description",
field=models.TextField(
blank=True,
default="",
help_text="The description of the plan.",
verbose_name="description",
),
),
migrations.AddField(
model_name="plantemplate",
name="description",
field=models.TextField(
blank=True,
default="",
help_text="The description of the plan.",
verbose_name="description",
),
),
]
12 changes: 12 additions & 0 deletions src/open_inwoner/plans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class PlanTemplate(models.Model):
"The goal for the plan. So that you and the contact knows what the goal is."
),
)
description = models.TextField(
verbose_name=_("description"),
default="",
blank=True,
help_text=_("The description of the plan."),
)

def __str__(self):
return self.name
Expand Down Expand Up @@ -95,6 +101,12 @@ class Plan(models.Model):
"The goal for the plan. So that you and the contact knows what the goal is."
),
)
description = models.TextField(
verbose_name=_("description"),
default="",
blank=True,
help_text=_("The description of the plan."),
)
end_date = models.DateField(
verbose_name=_("End date"), help_text=_("When the plan should be archived.")
)
Expand Down
5 changes: 5 additions & 0 deletions src/open_inwoner/plans/templates/plans/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<div>{{ plan_template.goal }}</div>
{% endif %}

{% if plan_template.description %}
<div class='preview__title'>{% trans "Description:" %}</div>
<div>{{ plan_template.description }}</div>
{% endif %}

{% if plan_template.file %}
<div class='preview__title'>{% trans 'File:' %}</div>
<div>{% link href=plan_template.file.url text=plan_template.file %}</div>
Expand Down
6 changes: 4 additions & 2 deletions src/open_inwoner/plans/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class PlanFactory(factory.django.DjangoModelFactory):
class Meta:
model = "plans.Plan"

title = factory.Faker("first_name")
goal = factory.Faker("last_name")
title = factory.Faker("sentence")
goal = factory.Faker("paragraph")
description = factory.Faker("paragraph")
end_date = factory.Faker("date")
created_by = factory.SubFactory(UserFactory)

Expand All @@ -45,6 +46,7 @@ class Meta:
name = factory.Faker("word")
file = factory.SubFactory(FilerFileFactory)
goal = factory.Faker("paragraph")
description = factory.Faker("paragraph")


class ActionTemplateFactory(factory.django.DjangoModelFactory):
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/plans/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_created_plan_is_logged(self):
"plan-form"
]
form["title"] = plan.title
form["goal"] = plan.goal
form["end_date"] = plan.end_date
form.submit()

Expand Down
36 changes: 35 additions & 1 deletion src/open_inwoner/plans/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_creator_is_added_when_create_plan(self):
response = self.app.get(self.create_url, user=self.user)
form = response.forms["plan-form"]
form["title"] = plan.title
form["goal"] = plan.goal
form["end_date"] = plan.end_date
response = form.submit()
created_plan = Plan.objects.get(title=plan.title)
Expand Down Expand Up @@ -168,25 +169,30 @@ def test_plan_goal_edit(self):
response = self.app.get(self.goal_edit_url, user=self.user)
self.assertEqual(response.status_code, 200)
self.assertContains(response, self.plan.goal)
self.assertContains(response, self.plan.description)
form = response.forms["goal-edit"]
form["goal"] = "editted goal"
form["description"] = "editted description"
response = form.submit(user=self.user)
self.assertEqual(response.status_code, 302)

self.plan.refresh_from_db()
self.assertEqual(self.plan.goal, "editted goal")
self.assertEqual(self.plan.description, "editted description")

def test_plan_goal_edit_contact_can_access(self):
response = self.app.get(self.goal_edit_url, user=self.contact)
self.assertEqual(response.status_code, 200)
self.assertContains(response, self.plan.goal)
form = response.forms["goal-edit"]
form["goal"] = "editted goal"
form["description"] = "editted description"
response = form.submit(user=self.user)
self.assertEqual(response.status_code, 302)

self.plan.refresh_from_db()
self.assertEqual(self.plan.goal, "editted goal")
self.assertEqual(self.plan.description, "editted description")

def test_plan_goal_edit_not_your_action(self):
other_user = UserFactory()
Expand Down Expand Up @@ -266,6 +272,7 @@ def test_plan_create_fields_required(self):
{
"title": [_("This field is required.")],
"end_date": [_("This field is required.")],
"goal": [_("This field is required when not using a template")],
},
)

Expand All @@ -274,14 +281,17 @@ def test_plan_create_plan(self):
response = self.app.get(self.create_url, user=self.user)
form = response.forms["plan-form"]
form["title"] = "Plan"
form["goal"] = "Goal"
form["description"] = "Description"
form["end_date"] = "2022-01-01"
form["plan_contacts"] = [self.contact.pk]
response = form.submit().follow()
self.assertEqual(response.status_code, 200)
self.assertEqual(Plan.objects.count(), 2)
plan = Plan.objects.exclude(pk=self.plan.id).first()
self.assertEqual(plan.title, "Plan")
self.assertEqual(plan.goal, "")
self.assertEqual(plan.goal, "Goal")
self.assertEqual(plan.description, "Description")

def test_plan_create_plan_with_template(self):
plan_template = PlanTemplateFactory(file=None)
Expand All @@ -298,6 +308,28 @@ def test_plan_create_plan_with_template(self):
plan = Plan.objects.exclude(pk=self.plan.id).first()
self.assertEqual(plan.title, "Plan")
self.assertEqual(plan.goal, plan_template.goal)
self.assertEqual(plan.description, plan_template.description)
self.assertEqual(plan.documents.count(), 0)
self.assertEqual(plan.actions.count(), 0)

def test_plan_create_plan_with_template_and_field_overrides(self):
plan_template = PlanTemplateFactory(file=None)
self.assertEqual(Plan.objects.count(), 1)
response = self.app.get(self.create_url, user=self.user)
form = response.forms["plan-form"]
form["title"] = "Plan"
form["goal"] = "Goal"
form["description"] = "Description"
form["end_date"] = "2022-01-01"
form["plan_contacts"] = [self.contact.pk]
form["template"] = plan_template.pk
response = form.submit().follow()
self.assertEqual(response.status_code, 200)
self.assertEqual(Plan.objects.count(), 2)
plan = Plan.objects.exclude(pk=self.plan.id).first()
self.assertEqual(plan.title, "Plan")
self.assertEqual(plan.goal, "Goal")
self.assertEqual(plan.description, "Description")
self.assertEqual(plan.documents.count(), 0)
self.assertEqual(plan.actions.count(), 0)

Expand All @@ -316,6 +348,7 @@ def test_plan_create_plan_with_template_and_file(self):
plan = Plan.objects.exclude(pk=self.plan.id).first()
self.assertEqual(plan.title, "Plan")
self.assertEqual(plan.goal, plan_template.goal)
self.assertEqual(plan.description, plan_template.description)
self.assertEqual(plan.documents.count(), 1)
self.assertEqual(plan.actions.count(), 0)

Expand All @@ -335,6 +368,7 @@ def test_plan_create_plan_with_template_and_actions(self):
plan = Plan.objects.exclude(pk=self.plan.id).first()
self.assertEqual(plan.title, "Plan")
self.assertEqual(plan.goal, plan_template.goal)
self.assertEqual(plan.description, plan_template.description)
self.assertEqual(plan.documents.count(), 0)
self.assertEqual(plan.actions.count(), 1)

Expand Down
6 changes: 5 additions & 1 deletion src/open_inwoner/templates/export/plans/plan_export.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ <h1 class="h1">{% trans "Plan" %} {{ object.title }}</h1>
<th class="table__header">{% trans "Title" %}</th>
<td class="table__item">{{ object.title }}</td>
</tr>
<tr>
<tr>
<th class="table__header">{% trans "Goal" %}</th>
<td class="table__item">{{ object.goal }}</td>
</tr>
<tr>
<th class="table__header">{% trans "Description" %}</th>
<td class="table__item">{{ object.description }}</td>
</tr>
<tr>
<th class="table__header">{% trans "End date" %}</th>
<td class="table__item">{{ object.end_date }}</td>
Expand Down
4 changes: 3 additions & 1 deletion src/open_inwoner/templates/pages/plans/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ <h1 class="h1">{% trans "Samenwerken" %}</h1>
{% render_form id="plan-form" form=form method="POST" %}
{% csrf_token %}
{% input form.title %}
{% input form.goal %}
{% input form.description %}
{% render_grid %}
{% if request.user.get_active_contacts %}
{% checkboxes form.plan_contacts %}
Expand All @@ -22,7 +24,7 @@ <h1 class="h1">{% trans "Samenwerken" %}</h1>
<div class="plan-template">
<div class="plan-template__header">
<div>{% trans "Templates" %}</div>
<div>{% trans "Omschrijving" %}</div>
<div>{% trans "Doel" %}</div>
<div></div>
</div>
<label class="plan-template__row radio">
Expand Down
8 changes: 7 additions & 1 deletion src/open_inwoner/templates/pages/plans/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ <h1 class="h1" id="title">

<h2 class="h2" id="goals">{% trans "Doel" %}</h2>
<p class="p">{{ object.goal|linebreaksbr }}</p>
{% button href="plans:plan_edit_goal" uuid=object.uuid text=_("Doel bewerken") primary=True %}

{% if object.description %}
<h2 class="h2" id="description">{% trans "Description" %}</h2>
<p class="p">{{ object.description|linebreaksbr }}</p>
{% endif %}

{% button href="plans:plan_edit_goal" uuid=object.uuid text=_("Doel en omschrijving bewerken") primary=True %}

<h2 class="h2" id="files">{% trans "Bestanden" %}</h2>
{% if object.get_latest_file %}
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/templates/pages/plans/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ <h1 class="h1">{% trans "Samenwerken" %}</h1>
{% render_form id="plan-form" form=form method="POST" %}
{% csrf_token %}
{% input form.title %}
{% input form.goal %}
{% input form.description %}
{% render_grid %}
{% checkboxes form.plan_contacts %}
{% date_field form.end_date %}
Expand Down
9 changes: 7 additions & 2 deletions src/open_inwoner/templates/pages/plans/goal_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
{% load i18n button_tags card_tags map_tags form_tags %}

{% block content %}
<h1 class="h1">{% trans "Doel aanpassen" %}</h1>
<h1 class="h1">{% trans "Doel en omschrijving aanpassen" %}</h1>
<p class="p">
{{configurable_text.plans_page.plans_edit_message}}
</p>

{% form id="goal-edit" form_object=form method="POST" %}
{% render_form id="goal-edit" form=form method="POST" %}
{% csrf_token %}
{% input form.goal %}
{% input form.description %}
{% form_actions primary_text=_("Verzender") %}
{% endrender_form %}
{% endblock %}
1 change: 1 addition & 0 deletions src/open_inwoner/templates/pages/user-home.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h2 class="h2">
{% render_card image_object_fit="cover" %}
<h3 class="h3">{{ plan.title }}</h3>
<p class="p">{{ plan.goal|truncatewords:20 }}</p>
<p class="p">{{ plan.description|truncatewords:20 }}</p>
<a
class="button button--icon-before button--transparent button--secondary"
href="{{ plan.get_absolute_url }}"
Expand Down
Loading

0 comments on commit 0162e4b

Please sign in to comment.