def get_state_instance(self, request): if request.method == 'POST': if 'ls-jrs' in request.data: return TemporaryReadingOnlySanction(request.data) else: return ReadingOnlySanction(request.data) elif request.method == 'DELETE': return DeleteReadingOnlySanction(request.data) raise ValueError('Method {0} is not supported in this API route.'.format(request.method))
def get_state_instance(self, request): if request.method == "POST": if "ls-jrs" in request.data: return TemporaryReadingOnlySanction(request.data) else: return ReadingOnlySanction(request.data) elif request.method == "DELETE": return DeleteReadingOnlySanction(request.data) raise ValueError(f"Method {request.method} is not supported in this API route.")
def modify_profile(request, user_pk): """Modifies sanction of a user if there is a POST request.""" 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.text, settings.ZDS_APP['site']['litteral_name']) state.notify_member(ban, msg) return redirect(profile.get_absolute_url())
def modify_profile(request, user_pk): """Modify the sanction of a user if there is a POST request.""" profile = get_object_or_404(Profile, user__pk=user_pk) if profile.is_private(): raise PermissionDenied if request.user.profile == profile: messages.error(request, _('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']['literal_name']) state.notify_member(ban, msg) return redirect(profile.get_absolute_url())