def _get_localities_from_dao(city_name): playgroundDao = DaoFactory.create_ro_playgroundDao() eventDao = DaoFactory.create_ro_eventDao() trainingcentreDao = DaoFactory.create_ro_trainingCentreDao() localities = set() active_playgrounds = playgroundDao.get_active(city_name, no_records=-1) for pg in active_playgrounds: localities.add(str(pg.address.locality)) active_tc = trainingcentreDao.get_active(city_name, no_records=-1) for tc in active_tc: localities.add(str(tc.address.locality)) active_events = eventDao.get_active(city_name, no_records=-1) for event in active_events: localities.add(str(event.address.locality)) return sorted(list(localities))
class TrainingCentreDetailsHandler(BaseHandler): trainingcentreDao = DaoFactory.create_ro_trainingCentreDao() mediaDao = DaoFactory.create_ro_mediaDao() def get(self, city_name, locality_name, entity_id, entity_alias): logger.debug('Training Centre details for city %s, locality %s, id %s, alias %s ' % (city_name, locality_name, entity_id, entity_alias)) if self.request.query_string != '': query_string = '?' + self.request.query_string else: query_string = '' continue_url = self.request.path_url + query_string if entity_id is None: message = ('Invalid Training Centre ID.') self.add_message(message, 'warning') self.redirect_to('home') else: tc = self.trainingcentreDao.get_record(entity_id) if tc is None: message = ('Training Centre could not be retrieved.') self.add_message(message, 'warning') return else: params = {} params['tc'] = tc params['types'] = constants.TRAINING_CENTRE params['sport'] = tc.sport params['city_name'] = tc.address.city params['locality_name'] = tc.address.locality params['media'] = self.mediaDao.get_active_media(tc.key, tc.sport, constants.TRAINING_CENTRE) params['continue_url'] = continue_url params['upload_cover_url'] = blobstore.create_upload_url(self.uri_for('upload-trainingcentre-cover', **{'continue': continue_url})) params['enquire_url'] = self.uri_for('enquire-trainingcentre', **{'continue': continue_url}) params['title'] = tc.name all_media = self.mediaDao.get_all_media(tc.key, constants.TRAINING_CENTRE) current_media = [] for photo in all_media: current_media.append({'name': photo.name, 'url':images.get_serving_url(photo.link), 'status': photo.status, 'primary': photo.primary}) params['current_media'] = current_media if tc.cover: params['tc_cover'] = images.get_serving_url(tc.cover) return self.render_template('/app/tc_details1.html', **params)
class CityHomeHandler(BaseHandler): mediaDao = DaoFactory.create_ro_mediaDao() eventDao = DaoFactory.create_ro_eventDao() playgroundDao = DaoFactory.create_ro_playgroundDao() trainingcentreDao = DaoFactory.create_ro_trainingCentreDao() def get(self, city_name=None, sport=None): params = {} logger.debug('home for city %s, and sport %s ' % (city_name, sport)) # if city_name is None: # city_name = get_default_city() # if sport is not None and sport != 'None' and sport != '': # return self.render_template('/cms/dashboard.html') recent_playgrounds = self.playgroundDao.get_recent(city_name, sport) featured_playgrounds = self.playgroundDao.get_featured(city_name, sport) popular_playgrounds = self.playgroundDao.get_popular(city_name, sport) logger.debug(' recent_playgrounds %s ' % len(recent_playgrounds)) logger.debug(' featured_playgrounds %s ' % len(featured_playgrounds)) logger.debug(' popular_playgrounds %s ' % len(popular_playgrounds)) playgrounds = recent_playgrounds + featured_playgrounds + popular_playgrounds playground_media = self.mediaDao.get_primary_media(playgrounds, constants.PLAYGROUND) logger.debug(' playground_media %s ' % len(playground_media)) recent_trainingcentres = self.trainingcentreDao.get_recent(city_name, sport) featured_trainingcentres = self.trainingcentreDao.get_featured(city_name, sport) popular_trainingcentres = self.trainingcentreDao.get_popular(city_name, sport) logger.debug(' recent_trainingcentres %s ' % len(recent_trainingcentres)) logger.debug(' featured_trainingcentres %s ' % len(featured_trainingcentres)) logger.debug(' popular_trainingcentres %s ' % len(popular_trainingcentres)) trainingcentres = recent_trainingcentres + featured_trainingcentres + popular_trainingcentres trainingcentre_media = self.mediaDao.get_primary_media(trainingcentres, constants.TRAINING_CENTRE) logger.debug(' trainingcentre_media %s ' % len(trainingcentre_media)) recent_events = self.eventDao.get_recent(city_name, sport) featured_events = self.eventDao.get_featured(city_name, sport) ongoing_events = self.eventDao.get_ongoing(city_name, sport) upcoming_events = self.eventDao.get_upcoming(city_name, sport) logger.debug(' recent_events %s ' % len(recent_events)) logger.debug(' featured_events %s ' % len(featured_events)) logger.debug(' ongoing_events %s ' % len(ongoing_events)) logger.debug(' upcoming_events %s ' % len(upcoming_events)) events = recent_events + featured_events + ongoing_events + upcoming_events event_media = self.mediaDao.get_primary_media(events, constants.EVENT) logger.debug(' event_media %s ' % len(event_media)) params['recent_playgrounds'] = recent_playgrounds params['featured_playgrounds'] = featured_playgrounds params['popular_playgrounds'] = popular_playgrounds params['playground_media'] = playground_media params['recent_events'] = recent_events params['featured_events'] = featured_events params['ongoing_events'] = ongoing_events params['upcoming_events'] = upcoming_events params['event_media'] = event_media params['recent_trainingcentres'] = recent_trainingcentres params['featured_trainingcentres'] = featured_trainingcentres params['popular_trainingcentres'] = popular_trainingcentres params['trainingcentre_media'] = trainingcentre_media if city_name is None: city_name = get_default_city() params['city_name'] = city_name params['sport'] = sport params['home'] = 'true' params['title'] = 'Sports Home' return self.render_template('/app/homenew.html', **params)