def get(self): os_type = self.request.get(PARAM_OS_TYPE) # create a new anonymous user entity, give json response with hashed id new_user = entities.User(os_type = os_type) new_user.put() generated_hash = wutil.createSecret( new_user.key().id() ) dictionary = {PARAM_USER_ID : generated_hash} self.response.headers['Content-Type'] = "application/json; charset=utf-8" self.write( json.dumps(dictionary) )
def get(self): os_type = self.request.get(PARAM_OS_TYPE) # create a new anonymous user entity, give json response with hashed id new_user = entities.User(os_type=os_type) new_user.put() generated_hash = wutil.createSecret(new_user.key().id()) dictionary = {PARAM_USER_ID: generated_hash} self.response.headers[ 'Content-Type'] = "application/json; charset=utf-8" self.write(json.dumps(dictionary))
def get(self): userHash = self.request.cookies.get(PARAM_USER_ID, None) if (userHash is None): os_type = self.request.headers["User-Agent"] # create a new anonymous user entity, give json response with hashed id new_user = entities.User(os_type=os_type) new_user.put() generated_hash = wutil.createSecret(new_user.key().id()) expires = datetime.now() + timedelta(days=1500) dead_date = expires.strftime('%a, %d-%b-%Y %H:%M:%S') self.response.headers.add_header( 'Set-Cookie', '%s=%s; Path=/; expires=%s;' % (PARAM_USER_ID, generated_hash, dead_date)) # user should have an identifier foodType = self.request.get(PARAM_FOOD_TYPE) if foodType not in (FOOD_MARKETPLACE, FOOD_SMOKEHOUSE): foodType = FOOD_MARKETPLACE dataTuple = dd.fetchRatings(foodType) entry = dataTuple[0] entry_id = entry.key().id() # find if the user voted, and change vote arrows cookie = self.request.cookies.get(str(entry_id), None) up_selected = "" down_selected = "" if cookie is not None: if cookie == '1': up_selected = "_selected" if cookie == '0': down_selected = "_selected" if entry.totalVotes == 0: percentage = 0 else: percentage = int( (((float(entry.upvotes) / entry.totalVotes) * 100))) downvotes = entry.totalVotes - entry.upvotes voteComments = dataTuple[1] commentHTML = dd.generateCommentsHTML(voteComments) self.render("index.html", type_name=entry.name, percentage=percentage, upvotes=entry.upvotes, downvotes=downvotes, entry_id=entry_id, up=up_selected, down=down_selected, comments=commentHTML)
def get(self): userHash = self.request.cookies.get(PARAM_USER_ID, None) if (userHash is None): os_type = self.request.headers["User-Agent"] # create a new anonymous user entity, give json response with hashed id new_user = entities.User(os_type = os_type) new_user.put() generated_hash = wutil.createSecret( new_user.key().id() ) expires = datetime.now() + timedelta(days=1500) dead_date = expires.strftime('%a, %d-%b-%Y %H:%M:%S') self.response.headers.add_header('Set-Cookie', '%s=%s; Path=/; expires=%s;' % (PARAM_USER_ID, generated_hash, dead_date)) # user should have an identifier foodType = self.request.get(PARAM_FOOD_TYPE) if foodType not in (FOOD_MARKETPLACE, FOOD_SMOKEHOUSE): foodType = FOOD_MARKETPLACE dataTuple = dd.fetchRatings(foodType) entry = dataTuple[0] entry_id = entry.key().id() # find if the user voted, and change vote arrows cookie = self.request.cookies.get(str(entry_id), None) up_selected = "" down_selected = "" if cookie is not None: if cookie == '1': up_selected = "_selected" if cookie == '0': down_selected = "_selected" if entry.totalVotes == 0: percentage = 0 else: percentage = int((((float(entry.upvotes) / entry.totalVotes) * 100))) downvotes = entry.totalVotes - entry.upvotes voteComments = dataTuple[1] commentHTML = dd.generateCommentsHTML(voteComments) self.render("index.html", type_name=entry.name, percentage=percentage, upvotes=entry.upvotes, downvotes=downvotes, entry_id = entry_id, up=up_selected, down=down_selected, comments=commentHTML)