Exemple #1
0
class DashboardHandler(BaseHandler):

    businessDao = DaoFactory.create_rw_businessDao()
    eventDao = DaoFactory.create_rw_eventDao()
    childeventDao = DaoFactory.create_rw_childeventDao()
    playgroundDao = DaoFactory.create_rw_playgroundDao()
    trainingcentreDao = DaoFactory.create_rw_trainingCentreDao()
    matchDao = DaoFactory.create_rw_matchDao()
    teamDao = DaoFactory.create_rw_teamDao()
    playerDao = DaoFactory.create_rw_playerDao()

    @user_required
    def get(self, business_id=None):
        params = {}
        params['title'] = 'Dashboard'
        params['owner_business'] = self.businessDao.query_by_owner(
            self.user_info)
        params['owner_playgrounds'] = self.playgroundDao.query_by_owner(
            self.user_info)
        params['owner_events'] = self.eventDao.query_by_owner(self.user_info)
        params['owner_childevents'] = self.childeventDao.query_by_owner(
            self.user_info)
        params[
            'owner_trainingcentres'] = self.trainingcentreDao.query_by_owner(
                self.user_info)
        params['owner_matches'] = self.matchDao.query_by_owner(self.user_info)
        params['owner_teams'] = self.teamDao.query_by_owner(self.user_info)
        params['owner_players'] = self.playerDao.query_by_owner(self.user_info)
        return self.render_template('/cms/dashboard.html', **params)
Exemple #2
0
class ViewTeamHandler(blobstore_handlers.BlobstoreUploadHandler, BaseHandler):
  
  teamDao = DaoFactory.create_rw_teamDao()
  playerDao = DaoFactory.create_rw_playerDao()
  profileDao = DaoFactory.create_rw_profileDao()
  mediaDao =  DaoFactory.create_ro_mediaDao()
  eventDao =  DaoFactory.create_rw_eventDao()
  
  @user_required
  def get(self, team_id=None):
    params = {}
    
    params['players'] = self.profileDao.query_by_all(self.user_info)
    if team_id is not None and len(team_id) > 1:
      team_info = self.teamDao.get_record(long(team_id))                  
      logger.debug('team_info : ' + str(team_info))
      #if team_info.logo:
        #params['team_logo'] = images.get_serving_url(team_info.logo)                 
      if team_info.players:
        players = []
        sel_players = []
        #for player in team_info.players:
        for x in xrange(len(team_info.players)):          
          players.append(self.profileDao.get_record(long(team_info.players[x].id())))
          sel_players.append(team_info.players[x].id())                
        logger.debug('team_players : ' + str(players))
        params['team_players'] = players
        params['sel_players'] = sel_players
        
      if team_info.owners:
        owners = []
        for owner in team_info.owners:            
          owners.append(self.user_model.get_by_id(long(owner.id())))
        params['team_owners'] = owners
        logger.debug('team_owners : ' + str(owners))
      
      params['user_info'] = self.user_info
      params['team_info'] = team_info
      params['title'] = str(team_info.name) + ' Team'
      upload_url = self.uri_for('edit-team-logo')
      params['media_upload_url'] = blobstore.create_upload_url(upload_url)
      upload_gallery_url = self.uri_for('upload-team-gallery')
      params['upload_gallery_url'] = blobstore.create_upload_url(upload_gallery_url)
      params['team_gallery'] = self.mediaDao.get_all_media(team_info.key, constants.TEAM)
      recommend_events = self.eventDao.get_recommend(self.user_info.locality, self.user_info.sport, 4)
      params['recommend_events'] = recommend_events
      event_media = self.mediaDao.get_primary_media(recommend_events, constants.EVENT)
      params['event_media'] = event_media
      
      return self.render_template('/cms/team_detail.html', **params)
  
  @webapp2.cached_property
  def form(self):
    return forms.TeamForm(self) 
Exemple #3
0
class EventSearchHandler(BaseHandler):

    eventDao = DaoFactory.create_rw_eventDao()
    mediaDao = DaoFactory.create_ro_mediaDao()

    def get(self, city_name=None, locality_name=None):
        return self.post(city_name, locality_name)

    def post(self, city_name=None, locality_name=None):
        city_str = str(self.request.get('city-name'))
        sport = str(self.request.get('sport'))
        #locality_str = str(self.request.get('se-locality'))
        locality_nav = str(self.request.get('nav-locality'))
        locality_home = str(self.request.get('se-locality'))
        locality_str = locality_nav if locality_nav != '' else locality_home
        #logger.debug('sporting event search :: locality_nav %s, locality_home %s, locality_str %s' % (locality_nav, locality_home, locality_str))

        se_sport = str(self.request.get('se-sport'))
        sport = se_sport if se_sport != '' and se_sport != 'None' else sport
        city = city_name if city_name is not None else city_str
        locality = locality_name if locality_name is not None else locality_str
        logger.debug(
            'sporting event search :: city %s, sport %s, locality %s' %
            (city, sport, locality))

        recent_events = self.eventDao.get_recent(city, sport, locality, -1)
        ongoing_events = self.eventDao.get_ongoing(city, sport, locality, -1)
        ongoing_events_future = self.eventDao.get_ongoing_future(
            city, sport, locality, -1)
        future_events = self.eventDao.get_upcoming(city, sport, locality, -1)
        logger.debug(' recent_events %s ' % len(recent_events))
        logger.debug(' future_events %s ' % len(future_events))
        logger.debug(' ongoing_events %s ' % len(ongoing_events))
        logger.debug(' ongoing_events_future %s ' % len(ongoing_events_future))

        ongoing_upcoming_events = []
        ongoing_upcoming_events = [
            val for val in ongoing_events if val in ongoing_events_future
        ]
        logger.debug(' ongoing_upcoming_events %s ' %
                     len(ongoing_upcoming_events))

        for event in future_events:
            ongoing_upcoming_events.append(event)
        #for event in ongoing_events:
        #ongoing_upcoming_events.append(event)

        temp_events = []
        for event in recent_events:
            temp_events.append(event)
        for event in ongoing_upcoming_events:
            temp_events.append(event)

        event_media = self.mediaDao.get_primary_media(temp_events,
                                                      constants.EVENT)
        logger.debug(' event_media %s ' % len(event_media))

        params = {}
        params['types'] = constants.EVENT
        params['sport'] = sport
        params['locality_name'] = locality
        if city != '' and city != 'None':
            params['city_name'] = city

        params['recent_events'] = recent_events
        params['future_events'] = ongoing_upcoming_events
        logger.debug(' future_events %s ' % len(ongoing_upcoming_events))
        params['event_media'] = event_media
        params['title'] = constants.EVENT
        #logger.debug('Params to template ' + str(params))

        return self.render_template('/app/events_home.html', **params)
Exemple #4
0
class ManageEventHandler(blobstore_handlers.BlobstoreUploadHandler,
                         BaseHandler):

    businessDao = DaoFactory.create_rw_businessDao()
    eventDao = DaoFactory.create_rw_eventDao()
    mediaDao = DaoFactory.create_rw_mediaDao()

    #@role_required('business')
    @user_required
    def get(self, business_id=None, event_id=None):
        params = {}

        upload_url = self.uri_for('select-for-event')
        continue_url = self.request.get('continue').encode('ascii', 'ignore')
        params[
            'continue_url'] = continue_url if continue_url != '' else upload_url
        status = self.request.get('status')
        event_status = status if status != '' else None
        params['title'] = 'Create New Event'

        if business_id is not None and len(business_id) > 1:
            self.form.business_id = business_id
            if event_id is not None and len(event_id) > 1:
                event = self.eventDao.get_record(event_id)
                params['title'] = 'Update - ' + str(event.name)
                if event_status is not None:
                    logger.info('current status: %s' % event_status)
                    key = self.eventDao.status_change(event, self.user_info)
                    if key is not None:
                        updated_event = self.eventDao.get_record(long(
                            key.id()))
                        logger.info('updated status : %s' %
                                    updated_event.status)
                        if event_status == str(updated_event.status):
                            logger.info('event status could not be changed.')
                            message = ('event status could not be changed.')
                            self.add_message(message, 'error')
                        else:
                            logger.info('event status succesfully changed.')
                            message = ('event status succesfully changed.')
                            self.add_message(message, 'success')
                        return self.redirect(continue_url)
                else:
                    upload_url = self.uri_for('edit-event',
                                              business_id=business_id,
                                              event_id=event_id)
                    all_media = self.mediaDao.get_all_media(
                        event.key, constants.EVENT)
                    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
                    logger.debug('event detail ' + str(event))
                    self.form = cms_utils.dao_to_form_city_info(
                        event, forms.EventForm(self, event))
                    self.form = cms_utils.dao_to_form_contact_info(
                        event, self.form)

                    params['media_upload_url'] = blobstore.create_upload_url(
                        upload_url)
                    return self.render_template('/cms/create_event.html',
                                                **params)
            else:
                upload_url = self.uri_for('create-event',
                                          business_id=business_id)
                params['media_upload_url'] = blobstore.create_upload_url(
                    upload_url)
                return self.render_template('/cms/create_event.html', **params)

        params['entity_name'] = 'Event'
        params['owner_business'] = self.businessDao.query_by_owner(
            self.user_info)
        logger.info('Result Params : ' + str(params['entity_name']))
        return self.render_template('/cms/select_business.html', **params)

    #@role_required('business')
    @user_required
    def post(self, business_id=None, event_id=None):
        params = {}

        if not self.form.validate():
            if business_id is not None and len(business_id) > 0:
                if event_id is not None and len(event_id) > 0:
                    return self.get(business_id, event_id)
                else:
                    return self.get(business_id)
            else:
                return self.get()

        save = self.request.get('save')
        next_fill = self.request.get('next')
        next_tab = next_fill if next_fill != '' else save
        locality_id = self.request.get('locality_id')

        event = self.form_to_dao(event_id)

        if locality_id is not None and len(locality_id) > 0:
            logger.info('Locality Id: %s ' % locality_id)
            locality_count = self.process_locality(event.address.locality,
                                                   locality_id,
                                                   constants.PLACES_API_KEY)
            event.address.locality_id = locality_id
        else:
            event.address.locality = ''
            event.address.locality_id = ''

        logger.debug('event populated ' + str(event))
        if business_id != None and business_id != 'user':
            business = self.businessDao.get_record(business_id)
            business_key = business.key
        else:
            business = self.create_or_update_business(event)
            business_key = self.businessDao.persist(business, self.user_info)

        if business_key is not None:
            logger.info('Business succesfully created for event, ' +
                        business.name)
            event.business_id = business_key
            key = self.eventDao.persist(event, self.user_info)
            logger.debug('key ' + str(key))

            if key is not None:
                self.upload_photos(key)
                logger.info('event succesfully created/updated')
                message = ('event succesfully created/updated.')
                self.add_message(message, 'success')
                if next_tab is not None:
                    if next_tab != 'save':
                        redirect_url = self.uri_for(
                            'edit-event',
                            business_id=event.business_id.id(),
                            event_id=key.id())
                        redirect_url = redirect_url + next_tab
                        logger.info('Url %s' % redirect_url)
                        return self.redirect(redirect_url)
                    else:
                        redirect_url = self.uri_for(
                            'event-details',
                            city_name=event.address.city,
                            entity_id=key.id(),
                            entity_alias=event.alias)
                        return self.redirect(redirect_url)
                        #return self.redirect_to('dashboard', **params)

        logger.error('event creation failed')
        message = ('event creation failed.')
        self.add_message(message, 'error')
        self.form = forms.EventForm(self, event)
        return self.render_template('/cms/create_event.html', **params)

    @webapp2.cached_property
    def form(self):
        return forms.EventForm(self)

    def upload_photos(self, key):
        upload_files = self.get_uploads()
        if upload_files is not None and len(upload_files) > 0:
            files_count = len(upload_files)
            logger.info('no of files uploaded ' + str(files_count))
            for x in xrange(files_count):
                blob_info = upload_files[x]
                media_obj = Media()
                media_obj.name = self.form.media.__getitem__(x).data['name']
                media_obj.type = constants.PHOTO
                media_obj.status = self.form.media.__getitem__(
                    x).data['status']
                media_obj.primary = self.form.media.__getitem__(
                    x).data['primary']
                media_obj.link = blob_info.key()
                media_obj.url = images.get_serving_url(blob_info.key())
                media_obj.entity_id = key
                media_obj.entity_type = constants.EVENT
                self.mediaDao.persist(media_obj)
                logger.info('Link to picture file ' + media_obj.name + ', ' +
                            images.get_serving_url(media_obj.link))

    def form_to_dao(self, event_id):
        event = None
        if event_id is not None and len(event_id) > 1:
            event = self.eventDao.get_record(long(event_id))
        else:
            event = Event()
        event.name = self.form.name.data
        event.sport = self.form.sport.data
        #Create an automatic alias for the event
        event.alias = utils.slugify(self.form.name.data)
        event.caption = self.form.caption.data
        event.description = self.form.description.data
        event.featured = self.form.featured.data
        event.start_datetime = datetime(
            *(self.form.start_datetime.data.timetuple()[:6]))
        event.end_datetime = datetime(
            *(self.form.end_datetime.data.timetuple()[:6]))
        self.form.address.city.data = self.form.city.data  #for city from basic info to address
        event = cms_utils.form_to_dao_address(self.form, event)
        event = cms_utils.form_to_dao_contact_info(self.form, event)
        return event

    def create_or_update_business(self, event):
        if event.business_id is not None:
            business = self.businessDao.get_record(long(
                event.business_id.id()))
        else:
            business = Business()
        business.name = event.name
        business.description = event.description
        business.alias = event.alias
        business.contact_info = event.contact_info
        return business
Exemple #5
0
class ManageRegisterHandler(blobstore_handlers.BlobstoreUploadHandler,
                            BaseHandler):

    eventDao = DaoFactory.create_rw_eventDao()
    mediaDao = DaoFactory.create_rw_mediaDao()
    teamDao = DaoFactory.create_rw_teamDao()
    profileDao = DaoFactory.create_rw_profileDao()
    registerDao = DaoFactory.create_rw_registerDao()

    @user_required
    def get(self):
        params = {}

        return True

    @user_required
    def post(self, record_id=None):
        params = {}

        continue_url = self.request.get('continue').encode('ascii', 'ignore')

        register = self.form_to_dao(record_id)
        logger.debug('registration populated ' + str(register))
        key = self.registerDao.persist(register, self.user_info)
        logger.debug('key ' + str(key))

        if key is not None:
            record = self.registerDao.get_record(key.id())
            message = ''
            if record.team_id:
                message += ('%s teams ' % len(record.team_id))
            if record.player_id:
                message += ('%s player ' % len(record.player_id))
            message += ('registered this event succesfully')
            logger.info(message)
            self.add_message(message, 'success')
            if continue_url:
                return self.redirect(continue_url)
            else:
                return self.redirect_to('profile', **params)

        logger.error('registration failed')
        message = ('registration failed.')
        self.add_message(message, 'error')
        return self.redirect_to('profile', **params)

    def form_to_dao(self, record_id=None):
        register = None
        if record_id is not None and len(record_id) > 1:
            register = self.registerDao.get_record(long(record_id))
        else:
            register = Register()
        event_id = self.request.get('event_id')
        event_data = self.eventDao.get_record(long(event_id))
        register.reg_id = event_data.key
        register.reg_type = self.request.get('participant_type')
        register.user_id = self.user_info.key

        sel_team = self.request.get_all('team')
        sel_player = self.request.get_all('player')
        logger.debug('sel_team:  ' + str(sel_team))
        logger.debug('sel_player:  ' + str(sel_player))
        payment = 0
        if len(sel_team) > 0:
            teams = []
            teams_count = len(sel_team)
            logger.debug('Teams Count: ' + str(teams_count))
            for x in xrange(teams_count):
                teams.append(self.teamDao.get_record(sel_team[x]).key)
            logger.debug('Teams ' + str(teams))
            payment += teams_count * constants.REG_PRICE
            register.team_id = teams

        if len(sel_player) > 0:
            players = []
            players_count = len(sel_player)
            logger.debug('Players Count: ' + str(players_count))
            for x in xrange(players_count):
                players.append(self.profileDao.get_record(sel_player[x]).key)
            logger.debug('Players ' + str(players))
            payment += players_count * constants.REG_PRICE
            register.player_id = players

        register.payment = payment
        return register

    '''def send_register_email(self, record_id):
Exemple #6
0
class ProfileHandler(blobstore_handlers.BlobstoreUploadHandler, BaseHandler):
  
  eventDao =  DaoFactory.create_rw_eventDao() 
  playgroundDao =  DaoFactory.create_rw_playgroundDao()   
  trainingcentreDao =  DaoFactory.create_rw_trainingCentreDao() 
  mediaDao =  DaoFactory.create_ro_mediaDao()
  profileDao =  DaoFactory.create_rw_profileDao()
  teamDao =  DaoFactory.create_rw_teamDao()
  
  @user_required
  def get(self, user_id=None):
    params = {}
    
    if user_id is not None  and len(user_id) > 1:
      user_info = self.user_model.get_by_id(long(user_id))
      upload_url = self.uri_for('edit-profile', user_id=user_id)            
      logger.debug('upload_url : ' + upload_url)
      if user_info.image:
        params['current_image'] = images.get_serving_url(user_info.image)
      if user_info.sport:
        params['sel_sport'] = [x.strip() for x in user_info.sport.split(',')]
      params['sports_list'] = constants.SPORTS_LIST
      params['media_upload_url'] = blobstore.create_upload_url(upload_url)      
      
      self.form = forms.UserProfileForm(self, user_info)
      return self.render_template('/cms/edit_profile.html', **params)
    
    '''logger.debug('User Id: ' + str(self.user_id))
    logger.debug('User Info: ' + str(self.user_info))
    logger.debug('User Type: ' + str(self.user_type))'''
    if self.user_info.image:
      params['current_image'] = images.get_serving_url(self.user_info.image)
    elif self.user_type[0] == 'facebook':
      params['current_image'] = 'https://graph.facebook.com/'+str(self.user_type[1])+'/picture?type=large'
    upload_url = self.uri_for('edit-user-image')
    params['media_upload_url'] = blobstore.create_upload_url(upload_url)
    upload_gallery_url = self.uri_for('upload-profile-gallery')
    params['upload_gallery_url'] = blobstore.create_upload_url(upload_gallery_url)
    params['title'] = self.user_info.name
    params['want_list'] = constants.WANT_DICT
    params['owner_info'] = self.user_info
    params['profile_gallery'] = self.mediaDao.get_all_media(self.user_info.key, constants.PROFILE)    
    params['owner_playgrounds'] = self.playgroundDao.query_by_owner(self.user_info)
    params['owner_events'] = self.eventDao.query_by_owner(self.user_info)    
    params['owner_trainingcentres'] = self.trainingcentreDao.query_by_owner(self.user_info)
    params['owner_teams'] = self.teamDao.query_by_owner(self.user_info, 'all', 4)
    
    recommend_events = self.eventDao.get_recommend(self.user_info.locality, self.user_info.sport, 4)
    params['recommend_events'] = recommend_events
    recommend_playgrounds = self.playgroundDao.get_recommend(self.user_info.locality, self.user_info.sport, 4)
    params['recommend_playgrounds'] = recommend_playgrounds    
    recommend_trainingcentres = self.trainingcentreDao.get_recommend(self.user_info.locality, self.user_info.sport, 4)
    params['recommend_trainingcentres'] = recommend_trainingcentres
        
    event_media = self.mediaDao.get_primary_media(recommend_events, constants.EVENT)
    params['event_media'] = event_media
    playground_media = self.mediaDao.get_primary_media(recommend_playgrounds, constants.PLAYGROUND)
    params['playground_media'] = playground_media
    trainingcentre_media = self.mediaDao.get_primary_media(recommend_trainingcentres, constants.TRAINING_CENTRE)
    params['trainingcentre_media'] = trainingcentre_media
    logger.debug(' event_media %s ' % len(event_media))
    logger.debug(' playground_media %s ' % len(playground_media))
    logger.debug(' trainingcentre_media %s ' % len(trainingcentre_media))
    
    return self.render_template('/cms/profile.html', **params)
Exemple #7
0
class ManageChildEventHandler(blobstore_handlers.BlobstoreUploadHandler,
                              BaseHandler):

    childeventDao = DaoFactory.create_rw_childeventDao()
    eventDao = DaoFactory.create_rw_eventDao()
    mediaDao = DaoFactory.create_rw_mediaDao()

    @role_required('business')
    def get(self, event_id=None, childevent_id=None):
        params = {}

        upload_url = self.uri_for('select-for-childevent')
        if event_id is not None and len(event_id) > 1:
            self.form.parent_event_id = event_id
            if childevent_id is not None and len(childevent_id) > 1:
                upload_url = self.uri_for('edit-child-event',
                                          event_id=event_id,
                                          childevent_id=childevent_id)
                childevent = self.childeventDao.get_record(childevent_id)
                all_media = self.mediaDao.get_all_media(
                    childevent.key, constants.EVENT)
                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
                self.form = cms_utils.dao_to_form_contact_info(
                    childevent, forms.ChildEventForm(self, childevent))

                params['media_upload_url'] = blobstore.create_upload_url(
                    upload_url)
                return self.render_template('/cms/create_childevent.html',
                                            **params)
            else:
                upload_url = self.uri_for('create-child-event',
                                          event_id=event_id)
                params['media_upload_url'] = blobstore.create_upload_url(
                    upload_url)
                return self.render_template('/cms/create_childevent.html',
                                            **params)

        params['continue_url'] = upload_url
        params['entity_name'] = 'Child Event'
        params['owner_event'] = self.eventDao.query_by_owner(self.user_info)
        return self.render_template('/cms/select_event.html', **params)

    @role_required('business')
    def post(self, event_id=None, childevent_id=None):
        params = {}

        if not self.form.validate():
            if event_id is not None and len(event_id) > 0:
                if childevent_id is not None and len(childevent_id) > 0:
                    return self.get(event_id, childevent_id)
                else:
                    return self.get(event_id)
            else:
                return self.get()

        childevent = self.form_to_dao(childevent_id)
        logger.debug('childevent populated ' + str(childevent))
        event = self.eventDao.get_record(event_id)
        event_key = event.key

        if event_key is not None:
            logger.info('Event succesfully created for childevent')
            childevent.parent_event_id = event_key
            key = self.childeventDao.persist(childevent, self.user_info)
            logger.debug('key ' + str(key))

            if key is not None:
                self.upload_photos(key)
                logger.info('childevent succesfully created/updated')
                message = ('childevent succesfully created/updated.')
                self.add_message(message, 'success')
                return self.redirect_to('dashboard', **params)

        logger.error('childevent creation failed')
        message = ('childevent creation failed.')
        self.add_message(message, 'error')
        self.form = forms.ChildEventForm(self, childevent)
        return self.render_template('/cms/create_childevent.html', **params)

    @webapp2.cached_property
    def form(self):
        return forms.ChildEventForm(self)

    def upload_photos(self, key):
        upload_files = self.get_uploads()
        if upload_files is not None and len(upload_files) > 0:
            files_count = len(upload_files)
            logger.info('no of files uploaded ' + str(files_count))
            for x in xrange(files_count):
                blob_info = upload_files[x]
                media_obj = Media()
                media_obj.name = self.form.media.__getitem__(x).data['name']
                media_obj.type = constants.PHOTO
                media_obj.status = self.form.media.__getitem__(
                    x).data['status']
                media_obj.primary = self.form.media.__getitem__(
                    x).data['primary']
                media_obj.link = blob_info.key()
                media_obj.event_id = key
                self.mediaDao.persist(media_obj)
                logger.info('Link to picture file ' + media_obj.name + ', ' +
                            images.get_serving_url(media_obj.link))

    def form_to_dao(self, childevent_id):
        childevent = None
        if childevent_id is not None and len(childevent_id) > 1:
            childevent = self.childeventDao.get_record(long(childevent_id))
        else:
            childevent = Event()
        childevent.name = self.form.name.data
        #Create an automatic alias for the childevent
        childevent.alias = utils.slugify(self.form.name.data)
        childevent.description = self.form.description.data
        childevent.start_datetime = self.form.start_datetime.data
        childevent.end_datetime = self.form.end_datetime.data
        childevent = cms_utils.form_to_dao_contact_info(self.form, childevent)
        return childevent
Exemple #8
0
class ManageMatchHandler(blobstore_handlers.BlobstoreUploadHandler,
                         BaseHandler):

    eventDao = DaoFactory.create_rw_eventDao()
    matchDao = DaoFactory.create_rw_matchDao()
    teamDao = DaoFactory.create_rw_teamDao()
    playerDao = DaoFactory.create_rw_playerDao()

    @role_required('business')
    def get(self, event_id=None, match_id=None):
        params = {}

        import_url = self.uri_for('import-team')
        params['import_url'] = blobstore.create_upload_url(import_url)
        upload_url = self.uri_for('select-for-match')
        continue_url = self.request.get('continue').encode('ascii', 'ignore')
        #params['continue_url'] = continue_url if continue_url != '' else upload_url
        status = self.request.get('status')
        match_status = status if status != '' else None
        params['title'] = 'Create New Match'

        if event_id is not None and len(event_id) > 1:
            self.form.event_id = event_id
            params['event_id'] = event_id
            params['teams'] = self.teamDao.query_by_owner(self.user_info)
            params['players'] = self.playerDao.query_by_owner(self.user_info)
            params['continue_url'] = continue_url
            #logger.debug('teams:  ' + str(params['teams']))
            if match_id is not None and len(match_id) > 1:
                match = self.matchDao.get_record(match_id)
                params['title'] = 'Update - ' + str(match.name)
                participants = []
                for x in xrange(len(match.participants)):
                    participants.append(match.participants[x].id())
                params['participants'] = participants
                logger.info('select participants: ' +
                            str(params['participants']))
                if match_status is not None:
                    logger.info('current status: %s' % match_status)
                    key = self.matchDao.status_change(match, self.user_info)
                    if key is not None:
                        updated_match = self.matchDao.get_record(long(
                            key.id()))
                        logger.info('updated status : %s' %
                                    updated_match.status)
                        if match_status == str(updated_match.status):
                            logger.info('match status could not be changed.')
                            message = ('match status could not be changed.')
                            self.add_message(message, 'error')
                        else:
                            logger.info('match status succesfully changed.')
                            message = ('match status succesfully changed.')
                            self.add_message(message, 'success')
                        return self.redirect(continue_url)
                else:
                    upload_url = self.uri_for('edit-match',
                                              event_id=event_id,
                                              match_id=match_id)
                    params['media_upload_url'] = blobstore.create_upload_url(
                        upload_url)
                    self.form = forms.MatchForm(self, match)
                    return self.render_template('/cms/create_match.html',
                                                **params)
            else:
                upload_url = self.uri_for('create-match', event_id=event_id)
                params['media_upload_url'] = blobstore.create_upload_url(
                    upload_url)
                return self.render_template('/cms/create_match.html', **params)

        params['continue_url'] = upload_url
        params['entity_name'] = 'Match'
        params['owner_event'] = self.eventDao.query_by_owner(self.user_info)
        return self.render_template('/cms/select_event.html', **params)

    @role_required('business')
    def post(self, event_id=None, match_id=None):
        params = {}

        if not self.form.validate():
            if event_id is not None and len(event_id) > 0:
                if match_id is not None and len(match_id) > 0:
                    return self.get(event_id, match_id)
                else:
                    return self.get(event_id)
            else:
                return self.get()

        continue_url = self.request.get('continue').encode('ascii', 'ignore')

        match = self.form_to_dao(match_id)
        logger.debug('match populated ' + str(match))
        event = self.eventDao.get_record(event_id)
        event_key = event.key

        if event_key is not None:
            logger.info('Event succesfully created for match')
            match.event_id = event_key
            key = self.matchDao.persist(match, self.user_info)
            logger.debug('key ' + str(key))

            if key is not None:
                logger.info('match succesfully created/updated')
                message = ('match succesfully created/updated.')
                self.add_message(message, 'success')
                if continue_url:
                    return self.redirect(continue_url)
                else:
                    return self.redirect_to('dashboard', **params)

        logger.error('match creation failed')
        message = ('match creation failed.')
        self.add_message(message, 'error')
        self.form = forms.MatchForm(self, event)
        return self.render_template('/cms/create_match.html', **params)

    @webapp2.cached_property
    def form(self):
        return forms.MatchForm(self)

    def form_to_dao(self, match_id):
        match = None
        if match_id is not None and len(match_id) > 1:
            match = self.matchDao.get_record(long(match_id))
        else:
            match = Match()
        match.name = self.form.name.data
        match.sport = self.form.sport.data
        #Create an automatic alias for the match
        match.alias = utils.slugify(self.form.name.data)
        match.start_datetime = self.form.start_datetime.data
        match.end_datetime = self.form.end_datetime.data
        match.result = self.form.result.data
        match.summary = self.form.summary.data
        match.participant_type = self.form.participant_type.data
        sel_team = self.request.get_all('team')
        sel_player = self.request.get_all('player')
        logger.debug('sel_team:  ' + str(sel_team))
        logger.debug('sel_player:  ' + str(sel_player))

        if match.participant_type == 'team':
            if len(sel_team) > 0:
                teams = []
                teams_count = len(sel_team)
                logger.debug('Teams Count: ' + str(teams_count))
                for x in xrange(teams_count):
                    teams.append(self.teamDao.get_record(sel_team[x]).key)
                logger.debug('Participants ' + str(teams))
                match.participants = teams
        else:
            if len(sel_player) > 0:
                players = []
                players_count = len(sel_player)
                logger.debug('Teams Count: ' + str(players_count))
                for x in xrange(players_count):
                    players.append(
                        self.playerDao.get_record(sel_player[x]).key)
                logger.debug('Participants ' + str(players))
                match.participants = players
        return match
Exemple #9
0
class ImportHandler(blobstore_handlers.BlobstoreUploadHandler, BaseHandler):

    eventDao = DaoFactory.create_rw_eventDao()
    businessDao = DaoFactory.create_rw_businessDao()
    playgroundDao = DaoFactory.create_rw_playgroundDao()
    trainingCentreDao = DaoFactory.create_rw_trainingCentreDao()

    @user_required
    def get(self):
        params = {}

        upload_url = self.uri_for('import')
        params['title'] = 'Import'
        params['media_upload_url'] = blobstore.create_upload_url(upload_url)
        return self.render_template('/cms/import.html', **params)

    @user_required
    def post(self):
        if not self.form.validate():
            return self.get()

        start_record = int(str(self.request.get('linenum')))
        upload_files = self.get_uploads(
            'importfile')  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        upload_count = self.process_csv(blob_info, start_record)
        self.add_message(
            str(upload_count) + ' entities created successfully.', 'success')
        return self.redirect_to('import')

    def process_csv(self, blob_info, start_record):
        update = {}
        upload_count = 0
        row_count = 0

        blob_reader = blobstore.BlobReader(blob_info.key())
        datareader = csv.reader(blob_reader)

        for row in datareader:
            row_count += 1
            if row_count >= (start_record + 1):  #to skip the header row
                logger.info('Starting to parse %s, %s' % (row_count, row[1]))
                entity_type = row[0].lower()
                update['name'] = utils.stringify(row[1])
                # Name is mandatory for all entities
                if update['name'] == '':
                    logger.error('Name is empty. Skipping this record')
                    continue

                update['locality'] = utils.stringify(row[5]).lower()
                update['city'] = utils.stringify(row[8]).lower()

                #Locality and city mandatory for playground and trainingcentre
                if entity_type != 'event':
                    if update['locality'] == '' or update['city'] == '':
                        logger.error(
                            'Locality or city is empty. Skipping this record')
                        continue
                alias_name = utils.slugify(update['name'].lower())

                try:
                    update['description'] = utils.stringify(row[2])
                    update['sport'] = utils.stringify(row[3]).lower()
                    update['person_name'] = utils.stringify(row[10])
                    update['phone'] = utils.stringify(row[11])
                    update['email'] = utils.stringify(row[12])
                    update['website'] = utils.stringify(row[13])
                    update['facebook'] = utils.stringify(row[18])
                    update['twitter'] = utils.stringify(row[19])
                    update['youtube'] = utils.stringify(row[20])
                    update['gplus'] = utils.stringify(row[21])
                    update['line1'] = utils.stringify(row[6])
                    update['line2'] = utils.stringify(row[7])
                    update['pin'] = int(
                        row[9].strip()) if row[9] != '' else None
                    #update['start_datetime'] = row[22]
                    #update['end_datetime'] = row[23]

                    logger.debug('Constructed Structure for upload ' +
                                 str(update))
                    logger.info('Entity type to be created, ' + entity_type)

                    if entity_type == 'ground':
                        import_data = self.form_to_dao_ground(
                            alias_name, **update)
                    elif entity_type == 'club':
                        import_data = self.form_to_dao_center(
                            alias_name, **update)
                    elif entity_type == 'event':
                        import_data = self.form_to_dao_event(
                            alias_name, **update)

                    # for add locality table
                    if import_data.address.locality != '':
                        place_name = import_data.address.locality
                        logger.info('Place: %s' % place_name)

                        newfeed_url = 'https://maps.googleapis.com/maps/api/place/autocomplete/xml?types=(regions)&input=' + urllib.quote(
                            place_name) + '&key=' + constants.PLACES_API_KEY
                        logging.info('newfeed url %s' % newfeed_url)

                        newroot = self.parse(newfeed_url)
                        auto_status = newroot.getElementsByTagName(
                            'status')[0].firstChild.data
                        logger.info('Auto Status: %s ' % auto_status)

                        if auto_status == 'OK':
                            items = newroot.getElementsByTagName(
                                'prediction')[0]
                            place_id = items.getElementsByTagName(
                                'place_id')[0].firstChild.data
                            place_name = items.getElementsByTagName(
                                'value')[0].firstChild.data  #description
                            logger.info('Place Name: %s Place Id: %s ' %
                                        (place_name, place_id))
                            import_data.address.locality_id = place_id
                            logger.info('Locality Id: %s ' %
                                        import_data.address.locality_id)
                            locality_add = self.process_locality(
                                place_name, place_id, constants.PLACES_API_KEY)
                            #if import_data.address.latlong == '':
                            #locality = self.importDao.query_by_place_id(place_id)
                            #import_data.address.latlong = locality.latlong
                            #logger.info('Geo Location New: %s ' % import_data.address.latlong)
                        else:
                            logger.error('Error: %s' % auto_status)

                    logger.debug('Populated File Data ' + str(import_data))
                    business_key = self.create_or_update_business(
                        alias_name, import_data)
                    import_data.business_id = business_key

                    if entity_type == 'ground':
                        ground = self.playgroundDao.query_by_alias(alias_name)
                        if ground is not None:
                            self.playgroundDao.copy_playground_model(
                                ground, import_data)
                            key = self.playgroundDao.persist(
                                ground, self.user_info)
                            upload_count += 1
                            logger.info(
                                'Playground updated for %s with key %s' %
                                (alias_name, key))
                        else:
                            key = self.playgroundDao.persist(
                                import_data, self.user_info)
                            upload_count += 1
                            logger.info('New playground created for %s' %
                                        (update['name']))
                    elif entity_type == 'club':
                        tc = self.trainingCentreDao.query_by_alias(alias_name)
                        if tc is not None:
                            self.trainingCentreDao.copy_trainingCentre_model(
                                tc, import_data)
                            key = self.trainingCentreDao.persist(
                                tc, self.user_info)
                            upload_count += 1
                            logger.info(
                                'TrainingCentre updated for %s with key %s' %
                                (alias_name, key))
                        else:
                            key = self.trainingCentreDao.persist(
                                import_data, self.user_info)
                            upload_count += 1
                            logger.info('New training centre created for %s' %
                                        (update['name']))
                    elif entity_type == 'event':
                        event = self.eventDao.query_by_alias(alias_name)
                        if event is not None:
                            self.eventDao.copy_event_model(event, import_data)
                            key = self.eventDao.persist(event, self.user_info)
                            upload_count += 1
                            logger.info('Event updated for %s with key %s' %
                                        (alias_name, key))
                        else:
                            key = self.eventDao.persist(
                                import_data, self.user_info)
                            upload_count += 1
                            logger.info('Event created for %s' %
                                        (update['name']))

                    if key is not None:
                        logger.info(
                            str(entity_type) + ' succesfully created/updated')
                    else:
                        logger.error('Already Exist of %s:%s' %
                                     (entity_type, update['name']))

                except StandardError as e:
                    #skipping to next record
                    logger.error('Error occured, %s, for %s' %
                                 (str(e), alias_name))
            else:
                logger.info("skipping record number, %s " % row_count)
        return upload_count

    @webapp2.cached_property
    def form(self):
        return forms.ImportForm(self)

    def upload_photos(self, photos):
        upload_files = self.get_uploads()
        if upload_files is not None and len(upload_files) > 0:
            files_count = len(upload_files)
            logger.info('no of files uploaded ' + str(files_count))
            for x in xrange(files_count):
                blob_info = upload_files[x]
                media_obj = Media()
                media_obj.name = self.form.media.__getitem__(x).data['name']
                media_obj.status = self.form.media.__getitem__(
                    x).data['status']
                media_obj.link = blob_info.key()
                photos.append(media_obj)
                logger.info('Link to picture file ' + media_obj.name + ', ' +
                            images.get_serving_url(media_obj.link))
        return photos

    def create_or_update_business(self, alias_name, import_data):
        business = self.businessDao.query_by_alias(alias_name)

        if business is not None:
            business_key = business.key
            import_data.business_id = business_key
            logger.info('Business Already Exist with Key %s' %
                        str(business_key))
        else:
            try:
                business = Business()
                business.name = import_data.name
                business.description = import_data.description
                business.alias = import_data.alias
                business.contact_info = import_data.contact_info
                business_key = self.businessDao.persist(
                    business, self.user_info)
                import_data.business_id = business_key
                logger.info('New Business Created for %s with key %s' %
                            (alias_name, str(business_key)))
            except StandardError as e:
                #Skip the error and continue
                logger.error('Error occured, %s, for %s' %
                             (str(e), alias_name))
                raise
        return business_key

    def form_to_dao_ground(self, alias_name, **update):
        try:
            playground = Playground()
            playground.name = update['name']
            #Create an automatic alias for the playground
            playground.alias = alias_name
            playground.description = update['description']
            playground.sport = update['sport']
            playground = self.form_to_dao_address_import(playground, **update)
            playground = self.form_to_dao_contact_info_import(
                playground, **update)
            #if playground.photos is None:
            #playground.photos = []
            #self.upload_photos(playground.photos)
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return playground

    def form_to_dao_center(self, alias_name, **update):
        try:
            trainingcentre = TrainingCentre()
            trainingcentre.name = update['name']
            #Create an automatic alias for the trainingcentre
            trainingcentre.alias = alias_name
            trainingcentre.description = update['description']
            trainingcentre.sport = update['sport']
            trainingcentre = self.form_to_dao_address_import(
                trainingcentre, **update)
            trainingcentre = self.form_to_dao_contact_info_import(
                trainingcentre, **update)
            #if trainingcentre.photos is None:
            #trainingcentre.photos = []
            #self.upload_photos(trainingcentre.photos)
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return trainingcentre

    def form_to_dao_event(self, alias_name, **update):
        try:
            event = Event()
            event.name = update['name']
            #Create an automatic alias for the event
            event.alias = alias_name
            event.description = update['description']
            event.sport = update['sport']
            #event.start_datetime = update['start_datetime']
            #event.end_datetime = update['end_datetime']
            event = self.form_to_dao_contact_info_import(event, **update)
            #if event.photos is None:
            #event.photos = []
            #self.upload_photos(event.photos)
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return event

    def form_to_dao_business(self, **update):
        business = Business()
        business.name = update['name']
        #Create an automatic alias for the business
        business.alias = utils.slugify(update['name'])
        business.description = update['description']
        business = self.form_to_dao_contact_info_import(business, **update)
        return business

    def form_to_dao_address_import(self, entity, **update):
        #entity = playground
        try:
            if update['locality'] == '' or update['city'] == '':
                raise StandardError('Locality is empty. Cannot create entity')

            entity.address = Address()
            entity.address.line1 = update['line1'].lower()
            entity.address.line2 = update['line2'].lower()
            entity.address.locality = update['locality'].lower()
            entity.address.city = update['city'].lower()
            entity.address.pin = update['pin']
            lattitude, longitude = get_latlong_from_address(entity.address)
            if lattitude is not None and longitude is not None:
                entity.address.latlong = ndb.GeoPt(lattitude, longitude)
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return entity

    def form_to_dao_contact_info_import(self, entity, **update):
        try:
            entity.contact_info = ContactInfo()
            if len(update['person_name']) > 0:
                entity.contact_info.person_name = [
                    x.strip() for x in update['person_name'].split(',')
                ]
            if len(update['email']) > 0:
                entity.contact_info.email = [
                    x.strip() for x in update['email'].split(',')
                ]
            if len(update['phone']) > 0:
                entity.contact_info.phone = [
                    x.strip() for x in update['phone'].split(',')
                ]
            entity.contact_info.website = update['website']
            entity.contact_info.facebook = update['facebook']
            entity.contact_info.twitter = update['twitter']
            entity.contact_info.youtube = update['youtube']
            entity.contact_info.gplus = update['gplus']
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return entity
Exemple #10
0
class SearchUpdateHandler(blobstore_handlers.BlobstoreUploadHandler,
                          BaseHandler):
    eventDao = DaoFactory.create_rw_eventDao()
    playgroundDao = DaoFactory.create_rw_playgroundDao()
    trainingCentreDao = DaoFactory.create_rw_trainingCentreDao()

    @user_required
    def get(self):
        params = {}
        upload_url = self.uri_for('search-update')
        params['title'] = 'Search Update'
        params['media_upload_url'] = blobstore.create_upload_url(upload_url)
        return self.render_template('/cms/search_update.html', **params)

    @user_required
    def post(self):
        params = {}
        datas = []
        datas_count = 0
        type = self.request.get('type')
        logger.info('Type: %s' % type)

        if type != 'None':
            if type == 'event':
                datas = Event.query().fetch()
            elif type == 'playground':
                datas = Playground.query().fetch()
            elif type == 'trainingcentre':
                datas = TrainingCentre.query().fetch()

            for data in datas:
                if data.address.latlong is None:
                    latitude, longitude = get_latlong_from_address(
                        data.address)
                    if latitude is not None and longitude is not None:
                        data.address.latlong = ndb.GeoPt(latitude, longitude)
                        logger.info('New Lat Long: ' +
                                    str(data.address.latlong))
                logger.info('Populated Data: ' + str(data))

                if type == 'event':
                    key = self.eventDao.persist(data, self.user_info)
                elif type == 'playground':
                    key = self.playgroundDao.persist(data, self.user_info)
                elif type == 'trainingcentre':
                    key = self.trainingCentreDao.persist(data, self.user_info)

                if key is not None:
                    datas_count += 1
                    logger.info(str(key.id()) + ' succesfully search updated')
            logger.info('%s %s Entities Updated Search Successfully' %
                        (datas_count, type))
            message = ('%s %s Entities Updated Search Successfully' %
                       (datas_count, type))
            self.add_message(message, 'success')
            return self.redirect_to('search-update')

        logger.error('Select anyone of Type')
        message = ('Select anyone of Type')
        self.add_message(message, 'error')
        return self.redirect_to('search-update')
Exemple #11
0
class ImportTeamHandler(blobstore_handlers.BlobstoreUploadHandler,
                        BaseHandler):

    eventDao = DaoFactory.create_rw_eventDao()
    matchDao = DaoFactory.create_rw_matchDao()
    teamDao = DaoFactory.create_rw_teamDao()
    playerDao = DaoFactory.create_rw_playerDao()

    @user_required
    def get(self):
        params = {}

        event_id = self.request.get('event_id')
        upload_field = self.request.get('importfile')
        continue_url = self.request.get('continue').encode('ascii', 'ignore')
        logger.info('Continue Url: ' + str(continue_url))

        if upload_field != '':
            upload_files = self.get_uploads('importfile')
            logger.info('Upload Datas: ' + str(upload_files))
            blob_info = upload_files[0]
            start_record = 1
            upload_count = self.process_csv(blob_info, start_record, event_id)
            self.add_message(
                str(upload_count) + ' entities created successfully.',
                'success')
            if continue_url:
                return self.redirect(continue_url)
            else:
                return self.redirect_to('dashboard')

        upload_url = self.uri_for('import-team')
        params['title'] = 'Import Team'
        params['media_upload_url'] = blobstore.create_upload_url(upload_url)
        return self.render_template('/cms/import.html', **params)

    @user_required
    def post(self):
        if not self.form.validate():
            return self.get()

        start_record = int(str(self.request.get('linenum')))
        upload_field = self.request.get('importfile')
        continue_url = self.request.get('continue').encode('ascii', 'ignore')
        if upload_field != '':
            upload_files = self.get_uploads(
                'importfile')  # 'file' is file upload field in the form
            logger.info('Upload Datas: ' + str(upload_files))
            blob_info = upload_files[0]
            start_record = start_record if start_record != '' else 1
            upload_count = self.process_csv(blob_info, start_record)
            self.add_message(
                str(upload_count) + ' entities created successfully.',
                'success')
            if continue_url:
                return self.redirect(continue_url)
            else:
                return self.redirect_to('import-team')
        logger.error('Empty upload file field select correct file')
        message = ('Empty upload file field select correct file')
        self.add_message(message, 'error')
        return self.redirect_to('import-team')

    def process_csv(self, blob_info, start_record, event_id=None):
        update = {}
        upload_count = 0
        row_count = 0

        blob_reader = blobstore.BlobReader(blob_info.key())
        datareader = csv.reader(blob_reader)

        for row in datareader:
            row_count += 1
            if row_count >= (start_record + 1):  #to skip the header row
                logger.info('Starting to parse %s, %s' % (row_count, row[1]))
                entity_type = row[0].lower()
                update['name'] = utils.stringify(row[1])
                # Name is mandatory for all entities
                if update['name'] == '':
                    logger.error('Name is empty. Skipping this record')
                    continue
                alias_name = utils.slugify(update['name'].lower())

                # Event Id check for matches
                if event_id is not None and len(event_id) > 1:
                    event_data = self.eventDao.get_record(event_id)
                    event_alias_name = event_data.alias
                else:
                    event_alias_name = ''

                try:
                    update['sport'] = utils.stringify(row[2]).lower()

                    if entity_type == 'match':
                        update['start_datetime'] = datetime.strptime(
                            row[3], '%d-%m-%Y %I:%M%p')
                        update['end_datetime'] = datetime.strptime(
                            row[4], '%d-%m-%Y %I:%M%p')
                        update['result'] = utils.stringify(row[5])
                        event_alias_name = utils.slugify(row[6].lower(
                        )) if row[6] != '' else event_alias_name
                        update['participant_type'] = utils.stringify(
                            row[7]).lower()
                    elif entity_type == 'player':
                        update['email'] = utils.stringify(row[3])
                        update['phone'] = utils.stringify(row[4])
                        update['teamName'] = utils.stringify(row[5])
                        team_alias_name = utils.slugify(
                            update['teamName'].lower())

                    logger.debug('Constructed Structure for upload ' +
                                 str(update))
                    logger.info('Entity type to be created, ' + entity_type)

                    if entity_type == 'match':
                        import_data = self.form_to_dao_match(
                            alias_name, **update)
                    elif entity_type == 'team':
                        import_data = self.form_to_dao_team(
                            alias_name, **update)
                    elif entity_type == 'player':
                        import_data = self.form_to_dao_player(
                            alias_name, **update)

                    logger.debug('Populated File Data ' + str(import_data))

                    if entity_type == 'match':
                        event = self.eventDao.query_by_alias(event_alias_name)
                        if event is not None:
                            match_exist = self.matchDao.query_by_alias(
                                alias_name, event.key, update['sport'])
                            if match_exist is None:
                                import_data.event_id = event.key
                                key = self.matchDao.persist(
                                    import_data, self.user_info)
                                upload_count += 1
                                logger.info(
                                    'New Match Created for %s with key %s' %
                                    (alias_name, key))
                            else:
                                logger.error('Already Exist of %s:%s' %
                                             (entity_type, update['name']))
                        else:
                            logger.error('Event Name %s doesnot exist' %
                                         (event_alias_name))
                    elif entity_type == 'team':
                        team_exist = self.teamDao.query_by_alias(
                            alias_name, update['sport'])
                        logger.info('Team Exist Data: ' + str(team_exist))
                        if team_exist is None:
                            key = self.teamDao.persist(import_data,
                                                       self.user_info)
                            upload_count += 1
                            logger.info('New Team Created for %s with key %s' %
                                        (alias_name, key))
                        else:
                            logger.error('Already Exist of %s:%s' %
                                         (entity_type, update['name']))
                    elif entity_type == 'player':
                        player_exist = self.playerDao.query_by_email(
                            update['email'])
                        logger.info('Player Exist Data: ' + str(player_exist))
                        if player_exist is None:
                            team_exist = self.teamDao.query_by_team_alias(
                                team_alias_name, self.user_info)
                            logger.info('Exist Team for player: ' +
                                        str(team_exist))
                            if team_exist is None:
                                team_import_data = self.form_to_dao_team_auto(
                                    team_alias_name, **update)
                                team_key = self.teamDao.persist(
                                    team_import_data, self.user_info)
                                logger.info(
                                    'New Team Created for %s with key %s' %
                                    (team_alias_name, team_key))
                                import_data.teams = team_key
                            else:
                                import_data.teams = team_exist.key
                            key = self.playerDao.persist(
                                import_data, self.user_info)
                            upload_count += 1
                            logger.info(
                                'New Player Created for %s with key %s' %
                                (alias_name, key))
                        else:
                            logger.error('Already Exist of %s:%s' %
                                         (entity_type, update['name']))

                    if key is not None:
                        logger.info(
                            str(entity_type) + ' succesfully created/updated')
                    else:
                        logger.error('Already Exist of %s:%s' %
                                     (entity_type, update['name']))

                except StandardError as e:
                    #skipping to next record
                    logger.error('Error occured, %s, for %s' %
                                 (str(e), alias_name))
            else:
                logger.info("skipping record number, %s " % row_count)
        return upload_count

    @webapp2.cached_property
    def form(self):
        return forms.ImportForm(self)

    def form_to_dao_match(self, alias_name, **update):
        try:
            match = Match()
            match.name = update['name']
            #Create an automatic alias for the match
            match.alias = alias_name
            match.sport = update['sport']
            match.participant_type = update['participant_type']
            match.start_datetime = update['start_datetime']
            match.end_datetime = update['end_datetime']
            match.result = update['result']
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return match

    def form_to_dao_team(self, alias_name, **update):
        try:
            team = Team()
            team.name = update['name']
            #Create an automatic alias for the team
            team.alias = alias_name
            team.sport = update['sport']
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return team

    def form_to_dao_team_auto(self, team_alias_name, **update):
        try:
            team = Team()
            team.name = update['teamName']
            #Create an automatic alias for the team
            team.alias = team_alias_name
            team.sport = update['sport']
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return team

    def form_to_dao_player(self, alias_name, **update):
        try:
            player = Player()
            player.name = update['name']
            player.email = update['email']
            player.phone = update['phone']
            player.sport = update['sport']
        except StandardError as e:
            logger.error('Error occured, %s, for %s:%s' %
                         (str(e), type, update['name']))
            raise
        return player