Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add or create labels during upload #4901

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions seed/data_importer/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from celery import shared_task
from celery.utils.log import get_task_logger
from django.apps import apps
from django.contrib.postgres.aggregates.general import ArrayAgg
from django.db import IntegrityError, transaction
from django.db.models import Subquery
Expand All @@ -31,6 +32,8 @@
PropertyAuditLog,
PropertyState,
PropertyView,
PropertyViewLabel,
StatusLabel,
TaxLotAuditLog,
TaxLotState,
TaxLotView,
Expand Down Expand Up @@ -793,6 +796,17 @@ def link_states(states, ViewClass, cycle, highest_ali, sub_progress_key, tuple_v
state.raw_access_level_instance = ali
view = state.promote(cycle=cycle)

# assign incoming labels to view
if view and state.incoming_labels:
incoming_label_names = state.incoming_labels.split(",")
for incoming_label_name in incoming_label_names:
incoming_label, _ = StatusLabel.objects.get_or_create(name=incoming_label_name, super_organization=cycle.organization)
if isinstance(view, PropertyView):
PropertyViewLabel.objects.get_or_create(statuslabel=incoming_label, propertyview=view)
elif isinstance(view, TaxLotView):
TaxLotViewLabel = apps.get_model("seed", "TaxLotView_labels")
TaxLotViewLabel.objects.get_or_create(statuslabel=incoming_label, taxlotview=view)

# link state
link_count = _link_matches([*existing_views_matches, view], cycle.organization_id, view, ViewClass)
if link_count == 0:
Expand Down
6 changes: 5 additions & 1 deletion seed/data_importer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def map_row_chunk(ids, file_pk, source_type, prog_key, **kwargs):
if footprint_details.get("obj_field") and getattr(map_model_obj, footprint_details["obj_field"]) is None:
_store_raw_footprint_and_create_rule(footprint_details, table, org, import_file, original_row, map_model_obj)

# There was an error with a field being too long [> 255 chars].
# Store the incoming label names in state.incoming_labels. -ViewLabels will be created once a view is attatched
label_key = "Property Labels" if isinstance(map_model_obj, PropertyState) else "Tax Lot Labels"
if incoming_labels := map_model_obj.extra_data.pop(label_key, None):
map_model_obj.incoming_labels = incoming_labels

map_model_obj.save()

# if importing BuildingSync create a BuildingFile for the property
Expand Down
22 changes: 22 additions & 0 deletions seed/migrations/0235_state_incoming_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.25 on 2024-12-12 18:14

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("seed", "0234_transaction_goals"),
]

operations = [
migrations.AddField(
model_name="propertystate",
name="incoming_labels",
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name="taxlotstate",
name="incoming_labels",
field=models.TextField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions seed/models/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Column(models.Model):
"geocoding_confidence",
"id",
"import_file",
"incoming_labels",
"long_lat",
"merge_state",
"raw_access_level_instance_error",
Expand Down
1 change: 1 addition & 0 deletions seed/models/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class PropertyState(models.Model):
merge_state = models.IntegerField(choices=MERGE_STATE, default=MERGE_STATE_UNKNOWN, null=True)
raw_access_level_instance = models.ForeignKey(AccessLevelInstance, null=True, on_delete=models.SET_NULL)
raw_access_level_instance_error = models.TextField(null=True)
incoming_labels = models.TextField(null=True, blank=True)

jurisdiction_property_id = models.TextField(null=True, blank=True, db_collation="natural_sort")

Expand Down
1 change: 1 addition & 0 deletions seed/models/tax_lots.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TaxLotState(models.Model):
merge_state = models.IntegerField(choices=MERGE_STATE, default=MERGE_STATE_UNKNOWN, null=True)
raw_access_level_instance = models.ForeignKey(AccessLevelInstance, null=True, on_delete=models.SET_NULL)
raw_access_level_instance_error = models.TextField(null=True)
incoming_labels = models.TextField(null=True, blank=True)

custom_id_1 = models.CharField(max_length=255, null=True, blank=True, db_collation="natural_sort")

Expand Down
1 change: 1 addition & 0 deletions seed/serializers/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class PropertyStatePromoteWritableSerializer(serializers.ModelSerializer):
import_file_id = serializers.IntegerField(allow_null=True, read_only=True)
organization_id = serializers.IntegerField()
raw_access_level_instance_id = serializers.IntegerField()
incoming_labels = serializers.IntegerField(read_only=True)

# read-only core fields
id = serializers.IntegerField(read_only=True)
Expand Down
1 change: 0 additions & 1 deletion seed/views/v3/import_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ def map(self, request, pk=None):
if not import_file.exists():
return {"status": "error", "message": f"ImportFile {pk} does not exist"}

# return remap_data(import_file_id)
return JsonResponse(map_data(pk, remap, mark_as_done))

@swagger_auto_schema_org_query_param
Expand Down