def post(self): quote_uuid = self.request.get(self.http_post_key) current_vote_count = tlq_util.get_from_cache("%s%s" % (self.cache_uuid_prefix, quote_uuid), 0) # its possible that this memcache entry expired, we should check the original list for a rating if not current_vote_count: cached_quote = tlq_util.get_cache_quote(quote_uuid) if cached_quote is None: logging.warning("Someone just tried voting on a quote that isn't in the cache.") return else: if cached_quote["rating"] != current_vote_count: logging.info("Apparently the voting key expired. Good thing the list still existed.") current_vote_count = cached_quote["rating"] new_rating = 0 if self.request.get(self.vote_up_or_down_key) == "up": logging.info("Setting vote count to %s." % (current_vote_count + 1)) new_rating = current_vote_count + 1 elif self.request.get(self.vote_up_or_down_key) == "down": logging.info("Setting vote count to %s." % (current_vote_count - 1)) new_rating = current_vote_count - 1 memcache.set("%s%s" % (self.cache_uuid_prefix, quote_uuid), current_vote_count - 1) else: logging.info("Thumbs up / down not specified correctly.") if new_rating <= 0: new_rating = 0 memcache.set("%s%s" % (self.cache_uuid_prefix, quote_uuid), new_rating) tlq_util.update_rating_in_memcache(quote_uuid, new_rating) tlq_util.write_out_json(self.response, True)
def post(self): submitted_quote = self.request.get(self.http_post_quote_key) quote_submitter = self.request.get(self.http_post_user_key) success = False if len(submitted_quote) <= self.max_quote_size and len(submitted_quote) >= self.min_quote_size: success = True tlq_util.put_in_quote_set(tlq_util.form_quote(submitted_quote, quote_submitter)) tlq_util.write_out_json(self.response, success)
def get(self): if self.request.get(self.http_post_user_key) != "": tlq_util.write_out_json( self.response, [ quote.to_dict() for quote in tlq_util.fetch_quotes_for_user_uuid(self.request.get(self.http_post_user_key)) ], ) elif self.request.get(self.http_get_clear_user_quotes_key) != "": tlq_util.clear_user_quotes_in_datastore(self.request.get(self.http_get_clear_user_quotes_key)) else: current_quote = tlq_util.get_random_quote(self.request.get(self.http_get_last_quote_uuid_key)) if current_quote is None: current_quote = tlq_util.form_quote(self.default_return_quote) tlq_util.write_out_json(self.response, current_quote)
def get(self): if self.request.get(self.remove_item_key) != "": memcache.delete(self.request.get(self.remove_item_key)) elif self.request.get(self.return_item_key) != "": tlq_util.write_out_json( self.response, tlq_util.get_from_cache(self.request.get(self.return_item_key), None) ) elif self.request.get(self.persist_quotes_key) != "": tlq_util.store_quotes_in_datastore() tlq_util.write_out_json(self.response, {"result": "success"}) elif self.request.get(self.generate_fake_quotes_key) != "": tlq_util.generate_fake_quotes() else: logging.info("GET request handling entire cache clearing.") quotes = tlq_util.get_all_quotes() if len(quotes) > self.maximum_quotes_before_reset or self.request.get(self.force_clear_key) == "true": memcache.flush_all() tlq_util.write_out_json(self.response, True)
def get(self): number_of_quotes = int(self.request.get(self.http_list_size_key)) tlq_util.write_out_json(self.response, tlq_util.get_all_quotes()[:number_of_quotes])