Exemplo n.º 1
0
    def search_dicts(query, category):
        '''
			category in ('share', 'event', 'club')
			返回 yield 体
		'''
        if category == 'share':
            for i in ShareSnap.share_search(query):
                yield {
                 'data': i,
                 'avatar':
                  ShareSnap.thumbnail_find(i.attach_uuid, 'medium') or \
                  AvatarSnap.avatar_find \
                      (i.relation, i.account_id, 'medium'),
                }
        elif category == 'event':
            for i in EventSnap.event_search(query):
                yield {
                    'data': i,
                    'avatar': AvatarSnap.avatar_all(i.relation, i.account_id),
                }
        else:
            for i in ClubSnap.club_search(query):
                yield {
                    'data': i,
                    'avatar': AvatarSnap.avatar_all('club', i.id),
                }
Exemplo n.º 2
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
Exemplo n.º 3
0
	def single_event(request, evid) :
		event = EventSnap.event_find_by_evid(evid)
		if not event :
			return None
		evid = int(evid)
		event_dict = {'data':event,}
		date_string, time_end = ChineseSnap.datetime_comp(event.time_end)
		date_string, time_string = ChineseSnap.datetime_comp(event.time_set)
		event_dict['content'] = event.content.split('\n')
		event_dict['day_set'] = date_string
		event_dict['time_set'] = time_string
		event_dict['time_end'] = time_end
		event_dict['avatar'] = AvatarSnap.avatar_find(event.relation, event.account_id)
		event_dict['follower'] = EventSnap.follower_total(evid)
		event_dict['nice'] = EventSnap.nice_total(evid)
		event_dict['niced'] = EventSnap.niced_find_by_request(request, evid)
		event_dict['event_followed'] = EventSnap.followed_find_by_request(request, evid)
		if event.relation=='user':
			event_dict['sponsor_fname'] = '用户' + str(event.account_id)
		else:
			event_dict['sponsor_fname'] = ClubSnap.fname_find_by_cid \
															(event.account_id)
		event_dict['sponsor_sname'] = AccountSnap.sname_find_by_aid(event.relation, event.account_id)
		president = ClubSnap.cid_verify(request, event.account_id, True)
		event_dict.update(EventSnap.signed_get_by_event(event))
		event_dict['follower_list'] = EventSnap.follower_find_by_evid(event.id)
		event_dict['quest'] = EventSnap.quest_find_by_evid(event.id)
		time_status = EventSnap.time_status(event)

		# 计算需要显示的模块
		event_dict['president'] = president
		show = ()
		if president :
			if time_status == 0 and not event_dict['quest'] :
				show = ('signup_set', )
			elif time_status != -1 :
				show = ('join', 'signup_manual')
				if time_status == 0 :
					event_dict['signup_qrcode'] = \
									EventSnap.signup_qrcode_find_by_evid(evid)
		else :
			uid = UserSnap.uid_find_by_request(request)
			if time_status == 0 and event_dict['quest'] :
				if uid and not EventSnap.signed_find_by_uid(evid, uid) :
					show = ('signup', )
		for i in show :
			event_dict['show_%s' % i] = True
		
		# 为 share 和 event 关联渲染
		from quan_share.views import ShareSnap
		event_dict['share_list'] = [[]]
		event_dict['related_list'] = []
		related_list = []
		for i in ShareEventRelation.objects.filter(event_id=evid, status=0) :
			related_list.append(i.share_id)
		club_avatar = AvatarSnap.avatar_find \
			(event.relation, event.account_id, 'large')
		for i in ShareSnap.share_find_by_aid(event.relation, event.account_id) :
			thumbnail = ''
			if i.id in related_list :
				event_dict['relate_exist'] = True
				thumbnail = ShareSnap.thumbnail_find(i.attach_uuid, 'large')
			if not thumbnail :
				thumbnail = club_avatar
			append_object = {
				'data': i, 
				'related': i.id in related_list, 
				'date': ChineseSnap.datetime_simp(i.time_create), 
				'thumbnail': thumbnail, 
				'content': i.content.split('\n'), 
			}
			if len(event_dict['share_list'][-1]) < 10 :
				event_dict['share_list'][-1].append(append_object)
			else :
				event_dict['share_list'].append([append_object])
		return event_dict