def get(self):
        user = users.get_current_user()
        
        if users.get_current_user():
            if users.is_current_user_admin():
                highlight_id = 'meme_ipad_dashboard'
                highlight_query = None
                highlight_amount = None
                highlights = Highlight.all().filter('name =', highlight_id)

                for highlight in highlights:
                    highlight_query = highlight.query
                    highlight_amount = highlight.amount
                
                template_values = { 
                    'img_upload_url': blobstore.create_upload_url('/v1/img/upload'), 
                    'host': self.request.headers['Host'],
                    'logout_url': users.create_logout_url('/'),
                    'highlight_id': highlight_id,
                    'highlight_query': highlight_query or '',
                    'highlight_amount': highlight_amount or '',
                }
                path = os.path.join(os.path.dirname(__file__), '../templates/admin.html')
                self.response.out.write(template.render(path, template_values))
            else:
                self.error(403)
                self.response.out.write('<html><body><h1>Forbidden</h1><a href=\"%s\">sign out</a></body></html>' % users.create_logout_url('/'))
        else:
            self.response.out.write('<html><body><a href=\"%s\">sign in</a></body></html>' % users.create_login_url('/admin'))
            
 def get(self, name):
     highlights = Highlight.all().filter('name =', name)
     highlight_data = None
     
     for highlight in highlights:
         highlight_data = {
             'name': highlight.name, 
             'query': highlight.query, 
             'amount': highlight.amount, 
         }
     
     if highlight_data:
         self.response.headers['Content-Type'] = 'application/json'
         self.response.out.write(simplejson.dumps(highlight_data))
     else:
         self.error(404)
         self.response.out.write('Not found')
Beispiel #3
0
  def get(self):
    out = ""
    first_entry = Entry.all().order('date').get().date

    month = date(first_entry.year, first_entry.month, 1)
    while month < date.today():
      h = Highlight.all().filter("date =", month).filter("period =", "month").get()

      if h:
        out += "<h2>%s</h2>\n" % month.strftime("%B %Y")
        out += h.entry.render()
      else:
        out += "<a href='/highlights/month/%d'><h2>%s</h2></a>" % (
          month.toordinal(), month.strftime("%B %Y"))
      month = next_month(month)

    self.response.out.write(indexTemplate.render({
      'title': 'Highlights',
      'body': out,
      'active_page': 'highlights'
    }))
 def post(self):
     highlights = Highlight.all().filter('name =', self.request.get('highlight_name'))
     highlight = None
     
     # try to find the highlight already persisted
     for h in highlights:
         highlight = h
     
     # if highlight wasn't found, means that we sould create another one
     if highlight is None:
         highlight = Highlight(name=self.request.get('highlight_name'))
     
     # add new data to highlight and...
     highlight.query = self.request.get('highlight_query')
     highlight.amount = int(self.request.get('highlight_amount'))
     
     # ...create or update
     highlight.put()
     
     self.redirect('/admin')
Beispiel #5
0
 def post(self, ordinal):
   e = Entry.get(self.request.get('key'))
   h = Highlight(period='month', entry=e, date=date.fromordinal(int(ordinal)))
   h.put()
   self.redirect('/highlights')