def update(self, req): req.nav = '/update' start = req.get_form_var('start') limit = req.get_form_var('count', 20) cate = req.get_form_var('cate', 'b') topic_num, topics = Topic.gets() start = start and str(start).isdigit() and int(start) or 0 limit = limit and str(limit).isdigit() and int(limit) or 0 error = None prefix = "/update?cate=%s&" % cate print 'update', error, req.get_method(), req.get_method() == "POST" if req.get_method() == "POST": text = req.get_form_var("update_text", '').strip() upload_file = req.get_form_var("update_file", None) print 'post', text, upload_file if not text and not upload_file: error = "no_data" if error is None: filename = '' ftype = '' if upload_file: filename = upload_file.tmp_filename ftype = upload_file.content_type bid = Blog.new(req.user.id, Blog.TYPE_BLOG, content=text, filename=filename, ftype=ftype) blog = Blog.get(bid) for t in blog.topics: html = str(stf("/blog/utils.html", "blog_ui", b=blog, req=req)) data = { 'html': html } #publish_channel_msg('me-topic-%s' % t.id, data) return req.redirect('%sstart=%s' % (prefix, start)) total, blogs = Blog.gets(start=start, limit=limit, blog_type=cate) if req.get_form_var("output", None) == 'json': fireworks = req.get_form_var("fireworks", None) req.response.set_content_type('application/json; charset=utf-8') d = { 'total':total, 'start':start, 'count':limit, } if fireworks: d['blogs'] = [b.fireworks_dict() for b in blogs] else: d['blogs'] = [b.json_dict(req.user) for b in blogs] return json.dumps(d) return st('/update.html', **locals())
def _q_lookup(req, name): topic = Topic.get_by_name(name) if topic: return st('/blog/topic.html', **locals()) raise TraversalError("no such topic")