예제 #1
0
파일: views.py 프로젝트: josephcab/zds-site
def modify_karma(request):
    """Add a Karma note to a user profile."""

    try:
        profile_pk = int(request.POST['profile_pk'])
    except (KeyError, ValueError):
        raise Http404

    profile = get_object_or_404(Profile, pk=profile_pk)
    if profile.is_private():
        raise PermissionDenied

    note = KarmaNote(
        user=profile.user,
        moderator=request.user,
        note=request.POST.get('note', '').strip())

    try:
        note.karma = int(request.POST['karma'])
    except (KeyError, ValueError):
        note.karma = 0

    try:
        if not note.note:
            raise ValueError('note cannot be empty')
        elif note.karma > 100 or note.karma < -100:
            raise ValueError('Max karma amount has to be between -100 and 100, you entered {}'.format(note.karma))
        else:
            note.save()
            profile.karma += note.karma
            profile.save()
    except ValueError as e:
        logging.getLogger(__name__).warn('ValueError: modifying karma failed because {}'.format(e))

    return redirect(reverse('member-detail', args=[profile.user.username]))
예제 #2
0
파일: views.py 프로젝트: sgaist/zds-site
def modify_karma(request):
    """Add a Karma note to a user profile."""

    try:
        profile_pk = int(request.POST['profile_pk'])
    except (KeyError, ValueError):
        raise Http404

    profile = get_object_or_404(Profile, pk=profile_pk)
    if profile.is_private():
        raise PermissionDenied

    note = KarmaNote(
        user=profile.user,
        moderator=request.user,
        note=request.POST.get('note', '').strip())

    try:
        note.karma = int(request.POST['karma'])
    except (KeyError, ValueError):
        note.karma = 0

    try:
        if not note.note:
            raise ValueError('note cannot be empty')
        elif note.karma > 100 or note.karma < -100:
            raise ValueError('Max karma amount has to be between -100 and 100, you entered {}'.format(note.karma))
        else:
            note.save()
            profile.karma += note.karma
            profile.save()
    except ValueError as e:
        logging.getLogger('zds.member').warn('ValueError: modifying karma failed because {}'.format(e))

    return redirect(reverse('member-detail', args=[profile.user.username]))
예제 #3
0
def modify_karma(request):
    """Add a Karma note to a user profile."""

    try:
        profile_pk = int(request.POST["profile_pk"])
    except (KeyError, ValueError):
        raise Http404

    profile = get_object_or_404(Profile, pk=profile_pk)
    if profile.is_private():
        raise PermissionDenied

    note = KarmaNote(user=profile.user,
                     moderator=request.user,
                     note=request.POST.get("note", "").strip())

    try:
        note.karma = int(request.POST["karma"])
    except (KeyError, ValueError):
        note.karma = 0

    try:
        if not note.note:
            raise ValueError("note cannot be empty")
        elif note.karma > 100 or note.karma < -100:
            raise ValueError(
                f"Max karma amount has to be between -100 and 100, you entered {note.karma}"
            )
        else:
            note.save()
            profile.karma += note.karma
            profile.save()
    except ValueError as e:
        logging.getLogger(__name__).warning(
            f"ValueError: modifying karma failed because {e}")

    return redirect(reverse("member-detail", args=[profile.user.username]))