Esempio n. 1
0
 def query_by_owner(self, user, status='all'):
   logger.info('NdbPlaygroundDao:: DBHIT: query_by_owner for %s ' % user.email)
   owner_query = Playground.query()
   if not user_has_role(user, 'admin'):
     owner_query = Playground.query(ndb.OR(Playground.owners == user.key, Playground.created_by == user.key, Playground.updated_by == user.key))
   if status != 'all':
     status_value = STATUS_DICT.get(status)
     owner_query = owner_query.filter(status == status_value)
   owner_query = owner_query.order(-Playground.updated_on)
   return owner_query.fetch()
Esempio n. 2
0
  def search_datastore(self, status, curs, **params):
    if status != 'all':
      status_value = STATUS_DICT.get(status)
      logger.debug('status %d ' % (status_value))
      search_query = Playground.query(Playground.status == status_value)
    else:
      search_query = Playground.query()
    for key, value in params.items():
      #Constructing named queries for structured properties the round about way.
      # TO explore a better way later.
      if '.' in key and value is not None:
        struct, attr = key.split('.')
        if struct == 'address':
          search_query = search_query.filter(getattr(Playground.address, attr) == value)
        elif struct == 'contactInfo':
          search_query = search_query.filter(getattr(Playground.contact_info, attr) == value)
      else:
        if key == 'sport' and value is not None:
          search_query = self.build_query_for_sport(search_query, value, True)        
        elif value is not None:
          search_query = search_query.filter(getattr(Playground, key) == value)     
    #search_query = search_query.order(-Playground.updated_on)
    logger.info('NdbPlaygroundDao:: DBHIT: search query  ' + str(search_query))
    #return search_query.fetch()
    
    search_forward = search_query.order(-Playground.updated_on)
    search_reverse = search_query.order(Playground.updated_on)
    
    # Fetch a page going forward.
    logger.info('NdbPlaygroundDao:: DBHIT: Cursor ' + str(curs))
    if curs is not None:
        curs = Cursor(urlsafe=curs)
        next_data, next_curs, next_more = search_forward.fetch_page(PAGE_SIZE, start_cursor=curs)
        prev_data, prev_curs, prev_more = search_reverse.fetch_page(PAGE_SIZE, start_cursor=next_curs.reversed())
    else:
        next_data, next_curs, next_more = search_forward.fetch_page(PAGE_SIZE)
        if next_curs is not None:
            prev_data, prev_curs, prev_more = search_reverse.fetch_page(PAGE_SIZE, start_cursor=next_curs.reversed())
        else:
            prev_data = None
            prev_curs = None
            prev_more = None
        
    # Fetch the same page going backward.
    #if next_curs is not None:
     #   rev_cursor = next_curs.reversed()
      #  prev_data, prev_curs, prev_more = search_reverse.fetch_page(6, start_cursor=rev_cursor)
    #else:
        #curs = Cursor(urlsafe=curs)
        #prev_data, prev_curs, prev_more = search_reverse.fetch_page(6, start_cursor=curs)        

    return (next_data, next_curs, next_more, prev_data, prev_curs, prev_more)
Esempio n. 3
0
 def get_featured(self, city_name=None, sport=None, no_record=8):
     logger.info('NdbPlaygroundDao:: DBHIT: get_featured for %s, %s, %s ' % (city_name, sport, no_record))
     playground_query = Playground.query(Playground.status == 2, Playground.featured == True)
     if city_name is not None:
       playground_query = playground_query.filter(Playground.address.city == city_name.lower())
     if sport is not None:
       playground_query = self.build_query_for_sport(playground_query, sport, True)
     playground_query = playground_query.order(-Playground.created_on)
     return list(playground_query.fetch(no_record))
Esempio n. 4
0
 def get_recommend(self, locality=None, sport=None, no_record=8):
     logger.info('NdbPlaygroundDao:: DBHIT: get_recommend for %s, %s, %s ' % (locality, sport, no_record))
     playground_query = Playground.query(Playground.status == 2)
     if locality is not None and locality != '' and locality != 'None':       
       playground_query = playground_query.filter(ndb.OR(Playground.address.locality == locality.lower() , Playground.address.city == locality.lower()))    
     if sport is not None and sport != '' and sport != 'None':
       playground_query = self.build_query_for_multisport(playground_query, sport)
     playground_query = playground_query.order(-Playground.created_on)      
     if no_record > -1:
       return list(playground_query.fetch(no_record))
     else: #return all. simulating -1 for app engine
       return list(playground_query.fetch())
Esempio n. 5
0
 def get_active(self, city_name=None, sport=None, no_record=8):
     logger.info('NdbPlaygroundDao:: DBHIT: get_active for %s, %s, %s ' % (city_name, sport, no_record))
     playground_query = Playground.query(Playground.status == 2)
     if city_name is not None:
       playground_query = playground_query.filter(Playground.address.city == city_name.lower())
     if sport is not None:
       playground_query = self.build_query_for_sport(playground_query, sport)
     playground_query = playground_query.order(-Playground.created_on)
     if no_record > -1:
       return list(playground_query.fetch(no_record))
     else: #return all. simulating -1 for app engine
       return list(playground_query.fetch())
Esempio n. 6
0
    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')
Esempio n. 7
0
 def query_by_alias(self, alias):
     logger.info('NdbPlaygroundDao:: DBHIT: query_by_alias for %s ' % alias)
     playground_query = Playground.query(Playground.alias == alias)
     playground = playground_query.fetch(1)
     return playground[0] if playground is not None and len(playground) > 0 else None