def save(self, instance=None, commit=True): if self.errors: raise ValueError('form does not validate') location = instance or self.location is_new = location.location_id is None location.name = self.cleaned_data['name'] location.site_code = self.cleaned_data['site_code'] location.location_type = self.cleaned_data['location_type_object'] location.metadata = self.custom_data.get_data_to_save() location.parent = self.cleaned_data['parent'] coords = self.cleaned_data['coordinates'] if coords: location.latitude = coords[0] location.longitude = coords[1] location.metadata.update(get_prefixed(self.data)) if commit: location.save() if not is_new: orig_parent_id = self.cleaned_data.get('orig_parent_id') reparented = orig_parent_id is not None location_edited.send(sender='loc_mgmt', sql_loc=location, moved=reparented, previous_parent=orig_parent_id) return location
def save(self, metadata): if self.errors: raise ValueError('form does not validate') location = self.location is_new = location.location_id is None location.name = self.cleaned_data['name'] location.site_code = self.cleaned_data['site_code'] location.location_type = self.cleaned_data['location_type_object'] location.metadata = metadata or {} location.parent = self.cleaned_data['parent'] coords = self.cleaned_data['coordinates'] if coords: location.latitude = coords[0] location.longitude = coords[1] location.metadata.update(get_prefixed(self.data, CUSTOM_DATA_FIELD_PREFIX)) location.save() if not is_new: self._sync_location_user() orig_parent_id = self.cleaned_data.get('orig_parent_id') reparented = orig_parent_id is not None location_edited.send(sender='loc_mgmt', sql_loc=location, moved=reparented, previous_parent=orig_parent_id) return location
def save(self, metadata): if self.errors: raise ValueError('form does not validate') location = self.location is_new = location.location_id is None location.name = self.cleaned_data['name'] location.site_code = self.cleaned_data['site_code'] location.location_type = self.cleaned_data['location_type_object'] location.metadata = metadata or {} location.parent = self.cleaned_data['parent'] coords = self.cleaned_data['coordinates'] if coords: location.latitude = coords[0] location.longitude = coords[1] location.metadata.update(get_prefixed(self.data, CUSTOM_DATA_FIELD_PREFIX)) location.save() if not is_new: self._sync_location_user() orig_parent_id = self.cleaned_data.get('orig_parent_id') reparented = orig_parent_id is not None location_edited.send(sender='loc_mgmt', sql_loc=location, moved=reparented, previous_parent=orig_parent_id) return location
def save(self, instance=None, commit=True): if self.errors: raise ValueError('form does not validate') location = instance or self.location is_new = location.location_id is None location.name = self.cleaned_data['name'] location.site_code = self.cleaned_data['site_code'] location.location_type = self.cleaned_data['location_type_object'] location.metadata = self.custom_data.get_data_to_save() location.parent = self.cleaned_data['parent'] coords = self.cleaned_data['coordinates'] if coords: location.latitude = coords[0] location.longitude = coords[1] location.metadata.update(get_prefixed(self.data)) if commit: location.save() if not is_new: orig_parent_id = self.cleaned_data.get('orig_parent_id') reparented = orig_parent_id is not None location_edited.send(sender='loc_mgmt', sql_loc=location, moved=reparented, previous_parent=orig_parent_id) return location
def no_changes_needed(self, existing, form_data, consumption): if not existing: return False for prop in ['name', 'coordinates', 'site_code', 'external_id']: if getattr(existing, prop, None) != form_data.get(prop): return False if (form_data.get('location_type') != existing.location_type_name or form_data.get('parent_id') != existing.parent_location_id): return False if get_prefixed(form_data) != existing.metadata: return False for product_code, val in consumption: product = self.get_product(product_code) if get_default_consumption(self.domain, product._id, existing.location_type_name, existing.location_id) != val: return False return True