def getDeltaGigsByTimestamp(self, city, gigTimestamp): gig_query = Gig.all() gig_query.filter('city =', city) gig_query.filter('timestamp >', gigTimestamp) gig_query.order('-timestamp') #TODO: return all results in db tempGigs = gig_query.fetch(ClientGetGigs.CLIENT_GET_LIMIT) currDateTime = datetime.now() #can't do in one query as only one inequality filter allow in query #no need to convert as will be saved in db in utc format only gigs = [g for g in tempGigs if g.timing > currDateTime] return gigs
def getGigs(self, city, validRecentGig): #get recent gig stored at client gig_query = Gig.all() gigs = None if validRecentGig: #get all gigs gr8r than this gig's timestamp and for passed city #also timing > than current time gigs = self.getDeltaGigsByTimestamp(validRecentGig.city, validRecentGig.timestamp) else: #probably new update, get all gigs corresponding to city gig_query.filter('city =', city) #gig_query.filter('timing >', datetime.now()) #gig_query.order('timing') gig_query.order('-timestamp') #TODO: return all results from db tempGigs = gig_query.fetch(ClientGetGigs.CLIENT_GET_LIMIT) currDateTime = datetime.now() gigs = [g for g in tempGigs if g.timing > currDateTime] return gigs
def post(self): user = users.get_current_user(); rootPath = os.path.split(os.path.dirname(__file__))[0] if user and users.is_current_user_admin(): #delete the specified gigs from db prev = False next = True gigIds = self.request.get_all('gig_id'); deletedGigs = 0 for id in gigIds: gig = Gig.get_by_id(int(id)) if gig: gig.delete() deletedGigs += 1 gigs_query = Gig.all().order('-timing') gigs = gigs_query.fetch(DeleteGigs.PAGESIZE+1) if len(gigs) == DeleteGigs.PAGESIZE+1: gigs = gigs[:DeleteGigs.PAGESIZE] next = True template_values = { "gigslen" : len(gigs), "gigs" : gigs, 'username' : user.nickname(), 'success_msg' : str(deletedGigs)+" gigs successfully deleted", 'next' : next, 'previous' : prev, 'lastResultIndex' : len(gigs), } path = os.path.join(rootPath, "html/view.html") else: #insufficient privileges template_values = { 'error_msg' : "insufficient privileges" } path = os.path.join(rootPath, "html/error.html") self.response.out.write(template.render(path, template_values))
def post(self): user = users.get_current_user(); rootPath = os.path.split(os.path.dirname(__file__))[0] if user and users.is_current_user_admin(): #current user is admin #TODO: value error if Xscripting goToNext = self.request.get('goToNext'); goToPrevious = self.request.get('goToPrevious'); try: prevLastResultIndex = int(self.request.get('lastResultIndex')) except ValueError: prevLastResultIndex = 0 reqArtist = self.request.get('artist').strip() reqVenue = self.request.get('venue').strip() reqCity_loc = self.request.get('city_loc').strip() reqCity = self.request.get('city').strip().lower() reqGenre = self.request.get('genre').strip() reqTiming = self.request.get('date_time').strip().lower() next = False prev = False calcOffset = 0 if goToNext and len(goToNext) > 0: #show next PAGESIZE results calcOffset = prevLastResultIndex elif goToPrevious and len(goToPrevious) > 0: #show previous PAGESIZE results if (prevLastResultIndex % ViewGigs.PAGESIZE) != 0: prevLastResultIndex = (prevLastResultIndex / ViewGigs.PAGESIZE) * ViewGigs.PAGESIZE calcOffset = prevLastResultIndex - ViewGigs.PAGESIZE; else: calcOffset = prevLastResultIndex - 2*ViewGigs.PAGESIZE; calcOffset = 0 if (calcOffset < 0) else calcOffset else: calcOffset = 0 gigs_query = Gig.all() if reqTiming and len(reqTiming) > 0: #validate date time string timing = self.checkDateTime(reqTiming) gigs_query.filter('timing =', timing) gigs_query.order('-timing') if reqArtist and len(reqArtist) > 0: gigs_query.filter('artist >=', reqArtist) gigs_query.filter('artist <', reqArtist+u'\ufffd') gigs_query.order('artist') if reqVenue and len(reqVenue) > 0: gigs_query.filter('venue >=', reqVenue) gigs_query.filter('venue <', reqVenue+u'\ufffd') gigs_query.order('venue') if reqCity_loc and len(reqCity_loc) > 0: gigs_query.filter('city_loc >=', reqCity_loc) gigs_query.filter('city_loc <', reqCity_loc+u'\ufffd') gigs_query.order('city_loc') if reqCity and len(reqCity) > 0: gigs_query.filter('city >=', reqCity) gigs_query.filter('city <', reqCity+u'\ufffd') gigs_query.order('city') if reqGenre and len(reqGenre) > 0: gigs_query.filter('genre >=', reqGenre) gigs_query.filter('genre <', reqGenre+ u'\ufffd') gigs_query.order('genre') gigs_query.order('-timing') gigs = gigs_query.fetch(limit=FindPage.PAGESIZE+1, offset=calcOffset) if len(gigs) == ViewGigs.PAGESIZE + 1: gigs = gigs[:ViewGigs.PAGESIZE] next = True else: next = False if calcOffset == 0: prev = False else: prev = True lastResultIndex = calcOffset + len(gigs) template_values = { 'arist' : reqArtist, 'venue' : reqVenue, 'city_loc' : reqCity_loc, 'city' : reqCity, 'genre' : reqGenre, 'date_time' : reqTiming, "gigslen" : len(gigs), "gigs" : gigs, 'username' : user.nickname(), 'lastResultIndex' : lastResultIndex, 'next' : next, 'previous' : prev } path = os.path.join(rootPath, "html/find_results.html") else: #not allowed access render error page template_values = { 'errorMsg' : "Not sufficient privileges." } path = os.path.join(rootPath, "html/find_results.html") self.response.out.write(template.render(path, template_values))
def get(self): user = users.get_current_user(); rootPath = os.path.split(os.path.dirname(__file__))[0] if user and users.is_current_user_admin(): #TODO: value error if Xscripting goToNext = self.request.get('goToNext'); goToPrevious = self.request.get('goToPrevious'); try: prevLastResultIndex = int(self.request.get('lastResultIndex')) except ValueError: prevLastResultIndex = 0 next = False prev = False calcOffset = 0 gigs_query = Gig.all().order('-timing') if goToNext and len(goToNext) > 0: #show next PAGESIZE results calcOffset = prevLastResultIndex elif goToPrevious and len(goToPrevious) > 0: #show previous PAGESIZE results if (prevLastResultIndex % ViewGigs.PAGESIZE) != 0: prevLastResultIndex = (prevLastResultIndex / ViewGigs.PAGESIZE) * ViewGigs.PAGESIZE calcOffset = prevLastResultIndex - ViewGigs.PAGESIZE; else: calcOffset = prevLastResultIndex - 2*ViewGigs.PAGESIZE; calcOffset = 0 if (calcOffset < 0) else calcOffset else: calcOffset = 0 gigs = gigs_query.fetch(limit=ViewGigs.PAGESIZE+1, offset=calcOffset) if len(gigs) == ViewGigs.PAGESIZE + 1: gigs = gigs[:ViewGigs.PAGESIZE] next = True else: next = False if calcOffset == 0: prev = False else: prev = True lastResultIndex = calcOffset + len(gigs) template_values = { "gigslen" : len(gigs), "gigs" : gigs, 'username' : user.nickname(), 'lastResultIndex' : lastResultIndex, 'next' : next, 'previous' : prev } path = os.path.join(rootPath, "html/view.html") else: template_values = { 'errorMsg' : 'Not sufficient privileges' } path = os.path.join(rootPath, "html/error.html") self.response.out.write(template.render(path, template_values))