Beispiel #1
0
    def relation_filter(origin, uid, relation):
        '''
			此函数位于 PublicMessageAction
			处理的情况(可以叠加): ('', 'all', 'self', 'friend', 'follower')
			此函数返回 yield 体,不打乱顺序
		'''
        if 'friend' in relation:
            from quan_account.views import UserSnap
            friend_list = UserSnap.contact_list(uid)
        if 'follower' in relation:
            from quan_account.views import UserSnap
            following_list = UserSnap.following_find(uid)
        for i in origin:
            if not relation or 'all' in relation:
                yield i
                continue
            if 'self' in relation:
                if i.major_relation == 'user' and i.major_id == uid:
                    yield i
                    continue
            if i.major_relation == 'user':
                if 'friend' in relation and i.major_id in friend_list:
                    yield i
                    continue
                if 'follower' in relation and i.major_id in following_list:
                    yield i
                    continue
Beispiel #2
0
    def link_find(message):
        '''
			查找链接
		'''
        from quan_account.views import UserSnap, ClubSnap, AccountSnap
        relation = message.conn_relation
        minor_id = message.send_id
        try:
            if relation in ('event', 'signup'):
                return '/event/%d/' % minor_id
            elif relation == 'badge':
                from quan_badge.views import BadgeSnap
                qry = BadgeSnap.badge_find_by_bid(bid)
                return '/club/%s/' % ClubSnap.sname_find_by_cid(qry.account_id)
            elif relation in ('member', 'club'):
                sname = ClubSnap.sname_find_by_cid(minor_id)
                return '/club/%s/' % sname
            elif relation in ('share', 'comment'):
                suid = ShareSnap.uuid_find_by_sid(minor_id)
                return '/share/%s/' % suid
            elif relation == 'user':
                sname = UserSnap.sname_find_by_uid(major_id)
                return '/user/%s/' % sname
            elif relation == 'news':
                return '/news/%d/' % minor_id
            else:
                return '#'
        except Exception as e:
            print(e)
            return '#error'
Beispiel #3
0
    def private_message_fetch(request):
        '''
			[JSON] /message/private/
			status说明:
				-1	更新早于-time_create的最后16条消息
				0	更新最近16条
				1	更新晚于time_create的条目
			更新较早信息可以通过返回的time_stamp字段得到最早的信息的时间
		'''
        from quan_ua.views import UserAgentSnap, Snap
        dict_render = UserAgentSnap.record(request)
        if request.method != 'POST':
            raise Http404('请求方法不正确')
        from quan_account.views import UserSnap, ClubSnap
        uid = UserSnap.uid_find_by_request(request)
        if not uid:
            raise Http403('请先登录')
        current, time_create, status = MessageSnap.update_situation(request)
        send_src = request.POST.get('send_src', '')
        try:
            if send_src not in ('', 'club', 'user', 'system'):
                raise ValueError
            send_id = int(request.POST.get('send_id', '0'))
        except ValueError:
            raise Http404('参数错误')
        # 可能的情况
        #	从 0 更新所有的字段
        #	从 0 更新一个字段
        #	从一分钟前更新所有字段
        #	向前更新一个字段
        limit = 4
        if send_src:
            if send_src == 'club' and send_id not in ClubSnap.contact_list(
                    uid):
                raise Http403('权限错误')
            qry = PrivateMessageAction.find \
                (status, time_create, uid, send_src, send_id, limit)
        else:
            answer = PrivateMessageAction.all(status, time_create, uid, limit)
            qry = itertools.chain.from_iterable(answer.values())
        message_list = list(PrivateMessageAction.chat_wrap(qry, uid))

        if message_list:
            time_last = min(message_list, key=lambda x: x['time_stamp']) \
             ['time_stamp']
        elif status == -1:
            time_last = time_create.timestamp()
        else:
            time_last = current
        json_data = {
            'msglist': message_list,
            'time_update': current,
            'time_last': time_last,
        }
        resp = Snap.success(request, '', json_data)
        resp['Access-Control-Allow-Origin'] = \
         request.META['wsgi.url_scheme'] + '://shierquan.ercli.dev'
        return resp
Beispiel #4
0
    def contact_hi(request):
        '''
			[POST] user_view 打招呼
			status
				real
				conceal
		'''
        from quan_ua.views import UserAgentSnap, Snap
        dict_render = UserAgentSnap.record(request)
        from quan_account.views import UserSnap
        status = request.POST.get('status', '')
        content = request.POST.get('content', '')
        host_id = request.POST.get('uid', '0')
        sender_id = UserSnap.uid_find_by_request(request)
        if sender_id in ('0', 0, None):
            raise Snap.error('请先登录')
        if host_id in ('0', 0):
            raise Snap.error('请指明收件人')
        if status == 'real' or 1:  # from AccountViews.user_friend
            friend_status = UserSnap.friend_status_find(host_id, sender_id)
            if friend_status == 'friend-waiting-reverse':  #visitor需要确认
                UserSnap.friend_check(sender_id, host_id)
            elif friend_status == 'none' and not UserSnap.is_friend_annoy \
             (sender_id, host_id) :
                UserSnap.friend_wait(sender_id, host_id)
            sender_id_show = sender_id
            # sender_nickname_show = UserSnap.nickname_find_by_uid(sender_id)
        else:  # conceal, 暂时
            sender_id_show = 0
            # sender_nickname_show = "一个人"
        PrivateMessageAction.save(content, sender_id_show, 'hi', host_id,
                                  'user', sender_id_show, 'user')
        return Snap.success(request, '投递成功')
Beispiel #5
0
 def message_leave(request):
     '向社团社长和副社长的系统通知投递对社团的意见'
     from quan_ua.views import UserAgentSnap, Snap
     dict_render = UserAgentSnap.record(request)
     from quan_account.views import UserSnap, ClubSnap
     aid = int(request.POST.get('aid', '0'))
     src = request.POST.get('src', '')
     uid = UserSnap.uid_find_by_request(request)
     if not uid:
         raise Snap.error('您还没有登录')
     content = request.POST.get('content', '')
     if len(content) == 0:
         raise Snap.error('请写内容')
     for i in ClubSnap.leader_find_by_cid(aid):
         PrivateMessageAction.save(content, aid, 'leave', i.id, 'user', uid,
                                   'user')
     return Snap.success(request, '投递成功')
Beispiel #6
0
 def message_send(request):
     from quan_account.views import UserSnap
     from quan_share.views import ShareViews
     from quan_ua.views import UserAgentSnap, Snap
     dict_render = UserAgentSnap.record(request)
     send_id = UserSnap.uid_find_by_request(request)
     if not send_id:
         raise Snap.error('请先登录再发送消息')
     content = request.POST.get('content', '')
     if not content:
         raise Snap.error('不能发送空白消息')
     if request.POST.get('attach_uuid', ''):
         return ShareViews.share_create(request)
     try:
         recv_src = request.POST.get('recv_src', '')
         recv_id = int(request.POST.get('recv_id', '0'))
         if recv_src not in ('club', 'user', 'system'):
             raise ValueError
     except ValueError:
         raise Snap.error('参数错误')
     PrivateMessageAction.save \
      (content, 0, 'none', recv_id, recv_src, send_id, 'user')
     return Snap.success(request, '投递成功')
Beispiel #7
0
    def chat_wrap(qry, recv_id):
        '''
			为 PrivateMessage 写的 qry->list 函数
			其中 send_src 和 send_id 表明期望的 host_id
			返回 yield 体
		'''
        from quan_event.views import EventSnap
        from quan_avatar.views import AvatarSnap
        from quan_account.views import ClubSnap, AccountSnap, UserSnap
        from quan_ua.views import ChineseSnap
        message_list = []
        for i in qry:
            # user A = 自身
            # user B = 好友
            # club C = 一个社团
            # 可能出现的情况	host	avatar
            #	user
            #		A -> B	 B		A
            #		B -> A	 B		B
            #	club
            #		C -> A	 C		C
            #		A -> C	 C		A
            #		B -> C	 C		B
            host_src, host_id = PrivateMessageAction.get_host(i, recv_id)
            src = i.conn_relation
            if i.send_id == recv_id and i.send_relation == 'user':
                if src == 'share':
                    src = 'share-self'
                else:
                    src = 'self'
            elif src == 'none':
                src = 'other'
            if i.send_relation == 'user' and src == 'share':
                src = 'share-other'
            message_dict = {
                'content': i.content,
                'time_update': ChineseSnap.datetime_simp(i.time_create),
                'url': PrivateMessageAction.link_find(i),
                'avatar': AvatarSnap.avatar_all(i.send_relation, i.send_id),
                'type': src,
                'host_id': host_id,
                'host_src': host_src,
                'time_stamp': i.time_create.timestamp(),
            }
            aid = i.conn_id
            if src in ('share', 'share-self', 'share-other'):
                from quan_share.views import ShareSnap
                qry = ShareSnap.share_find_by_sid(aid)
                if qry:
                    from quan_share.views import ShareSnap
                    message_dict.update({
                     'data': {
                      'subject': qry.subject,
                      'uuid': qry.attach_uuid
                     },
                     'attach': ShareSnap.file_list_find_by_suid \
                            (qry.attach_uuid, True),
                    })
            elif src in ('event', 'event-signup'):
                from quan_event.views import EventSnap
                qry = EventSnap.event_find_by_evid(aid)
                if not qry:
                    continue
                club = ClubSnap.club_find_by_cid(qry.account_id)
                if not club:
                    continue
                message_dict.update({
                    'data': {
                        'subject': qry.subject,
                        'location': qry.location,
                        'content': qry.content,
                        'id': qry.id,
                    },
                    'avatar':
                    AvatarSnap.avatar_all(qry.relation, qry.account_id),
                    'club': {
                        'full_name': club.full_name
                    },
                    'date':
                    ChineseSnap.datetime_simp(qry.time_set),
                })
            elif src == 'badge':
                from quan_badge.views import BadgeSnap
                qry = BadgeSnap.badge_find_by_bid(aid)
                if not qry:
                    continue
                club = ClubSnap.club_find_by_cid(qry.account_id)
                if not club:
                    continue
                message_dict.update({
                    'name': qry.name,
                    'club': {
                        'simp_name': club.simp_name
                    },
                })
            elif src in ('friend', 'hi'):
                aid = i.send_id
                message_dict.update({
                    'avatar':
                    AvatarSnap.avatar_all('user', aid),
                    'nickname':
                    UserSnap.nickname_find_by_uid(aid),
                    'id':
                    aid,
                    'sname':
                    UserSnap.sname_find_by_uid(aid),
                    'disable':
                    '',
                })
                if AccountSnap.relation_check \
                 (recv_id, aid, ('uu-friend', 'uu-friend-wait')) :
                    message_dict['disable'] = 'disabled="disabled"'
            elif src == 'leave':
                message_dict.update({
                    'cname':
                    ClubSnap.fname_find_by_cid(i.conn_id),
                    'fname':
                    UserSnap.fname_find_by_uid(i.send_id),
                })
            else:  # other, self
                message_dict.update({
                 'avatar': AvatarSnap.avatar_all(i.send_relation, i.send_id),
                 'nickname': AccountSnap.nickname_find_by_aid \
                  (i.send_relation, i.send_id),
                })
                if i.send_id == recv_id and i.send_relation == 'user':
                    message_dict['type'] = 'self'
            yield message_dict
Beispiel #8
0
    def account_info_find(src, aid):
        '''
			得到用户/社团的信息字典(为了返回json消息)
		'''
        from quan_avatar.views import AvatarSnap
        from quan_account.views import UserSnap, ClubSnap, AccountSnap
        from quan_forum.views import ForumSnap
        default = {
            'link': '',
            'text': '',
            'image': '',
        }
        if src == 'club':
            return {
                'link': '/club/%s/' % ClubSnap.sname_find_by_cid(aid),
                'text': ClubSnap.fname_find_by_cid(aid),
                'image': AvatarSnap.avatar_find('club', aid, 'small'),
            }
        elif src == 'user':
            return {
                'link': '/user/%s/' % UserSnap.sname_find_by_uid(aid),
                'text': UserSnap.nickname_find_by_uid(aid),
                'image': AvatarSnap.avatar_find('user', aid, 'small'),
            }
        elif src == 'event':
            from quan_event.views import EventSnap
            event = EventSnap.event_find_by_evid(aid)
            if not event:
                return default
            cid = event.account_id
            return {
                'link': '/event/%d/' % aid,
                'text': event.subject,
                'image': AvatarSnap.avatar_find('club', cid, 'small'),
            }
        elif src == 'share':
            from quan_share.views import ShareSnap
            share = ShareSnap.share_find_by_sid(aid)
            if not share:
                return default
            suid = share.attach_uuid
            return {
             'link':  '/share/%s/' % suid,
             'text':  share.subject,
             'image': ShareSnap.thumbnail_find(suid, 'small') or \
                AvatarSnap.avatar_find \
                 (share.relation, share.account_id, 'small'),
            }
        elif src == 'badge':
            from quan_badge.views import BadgeSnap
            badge = BadgeSnap.badge_find_by_bid(aid)
            if not badge:
                return default
            sname = ClubSnap.sname_find_by_cid(badge.account_id)
            return {
                'link': '/club/%s/' % sname,
                'text': badge.name,
                'image': None,
            }
        elif src == 'news':
            from quan_news.views import NewsSnap
            news = NewsSnap.news_find(aid)
            if not news:
                return default
            return {
                'link': '/news/%d/' % aid,
                'text': news.subject,
                'image': None,
            }
        elif src == 'signature':
            user = UserSnap.user_find_by_uid(aid)
            if not user:
                return default
            return {
                'link': '/user/%s/' % user.last_name,
                'text': UserSnap.signature_find_by_uid(aid),
                'image': None,
            }
        elif src == 'nickname':
            user = UserSnap.user_find_by_uid(aid)
            if not user:
                return default
            return {
                'link': '/user/%s/' % user.last_name,
                'text': UserSnap.nickname_find_by_uid(aid),
                'image': None,
            }
        elif src == 'forum_thread':
            thread = ForumSnap.thread_find_by_thid(aid)
            sname = ForumSnap.sname_find_by_gid(thread.group_id)
            return {
                'link': '/forum/%s/%d/' % (sname, aid),
                'text': thread.subject,
                'image': None,
            }
        elif src == 'forum_response':
            thid = ForumSnap.thid_find_by_rid(aid)
            thread = ForumSnap.thread_find_by_thid(thid)
            sname = ForumSnap.sname_find_by_gid(thread.group_id)
            return {
             'link':  '/forum/%s/%d/?response=%d#response-%d' % \
                    (sname, thid, aid, aid),
             'text':  thread.subject,
             'image': None,
            }
        else:
            return default