def comment(self, author_id, content, filename='', ftype=''): print 'comment', filename, ftype store.execute("insert into me_blog_comment(`blog_id`,`author_id`,`content`)" " values(%s,%s,%s)", (self.id, author_id, content)); cid = store.get_cursor(table="me_blog_comment").lastrowid store.execute("update me_blog set `n_comment`=`n_comment`+1 where id=%s", self.id) store.commit() print 'comment_id', cid if cid and filename and ftype: ftype = CONTENT_TYPE_DICT.get(ftype, None) if ftype in ['jpg', 'png', 'gif']: data = open(filename).read() store.execute("update me_blog_comment set photo_id=photo_id+1," "rtime=rtime where id=%s", cid) store.commit() doubanfs.set("/me/bcp%s-%s-%s" % (cid, 1, Cate.ORIGIN), data) o = scale(data, Cate.LARGE, DEFAULT_CONFIG) doubanfs.set("/me/bcp%s-%s-%s" % (cid, 1, Cate.LARGE), o) Notify.new(self.user_id, author_id, Notify.TYPE_BLOG_COMMENT, extra={"comment_id":cid, "blog_id":self.id}) if '@' in content or '#' in content: from webapp.models.utils import mention_text ret = mention_text(content, True) for b, e, card_id, kind in ret['postions']: if kind == 'card': Notify.new(card_id, author_id, Notify.TYPE_BLOG_COMMENT_MENTION, extra={"card_id":self.user_id, "comment_id":cid, "blog_id":self.id}) aids = [cm.author_id for cm in self.comments if cm.author_id not in [self.user_id, author_id]] for aid in set(aids): Notify.new(aid, author_id, Notify.TYPE_BLOG_REPLY, extra={"comment_id":cid, "blog_id":self.id})
def comment(self, author_id, content): store.execute("insert into me_comment(`user_id`,`author_id`,`content`)" " values(%s,%s,%s)", (self.id, author_id, content)); store.commit() cid = store.get_cursor(table="me_comment").lastrowid Notify.new(self.id, author_id, Notify.TYPE_COMMENT, extra={"comment_id":cid}) if '@' in content: from webapp.models.utils import mention_text ret = mention_text(content) for b, e, card_id, kind in ret['postions']: Notify.new(card_id, author_id, Notify.TYPE_MENTION, extra={"card_id":self.id, "comment_id":cid})
def new(cls, user_id, btype, action='', content='', filename='', ftype='', extra={}, ctime=None): #print 'Blog new', user_id, btype, action, content, filename, ftype, extra, ctime try: extra = json.dumps(extra) except: extra = "{}" now = ctime or datetime.now() store.execute("insert into me_blog(`user_id`,`btype`,`action`, `content`, `extra`, `ctime`)" " values(%s,%s,%s,%s,%s,%s)", (user_id, btype, action or cls.BLOG_TEXT, content, extra, now)) id = store.get_cursor(table="me_blog").lastrowid if filename and ftype: ftype = CONTENT_TYPE_DICT.get(ftype, None) if not ftype: return "invalid_type" data = open(filename).read() if len(data) > MAX_SIZE: return "too_large" if ftype in ['jpg', 'png', 'gif']: store.execute("insert into me_blog_photo(blog_id,author_id,ftype) values(%s,%s,%s)", (id, user_id, ftype)) photo_id = store.get_cursor(table="me_blog_photo").lastrowid store.execute("update me_blog set photo_id=%s,action=%s where id=%s", (photo_id, cls.BLOG_PHOTO, id)) doubanfs.set("/me/bp%s-%s-%s" % (id, photo_id, Cate.ORIGIN), data) o = scale(data, Cate.LARGE, DEFAULT_CONFIG) doubanfs.set("/me/bp%s-%s-%s" % (id, photo_id, Cate.LARGE), o) elif ftype in ['mp3']: store.execute("insert into me_blog_audio(blog_id,author_id,ftype) values(%s,%s,%s)", (id, user_id, ftype)) audio_id = store.get_cursor(table="me_blog_audio").lastrowid store.execute("update me_blog set audio_id=%s,action=%s where id=%s", (audio_id, cls.BLOG_AUDIO, id)) doubanfs.set("/me/ba%s-%s-%s" % (id, audio_id, Cate.ORIGIN), data) store.commit() if '@' in content or '#' in content: from webapp.models.utils import mention_text ret = mention_text(content, True) for b, e, rid, kind in ret['postions']: if kind == 'card': card_id = rid Notify.new(card_id, user_id, Notify.TYPE_BLOG_MENTION, extra={"card_id":user_id, "blog_id":id}) elif kind == 'topic': name = rid topic_id = Topic.bind(name, user_id, id) if btype in [cls.TYPE_BLOG, cls.TYPE_NOTIFY]: blog = Blog.get(id) #send_fireworks(blog.fireworks_dict()) return id
def html(self): from webapp.models.utils import mention_text ret = mention_text(self.content) return ret['html']