Exemple #1
0
def can_vote(obj, user, request, vote=None):
    if not _votes_enabled(obj):
        return False

    # Common predicate
    try:
        v = Vote.objects.get(
                object_id=obj.id,
                content_type=ContentType.objects.get_for_model(obj),
                token=request.secretballot_token)
        return vote is not None and int(vote) != v.vote
    except:
        pass

    # The middleware could not generate a token, probably bot with missing UA
    if request.secretballot_token is None:
        return False

    try:
        can_vote_test.send(
            sender=obj.__class__,
            instance=obj,
            user=user,
            request=request
        )
    except CannotVoteException:
        return False
    return True
Exemple #2
0
def can_vote(obj, user, request):
    if not _votes_enabled(obj):
        return False

    # Common predicate
    if Vote.objects.filter(
        object_id=obj.id,
        content_type=ContentType.objects.get_for_model(obj),
        token=request.secretballot_token
    ).exists():
        return False

    # The middleware could not generate a token, probably bot with missing UA
    if request.secretballot_token is None:
        return False

    try:
        can_vote_test.send(
            sender=obj.__class__,
            instance=obj,
            user=user,
            request=request
        )
    except CannotVoteException:
        return False
    return True
Exemple #3
0
def can_vote(obj, user, request):
    if not _votes_enabled(obj):
        return False

    # Common predicate
    if Vote.objects.filter(
        object_id=obj.id,
        token=request.secretballot_token
    ).count() != 0:
        return False

    try:
        can_vote_test.send(obj, user=user, request=request)
    except CannotVoteException:
        return False
    return True
Exemple #4
0
def can_vote(obj, user, request):
    if not _votes_enabled(obj):
        return False

    # Common predicate
    if Vote.objects.filter(
        object_id=obj.id,
        content_type=ContentType.objects.get_for_model(obj),
        token=request.secretballot_token
    ).count() != 0:
        return False

    try:
        can_vote_test.send(
            sender=obj.__class__,
            instance=obj,
            user=user,
            request=request
        )
    except CannotVoteException:
        return False
    return True
Exemple #5
0
def can_vote(obj, user, request):
    if not _votes_enabled(obj):
        return False

    # Common predicate
    if Vote.objects.filter(
        object_id=obj.id,
        content_type=ContentType.objects.get_for_model(obj),
        user=user
    ).count() != 0:
        return False

    try:
        can_vote_test.send(
            sender=obj.__class__,
            instance=obj,
            user=user,
            request=request
        )
    except CannotVoteException:
        return False
    return True