예제 #1
0
파일: card.py 프로젝트: fordream/me
    def update_photo_data(self, data):
        success = False
        old_id = self.photo_id
        try:
            new_id = old_id + 1
            doubanfs.set("/me/card/%s/photo/%s/%s" % (self.id, new_id, Cate.ORIGIN), data)
            from webapp.models.utils import scale
            d = scale(data, Cate.LARGE, DEFAULT_CONFIG)
            doubanfs.set("/me/card/%s/photo/%s/%s" % (self.id, new_id, Cate.LARGE), d)
            print "update photo success photo_id=%s" % new_id
            store.execute("update me_card set `photo`=%s where `user_id`=%s", (new_id, self.id))
            store.commit()
            success = True
        except:
            print "doubanfs write fail!!! %s" % self.id
            self.photo_id = old_id
            store.execute("update me_card set `photo`=`photo`-1 where `user_id`=%s", self.id)
            store.commit()
            doubanfs.delete("/me/card/%s/photo/%s/%s" % (self.id, new_id, Cate.LARGE))
            doubanfs.delete("/me/card/%s/photo/%s/%s" % (self.id, new_id, Cate.ORIGIN))
            print 'rollback photo to old_id', old_id

        if success:
            Notify.new(self.id, self.id, Notify.TYPE_CHANGE_PHOTO, extra={'photo_id':new_id})
            print "send change photo blog"
            from webapp.models.blog import Blog
            Blog.new(self.id, Blog.TYPE_BLOG, Blog.BLOG_ICON, extra={'photo_id':new_id})


        doubanmc.delete(self.MC_KEY % self.id)
        doubanmc.delete(self.MC_KEY % self.uid)
예제 #2
0
파일: card.py 프로젝트: fordream/me
 def recreate_photo(self):
     try:
         data = doubanfs.get("/me/card/%s/photo/%s/%s" % (self.id, self.photo_id, Cate.ORIGIN))
         d = scale(data, Cate.LARGE, DEFAULT_CONFIG)
         doubanfs.set("/me/card/%s/photo/%s/%s" % (self.id, self.photo_id, Cate.LARGE), d)
     except:
         print "doubanfs write fail!!! %s" % self.id
예제 #3
0
파일: blog.py 프로젝트: leonsim/me
    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})
예제 #4
0
파일: event.py 프로젝트: leonsim/me
 def update_photo(cls, pid, event_id, data):
     doubanfs.set("/me/evp-%s-%s-%s" % (event_id, pid, Cate.ORIGIN), data)
     o = scale(data, Cate.LARGE, DEFAULT_CONFIG)
     doubanfs.set("/me/evp-%s-%s-%s" % (event_id, pid, Cate.LARGE), o)
     for c in CATES:
         d = scale(o, c, DEFAULT_CONFIG)
         doubanfs.set("/me/evp-%s-%s-%s" % (event_id, pid, c), d)
예제 #5
0
파일: group.py 프로젝트: fordream/me
 def update_photo(self, filename):
     data = open(filename).read()
     if len(data) > MAX_SIZE:
         return "too_large"
     store.execute("update me_group set `photo`=`photo`+1 where `id`=%s", self.id)
     store.commit()
     self.photo_id = self.photo_id + 1
     doubanfs.set("/me/g%s-%s-%s" % (self.id, self.photo_id, Cate.ORIGIN), data)
     o = scale(data, Cate.LARGE, DEFAULT_CONFIG)
     doubanfs.set("/me/g%s-%s-%s" % (self.id, self.photo_id, Cate.LARGE), o)
     for c in CATES[:2]:
         d = scale(o, c, DEFAULT_CONFIG)
         doubanfs.set("/me/g%s-%s-%s" % (self.id, self.photo_id, c), d)
예제 #6
0
파일: event.py 프로젝트: leonsim/me
 def update_photo(self, filename):
     data = open(filename).read()
     if len(data) > MAX_SIZE:
         return "too_large"
     store.execute("update me_event set `photo`=`photo`+1 where `id`=%s", self.id)
     store.commit()
     self.photo_id = self.photo_id + 1
     doubanfs.set("/me/evc%s-%s-%s" % (self.id, self.photo_id, Cate.ORIGIN), data)
     o = scale(data, Cate.LARGE, DEFAULT_CONFIG)
     doubanfs.set("/me/evc%s-%s-%s" % (self.id, self.photo_id, Cate.LARGE), o)
     for c in CATES[:2]:
         d = scale(o, c, DEFAULT_CONFIG)
         doubanfs.set("/me/evc%s-%s-%s" % (self.id, self.photo_id, c), d)
     if self.photo_id == 1:
         from webapp.models.blog import Blog
         Blog.new(self.author_id, Blog.TYPE_BLOG, Blog.BLOG_EVENT, extra={'photo_id':self.photo_id, 'event_id':self.id})
예제 #7
0
파일: blog.py 프로젝트: leonsim/me
    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