Beispiel #1
0
  def get(self):
    req = self.request
    after = req.get('after')

    after_date = datetime.fromtimestamp(float(after))
    q = Meme.all()
    q.order('-create_datetime')
    if after:
      q.filter('create_datetime >', after_date)
    q.filter('listed', True)

    memes = []
    first_date = None
    for meme in q.run(limit=1):
      if not first_date:
        first_date = meme.create_datetime
      memes.append(meme.create_data())

    if len(memes) == 0:
      self.response.write('')
      return

    timestamp = calendar.timegm(first_date.utctimetuple()) + 1

    html = template_helper.render('partial/stream_memes.html',
      memes=memes,
      first_date=timestamp)
    self.response.write(html)
Beispiel #2
0
  def get(self, user_name):
    req = self.request

    count = int(req.get('count', 20))
    if count > 100:
      count = 100

    # TODO(d): Super hack.
    user_email = utils.make_user_email(user_name)

    q = Meme.all().order('-create_datetime').filter('creator', user_email)

    cursor = req.get('cursor')
    if cursor:
      q.with_cursor(cursor)

    memes = []
    date_buckets = []
    date_buckets.append(memes)
    for meme in q.run(limit=count):
      memes.append(meme.create_data())

    page_title = user_name + '\'s Memes'

    html = template_helper.render('view_memes.html',
      page_title=page_title,
      date_buckets=date_buckets)
    self.response.write(html)
Beispiel #3
0
  def get(self):
    req = self.request

    count = int(req.get('count', 75))
    if count > 100:
      count = 100

    q = MemeTemplate.all()
    q.order('-last_used')
    cursor = req.get('cursor')
    if cursor:
      q.with_cursor(cursor)

    templates = []
    for template in q.run(limit=count):
      template_data = Expando({
        'name': template.name,
        'width': template.width,
        'height': template.height
      })
      templates.append(template_data)

    sorted_templates = sorted(templates[:], sort_templates)

    html = template_helper.render('view_templates.html',
      templates=templates,
      alpha_sorted_templates=sorted_templates,
      cursor=q.cursor)
    self.response.write(html)
Beispiel #4
0
    def get(self, meme_id):
        meme = Meme.get_by_key_name(meme_id)
        if not meme:
            self.error(404)
            return

        if not meme:
            self.error(400)
            return

        voters = []
        for voter in meme.voters:
            voters.append(voter.split("@")[0])

        html = template_helper.render("partial/voters.html", voters=voters)
        self.response.write(html)
Beispiel #5
0
  def get(self, meme_id):
    req = self.request

    meme = Meme.get_by_key_name(meme_id)
    if not meme:
      self.error(404)
      return

    author_name = utils.make_user_name(meme.creator)
    meme_data = meme.create_data()

    page_title = meme.template_name + ' Meme by ' + author_name
    html = template_helper.render('view_meme.html',
      page_title=page_title,
      meme=meme_data)
    self.response.write(html)
Beispiel #6
0
  def get(self):
    req = self.request

    template_name = sanitize.remove_tags(req.get('template_name'))
    if not template_name:
      self.error(400)
      return

    template = MemeTemplate.get_by_key_name(template_name)
    if not template:
      self.error(400)
      return

    is_owner = users.get_current_user().email() == template.creator

    html = template_helper.render('create_meme.html',
      name=template.name,
      is_owner=is_owner)
    self.response.write(html)
Beispiel #7
0
  def get(self):
    req = self.request

    q = Meme.all()
    q.order('-create_datetime')
    q.filter('listed', True)

    page_title = 'Live Meme Stream'

    memes = []
    first_date = None
    for meme in q.run(limit=25):
      if not first_date:
        first_date = meme.create_datetime
      memes.append(meme.create_data())

    timestamp = calendar.timegm(first_date.utctimetuple()) + 1

    html = template_helper.render('stream.html',
      page_title=page_title,
      memes=memes,
      first_date=timestamp)
    self.response.write(html)
Beispiel #8
0
  def get(self):
    req = self.request

    count = int(req.get('count', 50))
    if count > 100:
      count = 100

    q = Meme.all()

    bucket_dates = False
    page_title = ''
    order = req.get('order')
    if order == 'recent':
      q.order('-create_datetime')
      page_title = 'Recent'
    elif order == 'fame':
      q.order('-score').filter('score >', 9)
      page_title = 'Hall of Fame'
    else:
      # TODO(d): Decay score over time.
      bucket_dates = True
      order = 'top'
      q.order('-create_date').order('-score')
      page_title = 'Top'

    q.filter('listed', True)
    template_name = req.get('template_name')
    if template_name:
      page_title += ' ' + template_name
      q.filter('template_name', template_name)
    cursor = req.get('cursor')
    if cursor:
      q.with_cursor(cursor)

    page_title += ' Memes'

    memes = []
    more_results = False
    last_date = None
    date_buckets = []
    scanned = 0
    for meme in q.run(limit=count + 1):
      datetime = meme.create_datetime
      if last_date is None or datetime.day != last_date.day:
        # Only create more than one bucket if we're not showing recent
        if last_date is None or bucket_dates:
          last_date = datetime
          memes = []
          date_buckets.append(memes)
      memes.append(meme.create_data())
      scanned += 1
      if scanned >= count:
        more_results = True
        break

    if more_results:
      cursor = q.cursor()

    html = template_helper.render('view_memes.html',
      page_title=page_title,
      date_buckets=date_buckets,
      memes=memes,
      order=order,
      count=count,
      cursor=cursor)
    self.response.write(html)
Beispiel #9
0
  def get(self):
    req = self.request

    html = template_helper.render('upload_template.html')
    self.response.write(html)