Example #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))
Example #2
0
 def updateActivities(self):
   errors = []
   successes = []
   index = 0
   activities = []
   
   activity = self.retrieveActivity(index)
   while activity:
     if activity and activity.name != NEW_ACTIVITY_NAME:
       errorMsg = activity.getErrors()
       if errorMsg != '':
         errors.append('ERROR %s %s' % (activity.name, errorMsg))
       else:
         activities.append(activity)
     index += 1
     activity = self.retrieveActivity(index)
   
   activityMap = {}
   existingActivities = model.getActivities(False)
   for a in existingActivities:
     activityMap[a.name] = a
   
   for a in activities:
     if activityMap.has_key(a.name):
       if activityMap[a.name] and activityMap[a.name].updateFrom(a):
         successes.append('UPDATED: %s' % a.name)
         activityMap[a.name].put()
       activityMap[a.name] = None
     else:
       a.put()
       successes.append('CREATED: %s' % a.name)
   for a in activityMap.values():
     if a:
       successes.append('DELETED: %s' % a.name)
       a.delete()
             
   self.response.out.write(' / '.join(successes) + 
                             ' / '.join(errors))
Example #3
0
 def lazyLoad_(self, refresh):
   if not len(self.activities) or refresh:
     self.lastLoad = time.time()
     self.activities = model.getActivities(True)
     logging.info('Reloading %d activities' % len(self.activities))