def comment(req): r = { 'err':'invalid' } if req.get_method() == "POST": blog_id = req.get_form_var('bid', '') blog = Blog.get(blog_id) content = req.get_form_var('content', '').strip() single = req.get_form_var('single', '0') single = single == '1' upload_file = req.get_form_var("update_file", None) #print 'j comment', blog_id, content if blog and req.user and content: filename = '' ftype = '' if upload_file: filename = upload_file.tmp_filename ftype = upload_file.content_type blog.comment(req.user.id, content, filename, ftype) blog = Blog.get(blog.id) r = { 'err':'ok', 'inner_html': stf("/blog/utils.html", "blog_ui_inline", b=blog, req=req, single=single), } for t in blog.topics: html = str(stf("/blog/utils.html", "blog_ui_inline", b=blog, single=False, req=req)) data = { 'blog_id': blog.id, 'inner_html': html } publish_channel_msg('me-topic-%s' % t.id, data) return json.dumps(r)
def _q_index(req): app_id = req.get_form_var("app_id", "") app = App.get(app_id) name = req.get_form_var("name", "") x = req.get_form_var("x", 0) y = req.get_form_var("y", 0) w = req.get_form_var("w", None) h = req.get_form_var("h", None) x = x and str(x).isdigit() and int(x) or 0 y = y and str(y).isdigit() and int(y) or 0 w = w and str(w).isdigit() and int(w) or 0 h = h and str(h).isdigit() and int(h) or 0 parent_id = req.get_form_var("parent_id", 0) page_type = req.get_form_var("type", Page.TYPE_NORMAL) parent = parent_id and Page.get(parent_id) rect = None if req.get_method() == 'POST': if w and h: rect = Rect.get(Rect.new(x, y, w, h)) photo = req.get_form_var("photo", None) if name and app.can_admin(req.user): filename = photo and photo.tmp_filename page_id = Page.new(app, name, rect, filename, parent_id, page_type) if req.get_form_var("output", None) == 'json': req.response.set_content_type('application/json; charset=utf-8') ret = { 'err': 'ok', 'html': stf('/app.html', 'page_list', app=app, req=req) } return json.dumps(ret) else: rect = Rect(0, x*app.zoomout, y*app.zoomout, w*app.zoomout, h*app.zoomout) return stf('/app.html', 'page_form', app=app, rect=rect, parent=parent, page_type=page_type)
def add_action(self, req): page = self.page app = page.app if app.can_admin(req.user): x = req.get_form_var('x', None) y = req.get_form_var('y', None) w = req.get_form_var('w', None) h = req.get_form_var('h', None) x = x and str(x).isdigit() and int(x) or 0 y = y and str(y).isdigit() and int(y) or 0 w = w and str(w).isdigit() and int(w) or 0 h = h and str(h).isdigit() and int(h) or 0 type = req.get_form_var('type', None) dismiss = req.get_form_var('dismiss', None) to_page_id = req.get_form_var('to_page', 0) if req.get_method() == "GET": rect = Rect(0, x, y, w, h) return stf('/app.html', 'action_form', page=page, rect=rect, type=type) elif req.get_method() == "POST": if req.get_form_var("output", None) == 'json': req.response.set_content_type('application/json; charset=utf-8') rect = Rect.get(Rect.new(x, y, w, h)) Action.new(page.id, rect, type, dismiss, to_page_id) ret = { 'err': 'ok' } ret['html'] = stf('/app.html', 'page_worktable', p=page, req=req) return json.dumps(ret) return AccessError("need owner")
def like(req): r = { 'err':'invalid' } if req.get_method() == "POST": blog_id = req.get_form_var('bid', '') single = req.get_form_var('single', '0') single = single == '1' blog = Blog.get(blog_id) if blog and req.user and not blog.is_liked(req.user.id): blog.like(req.user.id) blog = Blog.get(blog.id) r = { 'err':'ok', 'inner_html': stf("/blog/utils.html", "blog_ui_inline", b=blog, req=req, single=single), } for t in blog.topics: html = str(stf("/blog/utils.html", "blog_ui_inline", b=blog, single=False, req=req)) data = { 'blog_id': blog.id, 'inner_html': html } publish_channel_msg('me-topic-%s' % t.id, data) return json.dumps(r)
def edit(self, req): name = req.get_form_var("name", "") photo = req.get_form_var("photo", None) app = self.page.app if app.can_admin(req.user): if name and req.get_method() == "POST": filename = photo and photo.tmp_filename self.page.update(name, filename) return json.dumps({'err':'ok', 'html': stf('/app.html', 'page_list', app=app, req=req)}) return stf('/app.html', 'page_edit_form', page=self.page, req=req) return AccessError("need owner")
def edit(self, req): app = self.app if req.get_method() == "POST" and app.can_admin(req.user): name = req.get_form_var("app_name", None) icon = req.get_form_var("app_icon", None) if name or icon: filename = icon and icon.tmp_filename app.update(name, filename) if req.get_form_var("output", None) == "json": req.response.set_content_type("application/json; charset=utf-8") total, apps = App.gets_by_user(req.user.id) ret = {"err": "ok", "html": stf("/apps.html", "app_list", apps=apps)} return json.dumps(ret) return stf("/apps.html", "app_edit_dialog", app=app)
def json_dict(self, user): ret = { 'id': self.id, 'alt': self.url, 'type': self.btype, 'action': self.action, 'like_num': self.n_like, 'unlike_num': self.n_unlike, 'comment_num': self.n_comment, 'created': self.ctime.strftime('%Y-%m-%d %H:%M:%S'), 'author': self.card.json_dict(user), 'photo':self.photo, 'extra':self.extra, } if self.btype == self.TYPE_BLOG: ret['content'] = self.content ret['html'] = self.html elif self.btype == self.TYPE_NOTIFY: from libs.template import stf html = str(stf("/blog/utils.html", "notify_inline", n=self)) html = html.replace('\n', '').replace('\t', '') H5_RE = re.compile(r'<h5>(.+)</h5>') HREF_RE = re.compile(r'<a [^>]+>|</a>') r = H5_RE.findall(html) html = r and r[0] or '' ret['html'] = html ret['content'] = HREF_RE.sub('', html) return ret
def tag(req): r = { 'err':'invalid' } tags = req.get_form_var('tags', '').strip() if len(tags) > 0: tags = tags.split() else: tags = [] if req.get_method() == "POST": cate = req.get_form_var('cate', '') card_id = req.get_form_var('cid', '') #print 'j tags', card_id, tags card = Card.get(card_id) if card and req.user and tags: card.tag(req.user.id, tags) card = Card.get(card.id) tmpl_func = 'card_tags' if cate == 'small': tmpl_func = 'small_card_tags' r = { 'err':'ok', 'inner_html': stf('/card/utils.html', tmpl_func, card=card, req=req) } return json.dumps(r)
def remove(self, req): app = self.app if req.get_method() == "POST" and app.can_admin(req.user): if req.get_form_var("output", None) == "json": req.response.set_content_type("application/json; charset=utf-8") app.remove() total, apps = App.gets_by_user(req.user.id) ret = {"err": "ok", "html": stf("/apps.html", "app_list", apps=apps)} return json.dumps(ret)
def _q_index(self, req): card = self.card if req.get_form_var("output", None) == 'json': req.response.set_content_type('application/json; charset=utf-8') return json.dumps(card.json_dict(req.user)) elif req.get_form_var("html_widget", None): return stf("/card/utils.html", "card_widget", card=card, req=req) n, blogs = Blog.gets(card.id, blog_type='b') return st('/card/card.html', **locals())
def like_photo(req): r = { 'err':'invalid' } if req.get_method() == "POST": photo_id = req.get_form_var('pid', '') photo = EventPhoto.get(photo_id) if photo and req.user: photo.like(req.user.id) photo = EventPhoto.get(photo.id) r = { 'err':'ok', 'html': stf("/event/photo.html", "photo_likers", photo=photo), } return json.dumps(r)
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 uncomment_photo(req): r = { 'err':'invalid' } if req.get_method() == "POST": photo_id = req.get_form_var('pid', '') comment_id = req.get_form_var('comment_id', '') photo = EventPhoto.get(photo_id) if photo and req.user: photo.uncomment(req.user.id, comment_id) photo = EventPhoto.get(photo.id) r = { 'err':'ok', 'html': stf("/event/photo.html", "photo_comments", photo=photo, req=req), } return json.dumps(r)
def like(req): r = { 'err':'invalid' } if req.get_method() == "POST": card_id = req.get_form_var('cid', '') card = Card.get(card_id) if card and req.user and not card.is_liked(req.user.id): card.like(req.user.id) card = Card.get(card.id) r = { 'err':'ok', 'inner_html': stf("/card/card.html", "card_likers", card=card, req=req), 'like_num': card.like_num, } return json.dumps(r)
def _q_index(req): if req.get_method() == "POST": name = req.get_form_var("app_name", None) icon = req.get_form_var("app_icon", None) screen_id = req.get_form_var("app_screen", None) screen = Screen.get(screen_id) if name and icon and req.user and screen: filename = icon.tmp_filename app_id = App.new(req.user.id, name, filename, screen.id) if req.get_form_var("output", None) == "json": req.response.set_content_type("application/json; charset=utf-8") total, apps = App.gets_by_user(req.user.id) ret = {"err": "ok", "html": stf("/apps.html", "app_list", apps=apps)} return json.dumps(ret) app = App.get(app_id) if app: return req.redirect(app.path)
def unlike(req): r = { 'err':'invalid' } if req.get_method() == "POST": blog_id = req.get_form_var('bid', '') single = req.get_form_var('single', '0') single = single == '1' blog = Blog.get(blog_id) if blog and req.user and not blog.is_unliked(req.user.id): blog.unlike(req.user.id) blog = Blog.get(blog.id) r = { 'err':'ok', 'inner_html': stf("/blog/utils.html", "blog_ui_inline", b=blog, req=req, single=single), } return json.dumps(r)
def comment(req): r = { 'err':'invalid' } if req.get_method() == "POST": card_id = req.get_form_var('cid', '') card = Card.get(card_id) content = req.get_form_var('content', '').strip() #print 'j comment', card_id, content if card and req.user and content: card.comment(req.user.id, content) card = Card.get(card.id) r = { 'err':'ok', 'html': stf("/card/card.html", "card_comments", card=card, req=req), } return json.dumps(r)
def ask(req): r = { 'err':'invalid' } if req.get_method() == "POST": card_id = req.get_form_var('cid', '') card = Card.get(card_id) content = req.get_form_var('content', '').strip() anonymous = req.get_form_var('anonymous', None) if card and req.user and content and req.user.id != card.id: qid = Question.new(card.id, req.user.id, content, anonymous == '1') card = Card.get(card.id) r = { 'err':'ok', 'html': stf("/card/card.html", "card_answers", card=card, req=req), } return json.dumps(r)
def uncomment(req): r = { 'err':'invalid' } if req.get_method() == "POST": card_id = req.get_form_var('cid', '') comment_id = req.get_form_var('comment_id', '') card = Card.get(card_id) #print 'j uncomment', comment_id if req.user and card: Comment.remove(req.user.id, comment_id) card = Card.get(card.id) r = { 'err':'ok', 'html': stf("/card/card.html", "card_comments", card=card, req=req), } return json.dumps(r)
def uncomment(req): r = { 'err':'invalid' } if req.get_method() == "POST": blog_id = req.get_form_var('bid', '') comment_id = req.get_form_var('comment_id', '') single = req.get_form_var('single', '0') single = single == '1' blog = Blog.get(blog_id) #print 'j uncomment', comment_id if req.user and blog: blog.uncomment(req.user.id, comment_id) blog = Blog.get(blog.id) r = { 'err':'ok', 'inner_html': stf("/blog/utils.html", "blog_ui_inline", b=blog, req=req, single=single), } return json.dumps(r)