Example #1
0
def tag(req):
    r = {
        'err':'invalid'
    }
    tags = req.get_form_var('tags', '').strip()
    if len(tags) > 0:
        tags = tags.split()
    else:
        tags = []
    if req.get_method() == "POST":
        cate = req.get_form_var('cate', '')
        card_id = req.get_form_var('cid', '')
        #print 'j tags', card_id, tags
        card = Card.get(card_id)
        if card and req.user and tags:
            card.tag(req.user.id, tags)
            card = Card.get(card.id)
            tmpl_func = 'card_tags'
            if cate == 'small':
                tmpl_func = 'small_card_tags'
            r = {
                'err':'ok',
                'inner_html': stf('/card/utils.html', tmpl_func, card=card, req=req)
            }
    return json.dumps(r)
Example #2
0
File: tag.py Project: fordream/me
 def get_taggers(cls, uid, tag):
     from webapp.models.card import Card
     d = Card.get(uid)
     t = cls.get_by_name(tag)
     if t and d:
         rs = store.execute("select tagger_id from me_user_tag where user_id=%s"
             " and tag_id=%s", (d.id, t.id))
         return [Card.get(str(r[0])) for r in rs]
     return []
Example #3
0
def add_photo_tag(req):
    r = { 'result':False }
    photo_id = req.get_form_var('image_id', None)
    photo = photo_id and EventPhoto.get(photo_id)
    if photo and req.user:
        left = req.get_form_var('left', None)
        top = req.get_form_var('top', None)
        width = req.get_form_var('width', None)
        height = req.get_form_var('height', None)
        name = req.get_form_var('name', None)
        uid = req.get_form_var('name_id', None)
        if name and not uid:
            user_dict = get_users_dict()
            uid = user_dict.get(name.cstrip().lower(), None)
        if uid:
            card = Card.get(uid)
            if card:
                tid = PhotoTag.new(photo_id, card.id, req.user.id, left, top, width, height)
                tag = PhotoTag.get(tid)
                if tag:
                    r = {
                            "result":True,
                            "tag": tag.json_dict(req.user)
                        }
    return json.dumps(r)
Example #4
0
def like(req):
    r = {
        'err':'invalid'
    }
    if req.get_method() == "POST":
        card_id = req.get_form_var('cid', '')
        card = Card.get(card_id)
        if card and req.user and not card.is_liked(req.user.id):
            card.like(req.user.id)
            card = Card.get(card.id)
            r = {
                'err':'ok',
                'inner_html': stf("/card/card.html", "card_likers", card=card, req=req),
                'like_num': card.like_num,
            }
    return json.dumps(r)
Example #5
0
def _q_lookup(req, id):
    card = Card.get(id)
    if card:
        if card.is_hide:
            return st('/misc/hide.html', **locals())
        return CardUI(req, card)
    return TraversalError("no such card")
Example #6
0
File: dig.py Project: fordream/me
 def boy_chart(cls):
     ids = {}
     for d in Card.gets_by_tag('萌'):
         ids[d.id] = 1
     for d in Card.gets_by_tag('单身'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     for d in Card.gets_by_tag('少年'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     for d in Card.gets_by_tag('gay'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     for d in Card.gets_by_tag('娘'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     rs = store.execute("select user_id from me_profile where flag=N and sex=1 and marriage in (1, 2, 12)")
     for r in rs:
         i = str(r[0])
         n = ids.get(i, 0)
         ids[i] = n + 2
     love_cards = [Card.get(i) for i, n in ids.iteritems() if n > 1]
     love_cards = [d for d in love_cards if d.profile.sex != 2]
     love_cards = sorted(love_cards, key=attrgetter('score'), reverse=True)
     return love_cards
Example #7
0
File: dig.py Project: fordream/me
 def girl_chart(cls):
     ids = {}
     for d in Card.gets_by_tag('萌'):
         ids[d.id] = 1
     for d in Card.gets_by_tag('单身'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     for d in Card.gets_by_tag('妹子'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     for d in Card.gets_by_tag('萝莉'):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     for d in Card.gets_by_tag(''):
         n = ids.get(d.id, 0)
         ids[d.id] = n + 1
     rs = store.execute("select user_id from me_profile where flag=N and sex=2 and marriage in (1, 2, 12)")
     for r in rs:
         i = str(r[0])
         n = ids.get(i, 0)
         ids[i] = n + 2
     love_cards = [Card.get(i) for i, n in ids.iteritems() if n > 1]
     love_cards = [d for d in love_cards if ('汉子' not in ' '.join(d.ptag_names) and d.profile.sex != 1)]
     love_cards = sorted(love_cards, key=attrgetter('score'), reverse=True)
     return love_cards
Example #8
0
File: dig.py Project: fordream/me
    def gossip_result(cls):
        ret = {}
        r = store.execute("select user_id from me_card where join_time > '2006-01-09'"
                " and flag=%s order by join_time limit 1", Card.FLAG_NORMAL)
        if r and r[0]:
            ret['first_employee'] = Card.get(r[0][0])

        r = store.execute("select user_id from me_card where user_id > 1000001"
                " and flag=%s order by user_id limit 1", Card.FLAG_NORMAL)
        if r and r[0]:
            ret['first_register'] = Card.get(r[0][0])

        r = store.execute("select user_id from (select user_id, count(user_id) as c from me_like"
                " group by user_id) as s order by s.c desc limit 1")
        if r and r[0]:
            ret['likest_card'] = Card.get(r[0][0])

        r = store.execute("select user_id from (select user_id, count(user_id) as c from me_question"
                " group by user_id) as s order by s.c desc limit 1")
        if r and r[0]:
            ret['question_card'] = Card.get(r[0][0])

        r = store.execute("select user_id from (select user_id, count(user_id) as c from me_comment"
                " group by user_id) as s order by s.c desc limit 1")
        if r and r[0]:
            ret['commentest_card'] = Card.get(r[0][0])

        r = store.execute("select user_id from (select user_id, count(tag_id) as c from me_user_tag"
                " group by user_id) as s order by s.c desc limit 1")
        if r and r[0]:
            ret['taggest_card'] = Card.get(r[0][0])

        rs = store.execute("select s.name, s.c from (select name, count(tag_id) as c from me_tag as t, me_user_tag as ut"
                " where t.id=ut.tag_id group by t.id) as s order by s.c desc limit 5")
        ret['hotest_tags'] = rs

        r = store.execute("select user_id from (select user_id, count(user_id) as c from me_user_badage"
                " group by user_id) as s order by s.c desc limit 1")
        if r and r[0]:
            ret['badagest_card'] = Card.get(r[0][0])

        r = store.execute("select user_id, s.c from (select user_id, count(user_id) as c from me_notify"
                " where ntype=%s group by user_id) as s order by s.c desc limit 1", Notify.TYPE_REQUEST_PHOTO)
        if r and r[0]:
            ret['most_request_photo_card'] = (Card.get(r[0][0]), r[0][1])

        r = store.execute("select user_id, s.c from (select user_id, count(user_id) as c from me_notify"
                " where ntype=%s group by user_id) as s order by s.c desc limit 1", Notify.TYPE_REQUEST_CHANGE_PHOTO)
        if r and r[0]:
            ret['most_request_change_photo_card'] = (Card.get(r[0][0]), r[0][1])

        return ret
Example #9
0
def comment(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()
        #print 'j comment', card_id, content
        if card and req.user and content:
            card.comment(req.user.id, content)
            card = Card.get(card.id)
            r = {
                'err':'ok',
                'html': stf("/card/card.html", "card_comments", card=card, req=req),
            }
    return json.dumps(r)
Example #10
0
def uncomment(req):
    r = {
        'err':'invalid'
    }
    if req.get_method() == "POST":
        card_id = req.get_form_var('cid', '')
        comment_id = req.get_form_var('comment_id', '')
        card = Card.get(card_id)
        #print 'j uncomment', comment_id
        if req.user and card:
            Comment.remove(req.user.id, comment_id)
            card = Card.get(card.id)
            r = {
                'err':'ok',
                'html': stf("/card/card.html", "card_comments", card=card, req=req),
            }
    return json.dumps(r)
Example #11
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)
Example #12
0
    def admin(self, req):
        if req.user and req.user.id in ADMINS:
            if req.get_method() == "POST":
                hide_id = req.get_form_var("hide_id", "")
                card = Card.get(hide_id)
                if card:
                    Card.hide(card.id, req.user.id)
                badage_id = req.get_form_var("badage_id", "")
                badage_name = req.get_form_var("badage_name", "")
                badage_intro = req.get_form_var("badage_intro", "")
                badage_icon = req.get_form_var("badage_icon", "")
                badage = None
                if badage_id:
                    badage = Badage.get(badage_id)
                if badage_name and badage_intro and badage_icon:
                    if badage:
                        badage.update(badage_name, badage_intro, badage_icon)
                    else:
                        Badage.new(badage_name, badage_intro, badage_icon)
                badage_name = req.get_form_var("add_badage_name", "")
                badage = Badage.get_by_name(badage_name)
                if badage:
                    badage_user_ids = req.get_form_var("badage_user_ids", "").strip().split()
                    for u in badage_user_ids:
                        card = Card.get(u)
                        if card:
                            Badage.add(card.id, badage.id, req.user.id)

                award_badage_name = req.get_form_var("award_badage_name", "")
                award_sponsor = req.get_form_var("award_sponsor", "")
                award_num = req.get_form_var("award_num", "")
                award_vote_days = req.get_form_var("award_vote_days", "")
                if award_badage_name and award_num and award_vote_days:
                    award_num = award_num.isdigit() and int(award_num) or 5
                    award_vote_days = award_vote_days.isdigit() and int(award_vote_days) or 7
                    Award.new(award_badage_name, award_sponsor, award_num, award_vote_days)
            badages = Badage.gets()
            awards = Award.gets()
            q_card = req.get_form_var("q_card", "")
            q_tag = req.get_form_var("q_tag", "")
            if q_card and q_tag:
                taggers = Tag.get_taggers(q_card, q_tag)
            return st('/misc/admin.html', **locals())
        raise AccessError("need admin")
Example #13
0
 def add_member(self, req):
     group = self.group
     q = req.get_form_var('q', None)
     if q and req.get_method() == 'POST':
         card = Card.get(q)
         if not card:
             card = Card.get_by_ldap(q)
         if card:
             group.add_member(card.id, req.user.id)
     return req.redirect(group.path)
Example #14
0
def names(req):
    q = req.get_form_var('term', None)
    q = q.strip()
    r = []
    if q:
        user_dict = get_users_dict()
        ids = set([v for k, v in user_dict.iteritems() if k.startswith(q)])
        for i in list(ids):
            card = Card.get(i)
            r.append({ "id": card.id, "label":card.screen_name , "value": card.uid})
    return json.dumps(r)
Example #15
0
def request_change_photo(req):
    r = {
        'err':'invalid'
    }
    if req.get_method() == "POST":
        card_id = req.get_form_var('cid', '')
        card = Card.get(card_id)
        if card and req.user:
            Notify.new(card.id, req.user.id, Notify.TYPE_REQUEST_CHANGE_PHOTO)
            r = {
                'err':'ok',
            }
    return json.dumps(r)
Example #16
0
def read_notify(req):
    r = {
        'err':'ok'
    }
    if req.get_method() == "POST":
        if req.user:
            blog_id = req.get_form_var('bid', None)
            if blog_id:
                Notify.read_by_blog(req.user.id, blog_id)
            else:
                Notify.read_by_card(req.user.id)
            card = Card.get(req.user.id)
            r['num'] = card and card.notify_num or 0
    return json.dumps(r)
Example #17
0
def vote(req):
    r = {
        'err':'invalid'
    }
    if req.get_method() == "POST":
        card_id = req.get_form_var('cid', '')
        aid = req.get_form_var('aid', '')
        card = Card.get(card_id)
        award = Award.get(aid)
        if card and req.user and award and \
            not award.is_expired and not award.is_voted(card.id, req.user.id):
            award.vote_by_user(card.id, req.user.id)
            r = {
                'err':'ok',
            }
    return json.dumps(r)
Example #18
0
File: utils.py Project: leonsim/me
 def repl(self, match):
     at, name, protocol, link, topic = match.groups()
     #print 'repl enable_topic=', self.enable_topic
     #print 'mention', at, name, protocol, link, topic
     if at and name:
         user_id = self.users_dict.get(name.lower(), None)
         card = user_id and Card.get(user_id)
         if card:
             return user_id, '<a href="%s">@%s</a>' % (card.path, card.screen_name), 'card'
     if protocol and link:
         url = protocol + link
         if url.startswith(SITE):
             return None, '<a href="%s">%s</a>' % (url, url), 'url'
         else:
             return None, '<a href="%s" target="_blank">%s</a>' % (url, url), 'url'
     if self.enable_topic and topic:
         return topic, '<a href="/topic/%s">#%s#</a>' % (html_quote(topic.upper()), html_quote(topic.upper())), 'topic'
     return None, at or topic, None
Example #19
0
def card(req):
    card_id = req.get_form_var('cid', '')
    card = Card.get(card_id)
    if card:
        return json.dumps(card.json_dict(req.user))
    raise TraversalError('no such card')
Example #20
0
File: blog.py Project: leonsim/me
 def author_card(self):
     from webapp.models.card import Card
     uid = self.extra.get('author_id', None)
     if uid:
         return Card.get(uid)
Example #21
0
File: event.py Project: leonsim/me
 def author_cards(self):
     rs = store.execute("select distinct(author_id) from me_event_photo where event_id=%s", self.id)
     return [Card.get(str(r[0])) for r in rs]
Example #22
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!!!'
Example #23
0
File: group.py Project: fordream/me
 def owner_card(self):
     return Card.get(self.user_id)
Example #24
0
 def card(self):
     from webapp.models.card import Card
     return Card.get(self.user_id)
Example #25
0
 def author_card(self):
     from webapp.models.card import Card
     return Card.get(self.author_id)
Example #26
0
File: event.py Project: leonsim/me
 def author_card(self):
     return Card.get(self.author_id)
Example #27
0
File: group.py Project: fordream/me
 def members(self):
     rs = store.execute("select user_id from me_group_member where group_id=%s order by rtime desc", self.id)
     return [Card.get(r[0]) for r in rs]
Example #28
0
File: event.py Project: leonsim/me
 def card(self):
     return Card.get(self.user_id)
Example #29
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