Geometry race condition fix
* fixes race condition for geometry conflict and parcel calculation * harmonizes empty geometries from None/MultiPolygonEmpty to MultiPolygonEmpty
This commit is contained in:
		
							parent
							
								
									618cf3a756
								
							
						
					
					
						commit
						0b2cf2a0a4
					
				@ -129,12 +129,11 @@ class NewCompensationForm(AbstractCompensationForm,
 | 
				
			|||||||
        self.initialize_form_field("identifier", identifier)
 | 
					        self.initialize_form_field("identifier", identifier)
 | 
				
			||||||
        self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:new-id")
 | 
					        self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:new-id")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __create_comp(self, user, geom_form) -> Compensation:
 | 
					    def __create_comp(self, user):
 | 
				
			||||||
        """ Creates the compensation from form data
 | 
					        """ Creates the compensation from form data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Args:
 | 
					        Args:
 | 
				
			||||||
            user (User): The performing user
 | 
					            user (User): The performing user
 | 
				
			||||||
            geom_form (SimpleGeomForm): The geometry form
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Returns:
 | 
					        Returns:
 | 
				
			||||||
            comp (Compensation): The compensation object
 | 
					            comp (Compensation): The compensation object
 | 
				
			||||||
@ -150,8 +149,6 @@ class NewCompensationForm(AbstractCompensationForm,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # Create log entry
 | 
					        # Create log entry
 | 
				
			||||||
        action = UserActionLogEntry.get_created_action(user)
 | 
					        action = UserActionLogEntry.get_created_action(user)
 | 
				
			||||||
        # Process the geometry form
 | 
					 | 
				
			||||||
        geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Finally create main object
 | 
					        # Finally create main object
 | 
				
			||||||
        comp = Compensation.objects.create(
 | 
					        comp = Compensation.objects.create(
 | 
				
			||||||
@ -162,18 +159,23 @@ class NewCompensationForm(AbstractCompensationForm,
 | 
				
			|||||||
            is_cef=is_cef,
 | 
					            is_cef=is_cef,
 | 
				
			||||||
            is_coherence_keeping=is_coherence_keeping,
 | 
					            is_coherence_keeping=is_coherence_keeping,
 | 
				
			||||||
            is_pik=is_pik,
 | 
					            is_pik=is_pik,
 | 
				
			||||||
            geometry=geometry,
 | 
					 | 
				
			||||||
            comment=comment,
 | 
					            comment=comment,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Add the log entry to the main objects log list
 | 
					        # Add the log entry to the main objects log list
 | 
				
			||||||
        comp.log.add(action)
 | 
					        comp.log.add(action)
 | 
				
			||||||
        return comp
 | 
					        return comp, action
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def save(self, user: User, geom_form: SimpleGeomForm):
 | 
					    def save(self, user: User, geom_form: SimpleGeomForm):
 | 
				
			||||||
        with transaction.atomic():
 | 
					        with transaction.atomic():
 | 
				
			||||||
            comp = self.__create_comp(user, geom_form)
 | 
					            comp, action = self.__create_comp(user)
 | 
				
			||||||
            comp.intervention.mark_as_edited(user, edit_comment=COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
 | 
					            comp.intervention.mark_as_edited(user, edit_comment=COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        comp.geometry = geometry
 | 
				
			||||||
 | 
					        comp.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return comp
 | 
					        return comp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -205,6 +207,9 @@ class EditCompensationForm(NewCompensationForm):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def save(self, user: User, geom_form: SimpleGeomForm):
 | 
					    def save(self, user: User, geom_form: SimpleGeomForm):
 | 
				
			||||||
        with transaction.atomic():
 | 
					        with transaction.atomic():
 | 
				
			||||||
 | 
					            # Create log entry
 | 
				
			||||||
 | 
					            action = UserActionLogEntry.get_edited_action(user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Fetch data from cleaned POST values
 | 
					            # Fetch data from cleaned POST values
 | 
				
			||||||
            identifier = self.cleaned_data.get("identifier", None)
 | 
					            identifier = self.cleaned_data.get("identifier", None)
 | 
				
			||||||
            title = self.cleaned_data.get("title", None)
 | 
					            title = self.cleaned_data.get("title", None)
 | 
				
			||||||
@ -214,17 +219,9 @@ class EditCompensationForm(NewCompensationForm):
 | 
				
			|||||||
            is_pik = self.cleaned_data.get("is_pik", None)
 | 
					            is_pik = self.cleaned_data.get("is_pik", None)
 | 
				
			||||||
            comment = self.cleaned_data.get("comment", None)
 | 
					            comment = self.cleaned_data.get("comment", None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Create log entry
 | 
					 | 
				
			||||||
            action = UserActionLogEntry.get_edited_action(user)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            # Process the geometry form
 | 
					 | 
				
			||||||
            geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            # Finally create main object
 | 
					 | 
				
			||||||
            self.instance.identifier = identifier
 | 
					            self.instance.identifier = identifier
 | 
				
			||||||
            self.instance.title = title
 | 
					            self.instance.title = title
 | 
				
			||||||
            self.instance.intervention = intervention
 | 
					            self.instance.intervention = intervention
 | 
				
			||||||
            self.instance.geometry = geometry
 | 
					 | 
				
			||||||
            self.instance.is_cef = is_cef
 | 
					            self.instance.is_cef = is_cef
 | 
				
			||||||
            self.instance.is_coherence_keeping = is_coherence_keeping
 | 
					            self.instance.is_coherence_keeping = is_coherence_keeping
 | 
				
			||||||
            self.instance.comment = comment
 | 
					            self.instance.comment = comment
 | 
				
			||||||
@ -233,6 +230,11 @@ class EditCompensationForm(NewCompensationForm):
 | 
				
			|||||||
            self.instance.save()
 | 
					            self.instance.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.instance.log.add(action)
 | 
					            self.instance.log.add(action)
 | 
				
			||||||
 | 
					 | 
				
			||||||
            intervention.mark_as_edited(user, self.request, EDITED_GENERAL_DATA)
 | 
					            intervention.mark_as_edited(user, self.request, EDITED_GENERAL_DATA)
 | 
				
			||||||
        return self.instance
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        self.instance.geometry = geometry
 | 
				
			||||||
 | 
					        self.instance.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return self.instance
 | 
				
			||||||
 | 
				
			|||||||
@ -94,8 +94,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # Create log entry
 | 
					            # Create log entry
 | 
				
			||||||
            action = UserActionLogEntry.get_created_action(user)
 | 
					            action = UserActionLogEntry.get_created_action(user)
 | 
				
			||||||
            # Process the geometry form
 | 
					 | 
				
			||||||
            geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            handler = Handler.objects.create(
 | 
					            handler = Handler.objects.create(
 | 
				
			||||||
                type=handler_type,
 | 
					                type=handler_type,
 | 
				
			||||||
@ -119,7 +117,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
 | 
				
			|||||||
                responsible=responsible,
 | 
					                responsible=responsible,
 | 
				
			||||||
                deductable_surface=surface,
 | 
					                deductable_surface=surface,
 | 
				
			||||||
                created=action,
 | 
					                created=action,
 | 
				
			||||||
                geometry=geometry,
 | 
					 | 
				
			||||||
                comment=comment,
 | 
					                comment=comment,
 | 
				
			||||||
                is_pik=is_pik,
 | 
					                is_pik=is_pik,
 | 
				
			||||||
                legal=legal
 | 
					                legal=legal
 | 
				
			||||||
@ -129,6 +126,10 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
 | 
				
			|||||||
            # Add the log entry to the main objects log list
 | 
					            # Add the log entry to the main objects log list
 | 
				
			||||||
            acc.log.add(action)
 | 
					            acc.log.add(action)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        acc.geometry = geometry
 | 
				
			||||||
 | 
					        acc.save()
 | 
				
			||||||
        acc.update_deductable_rest()
 | 
					        acc.update_deductable_rest()
 | 
				
			||||||
        return acc
 | 
					        return acc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -185,9 +186,6 @@ class EditEcoAccountForm(NewEcoAccountForm):
 | 
				
			|||||||
            # Create log entry
 | 
					            # Create log entry
 | 
				
			||||||
            action = UserActionLogEntry.get_edited_action(user)
 | 
					            action = UserActionLogEntry.get_edited_action(user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Process the geometry form
 | 
					 | 
				
			||||||
            geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            # Update responsible data
 | 
					            # Update responsible data
 | 
				
			||||||
            self.instance.responsible.handler.type = handler_type
 | 
					            self.instance.responsible.handler.type = handler_type
 | 
				
			||||||
            self.instance.responsible.handler.detail = handler_detail
 | 
					            self.instance.responsible.handler.detail = handler_detail
 | 
				
			||||||
@ -204,7 +202,6 @@ class EditEcoAccountForm(NewEcoAccountForm):
 | 
				
			|||||||
            self.instance.identifier = identifier
 | 
					            self.instance.identifier = identifier
 | 
				
			||||||
            self.instance.title = title
 | 
					            self.instance.title = title
 | 
				
			||||||
            self.instance.deductable_surface = surface
 | 
					            self.instance.deductable_surface = surface
 | 
				
			||||||
            self.instance.geometry = geometry
 | 
					 | 
				
			||||||
            self.instance.comment = comment
 | 
					            self.instance.comment = comment
 | 
				
			||||||
            self.instance.is_pik = is_pik
 | 
					            self.instance.is_pik = is_pik
 | 
				
			||||||
            self.instance.modified = action
 | 
					            self.instance.modified = action
 | 
				
			||||||
@ -213,6 +210,10 @@ class EditEcoAccountForm(NewEcoAccountForm):
 | 
				
			|||||||
            # Add the log entry to the main objects log list
 | 
					            # Add the log entry to the main objects log list
 | 
				
			||||||
            self.instance.log.add(action)
 | 
					            self.instance.log.add(action)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        self.instance.geometry = geometry
 | 
				
			||||||
 | 
					        self.instance.save()
 | 
				
			||||||
        self.instance.update_deductable_rest()
 | 
					        self.instance.update_deductable_rest()
 | 
				
			||||||
        return self.instance
 | 
					        return self.instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								ema/forms.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								ema/forms.py
									
									
									
									
									
								
							@ -64,8 +64,6 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin, Pik
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # Create log entry
 | 
					            # Create log entry
 | 
				
			||||||
            action = UserActionLogEntry.get_created_action(user)
 | 
					            action = UserActionLogEntry.get_created_action(user)
 | 
				
			||||||
            # Process the geometry form
 | 
					 | 
				
			||||||
            geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            handler = Handler.objects.create(
 | 
					            handler = Handler.objects.create(
 | 
				
			||||||
                type=handler_type,
 | 
					                type=handler_type,
 | 
				
			||||||
@ -83,7 +81,6 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin, Pik
 | 
				
			|||||||
                title=title,
 | 
					                title=title,
 | 
				
			||||||
                responsible=responsible,
 | 
					                responsible=responsible,
 | 
				
			||||||
                created=action,
 | 
					                created=action,
 | 
				
			||||||
                geometry=geometry,
 | 
					 | 
				
			||||||
                comment=comment,
 | 
					                comment=comment,
 | 
				
			||||||
                is_pik=is_pik,
 | 
					                is_pik=is_pik,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
@ -93,6 +90,11 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin, Pik
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # Add the log entry to the main objects log list
 | 
					            # Add the log entry to the main objects log list
 | 
				
			||||||
            acc.log.add(action)
 | 
					            acc.log.add(action)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        acc.geometry = geometry
 | 
				
			||||||
 | 
					        acc.save()
 | 
				
			||||||
        return acc
 | 
					        return acc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -141,8 +143,6 @@ class EditEmaForm(NewEmaForm):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # Create log entry
 | 
					            # Create log entry
 | 
				
			||||||
            action = UserActionLogEntry.get_edited_action(user)
 | 
					            action = UserActionLogEntry.get_edited_action(user)
 | 
				
			||||||
            # Process the geometry form
 | 
					 | 
				
			||||||
            geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Update responsible data
 | 
					            # Update responsible data
 | 
				
			||||||
            self.instance.responsible.handler.type = handler_type
 | 
					            self.instance.responsible.handler.type = handler_type
 | 
				
			||||||
@ -155,7 +155,6 @@ class EditEmaForm(NewEmaForm):
 | 
				
			|||||||
            # Update main oject data
 | 
					            # Update main oject data
 | 
				
			||||||
            self.instance.identifier = identifier
 | 
					            self.instance.identifier = identifier
 | 
				
			||||||
            self.instance.title = title
 | 
					            self.instance.title = title
 | 
				
			||||||
            self.instance.geometry = geometry
 | 
					 | 
				
			||||||
            self.instance.comment = comment
 | 
					            self.instance.comment = comment
 | 
				
			||||||
            self.instance.is_pik = is_pik
 | 
					            self.instance.is_pik = is_pik
 | 
				
			||||||
            self.instance.modified = action
 | 
					            self.instance.modified = action
 | 
				
			||||||
@ -163,6 +162,11 @@ class EditEmaForm(NewEmaForm):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # Add the log entry to the main objects log list
 | 
					            # Add the log entry to the main objects log list
 | 
				
			||||||
            self.instance.log.add(action)
 | 
					            self.instance.log.add(action)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        self.instance.geometry = geometry
 | 
				
			||||||
 | 
					        self.instance.save()
 | 
				
			||||||
        return self.instance
 | 
					        return self.instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -263,9 +263,6 @@ class NewInterventionForm(BaseForm):
 | 
				
			|||||||
                handler=handler,
 | 
					                handler=handler,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Process the geometry form
 | 
					 | 
				
			||||||
            geometry = geom_form.save(action)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            # Finally create main object, holding the other objects
 | 
					            # Finally create main object, holding the other objects
 | 
				
			||||||
            intervention = Intervention.objects.create(
 | 
					            intervention = Intervention.objects.create(
 | 
				
			||||||
                identifier=identifier,
 | 
					                identifier=identifier,
 | 
				
			||||||
@ -273,7 +270,6 @@ class NewInterventionForm(BaseForm):
 | 
				
			|||||||
                responsible=responsibility_data,
 | 
					                responsible=responsibility_data,
 | 
				
			||||||
                legal=legal_data,
 | 
					                legal=legal_data,
 | 
				
			||||||
                created=action,
 | 
					                created=action,
 | 
				
			||||||
                geometry=geometry,
 | 
					 | 
				
			||||||
                comment=comment,
 | 
					                comment=comment,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -282,6 +278,12 @@ class NewInterventionForm(BaseForm):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # Add the performing user as the first user having access to the data
 | 
					            # Add the performing user as the first user having access to the data
 | 
				
			||||||
            intervention.share_with_user(user)
 | 
					            intervention.share_with_user(user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
 | 
				
			||||||
 | 
					        geometry = geom_form.save(action)
 | 
				
			||||||
 | 
					        intervention.geometry = geometry
 | 
				
			||||||
 | 
					        intervention.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return intervention
 | 
					        return intervention
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -370,9 +372,6 @@ class EditInterventionForm(NewInterventionForm):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            user_action = self.instance.mark_as_edited(user, edit_comment=EDITED_GENERAL_DATA)
 | 
					            user_action = self.instance.mark_as_edited(user, edit_comment=EDITED_GENERAL_DATA)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            geometry = geom_form.save(user_action)
 | 
					 | 
				
			||||||
            self.instance.geometry = geometry
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            self.instance.log.add(user_action)
 | 
					            self.instance.log.add(user_action)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.instance.identifier = identifier
 | 
					            self.instance.identifier = identifier
 | 
				
			||||||
@ -381,5 +380,10 @@ class EditInterventionForm(NewInterventionForm):
 | 
				
			|||||||
            self.instance.modified = user_action
 | 
					            self.instance.modified = user_action
 | 
				
			||||||
            self.instance.save()
 | 
					            self.instance.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
 | 
				
			||||||
 | 
					        geometry = geom_form.save(user_action)
 | 
				
			||||||
 | 
					        self.instance.geometry = geometry
 | 
				
			||||||
 | 
					        self.instance.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return self.instance
 | 
					        return self.instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -63,6 +63,7 @@ class SimpleGeomForm(BaseForm):
 | 
				
			|||||||
        geom = self.data["geom"]
 | 
					        geom = self.data["geom"]
 | 
				
			||||||
        if geom is None or len(geom) == 0:
 | 
					        if geom is None or len(geom) == 0:
 | 
				
			||||||
            # empty geometry is a valid geometry
 | 
					            # empty geometry is a valid geometry
 | 
				
			||||||
 | 
					            self.cleaned_data["geom"] = MultiPolygon(srid=DEFAULT_SRID_RLP).ewkt
 | 
				
			||||||
            return is_valid
 | 
					            return is_valid
 | 
				
			||||||
        geom = json.loads(geom)
 | 
					        geom = json.loads(geom)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -106,6 +107,8 @@ class SimpleGeomForm(BaseForm):
 | 
				
			|||||||
                return is_valid
 | 
					                return is_valid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            features.append(polygon)
 | 
					            features.append(polygon)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Unionize all geometry features into one new MultiPolygon
 | 
				
			||||||
        form_geom = MultiPolygon(srid=DEFAULT_SRID_RLP)
 | 
					        form_geom = MultiPolygon(srid=DEFAULT_SRID_RLP)
 | 
				
			||||||
        for feature in features:
 | 
					        for feature in features:
 | 
				
			||||||
            form_geom = form_geom.union(feature)
 | 
					            form_geom = form_geom.union(feature)
 | 
				
			||||||
 | 
				
			|||||||
@ -116,6 +116,11 @@ class Geometry(BaseResource):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        from konova.models import Parcel, District, ParcelIntersection, Municipal, ParcelGroup
 | 
					        from konova.models import Parcel, District, ParcelIntersection, Municipal, ParcelGroup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if self.geom.empty:
 | 
				
			||||||
 | 
					            # Nothing to do
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parcel_fetcher = ParcelWFSFetcher(
 | 
					        parcel_fetcher = ParcelWFSFetcher(
 | 
				
			||||||
            geometry_id=self.id,
 | 
					            geometry_id=self.id,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
				
			|||||||
@ -17,11 +17,17 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="card-body">
 | 
					        <div class="card-body">
 | 
				
			||||||
 | 
					            {% if geom_form.instance.geometry %}
 | 
				
			||||||
            <div hx-trigger="load, every 5s" hx-get="{% url 'geometry-parcels' geom_form.instance.geometry.id %}">
 | 
					            <div hx-trigger="load, every 5s" hx-get="{% url 'geometry-parcels' geom_form.instance.geometry.id %}">
 | 
				
			||||||
                <div class="row justify-content-center">
 | 
					                <div class="row justify-content-center">
 | 
				
			||||||
                    <span class="spinner-border rlp-r-inv" role="status"></span>
 | 
					                    <span class="spinner-border rlp-r-inv" role="status"></span>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
 | 
					            {% else %}
 | 
				
			||||||
 | 
					            <div class="alert alert-danger">
 | 
				
			||||||
 | 
					                {% translate 'No geometry entry found on database. Please contact an admin!' %}
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            {% endif %}
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
@ -32,16 +32,16 @@ def get_geom_parcels(request: HttpRequest, id: str):
 | 
				
			|||||||
    parcels = geom.get_underlying_parcels()
 | 
					    parcels = geom.get_underlying_parcels()
 | 
				
			||||||
    geos_geom = geom.geom
 | 
					    geos_geom = geom.geom
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    parcels_are_currently_calculated = geos_geom is not None and geos_geom.area > 0 and len(parcels) == 0
 | 
					    geometry_exists = not geos_geom.empty
 | 
				
			||||||
 | 
					    parcels_are_currently_calculated = geometry_exists and geos_geom.area > 0 and len(parcels) == 0
 | 
				
			||||||
    parcels_available = len(parcels) > 0
 | 
					    parcels_available = len(parcels) > 0
 | 
				
			||||||
    no_geometry_given = geos_geom is None
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if parcels_are_currently_calculated:
 | 
					    if parcels_are_currently_calculated:
 | 
				
			||||||
        # Parcels are being calculated right now. Change the status code, so polling stays active for fetching
 | 
					        # Parcels are being calculated right now. Change the status code, so polling stays active for fetching
 | 
				
			||||||
        # resutls after the calculation
 | 
					        # resutls after the calculation
 | 
				
			||||||
        status_code = 200
 | 
					        status_code = 200
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if parcels_available or no_geometry_given:
 | 
					    if parcels_available or not geometry_exists:
 | 
				
			||||||
        parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr")
 | 
					        parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr")
 | 
				
			||||||
        municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id")
 | 
					        municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id")
 | 
				
			||||||
        municipals = Municipal.objects.filter(id__in=municipals)
 | 
					        municipals = Municipal.objects.filter(id__in=municipals)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user