def delete(id): entity = Facility.get(id) if (entity is None): raise ValueError("Facility does not exists") else: entity.active = False Facility.save(entity)
def _create_or_update_facility(self,submission,distance_threshold=1): """ Gets nearby submissions to determine duplicate by comparing name and submitter If the submitted facility already exists, it is updated; if not, it is created """ # # get facility/submissions within the set distance (in km) # distance_filter = (submission.location,D(km=distance_threshold)) # for facility in Facility.objects.filter(location__dwithin=distance_filter): # if not facility.name or facility.name == submission.name: # TODO: use proper string comparison function # for field in 'name address type'.split(): # new_value = getattr(submission,field,None) # existing_value = getattr(facility,field,None) # if new_value and not existing_value: # # currently keeps existing value # # TODO: if a value already exists, select the value with the highest submitter rating # setattr(facility,field,getattr(submission,field,None)) # nearby_submissions = Submission.objects.filter(location__dwithin=distance_filter) # facility.location = nearby_submissions.collect().centroid() # facility.save() # return facility logging.info('The submission is new') facility_args = {} for field in 'name address type location'.split(): facility_args[field] = getattr(submission,field) facility = Facility(**facility_args) facility.save() return facility
def save(entity): if entity.key is None: entity = Facility.save(entity) else: current = Facility.get(entity.key.urlsafe()) if current is not None: current.facility_name = entity.facility_name current.facility_address = entity.facility_address current.facility_zipcode = entity.facility_zipcode current.facility_state = entity.facility_state current.facility_city = entity.facility_city current.contact_name = entity.contact_name current.contact_email = entity.contact_email current.contact_phone = entity.contact_phone current.hours_of_operation = entity.hours_of_operation current.active = entity.active current.latitude = entity.latitude current.longitude = entity.longitude entity = Facility.save(entity) else: raise ValueError("Facility does not exists") return entity