Skip to content

Commit

Permalink
adjusting creation and update of organizers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ederporto committed Mar 5, 2024
1 parent 82a3efb commit 28f2999
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion report/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


class NewReportForm(forms.ModelForm):
is_update = False

class Meta:
model = Report
fields = "__all__"
Expand Down Expand Up @@ -66,7 +68,7 @@ def clean_organizers(self):
for organizer in organizers_list:
organizer_name, institution_name = (organizer + ";").split(";", maxsplit=1)
organizer_object, created = Organizer.objects.get_or_create(name=organizer_name.strip())
if not created:
if not created and not self.is_update:
organizer_object.retained = True
organizer_object.save()
if institution_name:
Expand Down
4 changes: 2 additions & 2 deletions report/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def add_report(request):
if request.method == "POST":
operation_metrics = operation_formset(request.POST, prefix='Operation')
if report_form.is_valid() and operation_metrics.is_valid():
report = report_form.save(user=request.user)
report = report_form.save(user=request.user, is_update=False)
instances = operation_metrics.save(commit=False)

operation_metrics_related = []
Expand Down Expand Up @@ -643,7 +643,7 @@ def update_report(request, report_id):
report_form = NewReportForm(request.POST or None, instance=obj, user=request.user)
operation_metrics = OperationUpdateFormSet(request.POST, instance=obj, prefix='Operation')
if report_form.is_valid() and operation_metrics.is_valid():
report_instance = report_form.save(commit=False)
report_instance = report_form.save(commit=False, is_update=True)

# Metrics
instances = operation_metrics.save()
Expand Down

0 comments on commit 28f2999

Please sign in to comment.