Skip to content

Commit

Permalink
fix: Update Business Area Model
Browse files Browse the repository at this point in the history
  • Loading branch information
idabblewith committed Feb 5, 2024
1 parent 66bab92 commit c3aebad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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),
),
]
4 changes: 3 additions & 1 deletion agencies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion agencies/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions agencies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -260,24 +260,26 @@ 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)

# 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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spms_migrator/Loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c3aebad

Please sign in to comment.