def make_results(self, loc, query, context): results = [] for service in loc.services: if self.matches_service(query, service): result = SearchResult( context, name=loc.name, address=loc.address, location=LatLong.from_geo(loc.geo), website=loc.websites and loc.websites[0] or None) result.id = loc.key.id() result.phone = loc.phone result.accessible = loc.accessible result.service_id = service.service_id result.service_type = service.service_type result.service_detail = service.service_detail result.service_times = service.times result.service_days = defaultdict(list) for time in result.service_times: if time.start: result.service_days[time.day].append(time) for times in result.service_days.viewvalues(): times.sort(key=lambda time: time.start) result.service_notes = service.extra_notes result.last_modified = loc.last_modified results.append(result) return results
def get_geo(self, request): if 'geo_name' in request.params: return LatLong.from_str(request.get('geo')) else: return self.default_geo
def populate(self, loc, for_put=False): loc.populate( name=self.request.get("name"), address=self.request.get("address"), geo=LatLong.to_geo(LatLong.from_str(self.request.get("location"))), websites=[self.request.get("website")], accessible="accessible" in self.request.arguments(), ) if "phone_number" in self.request.params: subset = param_subset(self.request.params, "phone_", "_0") start, end = parse_time_range(subset) loc.phone = models.ServicePhone( number=self.request.get("phone_number"), days=[d for d in range(7) if "phone_day_%s" % d in self.request.params], start=start, end=end, ) service_index = None selected_service = None if "switch_service" in self.request.params: service_index = int(self.request.get("switch_service")) elif "service_index" in self.request.params: service_index = int(self.request.get("service_index")) num_services = min(100, int(self.request.get("num_services"))) removed_services = [int(s) for s in self.request.get("removed_services").split()] for sindex in range(num_services): service_subset = param_subset(self.request.params, "s_%s_" % sindex) service = None if service_subset.get("service_id"): service = loc.service(int(service_subset.get("service_id"))) if service is None: if for_put: service = loc.add_service() else: service = Service() loc.services.append(service) if for_put and sindex in removed_services: loc.services.remove(service) continue if service_index == sindex: selected_service = service service_type = service_subset.get("service_type") service.populate( service_type=(service_type and ServiceType.for_name(service_type) or None), service_detail=service_subset.get("service_detail"), requires_ticket="requires_ticket" in service_subset, requires_local_addr="requires_local_addr" in service_subset, requires_church_attend="requires_church_attend" in service_subset, extra_notes=service_subset.get("extra_notes"), ) service.times = [] num_times = min(100, int(service_subset.get("num_times"))) for i in range(num_times): subset = param_subset(service_subset, suffix="_%s" % i) if "day" in subset: start, end = parse_time_range(subset) service.times.append( models.ServiceTime(day=DAY_NAMES.index(subset.get("day")), start=start, end=end) ) service.not_dates = [] num_not_dates = min(100, int(service_subset.get("num_not_dates"))) for i in range(num_not_dates): subset = param_subset(service_subset, "not_date_%s_" % i) not_date = models.ServiceNotDate() service.not_dates.append(not_date) if subset.get("month"): not_date.month = int(subset.get("month")) if subset.get("day"): not_date.day = int(subset.get("day")) return selected_service