From c3aebadb34c29ecdae477ef3ba09a85e6a8e2e35 Mon Sep 17 00:00:00 2001 From: idabblewith <109533655+idabblewith@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:05:04 +0800 Subject: [PATCH] fix: Update Business Area Model --- ...nessarea_old_id_alter_businessarea_slug.py | 23 +++++++++++++++++++ agencies/models.py | 4 +++- agencies/serializers.py | 5 +++- agencies/views.py | 22 ++++++++++-------- spms_migrator/Loader.py | 2 +- 5 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 agencies/migrations/0003_alter_businessarea_old_id_alter_businessarea_slug.py diff --git a/agencies/migrations/0003_alter_businessarea_old_id_alter_businessarea_slug.py b/agencies/migrations/0003_alter_businessarea_old_id_alter_businessarea_slug.py new file mode 100644 index 00000000..f2e43e59 --- /dev/null +++ b/agencies/migrations/0003_alter_businessarea_old_id_alter_businessarea_slug.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.1 on 2024-02-05 02:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('agencies', '0002_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='businessarea', + name='old_id', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name='businessarea', + name='slug', + field=models.SlugField(blank=True, help_text="A URL-sage acronym of the BA's name without whitespace", null=True), + ), + ] diff --git a/agencies/models.py b/agencies/models.py index 7ba5e586..425b1abd 100644 --- a/agencies/models.py +++ b/agencies/models.py @@ -81,6 +81,8 @@ class BusinessArea(CommonModel): # Renamed from program ) name = models.CharField(max_length=140) slug = models.SlugField( + blank=True, + null=True, help_text="A URL-sage acronym of the BA's name without whitespace", ) @@ -130,7 +132,7 @@ class BusinessArea(CommonModel): # Renamed from program blank=True, ) - old_id = models.IntegerField() + old_id = models.IntegerField(blank=True, null=True) # NOTE SPECIES AND COMMUNITIES 1230 words (this was originally 250 words - expand further when doing lexical) focus = models.CharField( diff --git a/agencies/serializers.py b/agencies/serializers.py index 0c27c566..bca6f623 100644 --- a/agencies/serializers.py +++ b/agencies/serializers.py @@ -112,7 +112,10 @@ def get_image(self, obj): # Get the image URL (choose old_file or file based on your requirement) pk = business_area_photo.pk # old_file = business_area_photo.old_file - file = business_area_photo.file.url + if business_area_photo.file: + file = business_area_photo.file.url + else: file = None + print({business_area_photo, file}) return { "pk": pk, # "old_file": old_file, diff --git a/agencies/views.py b/agencies/views.py index 9353af8f..44a4650b 100644 --- a/agencies/views.py +++ b/agencies/views.py @@ -239,10 +239,10 @@ def post(self, req): return Response(error_message, status=HTTP_400_BAD_REQUEST) ba_data = { - "old_id": req.data.get("old_id"), - "name": req.data.get("name"), - "slug": req.data.get("slug"), + # "old_id": req.data.get("old_id"), + # "slug": req.data.get("slug"), "agency": req.data.get("agency"), + "name": req.data.get("name"), "focus": req.data.get("focus"), "introduction": req.data.get("introduction"), "data_custodian": req.data.get("data_custodian"), @@ -260,12 +260,12 @@ def post(self, req): # Then create the related image based on the ba try: image_data = { - "file": self.handle_ba_image(image), + "file": self.handle_ba_image(image) if image else None, "uploader": req.user, "business_area": new_business_area, } except ValueError as e: - settings.LOGGER.error(msg=f"{e}") + settings.LOGGER.error(msg=f"Error on handling BA image: {e}") error_message = str(e) response_data = {"error": error_message} return Response(response_data, status=HTTP_400_BAD_REQUEST) @@ -273,11 +273,13 @@ def post(self, req): # Create the image with prepped data try: new_bap_instance = BusinessAreaPhoto.objects.create(**image_data) - bap_response = TinyBusinessAreaPhotoSerializer( - new_bap_instance - ).data + print(image_data) + # bap_response = TinyBusinessAreaPhotoSerializer( + # new_bap_instance + # ).data except Exception as e: - settings.LOGGER.error(msg=f"{e}") + settings.LOGGER.error(msg=f"Error on creating new BA Photo instance: {e}") + new_business_area.delete() response_data = {"error": str(e)} return Response( response_data, status=HTTP_500_INTERNAL_SERVER_ERROR @@ -288,7 +290,7 @@ def post(self, req): status=HTTP_201_CREATED, ) else: - settings.LOGGER.error(msg=f"{ser.errors}") + settings.LOGGER.error(msg=f"BA Serializer invalid: {ser.errors}") return Response( ser.errors, status=HTTP_400_BAD_REQUEST, diff --git a/spms_migrator/Loader.py b/spms_migrator/Loader.py index dc9bcae4..c4c3d99f 100644 --- a/spms_migrator/Loader.py +++ b/spms_migrator/Loader.py @@ -7371,7 +7371,7 @@ def spms_project_closure_setter( ) # Get project to check status - + proj_status = self.spms_get_new_project_status(connection=connection, new_proj_id=new_proj_id) # status = proj_closure["status"] kind = "projectclosure"