Пример #1
0
def init_data():
    from webapp.models.user import User
    from webapp.models.question import Question, Tag, Answer

    # Role.insert_roles()

    User.generate_fake(100)
    Tag.generate_fake(20)
    Question.generate_fake(1000)
    Answer.generate_fake(100)
Пример #2
0
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)
Пример #3
0
 def questions(self):
     return Question.gets_by_card(self.id)
Пример #4
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!!!'