Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def agree(request):
    arg = {}
    try:
        dynamicId = int(request.REQUEST.get('dynamicId'))
        argeeNum = FriendDynamic.objects.get(id=dynamicId).argeeNum
        if FriendDynamicArgee.objects.filter(friendDynamic_id=dynamicId,
                                             user=request.user).exists():
            FriendDynamicArgee.objects.get(friendDynamic_id=dynamicId,
                                           user=request.user).delete()
            argeeNum = argeeNum - 1
            FriendDynamic.objects.filter(id=dynamicId).update(
                argeeNum=argeeNum)
            arg['result'] = 'delSuccess'
        else:
            from util.cache import is_black_list
            if is_black_list(
                    int(
                        FriendDynamic.objects.get(
                            id=dynamicId).publishUser_id),
                    int(request.user.id)):
                arg = {
                    'result': 'error',
                    'error_message': '该用户已经将你拉入黑名单,你不能点赞!'
                }
            else:
                friendDynamicArgee = FriendDynamicArgee()
                friendDynamicArgee.friendDynamic_id = dynamicId
                friendDynamicArgee.user = request.user
                friendDynamicArgee.save()
                argeeNum = argeeNum + 1
                FriendDynamic.objects.filter(id=dynamicId).update(
                    argeeNum=argeeNum)
                from apps.user_app.method import get_avatar_name
                arg['obj'] = simplejson.dumps([{
                    'userId':
                    friendDynamicArgee.user_id,
                    'username':
                    request.user.username,
                    'avatarName':
                    get_avatar_name(friendDynamicArgee.user_id,
                                    friendDynamicArgee.user_id),
                    'time':
                    friendDynamicArgee.time.strftime("%m-%d %H:%M")
                }])
                arg['result'] = 'addSuccess'
        json = simplejson.dumps(arg)
        return HttpResponse(json)
    except Exception as e:
        logger.exception('添加删除点赞出错')
        arg['result'] = 'error'
        arg['error_message'] = e.message
        json = simplejson.dumps(arg)
        return HttpResponse(json)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
 def get_messagebean(self,obj,userId,**kwargs):
     message=obj.message
     self.id=getattr(obj,'id1',None)
     self.senderId=getattr(message,'sender_id',None)
     self.receiverId=getattr(obj,'receiver_id',None)
     self.content=getattr(message,'content',None)
     if self.content:
         self.content=regex_expression( self.content)
     self.sendTime=getattr(message,'sendTime',None)
     if self.sendTime :
         self.sendTime=self.sendTime.strftime("%Y-%m-%d %H:%M:%S")
     self.isDeleteSender=getattr(obj,'isDeleteSender',None)
     self.isDeletereceiver=getattr(obj,'isDeletereceiver',None)
     self.isRead=getattr(obj,'isRead',None)
     self.senderName=message.sender.username
     self.receiverName=obj.receiver.username
     self.avatarName=get_avatar_name(userId,self.senderId)
Ejemplo n.º 6
0
 def __init__(self,*args,**kwargs):
     self.id=kwargs.pop('id',None)
     self.senderId=kwargs.pop('sender_id',None)
     self.receiverId=kwargs.pop('receiver_id',None)
     self.senderName=kwargs.pop('sender_name',None)
     self.receiverName=kwargs.pop('receiver_name',None)
     self.content=kwargs.pop('content',None)
     if self.content:
         self.content=regex_expression(self.content)
     self.sendTime=kwargs.pop('sendTime',None)
     if self.sendTime :
         self.sendTime=self.sendTime.strftime("%Y-%m-%d %H:%M:%S")
     self.isDeleteSender=kwargs.pop('isDeletereceiver',None)
     self.isDeletereceiver=kwargs.pop('isDeletereceiver',None)
     self.isRead=kwargs.pop('isRead',None)
     if self.senderId:
         self.avatarName=get_avatar_name(kwargs.get('userId'),self.senderId)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def FriendDynamicCommentList_to_DynamicCommentList(userId,
                                                   friendDynamicCommentList):
    dynamicCommentList = []
    for friendDynamicComment in friendDynamicCommentList:
        id = friendDynamicComment.id
        reviewer = friendDynamicComment.reviewer
        try:
            receiver = friendDynamicComment.receiver
        except FriendDynamicComment.DoesNotExist:
            receiver = None
        content = friendDynamicComment.content
        commentTime = friendDynamicComment.commentTime
        from apps.user_app.method import get_avatar_name
        reviewerAvatarName = get_avatar_name(userId,
                                             friendDynamicComment.reviewer.id)
        dynamicComment = DynamicComment(id, reviewer, receiver, content,
                                        commentTime, reviewerAvatarName)
        dynamicCommentList.append(dynamicComment)
    return dynamicCommentList
Ejemplo n.º 9
0
def friendDynamicList_to_Dynamic(friendDynamicList, userId):
    dynamicList = []
    from apps.friend_dynamic_app.models import FriendDynamicArgee
    from apps.friend_dynamic_app.models import FriendDynamic
    for friendDynamic in friendDynamicList:
        dynamic = Dynamic()
        for field in ['id', 'type', 'content']:
            setattr(dynamic, field, getattr(friendDynamic, field))
        dynamic.content = regex_url(dynamic.content)
        dynamic.content = regex_expression(dynamic.content)
        dynamic.publishUserId = friendDynamic.publishUser.id
        dynamic.publishUserName = friendDynamic.publishUser.username
        from apps.user_app.method import get_avatar_name
        dynamic.avatarName = get_avatar_name(userId,
                                             friendDynamic.publishUser.id)
        from util.util import time_for_now
        dynamic.publishTime = time_for_now(friendDynamic.publishTime)
        if friendDynamic.type == 2:
            dynamic.data = simplejson.loads(friendDynamic.data)
        dynamic.isAgree = FriendDynamicArgee.objects.is_agree(
            friendDynamic.id, userId)
        dynamic.commentNum = FriendDynamic.objects.get_coment_count(
            friendDynamic.publishUser.id, userId, friendDynamic.id)
        #获得评论
        if dynamic.publishUserId == userId:
            friendDynamicCommentList = FriendDynamicComment.objects.select_related(
                'reviewer',
                'receiver').filter(friendDynamic_id=friendDynamic.id,
                                   isDelete=False).order_by('-commentTime')
            friendDynamicArgeeList = FriendDynamicArgee.objects.get_agree_List_by_dynamic(
                userId, friendDynamic.id)
            dynamic.argeeNum = FriendDynamicArgee.objects.filter(
                friendDynamic_id=friendDynamic.id).count()
        else:
            from django.db.models.query_utils import Q
            friendDynamicCommentList = FriendDynamicComment.objects.select_related(
                'reviewer', 'receiver').filter(
                    friendDynamic_id=friendDynamic.id,
                    reviewer_id__in=[userId, dynamic.publishUserId],
                    isDelete=False).filter(
                        Q(receiver_id__in=[userId, dynamic.publishUserId])
                        | Q(receiver_id=None)).order_by('-commentTime')
            friendDynamicArgeeList = FriendDynamicArgee.objects.get_agree_List_by_ids(
                [userId, dynamic.publishUserId], friendDynamic.id)
            dynamic.argeeNum = FriendDynamicArgee.objects.filter(
                friendDynamic_id=friendDynamic.id,
                user_id__in=[dynamic.publishUserId, userId]).count()
        friendDynamicCommentList = friendDynamicCommentList.reverse()
        dynamic.commentList = simplejson.dumps(
            FriendDynamicCommentList_to_DynamicCommentList(
                userId, friendDynamicCommentList),
            cls=DynamicCommentEncoder)
        for friendDynamicArgee in friendDynamicArgeeList:
            from apps.user_app.method import get_avatar_name
            dynamic.agreeList.append({
                'userId':
                friendDynamicArgee['sender_id'],
                'username':
                friendDynamicArgee['sender_name'],
                'avatarName':
                get_avatar_name(userId, friendDynamicArgee['sender_id']),
                'time':
                friendDynamicArgee['sendTime'].strftime("%m-%d %H:%M")
            })
        dynamicList.append(dynamic)
    return dynamicList