diff --git a/edivorce/apps/core/models.py b/edivorce/apps/core/models.py index 7a643d89..a55430dc 100644 --- a/edivorce/apps/core/models.py +++ b/edivorce/apps/core/models.py @@ -213,7 +213,11 @@ class Document(models.Model): content_type = content_types.get(extension) if not content_type: return "application/unknown" - return content_type + return content_type + + @property + def is_pdf(self): + return self.filename.split('.')[-1].lower() == 'pdf' class DontLog: diff --git a/edivorce/apps/core/serializer.py b/edivorce/apps/core/serializer.py index 019e3542..4662d6a2 100644 --- a/edivorce/apps/core/serializer.py +++ b/edivorce/apps/core/serializer.py @@ -42,13 +42,20 @@ class CreateDocumentSerializer(serializers.ModelSerializer): filename = validated_data['file'].name size = validated_data['file'].size user = self.context['request'].user - order = Document.objects.filter(bceid_user=user, doc_type=validated_data['doc_type'], party_code=validated_data['party_code']).count() + 1 - response = Document(bceid_user=user, filename=filename, size=size, sort_order=order, **validated_data) + existing_docs = Document.objects.filter(bceid_user=user, doc_type=validated_data['doc_type'], party_code=validated_data['party_code']) + for other_doc in existing_docs: + if other_doc.is_pdf: + raise ValidationError("PDF documents cannot be combined with images. Only a single PDF or multiple images can be uploaded into one form.") + + sort_order = existing_docs.count() + 1 + document = Document(bceid_user=user, filename=filename, size=size, sort_order=sort_order, **validated_data) + if document.is_pdf and existing_docs.count() > 0: + raise ValidationError("Only one PDF is allowed per form, and PDF documents cannot be combined with images.") try: - response.save() + document.save() except IntegrityError: raise ValidationError("This file appears to have already been uploaded for this document. Duplicate filename: " + filename) - return response + return document class DocumentMetadataSerializer(serializers.ModelSerializer): diff --git a/edivorce/apps/core/templates/overview.html b/edivorce/apps/core/templates/overview.html index a1c96995..294e9b2a 100644 --- a/edivorce/apps/core/templates/overview.html +++ b/edivorce/apps/core/templates/overview.html @@ -41,7 +41,7 @@ Step 5
Your separation
{% include "partials/progress_icon.html" with step_status_string=step_status.your_separation with_status=True %} - {% if children_of_marriage == 'YES' or derived.has_children_of_marriage %} + {% if derived.has_children_of_marriage %} Step {% step_order step="children" %}
Your children
@@ -49,7 +49,7 @@
{% endif %} - {% if 'Spousal support' in which_orders.0.value|load_json %} + {% if derived.wants_spousal_support %} Step {% step_order step="support" %}
Spousal support
@@ -57,7 +57,7 @@
{% endif %} - {% if 'Division of property and debts' in which_orders.0.value|load_json %} + {% if derived.wants_property_division %} Step {% step_order step="property" %}
Property and debt
@@ -65,7 +65,7 @@
{% endif %} - {% if 'Other orders' in which_orders.0.value|load_json %} + {% if derived.wants_other_orders %} Step {% step_order step="other_orders" %}
Other orders
diff --git a/edivorce/apps/core/templates/partials/progress.html b/edivorce/apps/core/templates/partials/progress.html index b1c38b91..510c34b6 100644 --- a/edivorce/apps/core/templates/partials/progress.html +++ b/edivorce/apps/core/templates/partials/progress.html @@ -34,7 +34,7 @@ {% include "partials/progress_icon.html" with step_status_string=step_status.your_separation%}
- {% if children_of_marriage == 'YES' or derived.has_children_of_marriage %} + {% if derived.has_children_of_marriage %}