Exemple #1
0
def get_recommend_list(request, userProfile, **kwargs):
    #判断推荐分数是否生成
    flag = MatchResult.objects.is_exist_by_userid(request.user.id)
    #从缓存中获取不推荐用户id
    from util.cache import get_no_recomend_list_by_cache
    disLikeUserIdList = get_no_recomend_list_by_cache(request.user.id)
    if flag:
        matchResultList = MatchResult.objects.get_match_result_by_userid(
            request.user.id, disLikeUserIdList)
        arg = page(request, matchResultList, **kwargs)
        matchResultList = arg['pages']
        from apps.pojo.card import matchResultList_to_CardList
        matchResultList.object_list = matchResultList_to_CardList(
            request.user.id, matchResultList.object_list)
    else:
        if disLikeUserIdList is None:
            userProfileList = UserProfile.objects.filter(
                avatar_name_status='3').exclude(
                    gender=userProfile.gender).exclude(
                        user_id__in=STAFF_MEMBERS, )
        else:
            userProfileList = UserProfile.objects.filter(
                avatar_name_status='3').exclude(
                    user_id__in=disLikeUserIdList).exclude(
                        gender=userProfile.gender).exclude(
                            user_id__in=STAFF_MEMBERS)
        arg = page(request, userProfileList, **kwargs)
        matchResultList = arg['pages']
        from apps.pojo.card import userProfileList_to_CardList
        matchResultList.object_list = userProfileList_to_CardList(
            request.user.id, matchResultList.object_list)

    return matchResultList
Exemple #2
0
def get_recommend_list(request, flag, disLikeUserIdList, userProfile,
                       **kwargs):
    if flag:
        matchResultList = MatchResult.objects.get_match_result_by_userid(
            request.user.id, disLikeUserIdList)
        arg = page(request, matchResultList, **kwargs)
        matchResultList = arg['pages']
        from apps.pojo.card import matchResultList_to_CardMobileList
        matchResultList.object_list = matchResultList_to_CardMobileList(
            request.user.id, matchResultList.object_list)
    else:
        if disLikeUserIdList is None:
            userProfileList = UserProfile.objects.filter(
                avatar_name_status='3').exclude(
                    gender=userProfile.gender).exclude(
                        user_id__in=STAFF_MEMBERS, )
        else:
            userProfileList = UserProfile.objects.filter(
                avatar_name_status='3').exclude(
                    user_id__in=disLikeUserIdList).exclude(
                        gender=userProfile.gender).exclude(
                            user_id__in=STAFF_MEMBERS)
        arg = page(request, userProfileList, **kwargs)
        matchResultList = arg['pages']
        from apps.pojo.card import userProfileList_to_CardMobileList
        matchResultList.object_list = userProfileList_to_CardMobileList(
            request.user.id, matchResultList.object_list)
    return matchResultList
Exemple #3
0
def comment_list(request, template_name):
    args = {}
    try:
        if request.is_ajax():
            if FriendDynamicComment.objects.get_no_read_comment_count(
                    request.user.id) > 0:
                friendDynamicCommentList = FriendDynamicComment.objects.get_no_read_comment_list(
                    request.user.id)
                data = page(request, friendDynamicCommentList)
                friendDynamicIds = [
                    friendDynamic['id']
                    for friendDynamic in data['pages'].object_list
                ]
                FriendDynamicComment.objects.filter(
                    id__in=friendDynamicIds).update(isRead=True)
            else:
                friendDynamicCommentList = FriendDynamicComment.objects.get_comment_list(
                    request.user.id)
                data = page(request, friendDynamicCommentList)
            from apps.pojo.message import messagedynamics_to_message_page
            messageList = messagedynamics_to_message_page(
                data['pages'].object_list)
            args['messageList'] = simplejson.dumps(messageList)
            if data['pages'].has_next():
                #如果为未读
                if data['pages'].object_list[0]['isRead']:
                    args['next_page_number'] = 1
                else:
                    args['next_page_number'] = data['pages'].next_page_number()
            else:
                args['next_page_number'] = -1
            json = simplejson.dumps(args)
            return HttpResponse(json)
        else:
            from pinloveweb.method import get_no_read_web_count
            args.update(get_no_read_web_count(request.user.id, u'message'))
            args['user'] = request.user
            from apps.user_app.method import get_avatar_name
            args['avatar_name'] = get_avatar_name(request.user.id,
                                                  request.user.id)
            return render(
                request,
                template_name,
                args,
            )
    except Exception, e:
        logger.exception('获取评论列表,出错')
        args = {'result': 'error', 'error_message': '获取评论列表出错'}
        if request.is_ajax():
            json = simplejson.dumps(args)
            return HttpResponse(json)
        else:
            return render(request, 'error.html', args)
Exemple #4
0
def message_list(request, template_name):
    args = {}
    try:
        if request.is_ajax():
            if MessageLog.objects.get_no_read_private_msessge_count(
                    request.user.id) > 0:
                messageLogList = MessageLog.objects.get_no_read_messagelog(
                    request.user.id)
                data = page(request, messageLogList)
                MessageIds = [
                    messageLog['id']
                    for messageLog in data['pages'].object_list
                ]
                MessageLog.objects.filter(message_id__in=MessageIds).update(
                    isRead=True)
            else:
                messageLogList = MessageLog.objects.messagelog_list(
                    request.user.id)
                data = page(request, messageLogList)
            from apps.pojo.message import messagedynamics_to_message_page
            messageList = messagedynamics_to_message_page(
                data['pages'].object_list)
            args['messageList'] = simplejson.dumps(messageList)
            if data['pages'].has_next():
                #如果为未读
                if data['pages'].object_list[0]['isRead']:
                    args['next_page_number'] = 1
                else:
                    args['next_page_number'] = data['pages'].next_page_number()
            else:
                args['next_page_number'] = -1
            json = simplejson.dumps(args)
            return HttpResponse(json)
        else:
            #获取未读信息条数
            from pinloveweb.method import get_no_read_web_count
            args.update(
                get_no_read_web_count(request.user.id, fromPage=u'message'))
            args['user'] = request.user
            from apps.user_app.method import get_avatar_name
            args['avatar_name'] = get_avatar_name(request.user.id,
                                                  request.user.id)
            return render(request, template_name, args)

    except Exception, e:
        logger.exception('私信列表私信列表出错!')
        args = {'result': 'error', 'error_message': '私信列表出错'}
        if request.is_ajax():
            json = simplejson.dumps(args)
            return HttpResponse(json)
        else:
            return render(request, 'error.html', args)
Exemple #5
0
def no_read_comment_list(request, template_name):
    args = {}
    try:
        user = request.user
        userProfile = UserProfile.objects.get(user=user)
        commentList = FriendDynamicComment.objects.get_no_read_comment_by_user_id(
            user.id)
        args = page(request, commentList)
        from apps.pojo.dynamic import FriendDynamicCommentList_to_CommentDynamicList
        args[
            'pages'].object_list = FriendDynamicCommentList_to_CommentDynamicList(
                args['pages'].object_list)
        commentList.update(isRead=True)
        if args['pages'].has_next():
            args['next_page_number'] = args['pages'].next_page_number()
        else:
            args['next_page_number'] = -1
        #初始化个人信息模块
        from pinloveweb.method import init_person_info_for_card_page
        args.update(init_person_info_for_card_page(userProfile))
        if request.is_ajax():
            from django.core.serializers.json import DjangoJSONEncoder
            json = simplejson.dumps(
                {
                    'friendDynamicCommentList': args['pages'].object_list,
                    'next_page_number': args['next_page_number']
                },
                cls=DjangoJSONEncoder)
            return HttpResponse(json, mimetype='application/json')
        return render(request, template_name, args)
    except Exception, e:
        logger.exception('获取未读评论列表,出错')
Exemple #6
0
def init_dynamic(request, userId, arg, type=None, **kwargs):
    from apps.pojo.dynamic import friendDynamicList_to_Dynamic
    #获取单条消息列表
    if not kwargs.get('dynamicId') is None:
        friendDynamicList = FriendDynamic.objects.filter(
            id=kwargs.get('dynamicId'))
        arg['friendDynamicList'] = simplejson.dumps(
            friendDynamicList_to_Dynamic(friendDynamicList, userId),
            cls=MyEncoder)
        arg['next_page_number'] = -1
        arg['publish'] = False
        return arg
    elif type == 0:
        friendDynamicList = FriendDynamic.objects.get_follow_list(userId)
        arg['publish'] = True
    else:
        friendDynamicList = FriendDynamic.objects.select_related(
            'publishUser').filter(
                publishUser_id=userId).order_by('-publishTime')
        userId = request.user.id
        arg['False'] = False
    data = page(request, friendDynamicList)
    friendDynamicList = friendDynamicList_to_Dynamic(data['pages'].object_list,
                                                     userId)
    arg['friendDynamicList'] = simplejson.dumps(friendDynamicList,
                                                cls=MyEncoder)
    if data['pages'].has_next():
        arg['next_page_number'] = data['pages'].next_page_number()
    else:
        arg['next_page_number'] = -1
    return arg
Exemple #7
0
def no_read_message(request, template_name):
    args = {}
    try:
        messageList = MessageLog.objects.get_no_read_messagelog(
            request.user.id)
        args = page(request, messageList)
        messageList = args['pages']
        messageList.object_list = MessageLog_to_Message(
            messageList.object_list, request.user.id)
        #用户消息标记为已读
        MessageLog.objects.clean_message(request.user.id)
        if request.is_ajax():
            data = {}
            data['messageList'] = messageList.object_list
            data['has_next'] = messageList.has_next()
            if messageList.has_next():
                data['next_page_number'] = messageList.next_page_number()
            json = simplejson.dumps(data, cls=MessageBeanEncoder)
            return HttpResponse(json)
        args['pages'] = messageList
        userProfile = UserProfile.objects.get(user_id=request.user.id)
        from pinloveweb.method import init_person_info_for_card_page
        args.update(init_person_info_for_card_page(userProfile))
        args['from'] = 'no_read_message'
        return render(request, template_name, args)
    except Exception, e:
        error_mesage = '获取用户未读消息,出错!'
        logger.exception(error_mesage)
Exemple #8
0
def charge_record(request):   
    args={} 
    sql='''
    SELECT *   from `order` u
where u.user_id=%s and not(u.`status`='initial' and u.channel='1' and u.updateTime is null)
ORDER BY IF(u.createTime>IFNULL(u.updateTime,DATE(0)),u.createTime,u.updateTime) DESC

    '''
    orderList=Order.objects.raw(sql,[request.user.id])
    data=page(request,orderList,page_num=8)
    args['has_next']=data['pages'].has_next()
    if data['pages'].has_next():
        args['next_page_number']=data['pages'].next_page_number()
    if data['pages'].has_previous():
        args['previous_page_number']=data['pages'].previous_page_number()
    args['has_previous']=data['pages'].has_previous()
    list=[]
    for order in data['pages'].object_list:
        dict={}
        dict['amount']=order.amount
        dict['data']=order.data
        if order.updateTime!=None:
            dict['time']=order.updateTime.strftime("%Y-%m-%d")
        else:
             dict['time']=order.createTime.strftime("%Y-%m-%d")
        dict['channel']=order.get_channel_display()
        dict['type']=order.type
        dict['status']=order.get_status()
        list.append(dict)
    args['orderList']=list
    args['result']='success'
    json=simplejson.dumps(args)
    return HttpResponse(json)
Exemple #9
0
def the_people_nearby(request):
    arg = {}
    userProfile = UserProfile.objects.get_user_info(request.user.id)
    userProfileList = UserProfile.objects.filter(
        lastLoginAddress=GetLocation(request)).exclude(
            user=request.user).filter(avatar_name_status='3').exclude(
                gender=userProfile.gender)
    #分页
    from util.page import page
    arg = page(request, userProfileList)
    userList = arg['pages']
    if len(userList.object_list) > 0:
        from apps.pojo.card import userProfileList_to_CardList
        userList.object_list = userProfileList_to_CardList(
            request.user.id, userList.object_list)
        from pinloveweb.method import is_focus_each_other
        userList = is_focus_each_other(request.user.id, userList)
    else:
        userList.object_list = []
    if request.is_ajax():
        from pinloveweb.method import load_cards_by_ajax
        return load_cards_by_ajax(request, userList)
    from apps.pojo.card import MyEncoder
    userList.object_list = simplejson.dumps(userList.object_list,
                                            cls=MyEncoder)
    arg['pages'] = userList
    from pinloveweb.method import init_person_info_for_card_page
    arg.update(init_person_info_for_card_page(userProfile))
    from pinloveweb.method import get_no_read_web_count
    arg.update(get_no_read_web_count(request.user.id, fromPage=u'card'))
    return render(request, 'the_people_nearby.html', arg)
Exemple #10
0
def get_recommend_list(request, userProfile, userProfileList, **kwargs):
    args = page(request, userProfileList)
    matchResultList = args['pages']
    from apps.pojo.card import userProfileList_to_CardList
    matchResultList.object_list = userProfileList_to_CardList(
        request.user.id, matchResultList.object_list)
    return matchResultList
Exemple #11
0
def message(request, template_name):
    args = {}
    try:
        isRad = False
        user = request.user
        if request.is_ajax():
            from apps.message_app.models import get_no_read_message_dynamic_list_count, get_message_dynamic_list
            if get_no_read_message_dynamic_list_count(user.id) > 0:
                messageDynamicList = get_message_dynamic_list(user.id, False)
            else:
                messageDynamicList = get_message_dynamic_list(user.id, True)
                isRad = True
            pages = page(request, messageDynamicList)
            if not isRad:
                #标记成已读
                from apps.message_app.method import clean_message_Dynamic
                clean_message_Dynamic(user.id, pages['pages'].object_list)
            from apps.pojo.message import messagedynamics_to_message_page
            messageDynamicsList = messagedynamics_to_message_page(
                pages['pages'].object_list)
            if pages['pages'].has_next():
                #如果为未读
                if not pages['pages'].object_list[0]['isRead']:
                    args['next_page_number'] = 1
                else:
                    args['next_page_number'] = pages['pages'].next_page_number(
                    )
            else:
                args['next_page_number'] = -1
            args['messageList'] = simplejson.dumps(messageDynamicsList)
            json = simplejson.dumps(args)
            return HttpResponse(json)
        else:
            #获取未读信息条数
            from pinloveweb.method import get_no_read_web_count
            args.update(get_no_read_web_count(user.id, fromPage=u'message'))
            return render(request, template_name, args)

    except Exception as e:
        logger.exception('初始化个人消息出错!')
        args = {'result': 'error', 'error_message': '初始化个人消息出错'}
        if request.is_ajax():
            json = simplejson.dumps(args)
            return HttpResponse(json)
        else:
            return render(request, 'error.html', args)
Exemple #12
0
def message_detail(request, template_name):
    args = {}
    try:
        senderId = int(request.REQUEST.get('senderId', False))
        if senderId:
            args['userId'] = request.user.id
            args['username'] = User.objects.get(id=senderId).username
            args['senderId'] = senderId
            from apps.user_app.method import get_avatar_name
            args['avatarName'] = get_avatar_name(request.user.id,
                                                 request.user.id)
            #获取未读信息条数
            from pinloveweb.method import get_no_read_web_count
            args.update(
                get_no_read_web_count(request.user.id, fromPage=u'message'))
        else:
            args = {'result': 'error', 'error_message': '传递参数出错!'}
        if request.is_ajax():
            messageList = MessageLog.objects.messagelog_list_by_userid(
                senderId, request.user.id)
            data = page(request, messageList)
            from apps.pojo.message import messagedynamics_to_message_page
            messageList = messagedynamics_to_message_page(
                data['pages'].object_list)
            args['messageList'] = simplejson.dumps(messageList)
            if data['pages'].has_next():
                args['next_page_number'] = data['pages'].next_page_number()
            else:
                args['next_page_number'] = -1
            args['userId'] = request.user.id
            #标记已读
            from apps.message_app.method import clean_message_by_user
            clean_message_by_user(senderId, request.user.id)
            from apps.pojo.message import MessageBeanEncoder
            json = simplejson.dumps(args, cls=MessageBeanEncoder)
            return HttpResponse(json)
        else:
            return render(request, template_name, args)
    except Exception as e:
        print '%s%s' % ('获取我和指定异性之间所有私信出错,出错原因', e)
        args = {'result': 'error', 'error_message': '获取我和指定异性之间所有私信出错!'}
        json = simplejson.dumps(args)
        return HttpResponse(json)
Exemple #13
0
def nearby(request, template_name="mobile_neardy.html"):
    '''
    附近的人
    '''
    args = {}
    try:
        userProfile = UserProfile.objects.get_user_info(request.user.id)
        from apps.the_people_nearby.views import GetLocation
        userProfileList = UserProfile.objects.filter(
            lastLoginAddress=GetLocation(request)).exclude(
                user=request.user).filter(avatar_name_status='3').exclude(
                    gender=userProfile.gender)
        #分页
        args = page(request, userProfileList)
        userList = args['pages']
        if len(userList.object_list) > 0:
            from apps.pojo.card import userProfileList_to_CardMobileList
            userList.object_list = userProfileList_to_CardMobileList(
                request.user.id, userList.object_list)
        else:
            userList.object_list = []
        #判断推荐完成情况
        recommend_status = recommend_info_status(request.user.id,
                                                 channel='mobile')
        if not recommend_status['result']:
            args['has_recommend'] = True
        else:
            args['recommend_finish'] = simplejson.dumps(
                simplejson.dumps(recommend_status['data']))
        if request.is_ajax():
            from pinloveweb.method import load_cards_by_ajax
            return load_cards_by_ajax(request, userList, chanel='mobile')
        userList.object_list = simplejson.dumps(userList.object_list,
                                                cls=CardMobileEncoder)
        args['pages'] = userList
        from pinloveweb.method import init_person_info_for_card_page
        args.update(init_person_info_for_card_page(userProfile))
        return render(request, template_name, args)
    except Exception as e:
        logger.exception(e.message)
        args = {'result': 'error', 'error_message': e.message}
        return render(request, ERROR_TEMLATE_NAMR, args)
Exemple #14
0
def search(request, template_name='mobile_search.html'):
    '''
    搜索页面
    '''
    args = {}
    try:
        userProfile = UserProfile.objects.get_user_info(request.user.id)
        if request.method == 'POST':
            searchForm = SearchMobileForm(request.POST)
            if searchForm.is_valid():
                userProfileList = searchForm.select_data(
                    request.REQUEST.get('sunSign', '').rstrip(),
                    userProfile.gender, request.user.id)
                args = page(request, userProfileList)
                searchList = args['pages']
                from apps.pojo.card import userProfileList_to_CardMobileList
                searchList.object_list = userProfileList_to_CardMobileList(
                    request.user.id, searchList.object_list)
                searchList.object_list = simplejson.dumps(
                    searchList.object_list, cls=CardMobileEncoder)
                args['pages'] = searchList
                from pinloveweb.method import init_person_info_for_card_page
                args.update(init_person_info_for_card_page(userProfile))
                args['result'] = 'success'
                POSTcopy = request.POST.copy()
                POSTcopy.pop('csrfmiddlewaretoken')
                args['url'] = (request.path + '?' + urllib.urlencode(POSTcopy))
                #推荐信息完善情况
                recommend_status = recommend_info_status(request.user.id,
                                                         channel='mobile')
                if not recommend_status['result']:
                    args['has_recommend'] = True
                else:
                    args['recommend_finish'] = simplejson.dumps(
                        simplejson.dumps(recommend_status['data']))
                return render(request, 'mobile_search_result.html', args)
        elif request.is_ajax():
            searchForm = SearchMobileForm(request.GET)
            if searchForm.is_valid():
                userProfileList = searchForm.select_data(
                    request.REQUEST.get('sunSign', '').rstrip(),
                    userProfile.gender, request.user.id)
                args = page(request, userProfileList)
                searchList = args['pages']
                from apps.pojo.card import userProfileList_to_CardMobileList
                searchList.object_list = userProfileList_to_CardMobileList(
                    request.user.id, searchList.object_list)
                searchList.object_list = simplejson.dumps(
                    searchList.object_list, cls=CardMobileEncoder)
                args['pages'] = searchList
                args['result'] = 'success'

        else:
            searchForm = SearchMobileForm()
            searchForm.init_search_condition(request.user.id)
            from apps.search_app.views import get_disable_condition
            args.update(get_disable_condition(userProfile))
            args['searchForm'] = searchForm
            from apps.search_app.forms import SUN_SIGN_CHOOSICE
            args['sunSign'] = SUN_SIGN_CHOOSICE
            from pinloveweb.method import get_no_read_web_count
            args.update(
                get_no_read_web_count(request.user.id, fromPage=u'card'))
            args['result'] = 'success'
        if args.get('result', False) != 'success':
            args['result'] = 'error'
            args['error_message'] = []
            errorList = searchForm.errors.items()
            for error in errorList:
                args['error_message'].append([
                    SearchMobileForm.base_fields[error[0]].label, error[1][0]
                ])
            json = simplejson.dumps(args)
            return HttpResponse(json)
    except Exception as e:
        error_message = '搜索也卖弄出错:出错原因:' + e.message
        logger.exception(error_message)
        args['result'] = 'success'
        args['error_message'] = error_message
        template_name = 'error.html'
    if request.is_ajax():
        from pinloveweb.method import load_cards_by_ajax
        return load_cards_by_ajax(request, searchList, chanel='mobile')
    else:
        return render(request, template_name, args)
Exemple #15
0
def follow(request, type, ajax='false', template_name="mobile_follow.html"):
    args = {}
    try:
        try:
            type = int(type)
        except ValueError:
            raise Http404()
        if type == 1:
            #获得我的关注列表
            fllowList = Follow.objects.filter(my=request.user)
            theme = '关注'
        elif type == 2:
            #获得我的粉丝列表
            fllowList = Follow.objects.filter(follow=request.user)
            theme = '粉丝'
        elif type == 3:
            #获得相互关注列表
            fllowList = Follow.objects.follow_each(request.user.id)
            theme = '相互关注'

        userProfile = UserProfile.objects.get(user_id=request.user.id)
        #分页
        args = page(request, fllowList)
        cardList = args.get('pages')
        #将关注列表转换成Card列表
        if len(cardList.object_list) > 0:
            from apps.pojo.card import fllowList_to_CardMobileList
            cardList.object_list = fllowList_to_CardMobileList(
                request.user.id, cardList.object_list, type)
        else:
            cardList.object_list = []
        if cardList.has_next():
            args['next_page_number'] = cardList.next_page_number()
        else:
            args['next_page_number'] = -1
        #判断推荐完成情况
        recommend_status = recommend_info_status(request.user.id,
                                                 channel='mobile')
        if not recommend_status['result']:
            args['has_recommend'] = True
        else:
            args['recommend_finish'] = simplejson.dumps(
                simplejson.dumps(recommend_status['data']))
        if request.is_ajax():
            data = {}
            if cardList.has_next():
                data['next_page_number'] = args['next_page_number']
            else:
                data['next_page_number'] = -1
            data['result'] = 'success'
            data['cards'] = cardList.object_list
            json = simplejson.dumps(data, cls=CardMobileEncoder)
            return HttpResponse(json)
        cardList.object_list = simplejson.dumps(cardList.object_list,
                                                cls=CardMobileEncoder)
        args['pages'] = cardList
        from pinloveweb.method import init_person_info_for_card_page
        args.update(init_person_info_for_card_page(userProfile))
        args['title'] = theme
        return render(request, template_name, args)
    except Exception as e:
        logger.exception(e.message)
        args = {'result': 'error', 'error_message': e.message}
        return render(request, ERROR_TEMLATE_NAMR, args)