Beispiel #1
0
 def get(self, url):
     user = users.get_current_user()
         
     if user and users.is_current_user_admin():
         context = {'user' : user.nickname()}
         logout_url = users.create_logout_url(self.request.uri)
         context['logout_url'] = logout_url
         if url == 'algorithm.html':
           context['alg'] =  model.getOrderingAlgorithmParams()
         elif url == 'background.html':
           activities = model.getActivities(False)
           i = 0
           for activity in activities:
             activity.index = i
             i += 1
           newActivity = model.ActivityParams()
           newActivity.name = NEW_ACTIVITY_NAME
           newActivity.activity_load = 0
           newActivity.index = i
           newActivity.enabled = False
           newActivity.threshold_total[model.ActivityTypes.ITEM] = 0
           newActivity.threshold_time_sec[model.ActivityTypes.ITEM] = 0
           activities.append(newActivity)
           context['activities'] = activities
           context['timePeriod'] = activityManager.getActivityPeriod()
         elif url =='publishers.html':
           publishers = model.getPublisherSites()
           context['publishers'] = publishers
         elif url =='paymentsconfig.html':
           context['paymentparams'] = model.getPaymentConfig()
         elif url =='ligerpediaconfig.html':
           context['ligerpediaconfig'] = model.getLigerpediaConfig()
         elif url =='defaultlinks.html':
           config = model.getDefaultLinksConfig()
           context['publisher'] = model.getPublisherSite(config.default_links_url)
           context['defaultlinksconfig'] = config
           items = defaultItemList.getOrderedItems()
           views = 0
           for item in items:
             views += item.stats[model.StatType.VIEWS]
           context['items'] = items
           context['totalviews'] = views
         path = ''
         if url and len(url) > 0:
           path = os.path.join(os.path.dirname(__file__), 'webadmin', url)
         else:
           path = os.path.join(os.path.dirname(__file__), 'webadmin', 'index.html')
         self.response.out.write(template.render(path, context))
     elif user and users.is_current_user_admin() == False:
         context = {'user' : user.nickname()}
         login_url = users.create_login_url(self.request.uri)
         context['login_url'] = login_url
         path = os.path.join(os.path.dirname(__file__), 'webadmin', 'unauthorized.html')
         self.response.out.write(template.render(path, context))
     else:
         self.redirect(users.create_login_url(self.request.uri))
Beispiel #2
0
 def getPublisherActivityLoad_(self, publisherUrl):
   needRefresh = False
   if self.publisherActivityLoadUpdateMap.has_key(publisherUrl):
     lastUpdate = self.publisherActivityLoadUpdateMap[publisherUrl]
     now = time.time()
     if now - lastUpdate > self.secToRefreshPublisherLoad:
       needRefresh = True
   if needRefresh or not self.publisherActivityLoadMap.has_key(publisherUrl):
     publisherSite = model.getPublisherSite(publisherUrl)
     self.updatePublisherActivityLoad_(publisherSite)
   return self.publisherActivityLoadMap[publisherUrl]
Beispiel #3
0
 def post(self):
   try:
     BaseHandler.initFromRequest(self, self.request)
     #publisherUrl is space delimited list of publishers
     publishers = self.getParam('publisherUrl').split(" ")
     publishersWithStats = []
     for publisher in publishers:
         publishersWithStats.append(model.getPublisherSite(publisher)) 
     self.common_response.setPublisherSites(publishersWithStats)
   except Exception:
     BaseHandler.logException(self)
   BaseHandler.writeResponse(self)
Beispiel #4
0
 def flushPublisherSiteUpdate(cls, publisherUrl):
   key = cls.getPublisherSiteKey_(publisherUrl)
   updated = memcache.get(key)
   if updated:
     publisherSite = model.getPublisherSite(publisherUrl)
     clone = copy.deepcopy(updated)
     updated.reset(clone)
     # reset counters as soon as possible and write into memcache
     memcache.set(key, updated)
     publisherSite.updateStats(clone)
     publisherSite.put()    
     if activityManager.needsToRefreshDefaultOrderedItems(clone): 
       cls.refreshCacheForDefaultOrderedItems(publisherUrl)   
Beispiel #5
0
 def post(self):
   try:
     BaseHandler.initFromRequest(self, self.request)
     # TODO: assert https
     item = BaseHandler.getItem(self, self.getParam('itemId'))
     paymentConfig = model.getPaymentConfig()
     if item and self._verifyTransaction(item, paymentConfig.test_mode):  
       price = int(self.getParam('price'))
       item.updatePrice(price, self.getParam('email'))
       item.put()
       publisherSite = model.getPublisherSite(item.publisherUrl)
       db.run_in_transaction(updatePublisherPrice_, publisherSite.key(), price)
       itemList.refreshCacheForDefaultOrderedItems(item.publisherUrl)
       logging.info('Number of price updates : %d' % len(item.payments))
       logging.info('Last price update : %s' % str(item.payments[len(item.payments)-1]))
       if paymentConfig.send_email:
         BaseHandler.sendConfirmationEmail(self, self.getParam('email'), self.getParam('price'), item)                                   
     self.common_response.setItems([item], response.ItemInfo.WITH_PRICE)
   except Exception:
     BaseHandler.logException(self)
   BaseHandler.writeResponse(self)