Beispiel #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)
Beispiel #2
0
 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 []
Beispiel #3
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)
Beispiel #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)
Beispiel #5
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)
Beispiel #6
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")
Beispiel #7
0
 def search(self, req):
     req.nav = '/'
     q = req.get_form_var("q", None)
     cards = []
     if q:
         cards = Card.search(q)
     return st('/search.html', **locals())
Beispiel #8
0
    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
Beispiel #9
0
 def dig(self, req):
     req.nav = '/dig'
     basic_result = Dig.basic_result()
     gossip_result = Dig.gossip_result()
     hometowns = Dig.all_hometowns()
     hot_tags = Tag.gets(count=3)
     score_cards = Card.gets_by_score()
     return st('/dig.html', **locals())
Beispiel #10
0
 def cardcase(self, req):
     req.nav = '/cardcase'
     start = req.get_form_var('start')
     start = start and start.isdigit() and int(start) or 0
     card = req.card
     limit = DEVELOP_MODE and 2 or 16
     total, cards = Card.gets_by_card(req.user.id, start, limit)
     return st('/cardcase.html', **locals())
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
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")
Beispiel #15
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)
Beispiel #16
0
 def timeline(self, req):
     req.nav = '/timeline'
     years = xrange(datetime.now().year - 1, 2005, -1)
     now_year = str(datetime.now().year)
     year = req.get_form_var("year", now_year)
     start = req.get_form_var('start')
     limit = req.get_form_var('count', 20)
     start = start and str(start).isdigit() and int(start) or 0
     limit = limit and str(limit).isdigit() and int(limit) or 0
     n, cards = Card.gets_by_time(year, start, 200)
     return st('/timeline.html', **locals())
Beispiel #17
0
 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
Beispiel #18
0
 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
Beispiel #19
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)
Beispiel #20
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)
Beispiel #21
0
 def cards(self, req):
     req.nav = '/cards'
     cate = req.get_form_var('cate', '')
     start = req.get_form_var('start')
     start = start and str(start).isdigit() and int(start) or 0
     limit = 32
     total, cards = Card.gets(cate, start, limit)
     prefix = "/cards?cate=%s&" % cate
     if req.get_form_var("output", None) == 'json':
         req.response.set_content_type('application/json; charset=utf-8')
         r = {
                 "cards": [c.json_dict(req.user) for c in cards]
         }
         return json.dumps(r)
     return st('/cards/cards.html', **locals())
Beispiel #22
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)
Beispiel #23
0
    def _q_index(self, req):
        print 'Enter into index.'
        if req.card and not req.card.is_basic:
            return req.redirect('/mine')
        req.nav = '/'
        card = req.card
        photo_num, photo_cards = Card.gets(cate='photo', limit=20)

        all_badages = Badage.gets()

        num, blogs = Blog.gets(limit=30)
        num, photo_blogs = Blog.get_photo_blogs(limit=40)
        photo_blogs = [b for b in photo_blogs if b.n_unlike == 0]
        num, event_photos = EventPhoto.gets(limit=20)
        new_photos = sorted(photo_blogs + event_photos + photo_cards, key=attrgetter('sort_time'), reverse=True)
        print 'Index...'
        return st('/index.html', **locals())
Beispiel #24
0
 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
Beispiel #25
0
    def update_tags(self, tags):
        rs = store.execute("select tag_id from me_group_tag where group_id=%s and tagger_id=%s"
            " order by tag_id", (self.id, self.user_id))
        old_tag_ids = [str(r[0]) for r in rs]
        #print 'old tag ids', old_tag_ids
        store.execute("delete from me_group_tag where group_id=%s and tagger_id=%s", (self.id, self.user_id))
        for t in tags:
            if t:
                r = store.execute("select id from me_tag where name=%s", t)
                if r and r[0]:
                    tag_id = r[0][0]
                else:
                    store.execute("insert into me_tag(name) values(%s)", t)
                    tag_id = store.get_cursor(table="me_tag").lastrowid
                if tag_id:
                    store.execute("replace into me_group_tag(group_id, tagger_id, tag_id)"
                        " values(%s,%s,%s)", (self.id, self.user_id, tag_id))

        store.commit()
        for t in self.tag_names:
            ds = Card.gets_by_tag(t)
            [self._join(d.id) for d in ds]
            Notify.new(self.user_id, self.user_id, Notify.TYPE_TAG_ADD_GROUP, extra={"group_id":self.id, "tag":t})
Beispiel #26
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')
Beispiel #27
0
def _q_lookup(req, name):
    card = Card.get_by_ldap(name)
    if card and not card.is_hide:
        return CardUI(req, card)
    return TraversalError("no such card")
Beispiel #28
0
def get_sorted_objects():
    cards = Card.gets_all()
    events = Event.gets()
    objects = sorted(cards + events, key=attrgetter('sort_date'))
    return objects
Beispiel #29
0
def _q_lookup(req, tag):
    tag = unescape_path(tag)
    cards = Card.gets_by_tag(tag)
    return st('/cards/tag.html', **locals())
Beispiel #30
0
def _q_lookup(req, name):
    cards = Card.gets_by_hometown(name)
    return st('/cards/hometown.html', **locals())