Пример #1
0
 def get_state_instance(self, request):
     if request.method == 'POST':
         if 'ban-jrs' in request.data:
             return TemporaryBanSanction(request.data)
         else:
             return BanSanction(request.POST)
     elif request.method == 'DELETE':
         return DeleteBanSanction(request.data)
     raise ValueError('Method {0} is not supported in this API route.'.format(request.method))
Пример #2
0
 def get_state_instance(self, request):
     if request.method == "POST":
         if "ban-jrs" in request.data:
             return TemporaryBanSanction(request.data)
         else:
             return BanSanction(request.POST)
     elif request.method == "DELETE":
         return DeleteBanSanction(request.data)
     raise ValueError(f"Method {request.method} is not supported in this API route.")
Пример #3
0
def modify_profile(request, user_pk):
    """Modifies sanction of a user if there is a POST request."""

    if not request.user.has_perm('member.change_profile'):
        raise PermissionDenied

    profile = get_object_or_404(Profile, user__pk=user_pk)
    if profile.is_private():
        raise PermissionDenied
    if request.user.profile == profile:
        messages.error(request,
                       _(u'Vous ne pouvez pas vous sanctionner vous-même !'))
        raise PermissionDenied

    if 'ls' in request.POST:
        state = ReadingOnlySanction(request.POST)
    elif 'ls-temp' in request.POST:
        state = TemporaryReadingOnlySanction(request.POST)
    elif 'ban' in request.POST:
        state = BanSanction(request.POST)
    elif 'ban-temp' in request.POST:
        state = TemporaryBanSanction(request.POST)
    elif 'un-ls' in request.POST:
        state = DeleteReadingOnlySanction(request.POST)
    else:
        # un-ban
        state = DeleteBanSanction(request.POST)

    try:
        ban = state.get_sanction(request.user, profile.user)
    except ValueError:
        raise HttpResponseBadRequest

    state.apply_sanction(profile, ban)

    if 'un-ls' in request.POST or 'un-ban' in request.POST:
        msg = state.get_message_unsanction()
    else:
        msg = state.get_message_sanction()

    msg = msg.format(ban.user, ban.moderator, ban.type, state.get_detail(),
                     ban.note, settings.ZDS_APP['site']['litteral_name'])

    state.notify_member(ban, msg)
    return redirect(profile.get_absolute_url())