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)
def send_blog(cls, card_id, author_id, ntype, extra={}, ctime=None): from webapp.models.blog import Blog TYPES = [cls.TYPE_LIKE, cls.TYPE_TAG, cls.TYPE_REQUEST_PHOTO, cls.TYPE_REQUEST_CHANGE_PHOTO, cls.TYPE_BADAGE, cls.TYPE_AWARD_VOTED, cls.TYPE_QUESTION, cls.TYPE_PHOTO_LIKE, cls.TYPE_PHOTO_TAG, cls.TYPE_REC, cls.TYPE_CREATE_GROUP, cls.TYPE_TAG_ADD_GROUP, cls.TYPE_JOIN_GROUP, cls.TYPE_ADD_GROUP, cls.TYPE_NEW_THREAD, ] #print 'send_blog', ntype, TYPES, ntype in TYPES if ntype in TYPES: extra = extra extra['author_id'] = author_id #print 'do send_blog', ntype Blog.new(card_id, Blog.TYPE_NOTIFY, ntype, extra=extra, ctime=ctime)
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})
def new(cls, user_id, group_id, title, content, filename, ftype): from webapp.models.blog import Blog id = Blog.new(user_id, Blog.TYPE_THREAD, content=content, filename=filename, ftype=ftype) if id: store.execute("insert into me_thread(id, title, group_id, author_id)" " values(%s,%s,%s,%s)", (id, title, group_id, user_id)) store.execute("update me_group set `n_thread`=`n_thread`+1, rtime=rtime where id=%s", group_id) store.commit() Notify.new(user_id, user_id, Notify.TYPE_NEW_THREAD, extra={"thread_id":id}) return id
def new(cls, question_id, author_id, content, filename='', ftype=''): q = Question.get(question_id) if q and q.user_id == author_id: blog_id = '0' store.execute("insert into me_answer(question_id, author_id, blog_id)" " values(%s,%s,%s)", (question_id, author_id, blog_id)) id = store.get_cursor(table="me_answer").lastrowid from webapp.models.blog import Blog blog_id = Blog.new(author_id, Blog.TYPE_BLOG, '', content, filename, ftype, extra={'question_id':q.id}) store.execute("update me_answer set blog_id=%s, rtime=rtime where id=%s", (blog_id, id)) store.commit() Notify.new(q.author_id, q.user_id, Notify.TYPE_ANSWER, extra={"question_id":q.id, "blog_id":blog_id}) return id
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())