Exemple #1
0
 def edit(self, req):
     group = self.group
     uid = req.get_form_var('uid', '').strip()
     name = req.get_form_var('name', '')
     member_name = req.get_form_var('member_name', '')
     intro = req.get_form_var('intro', '')
     upload_file = req.get_form_var("upload_file", None)
     tags = req.get_form_var('tags', '').strip()
     error = None
     if req.user and req.get_method() == 'POST':
         if uid:
             if not Group.is_valid_uid(uid):
                 error = 'uid_invalid'
             elif Group.get(uid):
                 error = 'uid_exists'
             else:
                 group.update_uid(uid)
         if name and member_name and intro:
             group.update(name, member_name, intro)
         if len(tags) > 0:
             tags = tags.split()
         else:
             tags = []
         group.update_tags(tags)
         group = Group.get(group.id)
         return req.redirect(group.path)
     return st('/group/edit.html', **locals())
Exemple #2
0
def _q_index(req):
    uid = req.get_form_var('uid', '').strip()
    name = req.get_form_var('name', '')
    member_name = req.get_form_var('member_name', '')
    intro = req.get_form_var('intro', '')
    upload_file = req.get_form_var("upload_file", None)
    tags = req.get_form_var('tags', '').strip()
    error = None
    if req.user and req.get_method() == 'POST':
        if not uid or not name or not intro or not upload_file:
            error = 'miss_args'
        elif not Group.is_valid_uid(uid):
            error = 'uid_invalid'
        elif Group.get(uid):
            error = 'uid_exists'
        if error is None:
            if len(tags) > 0:
                tags = tags.split()
            else:
                tags = []
            id = Group.new(uid, req.user.id, name, member_name, intro, tags, upload_file.tmp_filename)
            return req.redirect('/group/%s/' % uid)
    return st('/group/edit.html', **locals())
Exemple #3
0
 def groups(self, req):
     req.nav = '/groups'
     groups = Group.gets()
     return st('/group/groups.html', **locals())
Exemple #4
0
def _q_lookup(req, name):
    if not ('-' in name and name.lower()[-4:] in ['.jpg','.png','.gif']):
        raise TraversalError("no such photo")
    ftype = name[-3:]
    n = name[:-4]
    if '$' in name:
        n = name[:name.rindex('$')]
    target_id, photo_id, cate = n.split('-')
    print 'p target_id=%s photo_id=%s cate=%s' % (target_id, photo_id, cate)
    data = None

    scale_type = None
    width = None
    height = None

    if cate.startswith("r_"):
        try:
            r, scale_type, sizes = cate.split('_')
            width, height = sizes.split('x')
            width = int(width)
            height = int(height)
            print 'do resize x=%s, y=%s' % (width, height)
        except:
            print 'do resize fail !!!! ', name
        cate = Cate.LARGE

    if target_id.startswith('evc'):
        event = Event.get(target_id.replace('evc',''))
        if event:
            data = event.photo_data(cate)
    elif target_id.startswith('evp'):
        photo = EventPhoto.get(photo_id)
        if photo:
            data = photo.photo_data(cate)
    elif target_id.startswith('bc'):
        blog_comment = BlogComment.get(target_id.replace('bc', ''))
        if blog_comment:
            data = blog_comment.photo_data(cate)
    elif target_id.startswith('b'):
        blog = Blog.get(target_id.replace('b', ''))
        if blog:
            data = blog.photo_data(cate)
    elif target_id.startswith('g'):
        group = Group.get(target_id.replace('g', ''))
        if group:
            data = group.photo_data(cate)
    else:
        if target_id.startswith('_u_'):
            target_id = target_id.replace('_u_', '')
        card = Card.get(target_id)
        if not card:
            card = Card.get_by_ldap(target_id)
        if card:
            data = card.photo_data(photo_id, cate)
    if not data:
        print "no such photo"
        raise TraversalError("no such photo")
    scale_type = SCALES.get(scale_type, None)
    if scale_type:
        configs = {}
        configs[Cate.RESIZE] = {
            'width': width,
            'height': height,
            'scale': scale_type,
            'gif_scale': scale_type,
        }
        data = scale(data, Cate.RESIZE, configs)
    resp = req.response
    resp.set_content_type('image/jpeg')
    resp.set_header('Cache-Control', 'max-age=%d' % (365*24*60*60))
    resp.set_header('Expires', 'Wed, 01 Jan 2020 00:00:00 GMT')
    if 'pragma' in resp.headers:
        del resp.headers['pragma']
    if cate == Cate.ORIGIN:
        resp.set_content_type('application/force-download')
        resp.set_header('Content-Disposition', 'attachment; filename="%s.%s"' % (name, ftype));
    return data
Exemple #5
0
    def send_irc(self):
        from webapp.models.blog import Blog
        if self.card and self.card and self.card.email:
            message = ''
            if self.ntype == self.TYPE_ADD_GROUP:
                from webapp.models.group import Group
                gid = self.extra.get('group_id', 0)
                group = Group.get(gid)
                if group:
                    message = "#me: 厂工 %s 把你拉进了小组 %s 查看:%s" % (self.author.name, group.name, group.url)
            elif self.ntype == self.TYPE_ANSWER:
                from webapp.models.question import Question
                qid = self.extra.get('question_id', 0)
                bid = self.extra.get('blog_id', 0)
                question = Question.get(qid)
                blog = Blog.get(bid)
                if question and blog:
                    message = "#me: 厂工 %s 回答了你的问题 查看:%s" % (self.author.name, blog.url)
            elif self.ntype == self.TYPE_QUESTION:
                from webapp.models.question import Question
                qid = self.extra.get('question_id', 0)
                question = Question.get(qid)
                if question:
                    if question.is_anonymous:
                        message = "#me: 某厂工问了你一个问题 查看:%s#answers" % (self.card.url)
                    else:
                        message = "#me: 厂工 %s 问了你一个问题 查看:%s#answers" % (self.author.name, self.card.url)
            elif self.ntype == self.TYPE_AWARD_VOTED:
                from webapp.models.badage import Badage, Award
                aid = self.extra.get('badage_id', 0)
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                award = Award.get(aid)
                if award:
                    if blog:
                        message = "#me: 厂工 %s 在评选%s大奖时,投了你一票哦~ 查看:%s" % (self.author.name,
                                award.fullname, blog.url)
                    else:
                        message = "#me: 厂工 %s 在评选%s大奖时,投了你一票哦~ " % (self.author.name,
                                award.fullname)
            elif self.ntype == self.TYPE_PHOTO_LIKE:
                from webapp.models.event import Event, EventPhoto
                pid = self.extra.get('photo_id', 0)
                photo = EventPhoto.get(pid)
                if photo:
                    message = "#me: 厂工 %s 给你上传的照片 + 1了哦~ 查看:%s" % (self.author.name, photo.photo_url)
            elif self.ntype == self.TYPE_PHOTO_TAG:
                from webapp.models.event import Event, EventPhoto
                pid = self.extra.get('photo_id', 0)
                photo = EventPhoto.get(pid)
                if photo:
                    message = "#me: 厂工 %s 在上传的照片圈出了你哦~ 查看:%s" % (self.author.name, photo.photo_url)
            elif self.ntype == self.TYPE_BLOG_LIKE:
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                if blog:
                    message = "#me: 厂工 %s 赞了你的%s~ 查看:%s" % (self.author.name, blog.type_name, blog.url)
            elif self.ntype == self.TYPE_BLOG_UNLIKE:
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                if blog:
                    message = "#me: 你的%s被人踩了哦~ 查看:%s" % (blog.type_name, blog.url)
            elif self.ntype == self.TYPE_BLOG_COMMENT:
                cid = self.extra.get('comment_id', 0)
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                if blog:
                    message = "#me: 厂工 %s 回复了你的%s哦~ 查看:%s#comment_%s" % (self.author.name,
                            blog.type_name, blog.url, cid)
            elif self.ntype == self.TYPE_BLOG_REPLY:
                cid = self.extra.get('comment_id', 0)
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                if blog:
                    message = "#me: 你回复的%s有了新回复哦~ 查看:%s#comment_%s" % (blog.type_name, blog.url, cid)
            elif self.ntype == self.TYPE_BLOG_MENTION:
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                if blog:
                    message = "#me: 厂工 %s 的%s提到了你哦~ 查看:%s" % (self.author.name, blog.type_name, blog.url)
            elif self.ntype == self.TYPE_BLOG_COMMENT_MENTION:
                cid = self.extra.get('comment_id', 0)
                bid = self.extra.get('blog_id', 0)
                blog = Blog.get(bid)
                if blog:
                    message = "#me: 厂工 %s 在 %s 的%s回复里提到了你哦~ 查看:%s" % (self.author.name,
                        blog.owner.name, blog.type_name, blog.url)
            elif self.ntype == self.TYPE_LIKE:
                message = "#me: 厂工 %s ( %s )收藏了你的卡片哦~ 你说他/她/它是不是对你感兴趣?(//▽//)" % (self.author.name,
                        self.author_card.url)
            elif self.ntype == self.TYPE_COMMENT:
                cid = self.extra.get('comment_id', 0)
                message = "#me: 厂工 %s 给你的卡片留言了哦~ 查看:%s#comment_%s" % (self.author.name, self.card.url, cid)
            elif self.ntype == self.TYPE_MENTION:
                cid = self.extra.get('comment_id', 0)
                card_id = self.extra.get('card_id', 0)
                if card_id == self.card_id:
                    message = "#me: 厂工 %s 在给你的卡片留言中提到了你~ 查看:%s#comment_%s" % (self.author.name, self.card.url, cid)
                else:
                    from webapp.models.card import Card
                    card = Card.get(card_id)
                    message = "#me: 厂工 %s 在给 %s 的卡片留言中提到了你了哦~ 查看:%s#comment_%s" % (self.author.name, card.screen_name, card.url, cid)
            elif self.ntype == self.TYPE_PHOTO_COMMENT:
                cid = self.extra.get('comment_id', 0)
                pid = self.extra.get('photo_id', 0)
                from webapp.models.event import Event, EventPhoto
                photo = EventPhoto.get(pid)
                if photo:
                    message = "#me: 厂工 %s 给你上传的照片留言了哦~ 查看:%s%s#comment_%s" % (self.author.name, SITE, photo.path, cid)

            elif self.ntype == self.TYPE_PHOTO_COMMENT_MENTION:
                cid = self.extra.get('comment_id', 0)
                pid = self.extra.get('photo_id', 0)
                from webapp.models.event import Event, EventPhoto
                photo = EventPhoto.get(pid)
                if photo:
                    message = "#me: 厂工 %s 照片里提到你了哦~ 查看:%s%s#comment_%s" % (self.author.name, SITE, photo.path, cid)
            elif self.ntype == self.TYPE_TAG:
                tags = self.extra.get('tags').encode('utf-8')
                message = "#me: 你的卡片有了新的标签(%s),你猜谁给你打的? ≖‿≖✧  查看:%s" % (tags, self.card.url)
            elif self.ntype == self.TYPE_REQUEST_PHOTO:
                message = "#me: 厂工 %s ( %s ) 求你的真相照片哦~ 传一张吧,拜托了!m(_ _)m  上传:%s/make" % (self.author.name, self.author_card.url, SITE)
            elif self.ntype == self.TYPE_REQUEST_CHANGE_PHOTO:
                message = "#me: 厂工 %s ( %s )和大家都觉得你的真相照片不真,简直是@#^&*! 换一张吧,拜托了!m(_ _)m  上传:%s/make" % (self.author.name, self.author_card.url, SITE)
            elif self.ntype == self.TYPE_BADAGE:
                from webapp.models.card import Badage
                badage = Badage.get(self.author_id)
                if badage:
                    message = "#me: 你得到了一枚%s徽章哦~ 点击查看:%s/badage/%s" % (badage.name, SITE, badage.name)
            iu = self.card.email.replace('@douban.com','')
            print 'send_irc', iu, message
            try:
                irc_send_message(iu, message)
            except:
                print 'sent irc error!!!'
Exemple #6
0
def _q_lookup(req, id):
    g = Group.get(id)
    if g:
        return GroupUI(req, g)
    return TraversalError("no such group")