示例#1
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)
示例#2
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)
示例#3
0
  def post(self, meme_id):
    req = self.request

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

    if not meme.is_owner():
      self.error(400)
      return

    meme.delete()

    # Write an empty 200 response
    self.response.headers['Content-Type'] = 'application/json'
    self.response.write('{}')
示例#4
0
  def get(self, meme_id):
    req = self.request

    # If there's a meme id, render it.
    # TODO(d): Guard against non-integer ids
    meme = Meme.get_by_key_name(meme_id)
    if not meme:
      self.error(404)
      return

    self.response.headers['Content-Type'] = 'image/png'
    self.response.headers['Cache-Control'] = 'private, max-age=3600'

    is_thumbnail = req.get('size') == 'thumbnail'
    if is_thumbnail:
      self.response.write(meme.thumbnail_image_data)
    else:
      self.response.write(meme.image_data)
示例#5
0
def generate_meme_key_name():
  key_name = randoms.randomString(5)
  while Meme.get_by_key_name(key_name):
    key_name = randoms.randomString(5)
  return key_name