Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def follow_object(request, content_type, object_id):
    """
    Creates the follow relationship between ``request.user`` and the
    actor defined by ``content_type_id``, ``object_id``.
    """
    ctype = ContentType.objects.get_for_id(content_type)
    if not Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
        actor = ctype.get_object_for_this_type(id=object_id)
        follow(request.user, actor)
        success = True
    else:
        success = False
    count = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
    payload = {'success': success, 'count': count}
    return ajax_answer_lazy(payload)
Exemplo n.º 9
0
def follow_object(request, content_type_id, object_id):
    """
    Creates the follow relationship between ``request.user`` and the
    actor defined by ``content_type_id``, ``object_id``.
    """
    ctype = get_object_or_404(ContentType, id=content_type_id)
    if not Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count():
        actor = ctype.get_object_for_this_type(id=object_id)
        follow(request.user, actor)
        success = True
    else:
        success = False
    count = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
    payload = {"success": success, "count": count}
    return AjaxLazyAnswer(payload)
Exemplo n.º 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)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def follow_unfollow(request, content_type, object_id):
    count = None
    if 1>0: #try:
        ctype = get_object_or_404(ContentType, id=content_type)
        follow_count = Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count()
        actor = ctype.get_object_for_this_type(id=object_id)
        if not follow_count:
            follow(request.user, actor)
        else:
            unfollow(request.user, actor, send_action=True)
        count = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        success = True
    # except:
    #     success = False
    payload = {'success': success, 'count': count}
    return AjaxLazyAnswer(payload)
Exemplo n.º 13
0
def follow_unfollow(request, content_type, object_id):
    count = None
    try:
        ctype = ContentType.objects.get_for_id(content_type)
        follow_count = Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count()
        actor = ctype.get_object_for_this_type(id=object_id)
        if not follow_count:
            follow(request.user, actor)
        else:
            unfollow(request.user, actor, send_action=True)
        count = Follow.objects.filter(content_type=ctype, object_id=object_id).count()
        success = True
    except:
        success = False
    payload = {'success': success, 'count': count}
    return ajax_answer_lazy(payload)
Exemplo n.º 14
0
def follow_object(request, content_type, object_id):
    """
    Creates the follow relationship between ``request.user`` and the
    actor defined by ``content_type_id``, ``object_id``.
    """
    ctype = ContentType.objects.get_for_id(content_type)
    if not Follow.objects.filter(user=request.user,
                                 content_type=ctype,
                                 object_id=object_id).count():
        actor = ctype.get_object_for_this_type(id=object_id)
        follow(request.user, actor)
        success = True
    else:
        success = False
    count = Follow.objects.filter(content_type=ctype,
                                  object_id=object_id).count()
    payload = {'success': success, 'count': count}
    return ajax_answer_lazy(payload)
Exemplo n.º 15
0
def follow_unfollow(request, content_type, object_id):
    count = None
    if 1 > 0:  #try:
        ctype = get_object_or_404(ContentType, id=content_type)
        follow_count = Follow.objects.filter(user=request.user,
                                             content_type=ctype,
                                             object_id=object_id).count()
        actor = ctype.get_object_for_this_type(id=object_id)
        if not follow_count:
            follow(request.user, actor)
        else:
            unfollow(request.user, actor, send_action=True)
        count = Follow.objects.filter(content_type=ctype,
                                      object_id=object_id).count()
        success = True
    # except:
    #     success = False
    payload = {'success': success, 'count': count}
    return AjaxLazyAnswer(payload)
Exemplo n.º 16
0
def follow_unfollow(request, content_type, object_id):
    count = None
    try:
        ctype = ContentType.objects.get_for_id(content_type)
        follow_count = Follow.objects.filter(user=request.user,
                                             content_type=ctype,
                                             object_id=object_id).count()
        actor = ctype.get_object_for_this_type(id=object_id)
        if not follow_count:
            follow(request.user, actor)
        else:
            unfollow(request.user, actor, send_action=True)
        count = Follow.objects.filter(content_type=ctype,
                                      object_id=object_id).count()
        success = True
    except:
        success = False
    payload = {'success': success, 'count': count}
    return ajax_answer_lazy(payload)
Exemplo n.º 17
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)