diff --git a/report/forms.py b/report/forms.py index 614aeb2..33c2826 100644 --- a/report/forms.py +++ b/report/forms.py @@ -80,6 +80,20 @@ def clean_organizers(self): organizers.append(organizer_object) return organizers + def clean_partners_activated(self): + organizers_string = self.data.get("organizers_string", "") + organizers_list = organizers_string.split("\r\n") if organizers_string else [] + + partners = self.data.getlist("partners_activated", []) if "partners_activated" in self.data else [] + for organizer in organizers_list: + organizer_name, institution_name = (organizer + ";").split(";", maxsplit=1) + if institution_name: + for partner_name in institution_name.split(";"): + if partner_name: + partner, partner_created = Partner.objects.get_or_create(name=partner_name.strip()) + partners.append(partner.id) + return partners + def clean_initial_date(self): initial_date = self.cleaned_data.get('initial_date') return initial_date diff --git a/report/templates/report/quantitative.html b/report/templates/report/quantitative.html index 6a2d022..4a9a096 100644 --- a/report/templates/report/quantitative.html +++ b/report/templates/report/quantitative.html @@ -42,7 +42,7 @@
+Username 2; Institution 2">{% if report_form.instance.id %}{% for organizer in report_form.instance.organizers.all %}{{ organizer.name }}{% if not forloop.last %} {% endif %}{% endfor %}{% endif %}
diff --git a/report/tests_views.py b/report/tests_views.py index 6ca6d4a..08d2965 100644 --- a/report/tests_views.py +++ b/report/tests_views.py @@ -154,7 +154,8 @@ def test_add_report_view_post(self): "activity_associated": activity_associated.id, "area_responsible": area_reponsible.id, "links": "Links", - "metrics_related": [metric.id] + "metrics_related": [metric.id], + "organizers_string": "Organizer 1;Institution 1;Institution 2" } form = NewReportForm(data, user=self.user) self.assertTrue(form.is_valid())