Exemplo n.º 1
0
def member(request,template_name='buy.html'):
    try:
        args={}
        userProfile=UserProfile.objects.get(user=request.user)
        #获取城市代码
        from util.location import get_country_code
        countryCode=get_country_code(request)
        if countryCode=='US':
            chargeExchangeRelateList=ChargeExchangeRelate.objects.filter(currencyType=1)
        elif countryCode=='CN':
            chargeExchangeRelateList=ChargeExchangeRelate.objects.filter(currencyType=2)
        else:
            chargeExchangeRelateList=ChargeExchangeRelate.objects.filter(currencyType=2)
        charge=Charge.objects.get(user_id=request.user.id)
        args['chargeExchangeRelateList']=chargeExchangeRelateList
        #购买拼爱币
        args['charge']=charge
        #全部拼爱币
        from apps.pay_app.method import get_charge_amount
        args['pinLoveIcon']=get_charge_amount(request.user.id,vailPinLoveIcon=charge.validAmount)
        #初始化个人信息模块
        from pinloveweb.method import init_person_info_for_card_page
        args.update(init_person_info_for_card_page(userProfile))
        from pinloveweb.method import get_no_read_web_count
        args.update(get_no_read_web_count(request.user.id,fromPage=u'card'))
        return render(request,template_name,args)
    except Exception as e:
        error_message=('%s%s%s' %('会员购买页面出错!','出错原因:',e.message))
        logger.exception(error_message)
        return render(request,'error.html',{'error_message':error_message})
Exemplo n.º 2
0
def dynamic(request, template_name):
    arg = {}
    dynamicId = request.REQUEST.get('dynamicId', None)
    arg['user'] = request.user
    from apps.user_app.method import get_avatar_name
    arg['avatar_name'] = get_avatar_name(request.user.id, request.user.id)
    from pinloveweb.method import get_no_read_web_count
    arg.update(get_no_read_web_count(request.user.id, fromPage=u'message'))
    if request.is_ajax():
        arg = init_dynamic(request,
                           request.user.id,
                           arg,
                           0,
                           dynamicId=dynamicId)
        from apps.pojo.dynamic import MyEncoder
        json = simplejson.dumps(
            {
                'friendDynamicList': arg['friendDynamicList'],
                'next_page_number': arg['next_page_number']
            },
            cls=MyEncoder)
        return HttpResponse(json, mimetype='application/json')
    if 'images_path' in request.session:
        del request.session['images_path']
    arg['publish'] = True
    arg["title"] = '动态'
    return render(request, template_name, arg)
Exemplo n.º 3
0
def loggedin(request, template_name='index.html', **kwargs):
    arg = {}
    is_ajax = False
    try:
        userProfile = UserProfile.objects.get_user_info(request.user.id)
        if request.is_ajax():
            is_ajax = True
            matchResultList = get_recommend_list(request, userProfile)
            from pinloveweb.method import load_cards_by_ajax
            return load_cards_by_ajax(request, matchResultList)
        from pinloveweb.method import get_no_read_web_count
        arg.update(get_no_read_web_count(request.user.id, fromPage=u'card'))
        #判断是否是从注册页面过来
        if request.GET.get('previous_page', '') == 'register':
            arg['first'] = True
        #推荐信息完善
        if request.session.get('recommendStatus', False):
            arg['recommendStatus'] = request.session.pop('recommendStatus')
        from pinloveweb.method import init_person_info_for_card_page
        arg.update(init_person_info_for_card_page(userProfile))
        #检测设备
        if detect_device.detectTiermobileTablet(request):
            template_name = 'mobile_recommend.html'
    except Exception as e:
        errorMessage = '推荐页面出错,错误原因:' + e.message
        logger.exception(errorMessage)
        arg = {'result': 'error', 'error_message': errorMessage}
        template_name = 'error.html'
    if is_ajax:
        json = simplejson.dumps(arg)
        return HttpResponse(json)
    else:
        return render(request, template_name, arg)
Exemplo n.º 4
0
def get_no_read_messge_by_ids(request):
    args = {}
    try:
        userIdString = request.REQUEST.get('userIds')
        num = int(request.REQUEST.get('num', -1))
        userIdList = [int(x) for x in userIdString.split(',')]
        if num != -1:
            messageList = MessageLog.objects.get_no_read_messagelog(
                request.user.id, 0, num, userList=userIdList)
        elif len(userIdList) > 0:
            messageList = MessageLog.objects.get_no_read_messagelog(
                request.user.id, userList=userIdList)
        else:
            messageList = MessageLog.objects.get_no_read_messagelog(
                request.user.id)
        MessageLog.objects.filter(
            message_id__in=[messageTmp['id']
                            for messageTmp in messageList]).update(isRead=True)
        messageBeanList = MessageLog_to_MessageBean(messageList,
                                                    request.user.id)
        args['messageList'] = messageBeanList
        #         #获取消息数
        from pinloveweb.method import get_no_read_web_count
        args.update(get_no_read_web_count(request.user.id))
        json = simplejson.dumps(args, cls=MessageBeanEncoder)
        return HttpResponse(json)
    except Exception, e:
        logger.exception('根据id获取未读信息,出错!')
        args = {'result': 'error', 'error_message': e.message}
        json = simplejson.dumps(args)
        return HttpResponse(json)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def search(request, template_name='simple_search.html'):
    args = {}
    try:
        userProfile = UserProfile.objects.get_user_info(request.user.id)
        if request.method == 'POST':
            searchForm = SearchForm(request.POST)
            if searchForm.is_valid():
                userProfileList = searchForm.select_data(
                    request.REQUEST.get('sunSign', '').rstrip(),
                    userProfile.gender, request.user.id)
                searchList = get_recommend_list(request, userProfile,
                                                userProfileList)
                args['result'] = 'success'
        elif request.is_ajax():
            searchForm = SearchForm(request.GET)
            if searchForm.is_valid():
                userProfileList = searchForm.select_data(
                    request.REQUEST.get('sunSign', '').rstrip(),
                    userProfile.gender, request.user.id)
                searchList = get_recommend_list(request, userProfile,
                                                userProfileList)
                args['result'] = 'success'
        else:
            searchForm = SearchForm()
            searchForm.init_search_condition(request.user.id)
            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(
                    [SearchForm.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():
        url = ''
        if request.method == "POST":
            POSTcopy = request.POST.copy()
            POSTcopy.pop('csrfmiddlewaretoken')
            url = (request.path + '?' + urllib.urlencode(POSTcopy))
        from pinloveweb.method import load_cards_by_ajax
        return load_cards_by_ajax(request, searchList, url=url)
    else:
        return render(request, template_name, args)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def newcount(request):
    args = {}
    try:
        userId = request.user.id
        fromPage = request.REQUEST.get('from', False)
        #获取未读信息
        from pinloveweb.method import get_no_read_web_count
        args = get_no_read_web_count(userId, fromPage=fromPage)
        args['result'] = 'success'
    except Exception, e:
        logger.exception('检查是否有新未读消息,出错')
        args['result'] = 'error'
Exemplo n.º 9
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)
Exemplo n.º 10
0
def pintu(request):
    args = {}
    userId = request.user.id
    userProfile = UserProfile.objects.get(user_id=userId)
    from apps.game_app.models import get_recommend_history_web
    facebookUserListDcit = get_recommend_history_web(userId)
    from apps.pay_app.method import get_charge_amount
    args = {
        'pinLoveIcon': get_charge_amount(userId),
        'facebookUserListDcit': facebookUserListDcit
    }
    from pinloveweb.method import init_person_info_for_card_page
    args.update(init_person_info_for_card_page(userProfile))
    from pinloveweb.method import get_no_read_web_count
    args.update(get_no_read_web_count(request.user.id))
    return render(request, 'pintu.html', args)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 13
0
def recommend(request, template_name='mobile_recommend.html', **kwargs):
    '''
    推荐功能
    '''
    args = {}
    try:
        #判断推荐分数是否生成
        flag = MatchResult.objects.is_exist_by_userid(request.user.id)
        userProfile = UserProfile.objects.get_user_info(request.user.id)
        #从缓存中获取不推荐用户id
        from util.cache import get_no_recomend_list_by_cache
        disLikeUserIdList = get_no_recomend_list_by_cache(request.user.id)
        #获取推荐列表
        matchResultList = get_recommend_list(request, flag, disLikeUserIdList,
                                             userProfile, **kwargs)
        from pinloveweb.method import get_no_read_web_count
        args.update(get_no_read_web_count(request.user.id, fromPage=u'card'))
        #判断推荐完成情况
        if kwargs.get('card') == True:
            return matchResultList
        if request.is_ajax():
            from pinloveweb.method import load_cards_by_ajax
            return load_cards_by_ajax(request,
                                      matchResultList,
                                      chanel='mobile')
        matchResultList.object_list = simplejson.dumps(
            matchResultList.object_list, cls=CardMobileEncoder)
        args['pages'] = matchResultList
        #判断是否是从注册页面过来
        if request.GET.get('previous_page', '') == 'register':
            args['first'] = True
        #推荐信息完善
        if request.session.get('recommendStatus', False):
            args['recommendStatus'] = request.session.pop('recommendStatus')
        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)
Exemplo n.º 14
0
def web(request, template_name):
    from pinloveweb.method import get_no_read_web_count
    args = get_no_read_web_count(request.user.id)
    return render(request, template_name, args)
Exemplo n.º 15
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)