def get_success_url(self): success_url = reverse_lazy('authorize_user', kwargs={'pk': self.kwargs['pk']}) redirect_to = sanitize_next(self.request) if redirect_to: return format_lazy('{}?{}', success_url, next_link(self.request, redirect_to)) return success_url
def post(self, request, *args, **kwargs): map_type = kwargs.pop('map_type') if request.is_ajax(): response = JsonResponse({'success': 'map-type-configured'}) else: response = HttpResponseRedirect( sanitize_next(request, from_post=True) or reverse_lazy('home')) response.set_cookie('maptype', map_type, max_age=31557600) return response
def form_valid(self, form): response = super().form_valid(form) if '_gotomap' in self.request.POST or form.confidence < LocationConfidence.ACCEPTABLE: map_url = reverse('place_location_update', kwargs={'pk': self.object.pk}) redirect_to = sanitize_next(self.request) return HttpResponseRedirect( ('{}' if not redirect_to else '{}?{}').format( map_url, next_link(self.request, redirect_to) ) ) return response
def previous_link(context, default=''): """ A template tag used to provide the properly verified redirection target for going back to the previously visited page. - default: provides a default value to output in case the redirection target is empty or unsafe. """ url_param_value = '' if 'request' in context: referrer_url = context['request'].META.get('HTTP_REFERER', '') url_param_value = sanitize_next(context['request'], url=referrer_url) return urlparse(url_param_value).path or default
def get_success_url(self, *args, **kwargs): redirect_to = sanitize_next(self.request) if redirect_to: return redirect_to success_url, success_url_anchor = None, None if hasattr(self.object, 'profile'): success_url = self.object.profile.get_edit_url() success_url_anchor = self.url_anchors.get(self.model) if type(self.object) is Profile: success_url = self.object.get_edit_url() success_url_anchor = getattr(self, 'success_with_anchor', None) if success_url_anchor: return f'{success_url}#{success_url_anchor}{self.object.pk}' else: return success_url
def next_link( context, proceed_to, proceed_to_anchor=None, proceed_to_anchor_id=None, url_only=False, default=''): """ A template tag used to provide the properly encoded redirection target parameter for URLs. The target can be specified directly, or via the tokens 'this page' (meaning, the current page's URL will be used) or 'next page' (meaning, the value from current page's redirection parameter will be used). In the latter case, the target value is verified prior to use; an unsafe value is ignored. The additional parameters: - url_only: causes the tag to output only the calculated target's URL, without encoding for a Query String. - default: provides a default value to output in case the indicated redirection target is empty or unsafe. """ if str(proceed_to).startswith('#'): proceed_to_anchor_id, proceed_to_anchor, proceed_to = proceed_to_anchor, proceed_to, 'this page' if isinstance(context, HttpRequest): context = {'request': context} url_param = '' if proceed_to == "this page": if 'request' in context: url_param = context['request'].get_full_path() elif proceed_to == "next page": if 'request' in context: url_param = sanitize_next(context['request']) else: url_param = proceed_to url_param_value = ''.join([ str(url_param), str(proceed_to_anchor) if proceed_to_anchor else '', str(proceed_to_anchor_id) if proceed_to_anchor and proceed_to_anchor_id else '', ]) if url_param else default if not url_only and url_param_value: return urlencode( {settings.REDIRECT_FIELD_NAME: url_param_value}, quote_via=lambda v, *args: urlquote(v, safe='') ) else: return url_param_value or ''
def get_success_url(self, *args, **kwargs): redirect_to = sanitize_next(self.request) if redirect_to: return redirect_to return self.place.owner.get_edit_url()
def get_redirect_url(self): return sanitize_next(self.request)
def get_success_url(self, *args, **kwargs): success_url = reverse_lazy('place_detail_verbose', kwargs={'pk': self.object.pk}) redirect_to = sanitize_next(self.request) return redirect_to or success_url