Skip to content

Commit

Permalink
Merge pull request #664 from Gary-Community-Ventures/bug/bulk_import_…
Browse files Browse the repository at this point in the history
…navigator

Fix bulk import navigator
  • Loading branch information
CalebPena authored Dec 13, 2024
2 parents 13ac5c4 + f71e4cc commit 576af40
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions programs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["ProgramCategory"]) -> "ProgramCategory":
return Model.objects.new_program_category(external_name, "housing")
return Model.objects.new_program_category("_default", external_name, "housing")


class ProgramCategory(models.Model):
Expand Down Expand Up @@ -229,7 +229,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["Document"]) -> "Document":
return Model.objects.new_document(external_name)
return Model.objects.new_document("_default", external_name)


class Document(models.Model):
Expand Down Expand Up @@ -397,7 +397,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["Program"]) -> "Program":
return Model.objects.new_program(external_name)
return Model.objects.new_program("_default", external_name)


# This model describes all of the benefit programs available in the screener
Expand Down Expand Up @@ -615,11 +615,11 @@ def from_model_data(self, data: DataType):
for category in data["categories"]:
try:
cat_instance = UrgentNeedCategory.objects.get(name=category["name"])
cat_instance.white_label = white_label
cat_instance.save()
except UrgentNeedCategory.DoesNotExist:
cat_instance = UrgentNeedFunction.objects.create(name=category["name"])
cat_instance = UrgentNeedCategory.objects.create(name=category["name"], white_label=white_label)

cat_instance.white_label = white_label
cat_instance.save()
categories.append(cat_instance)
need.type_short.set(categories)

Expand All @@ -637,7 +637,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["UrgentNeed"]) -> "UrgentNeed":
return Model.objects.new_urgent_need(external_name, None)
return Model.objects.new_urgent_need("_default", external_name, None)


class UrgentNeed(models.Model):
Expand Down Expand Up @@ -704,7 +704,7 @@ class NavigatorManager(models.Manager):
)
no_auto_fields = ("assistance_link",)

def new_navigator(self, white_label: str, name: str, phone_number: str):
def new_navigator(self, white_label: str, name: str, phone_number: Optional[str] = None):
translations = {}
for field in self.translated_fields:
translations[field] = Translation.objects.add_translation(
Expand Down Expand Up @@ -779,11 +779,11 @@ def from_model_data(self, data: DataType):
for county in data["counties"]:
try:
county_instance = County.objects.get(name=county["name"])
county_instance.white_label = white_label
county_instance.save()
except County.DoesNotExist:
county_instance = County.objects.create(name=county["name"])
county_instance = County.objects.create(name=county["name"], white_label=white_label)

county_instance.white_label = white_label
county_instance.save()
counties.append(county_instance)
navigator.counties.set(counties)

Expand All @@ -808,7 +808,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["Navigator"]) -> "Navigator":
return Model.objects.new_navigator(external_name, None)
return Model.objects.new_navigator("_default", external_name, None)


class Navigator(models.Model):
Expand Down Expand Up @@ -909,8 +909,10 @@ def from_model_data(self, data: DataType):
for county in data["counties"]:
try:
county_instance = County.objects.get(name=county["name"])
county_instance.white_label = white_label
county_instance.save()
except County.DoesNotExist:
county_instance = County.objects.create(name=county["name"])
county_instance = County.objects.create(name=county["name"], white_label=white_label)
counties.append(county_instance)
warning.counties.set(counties)

Expand All @@ -925,7 +927,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["WarningMessage"]) -> "WarningMessage":
return Model.objects.new_warning("_show", external_name)
return Model.objects.new_warning("_default", "_show", external_name)


class WarningMessage(models.Model):
Expand Down Expand Up @@ -1055,8 +1057,10 @@ def from_model_data(self, data: DataType):
for county in data["counties"]:
try:
county_instance = County.objects.get(name=county["name"])
county_instance.white_label = white_label
county_instance.save()
except County.DoesNotExist:
county_instance = County.objects.create(name=county["name"])
county_instance = County.objects.create(name=county["name"], white_label=white_label)
counties.append(county_instance)
translation_override.counties.set(counties)

Expand All @@ -1067,7 +1071,7 @@ def from_model_data(self, data: DataType):

@classmethod
def create_instance(cls, external_name: str, Model: type["TranslationOverride"]) -> "TranslationOverride":
return Model.objects.new_translation_override("_show", "", external_name)
return Model.objects.new_translation_override("_default", "_show", "", external_name)


class TranslationOverride(models.Model):
Expand Down

0 comments on commit 576af40

Please sign in to comment.