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 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)
class EventDetailsHandler(BaseHandler): eventDao = DaoFactory.create_ro_eventDao() mediaDao = DaoFactory.create_ro_mediaDao() matchDao = DaoFactory.create_ro_matchDao() teamDao = DaoFactory.create_rw_teamDao() registerDao = DaoFactory.create_rw_registerDao() def get(self, city_name, entity_id, entity_alias): logger.debug('Event details for city %s, id %s, alias %s ' % (city_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 Event ID.') self.add_message(message, 'warning') self.redirect_to('home') else: event = self.eventDao.get_record(entity_id) if event is None: message = ('Event could not be retrieved.') self.add_message(message, 'warning') return else: past_events = [] future_events = [] other_events = self.eventDao.get_business_events(event.business_id) if other_events and len(other_events) > 0: for other_event in other_events: if other_event.key.id() != event.key.id(): if get_event_state(other_event) == 'past': past_events.append(other_event) else: future_events.append(other_event) event_media = self.mediaDao.get_primary_media(other_events, constants.EVENT) params = {} params['event'] = event params['types'] = constants.EVENT params['sport'] = event.sport params['city_name'] = event.address.city params['locality_name'] = event.address.locality params['past_events'] = past_events if len(past_events) > 0 else None params['future_events'] = future_events if len(future_events) > 0 else None params['event_media'] = event_media params['media'] = self.mediaDao.get_active_media(event.key, event.sport, constants.EVENT) params['matches'] = self.matchDao.get_matches_for_event(event.key, self.user_info) params['continue_url'] = continue_url params['event_state'] = get_event_state(event) params['title'] = event.name if self.user_info: register_url = self.uri_for('event-register') params['teams'] = self.teamDao.query_by_owner(self.user_info) event_reg = self.registerDao.query_by_reg_user_id(event.key, self.user_info) logger.info('Event Registered Details: ' + str(event_reg)) if event_reg: params['reg_type'] = event_reg.reg_type register_url = self.uri_for('edit-event-register', record_id = event_reg.key.id(), **{'continue': continue_url}) if event_reg.team_id: params['reg_teams'] = [x.id() for x in event_reg.team_id] logger.info('Event Registered Teams : ' + str(params['reg_teams'])) if event_reg.player_id: params['reg_players'] = [x.id() for x in event_reg.player_id] logger.info('Event Registered Players : ' + str(params['reg_players'])) params['register_url'] = register_url if event.sport == "cricket": return self.render_template('/app/event_details_cricket.html', **params) else: return self.render_template('/app/event_details.html', **params)