示例#1
0
文件: rss.py 项目: a37912/gaeaib
def add(board, thread, post, data):
   cache = Rss.load("thread", board, thread)

   if not cache:
     cache = Rss.create("thread", board, thread)

   rendered = render_template("rss_post.xml", 
	board = board,
        thread = thread,
        data = escape(data),
        post = post,
        cache = cache,
   )
   # FIXME: cant save long posts (>500)
   if len(rendered) > 500:
     rendered = render_template("rss_post.xml", 
          board = board,
          thread = thread,
          data = "too long",
          post = post,
          cache = cache,
     )

   cache.posts.append(rendered)
   cache.posts = cache.posts[-20:]
   xml = render_template("rss.xml",
	board = board, thread = thread, cache=cache)
   cache.xml = xml.encode("utf8")
   cache.put()
示例#2
0
    def get(self, user_key=None):
        '''
        Send e-mail to user ordered a delivery and the admin
        '''
        user = User.get(user_key)
        profile = Profile.all().filter('user ='******'already verified')

        context = {
            'user': user,
            'profile': profile,
        }

        body = render_template('mail/verify.html', **context)
        message = mail.EmailMessage()

        message.to = user.email
        message.body = body
        message.subject = SUBJECT_REGISTRATION
        message.sender = SENDER
        message.reply_to = REPLY_TO
        message.send()
        return Response(body)
示例#3
0
 def post(self, **kwargs):
     '''
     Send e-mail to user ordered a delivery and the admin
     '''
     order_id = self.request.form.get('order_id')
     order = Order.get_id(int(order_id))
     user = order[0].user
     language = self.get_locale()
     
     context = {
         'user': user,
         'order': order[0],
         'info': order[1],
         'language': language,
         'format_currency': i18n.format_currency,
     }
     
     body = render_template('mail/order.html', **context)
     message = mail.EmailMessage()
     message.to = user.email
     message.body = body
     message.bcc = SHOP
     message.subject = SUBJECT_ORDER
     message.sender = SENDER
     message.reply_to = REPLY_TO
     if message.send():
         logging.info(body)
     
     return Response('')
示例#4
0
文件: ib.py 项目: strogo/gaeaib
  def get(self, board, page=0):

    if page > self.PAGES:
      raise NotFound()

    if page == 0:
      cache = models.Cache.load("board", board)
      if cache:
        return Response(cache.data)

    data = {}
    data['threads'] = get_threads(board,page=page) # last threads
    data['show_captcha'] = True
    data['reply'] = True
    data['board_name'] = self.NAMES.get(board) or "Woooo???"
    data['board'] = board # board name
    data['boards'] =  get_config("aib", "boardlist")
    data['pages'] = range(self.PAGES)

    data['overlay'] = board in self.OVER

    html = render_template("board.html", **data)

    if page == 0:
      cache = models.Cache.create("board", board)
      cache.data = html
      cache.put()

    return Response(html)
示例#5
0
 def handle_exception(self, handler):
     logging.exception(handler)
     code = handler.code if hasattr(handler, 'code') else 500
     return Response(render_template("tipfy/ext/httpexceptions/templates/%s.html" % \
                                     str(code if code in (404, 500) else 500),
                                     ** {'request': Tipfy.request}),
                     status = code, mimetype = 'text/html')
 def handle_exception(self, handler):
   logging.exception(handler)
   code = handler.code if hasattr(handler, 'code') else 500
   return Response(render_template("tipfy/ext/httpexceptions/templates/%s.html" % \
                                   str(code if code in (404, 500) else 500),
                                   ** {'request': Tipfy.request}),
                   status = code, mimetype = 'text/html')
示例#7
0
文件: ib.py 项目: cklzqw/gaeaib
  def get(self, board, page=0):

    if page > BOARD_PAGES:
      raise NotFound()

    if page == 0:
      cache = models.Cache.load(Board=board)
      if cache:
        return Response(cache)

    data = {}
    data['threads'] = get_threads(board,page=page) # last threads
    data['show_captcha'] = True
    data['reply'] = True
    data['board_name'] = boardlist.get(board, 'WHooo??')
    data['board'] = board # board name
    data['boards'] = boardlist_order
    data['pages'] = range(BOARD_PAGES)

    html = render_template("thread.html", **data)

    if page == 0:
      models.Cache.save(data = html, Board=board)

    return Response(html)
示例#8
0
    def get(self, user_key=None):
        '''
        Send e-mail to user ordered a delivery and the admin
        '''
        user = User.get(user_key)
        profile = Profile.all().filter('user ='******'already verified')
        
        context = {
            'user': user,
            'profile': profile,
        }
        
        body = render_template('mail/verify.html', **context)
        message = mail.EmailMessage()

        message.to = user.email
        message.body = body
        message.subject = SUBJECT_REGISTRATION
        message.sender = SENDER
        message.reply_to = REPLY_TO
        message.send()
        return Response(body)
示例#9
0
文件: api.py 项目: strogo/gaeaib
    def get(self, board, num):
        post = util.get_post(board, num)

        if not post:
            raise NotFound

        post["html"] = markup(board=board, postid=num, data=post.get("text"))
        post["full_html"] = render_template("post.html", post=post, board=board)

        return json_response(post)
示例#10
0
文件: render.py 项目: cklzqw/gaeaib
    def create(self, op):

        data = {"op": op, "id": self.thread, "board": self.board, "subject": op.get("subject")}
        self.html = render_template(
            "thread.html",
            threads=(data,),
            board=self.board,
            board_name=boardlist.get(self.board, "Woooo???"),
            boards=boardlist_order,
            thread=self.thread,
        )
示例#11
0
文件: render.py 项目: a37912/gaeaib
  def append(self, post):
    assert self.cache.data, 'nowhere to append'

    self.post_html = render_template("post.html", post=post, board=self.board)

    self.cache.data = self.cache.data.replace(
        u"<!--NPHERE-->", self.post_html)

    refs = re.findall(">>([0-9]+)", post.get("text", "")) or []

    if refs:
      refhtml = render_template("ref.html", 
          board = self.board,
          thread = self.thread,
          refpost = post.get("post"),
          rainbow = post.get("rainbow")
      )

    for ref in refs[:self.MAXREFS]:
      pattern = u"<!--REF-%s-->" % ref
      self.cache.data = self.cache.data.replace(pattern, refhtml+pattern)
示例#12
0
文件: render.py 项目: strogo/gaeaib
  def create(self,op):

    data = {
        "op" : op,
        "id" : self.thread,
        "board" : self.board,
        "subject" : op.get("subject"),
    }

    self.cache = Cache.create("thread", self.board, self.thread)
    self.cache.data = render_template("thread.html", 
        thread = data,
	threads = [data],
        board = self.board,
        board_name = NAMES.get(self.board) or get_config("aib",
          "default_name"),
        boards = get_config("aib", "boardlist"), # context?
    )
示例#13
0
文件: atom.py 项目: aristidb/cppbash
    def get(self, **kwargs):
        response = Response(mimetype = 'application/atom+xml')

        collection = FilterCollection(filters, request, response, cookies=False)
        
        q = models.accepted_quotes()
        collection.add_to_query(q)
        q.order('-creation_date')

        out = render_template(
            'cppbash/atom.xml',
            title = "C++ Bash",
            link = url_for('home', full=True),
            quotes = q)

        response.response = [out]

        return response
示例#14
0
文件: home.py 项目: aristidb/cppbash
    def get(self, **kwargs):
        json = request.is_xhr or request.args.get('json', '')

        response = Response(mimetype = 'application/json' if json else 'text/html')

        collection = FilterCollection(filters, request, response)
        
        q = models.accepted_quotes()
        collection.add_to_query(q)
        q.order('-creation_date')

        if json:
            out = quotejson.json(q)
        else:
            out = render_template(
                'cppbash/home.html',
                quotes = q,
                filter_collection = collection)

        response.response = [out]

        return response
示例#15
0
    def get(self, **kwargs):
        '''
        Send e-mail to user ordered a delivery and the admin
        '''
        user = self.auth_current_user  # todo: use real user
        order = Order.get_orders_by_user(user)
        context = {
            'order': order,
            'username': user.username,
            'format_currency': i18n.format_currency,
        }

        body = render_template('mail/order.html', **context)
        message = mail.EmailMessage()

        message.to = user.email
        message.body = body
        message.subject = SUBJECT_ORDER
        message.sender = SENDER
        message.reply_to = REPLY_TO
        message.send()

        return Response(body)
示例#16
0
 def get(self, **kwargs):
     '''
     Send e-mail to user ordered a delivery and the admin
     '''
     user = self.auth_current_user # todo: use real user
     order = Order.get_orders_by_user(user)
     context = {
         'order': order,
         'username': user.username,
         'format_currency': i18n.format_currency,
     }
     
     body = render_template('mail/order.html', **context)
     message = mail.EmailMessage()
     
     message.to = user.email
     message.body = body
     message.subject = SUBJECT_ORDER
     message.sender = SENDER
     message.reply_to = REPLY_TO
     message.send()
     
     return Response(body)
示例#17
0
    def get(self, **kwargs):
        json = request.is_xhr or request.args.get('json', '')

        response = Response(mimetype = 'application/json' if json else 'text/html')

        collection = FilterCollection(filters, request, response)
        
        query = models.accepted_quotes()
        collection.add_to_query(query)
        query.filter('random >', random.random())
        query.order('random')

        qs = [ q for q in query.fetch(_n) ]

        if len(qs) < _n: # wraparound!
            query = models.accepted_quotes()
            collection.add_to_query(query)
            query.order('random')
            qs.extend(query.fetch(_n - len(qs)))

        if len(qs) > 0:
            q = random.choice(qs)
        else:
            q = None

        if json:
            out = quotejson.single(q)
        else:
            out = render_template(
                'cppbash/random_quote.html',
                quote = q,
                filter_collection = collection)

        response.response = [out]

        return response
示例#18
0
 def render_js_template(self, template, **kwargs):
     return ' '.join(render_template(template, **kwargs).splitlines())