Skip to content

Commit

Permalink
Fixing creation of partnership
Browse files Browse the repository at this point in the history
  • Loading branch information
Ederporto committed Mar 6, 2024
1 parent 28f2999 commit e66d188
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions report/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion report/templates/report/quantitative.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="w3-twothird formfield">
<textarea id="organizers" name="organizers_string" rows="4" placeholder="Username 1; Institution 1
Username 2; Institution 2">{% if report_form.instance.id %}{% for organizer in report_form.instance.organizers.all %}{{ organizer.name }}{% for institution in organizer.institution.all %};{{ institution.name }}{% endfor %}{% if not forloop.last %}&#13;&#10;{% endif %}{% endfor %}{% endif %}</textarea>
Username 2; Institution 2">{% if report_form.instance.id %}{% for organizer in report_form.instance.organizers.all %}{{ organizer.name }}{% if not forloop.last %}&#13;&#10;{% endif %}{% endfor %}{% endif %}</textarea>
</div>
</div>
<div class="w3-row">
Expand Down
3 changes: 2 additions & 1 deletion report/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit e66d188

Please sign in to comment.