def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved if not self.location_id: self.location_id = uuid.uuid4().hex set_site_code_if_needed(self) sync_supply_point(self) super(SQLLocation, self).save(*args, **kwargs) publish_location_saved(self.domain, self.location_id)
def delete(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved to_delete = self.get_descendants(include_self=True) for loc in to_delete: loc._remove_users() sync_supply_point(loc, is_deletion=True) super(SQLLocation, self).delete(*args, **kwargs) publish_location_saved(self.domain, self.location_id, is_deletion=True)
def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved if not self.location_id: self.location_id = uuid.uuid4().hex with transaction.atomic(): set_site_code_if_needed(self) sync_supply_point(self) super(SQLLocation, self).save(*args, **kwargs) publish_location_saved(self.domain, self.location_id)
def delete(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved to_delete = self.get_descendants(include_self=True) # This deletion should ideally happen in a transaction. It's not # currently possible as supply point cases are stored either in a # separate database or in couch. Happy Debugging! for loc in to_delete: loc._remove_users() sync_supply_point(loc, is_deletion=True) super(SQLLocation, self).delete(*args, **kwargs) publish_location_saved(self.domain, self.location_id, is_deletion=True)
def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved if not self.location_id: self.location_id = uuid.uuid4().hex if six.PY2: self.location_id = self.location_id.decode('utf-8') with transaction.atomic(): set_site_code_if_needed(self) sync_supply_point(self) super(SQLLocation, self).save(*args, **kwargs) publish_location_saved(self.domain, self.location_id)
def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point self.supply_point_id = sync_supply_point(self) sync_to_couch = kwargs.pop('sync_to_couch', True) kwargs['sync_to_couch'] = False # call it here super(SQLLocation, self).save(*args, **kwargs) if sync_to_couch: self._migration_do_sync()
def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved self.supply_point_id = sync_supply_point(self) sync_to_couch = kwargs.pop('sync_to_couch', True) kwargs['sync_to_couch'] = False # call it here super(SQLLocation, self).save(*args, **kwargs) if sync_to_couch: self._migration_do_sync() publish_location_saved(self.domain, self.location_id)
def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point from .document_store import publish_location_saved set_site_code_if_needed(self) sync_to_couch = kwargs.pop('sync_to_couch', True) if sync_to_couch: couch_obj = self.sync_couch_location() self.supply_point_id = sync_supply_point(self) if not self.location_id: raise ValueError("Expected non-empty location_id") super(SQLLocation, self).save(*args, **kwargs) if sync_to_couch: couch_obj.save(sync_to_sql=False) publish_location_saved(self.domain, self.location_id)
def sync_supply_points(location_type): for location in SQLLocation.objects.filter(location_type=location_type): sync_supply_point(location) location.save()
def save(self, *args, **kwargs): from corehq.apps.commtrack.models import sync_supply_point self.supply_point_id = sync_supply_point(self) return super(SQLLocation, self).save(*args, **kwargs)