Exemple #1
0
def do_render_cache(cursor=None):
  thq = Thread.all()

  if cursor:
    thq.with_cursor(cursor)

  thread = thq.get()

  if not thread:
    logging.info("stop thread clean")
    return

  board = thread.parent_key().name()
  render = Render(board=board, thread = thread.key().id())

  for idx,post in enumerate(thread.posts):
    post['text_html'] = markup(
          board=board, postid=post.get("post"),
          data=escape(post.get('text', '')),
    )

    if idx == 0:
      render.create(post)
    else:
      render.append(post)

  if len(thread.posts) > 1:
    thread.put()
  else:
    thread.delete()

  render.save()

  deferred.defer(do_render_cache, thq.cursor())
Exemple #2
0
def process(thread_key):
  logging.info('process %r' % thread_key)
  thread = db.get(thread_key)

  render = Render(thread = thread)

  for idx,post in enumerate(thread.posts):
    if 'text' in post:
      post['text_html'] = markup(
            board=thread.board, postid=post.get("post"),
            data=escape(post.get('text', '')),
      )
      if 'rainbow_html' in post:
        post.pop("rainbow_html")
        post['rainbow'] = rainbow.make_rainbow(post['rainbow'])

    if 'image' in post and not post.get("key"):
      post.pop("image")
      post['name'] = 'Kuroneko'

    if idx == 0:
      render.create(post)
    else:
      render.append(post)

  thread.put()

  render.save()
Exemple #3
0
def delete_post(board, thread_num, post_num, rape_msg):

  last_deletion = False
  th = Thread.get(db.Key.from_path(
      "Board", board, 
      "Thread", thread_num
      ))

  [post] = [p for p in th.posts if p.get('post') == post_num]
  logging.info("found: %r" % post)

  key = post.get("key")
  if key:
    post.pop("key", None)
    post.pop("image", None)
    info = blobstore.BlobInfo.get(
      blobstore.BlobKey(key))
    info.delete()
    
    try:
      th.images.remove(post.get("key"))
    except:
      pass
    
    logging.info("removed image %r" % post)
    
  else:
    last_deletion = True
    post['text'] = 'Fuuuuuu'       
    post['text_html'] = 'Fuuuuuu'       
    post['rainbow_html'] = u'<b>' + rape_msg + '</b>'

  th.put()
  Cache.delete(
    (
      dict(Board=board),
    )
  )

  r = Render(board, thread_num)
  #kind of shit:
  r.create(th.posts[0])
  for a_post in th.posts[1:]:
    r.append(a_post)
  r.save()
  
  #FIXME: update records in memcache 

  return last_deletion
Exemple #4
0
def delete_post(board, thread_num, post_num, rape_msg):

  last_deletion = False
  th = Thread.load(thread_num, board)

  [post] = [p for p in th.posts if p.get('post') == post_num]
  logging.info("found: %r" % post)

  key = post.get("key")
  if key:
    post.pop("key", None)
    post.pop("image", None)
    info = blobstore.BlobInfo.get(
      blobstore.BlobKey(key))

    if info:
      info.delete()
    
    try:
      th.images.remove(post.get("key"))
    except:
      pass
    
    logging.info("removed image %r" % post)
    
  else:
    last_deletion = True
    post['text'] = 'Fuuuuuu'       
    post['text_html'] = 'Fuuuuuu'       
    post['rainbow_html'] = u'<b>' + rape_msg + '</b>'

  th.put()
  Cache.remove("board", board)

  r = Render(thread=th)
  #kind of shit:
  r.create(th.posts[0])
  for a_post in th.posts[1:]:
    r.append(a_post)
  r.save()
  
  return last_deletion
Exemple #5
0
def do_render_cache(cursor=None):
  thq = Thread.all()

  if cursor:
    thq.with_cursor(cursor)

  thread = thq.get()

  if not thread:
    logging.info("stop thread clean")
    return

  board = thread.board
  render = Render(board=board, thread = thread.id)

  for idx,post in enumerate(thread.posts):
    if 'text' in post:
      post['text_html'] = markup(
            board=board, postid=post.get("post"),
            data=escape(post.get('text', '')),
      )
      if 'rainbow_html' in post:
        post.pop("rainbow_html")
        post['rainbow'] = rainbow.make_rainbow(post['rainbow'])

    if 'image' in post and not post.get("key"):
      post.pop("image")
      post['name'] = 'Kuroneko'

    if idx == 0:
      render.create(post)
    else:
      render.append(post)

  if len(thread.posts) > 1:
    thread.put()
  else:
    thread.delete()

  render.save()

  deferred.defer(do_render_cache, thq.cursor())