Example #1
0
def push_tag(request, object_id):
    # Link used for User follow tag
    # noinspection PyBroadException
    try:
        tag = Tag.objects.get(id=object_id)
        ctype = ContentType.objects.get_for_model(Tag)
        status = False
        if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
            unfollow(request.user, tag)
            action.send(request.user, verb=_('unfollow the tag'), target=tag)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    notice.send(request.user, user=u, verb=_('now follow'), target=tag)
        else:
            follow(request.user, tag)
            status = True
            action.send(request.user, verb=_('follow the tag'), action_type=ACTION_FOLLOWED, target=tag,
                        request=request)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    if u.follow_set.filter(content_type=ctype, object_id=tag.pk).count:
                        notice.send(request.user, user=u, verb=_('also now follow'), target=tag)
                    else:
                        notice.send(request.user, user=u, verb=_('now follow'), target=tag)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {'success': True, 'count': result, 'id': tag.pk, 'status': status}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Example #2
0
def push_user(request, object_id):
    # Link used for User press button in user panel
    # noinspection PyBroadException
    try:
        user = get_user_model().objects.get(id=object_id)
        if request.user == user:
            raise AccessError
        ctype = ContentType.objects.get_for_model(get_user_model())
        status = False
        if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
            unfollow(request.user, user)
            action.send(request.user, verb=_('unfollow the user'), target=user)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    notice.send(request.user, user=u, verb=_('now unfollow'), target=user)
        else:
            follow(request.user, user)
            status = True
            action.send(request.user, verb=_('follow the user'), target=user)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    if u.follow_set.filter(content_type=ctype, object_id=user.pk).count:
                        notice.send(request.user, user=u, verb=_('also now follow'), target=user)
                    else:
                        notice.send(request.user, user=u, verb=_('now follow'), target=user)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {'success': True, 'count': result, 'id': user.pk, 'status': status}
    except AccessError as aerr:
        payload = {'success': False}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Example #3
0
def push_video(request, object_id):
    # Link used for User press Like on Video Detail Page
    # noinspection PyBroadException
    try:
        video = get_object_or_404(Video, id=int(object_id))
        ctype = ContentType.objects.get_for_model(Video)
        status = False
        if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
            if unfollow(request.user, video):
                # action.send(request.user, verb=_('disliked the video'), target=video)
                if request.user.followers_count:
                    for u in get_user_model().objects.filter(pk__in=request.user.followers):
                        notice.send(request.user, user=u, verb=_('now disliked'), target=video)
        else:
            if follow(request.user, video):
                status = True
                action.send(request.user, verb=_('liked the video'), action_type=ACTION_LIKED,
                            target=video, request=request)
                if request.user.followers_count:
                    for u in get_user_model().objects.filter(pk__in=request.user.followers):
                        if u.follow_set.filter(content_type=ctype, object_id=video.pk).count:
                            notice.send(request.user, user=u, verb=_('also now liked'), target=video)
                        else:
                            notice.send(request.user, user=u, verb=_('now liked'), target=video)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {'success': True, 'count': result, 'id': video.pk, 'status': status}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Example #4
0
def push_user(request, object_id):
    # Link used for User press button in user panel
    try:
        user = settings.AUTH_USER_MODEL.objects.get(id=object_id)
        if request.user == user:
            raise AccessError
        ctype = ContentType.objects.get_for_model(settings.AUTH_USER_MODEL)
        status = False
        if Follow.objects.filter(user=request.user,content_type=ctype,object_id=object_id).count():
            unfollow(request.user, user)
            action.send(request.user, verb=_('unfollow the user'), target=user)
            if request.user.get_profile().followers_count:
                for u in settings.AUTH_USER_MODEL.objects.filter(pk__in=request.user.get_profile().followers):
                    notice.send(request.user, user=u, verb=_('now unfollow'), target=user)
        else:
            follow(request.user, user)
            status = True
            action.send(request.user, verb=_('follow the user'), target=user)
            if request.user.get_profile().followers_count:
                for u in settings.AUTH_USER_MODEL.objects.filter(pk__in=request.user.get_profile().followers):
                    if u.follow_set.filter(content_type=ctype, object_id=user.pk).count:
                        notice.send(request.user, user=u, verb=_('also now follow'), target=user)
                    else:
                        notice.send(request.user, user=u, verb=_('now follow'), target=user)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {'success': True, 'count': result, 'id': user.pk, 'status':status}
    except AccessError:
        payload = {'success': False}
    except :
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Example #5
0
def push_user(request, object_id):
    # Link used for User press button in user panel
    try:
        user = get_user_model().objects.get(id=object_id)
        if request.user == user:
            raise AccessError
        ctype = ContentType.objects.get_for_model(get_user_model())
        status = False
        if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
            unfollow(request.user, user)
            action.send(request.user, verb=_("unfollow the user"), target=user)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    notice.send(request.user, user=u, verb=_("now unfollow"), target=user)
        else:
            follow(request.user, user)
            status = True
            action.send(request.user, verb=_("follow the user"), target=user)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    if u.follow_set.filter(content_type=ctype, object_id=user.pk).count:
                        notice.send(request.user, user=u, verb=_("also now follow"), target=user)
                    else:
                        notice.send(request.user, user=u, verb=_("now follow"), target=user)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {"success": True, "count": result, "id": user.pk, "status": status}
    except AccessError:
        payload = {"success": False}
    except:
        payload = {"success": False}
    return AjaxLazyAnswer(payload)
Example #6
0
def push_tag(request, object_id):
    # Link used for User follow tag
    try:
        tag = Tag.objects.get(id=object_id)
        ctype = ContentType.objects.get_for_model(Tag)
        status = False
        if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
            unfollow(request.user, tag)
            action.send(request.user, verb=_("unfollow the tag"), target=tag)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    notice.send(request.user, user=u, verb=_("now follow"), target=tag)
        else:
            follow(request.user, tag)
            status = True
            action.send(
                request.user, verb=_("follow the tag"), action_type=ACTION_FOLLOWED, target=tag, request=request
            )
            if request.user.followers_count:
                for u in get_user_model().objects.filter(pk__in=request.user.followers):
                    if u.follow_set.filter(content_type=ctype, object_id=tag.pk).count:
                        notice.send(request.user, user=u, verb=_("also now follow"), target=tag)
                    else:
                        notice.send(request.user, user=u, verb=_("now follow"), target=tag)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {"success": True, "count": result, "id": tag.pk, "status": status}
    except:
        payload = {"success": False}
    return AjaxLazyAnswer(payload)
Example #7
0
def push_video(request, object_id):
    # Link used for User press Like on Video Detail Page
    try:
        video = get_object_or_404(Video, id=int(object_id))
        ctype = ContentType.objects.get_for_model(Video)
        status = False
        if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
            if unfollow(request.user, video):
                #                action.send(request.user, verb=_('disliked the video'), target=video)
                if request.user.followers_count:
                    for u in get_user_model().objects.filter(pk__in=request.user.followers):
                        notice.send(request.user, user=u, verb=_("now disliked"), target=video)
        else:
            if follow(request.user, video):
                status = True
                action.send(
                    request.user, verb=_("liked the video"), action_type=ACTION_LIKED, target=video, request=request
                )
                if request.user.followers_count:
                    for u in get_user_model().objects.filter(pk__in=request.user.followers):
                        if u.follow_set.filter(content_type=ctype, object_id=video.pk).count:
                            notice.send(request.user, user=u, verb=_("also now liked"), target=video)
                        else:
                            notice.send(request.user, user=u, verb=_("now liked"), target=video)
        result = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        payload = {"success": True, "count": result, "id": video.pk, "status": status}
    except:
        payload = {"success": False}
    return AjaxLazyAnswer(payload)
Example #8
0
def push_user(request, object_id):
    # Link used for User press button in user panel
    # noinspection PyBroadException
    try:
        user = get_user_model().objects.get(id=object_id)
        if request.user == user:
            raise AccessError
        ctype = ContentType.objects.get_for_model(get_user_model())
        status = False
        if Follow.objects.filter(user=request.user,
                                 content_type=ctype,
                                 object_id=object_id).count():
            unfollow(request.user, user)
            action.send(request.user, verb=_('unfollow the user'), target=user)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(
                        pk__in=request.user.followers):
                    notice.send(request.user,
                                user=u,
                                verb=_('now unfollow'),
                                target=user)
        else:
            follow(request.user, user)
            status = True
            action.send(request.user, verb=_('follow the user'), target=user)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(
                        pk__in=request.user.followers):
                    if u.follow_set.filter(content_type=ctype,
                                           object_id=user.pk).count:
                        notice.send(request.user,
                                    user=u,
                                    verb=_('also now follow'),
                                    target=user)
                    else:
                        notice.send(request.user,
                                    user=u,
                                    verb=_('now follow'),
                                    target=user)
        result = Follow.objects.filter(content_type=ctype,
                                       object_id=object_id).count()
        payload = {
            'success': True,
            'count': result,
            'id': user.pk,
            'status': status
        }
    except AccessError as aerr:
        payload = {'success': False}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Example #9
0
def push_tag(request, object_id):
    # Link used for User follow tag
    # noinspection PyBroadException
    try:
        tag = Tag.objects.get(id=object_id)
        ctype = ContentType.objects.get_for_model(Tag)
        status = False
        if Follow.objects.filter(user=request.user,
                                 content_type=ctype,
                                 object_id=object_id).count():
            unfollow(request.user, tag)
            action.send(request.user, verb=_('unfollow the tag'), target=tag)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(
                        pk__in=request.user.followers):
                    notice.send(request.user,
                                user=u,
                                verb=_('now follow'),
                                target=tag)
        else:
            follow(request.user, tag)
            status = True
            action.send(request.user,
                        verb=_('follow the tag'),
                        action_type=ACTION_FOLLOWED,
                        target=tag,
                        request=request)
            if request.user.followers_count:
                for u in get_user_model().objects.filter(
                        pk__in=request.user.followers):
                    if u.follow_set.filter(content_type=ctype,
                                           object_id=tag.pk).count:
                        notice.send(request.user,
                                    user=u,
                                    verb=_('also now follow'),
                                    target=tag)
                    else:
                        notice.send(request.user,
                                    user=u,
                                    verb=_('now follow'),
                                    target=tag)
        result = Follow.objects.filter(content_type=ctype,
                                       object_id=object_id).count()
        payload = {
            'success': True,
            'count': result,
            'id': tag.pk,
            'status': status
        }
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Example #10
0
def push_video(request, object_id):
    # Link used for User press Like on Video Detail Page
    # noinspection PyBroadException
    try:
        video = get_object_or_404(Video, id=int(object_id))
        ctype = ContentType.objects.get_for_model(Video)
        status = False
        if Follow.objects.filter(user=request.user,
                                 content_type=ctype,
                                 object_id=object_id).count():
            if unfollow(request.user, video):
                # action.send(request.user, verb=_('disliked the video'), target=video)
                if request.user.followers_count:
                    for u in get_user_model().objects.filter(
                            pk__in=request.user.followers):
                        notice.send(request.user,
                                    user=u,
                                    verb=_('now disliked'),
                                    target=video)
        else:
            if follow(request.user, video):
                status = True
                action.send(request.user,
                            verb=_('liked the video'),
                            action_type=ACTION_LIKED,
                            target=video,
                            request=request)
                if request.user.followers_count:
                    for u in get_user_model().objects.filter(
                            pk__in=request.user.followers):
                        if u.follow_set.filter(content_type=ctype,
                                               object_id=video.pk).count:
                            notice.send(request.user,
                                        user=u,
                                        verb=_('also now liked'),
                                        target=video)
                        else:
                            notice.send(request.user,
                                        user=u,
                                        verb=_('now liked'),
                                        target=video)
        result = Follow.objects.filter(content_type=ctype,
                                       object_id=object_id).count()
        payload = {
            'success': True,
            'count': result,
            'id': video.pk,
            'status': status
        }
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)