Esempio n. 1
0
 def get(self,i_d):
     if re.match(r'[0-9]*',i_d): #make sure it's only a number just in case a non-integer id does slip into the database
         #query=db.GqlQuery("SELECT * FROM DBQuote WHERE quote_id=:x",x=int(i_d)).get() #without memcached
         query=qdb_cache.return_quote(i_d)
     else:
         query=None
     if query: #makes sure only the specified quote is displayed, if any
         self.render("singlequote.html",DBQuote=query)
     else:
         self.redirect('/error')
Esempio n. 2
0
 def get(self):
     quote_ids=qdb_cache.return_ID_list()
     if quote_ids is None:#database is empty
         quotes=[]
     else:
         quote_ids=quote_ids.IDs #get quote IDs
         quote_ids.sort()
         quote_ids.reverse() #most recent first
         #quotes_per_page=20 #set at start of file
         quote_list=quote_ids[:quotes_per_page] #gets latest quotes, or all if quotes per page>total
         quotes=[qdb_cache.return_quote(id) for id in quote_list]
     self.render('mainpage.html',quotes=quotes)
Esempio n. 3
0
 def get(self,u_or_d,i_d): #u_or_d decides whether the vote is up or down
     if re.match(r'[0-9]*',i_d): #make sure it's only a number just in case a non-integer id does slip into the database
         ip = '"'+str(self.request.remote_addr)+':'+str(i_d)+'"' #unique ID for quote ID/IP address combination
         query=qdb_cache.return_quote(i_d)
     if not_spammer(ip):
         delta={'u':1,'d':-1}
         query.score+=delta[u_or_d] #upvotes for u, downvotes for d
         qdb_cache.update_quote(i_d,query) #update cache and db
         visitor=Visitor(ip=str(ip),last_voted=time.time(),Banned=False) #updates visitor with the new last voted time
         qdb_cache.update_ip(ip,visitor) #update db and cache with new visitor instance
         self.write('Your vote was recorded. <a href=\'/\'>Return to the main page.</a>')
     else:
         self.write('You\'re doing that too much. Try again in 24 hours.')
Esempio n. 4
0
 def get(self,i_d):
     if re.match(r'[1-9][0-9]*',i_d): #make sure i_d is a number; this code is repeated elsewhere so there's probably a better way of doing it
         query=qdb_cache.return_quote(i_d)
     else:
         query=None
     if not query:
         self.write(query)
         return
         self.redirect('/error')
     else:
         if query.Flagged==True:
             query.Flagged=False #mark quote as flagged
             qdb_cache.update_quote(i_d,query) #update quote with flagged status
             self.write('Quote flag removed. <a href=\'/\'>Return to the main page.</a>') #placeholder message until page is written
         else:
             self.write('Quote flag already removed. <a href=\'/\'>Return to the main page.</a>')
Esempio n. 5
0
 def get(self):
     #quotes_per_page=20 #set at start of file
     quote_id_list=qdb_cache.return_ID_list().IDs # list of quote ids
     rand_id_list=random_list(quote_id_list,quotes_per_page)#gives a list up to quotes_per_page long of quote_id_list numbers selected at random
     random_quotes=[qdb_cache.return_quote(quote_id) for quote_id in rand_id_list] #list of random quotes
     self.render('page.html',quotes=random_quotes,param='Random')