def Handle(self, data): user = users.get_current_user() response = { 'is_admin': users.is_current_user_admin(), 'is_new_user': models.IsNewUser(user), 'connection_info': models.GetConnectionInfo(user.user_id()), 'signed_in_as_name': user.email(), 'switch_account_url': users.create_login_url('/').replace('passive=true', 'passive=false') } # We replace 'passive=true' with 'passive=false' so that it shows this page # that allows to switch account: # with passive=true it just silently relogs in under the current account. # See also: # - https://p.ota.to/blog/multiple-google-account-sign-in-on-app-engine/ if config.IsDev(): response['theme'] = 'gray' else: response['theme'] = 'green' self.SendJson(response)
def _SetXSRFCookie(self): """Generates XSRF token.""" user = users.get_current_user() if not user: return token = xsrf.GenerateToken(self._GetXsrfSecret(), user.user_id(), '') # Allow XSRF cookie over HTTP on dev server (which has no HTTPS). # We don't set httponly because we need the client JavaScript code to read # it and put it in the X-XSRF-TOKEN header. self.response.set_cookie(XSRF_COOKIE, token, httponly=False, secure=not config.IsDev())
# ndb.toplevel makes sure that all *_async() functions that we didn't wait for # with get_result() finish before the handler returns. application = ndb.toplevel( webapp2.WSGIApplication( [ ('/rest/ratingHistory', RatingHistoryHandler), ('/rest/rate', RateHandler), ('/rest/extendedPageDetails', ExtendedPageDetailsHandler), ('/rest/recommendations', RecommendationsHandler), ('/rest/pastRecommendations', PastRecommendationsHandler), ('/rest/markUnread', MarkUnreadHandler), ('/rest/popularPages', PopularPagesHandler), ('/rest/deleteRating', DeleteRatingHandler), ('/rest/getConfig', GetConfigHandler), ('/rest/categories', CategoriesHandler), ('/rest/addCategory', AddCategoryHandler), ('/rest/renameCategory', RenameCategoryHandler), ('/rest/removeCategory', RemoveCategoryHandler), ('/rest/suggestCategory', SuggestCategoryHandler), ('/rest/setPageCategory', SetPageCategoryHandler), ('/rest/requestExportRatings', RequestExportRatingsHandler), ('/rest/exportStatus', ExportStatusHandler), ('/rest/deleteAccount', DeleteAccountHandler), # Admin actions. ('/rest/admin/actions', AdminActionsHandler), ('/rest/admin/executeAction', AdminExecuteActionHandler), ('/download_history', DownloadHistoryHandler), ('/', MainPageHandler) ], debug=config.IsDev()))
"""Saves past recommendations and caches the item ids of past recommendations.""" from datetime import datetime from datetime import timedelta from google.appengine.api import memcache from google.appengine.ext import deferred from google.appengine.ext import ndb from recommender import config from recommender import items from recommender import models from recommender import time_periods TIME_TO_COMMIT_PAST_RECOMMENDATIONS = timedelta( minutes=20 if config.IsDev() else 60) def SavePastRecommendations(user_id, time_period, recommendations): time_period_numeric = time_periods.Get(time_period)['numeric'] user_key = models.UserKey(user_id) save_time = datetime.now() past_recommendations = [ models.PastRecommendation( key=ndb.Key(models.PastRecommendation, str(time_period_numeric) + ':' + r.destination_url, parent=user_key), user_id=user_id, item_id=r.item_id or items.UrlToItemId(r.destination_url), url=r.destination_url, weight=r.weight,
from datetime import datetime from datetime import timedelta import logging import pickle from mapreduce import base_handler from mapreduce import control as mr_control from mapreduce import mapper_pipeline from mapreduce import mapreduce_pipeline from pipeline import pipeline import webapp2 from recommender import config from recommender import models from recommender import recommendations DEFAULT_SHARDS = 10 if not config.IsDev() else 1 def StartDatetimeFromContext(): return LoadFromContext('start_datetime') class SelfCleaningPipeline(base_handler.PipelineBase): def finalized(self): if not self.was_aborted: self.cleanup() routes = []
if page_info.feed_url: UpdateFeed(feeds.AddFeed(page_info.feed_url, page_info.feed_title)) stats['own_feed'] = page_info.feed_url # If the page itself is a feed url then also register it. if page_info.is_feed: UpdateFeed(feeds.AddFeed(page_info.canonical_url, page_info.title)) stats['own_feed'] = page_info.canonical_url RatingAdded(models.Source(models.SOURCE_TYPE_USER, user_id, category_id), url, rating) return stats DELAY_BEFORE_UPDATING_CONNECTIONS = (timedelta( seconds=10) if config.IsDev() else timedelta(minutes=1)) def RatingAdded(source, url, rating): source = models.SerializeSource(source) deferred.defer( RatingAddedImpl, source, url, rating, _queue='recommendation-updates', _countdown=DELAY_BEFORE_UPDATING_CONNECTIONS.total_seconds()) def RatingAddedImpl(source, url, rating): source = models.DeserializeSource(source)