Skip to content

Commit

Permalink
Fix errors and unwanted behavior caused by universal fields (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezkat committed May 6, 2024
1 parent c251aea commit 02cf809
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 0 additions & 3 deletions resources/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,6 @@ class Meta:
def options(self):
return ResourceUniversalFormOption.objects.filter(resource_universal_field=self)

def save(self, *args, **kwargs):
return super(ResourceUniversalField, self).save(*args, **kwargs)

def __str__(self):
return "%s / %s / %s" % (self.name, self.field_type, self.resource)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
margin-top: 20px;
}
</style>
<div id="equipment3">
<div id="universal-field-options">
<div class="form-section-header">
<h2>{% trans "Universal form options" %}</h2>
<span class="pull-right">{% trans "*Mandatory fields" %}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
margin-top: 20px;
}
</style>
<div id="equipment2">
<div id="universal-field">
<div class="form-section-header">
<h2>{% trans "Universal form field" %}</h2>
<span class="pull-right">{% trans "*Mandatory fields" %}</span>
Expand Down
8 changes: 7 additions & 1 deletion respa_admin/views/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,13 @@ def _save_resource_images(self, resource_image_formset):
resource_image.save()

def _save_resource_universal(self, resource_universal_formset):
resource_universal_formset.save()
if not any([bool(value) for value in resource_universal_formset.cleaned_data or []]):
return

for idx in range(len(resource_universal_formset)):
universal_field = resource_universal_formset.forms[idx].save(commit=False)
universal_field.resource = self.object
universal_field.save()

def _save_universal_options(self, resource_options_formset):
resource_options_formset.save()
Expand Down

0 comments on commit 02cf809

Please sign in to comment.