Python django.http.response.HttpResponseRedirect() Examples
The following are 30
code examples of django.http.response.HttpResponseRedirect().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.http.response
, or try the search function
.
Example #1
Source File: views.py From oxidizr with GNU General Public License v2.0 | 7 votes |
def form_valid(self, form): base, created = BaseKeyword.objects.get_or_create(term=form.cleaned_data['term']) keyword = Keyword() keyword.base = base keyword.project = self.request.project try: keyword.save() except IntegrityError: # The unique_together constraint on Keyword model failed # TODO: Handle a more specific error, IntegrityError could be raised by things other than duplicate too messages.add_message( message=_('You already have that keyword for this project, so we did not add it again.'), level=messages.INFO, request=self.request, extra_tags='module-level' ) return HttpResponseRedirect(self.get_success_url())
Example #2
Source File: inventory.py From lykops with Apache License 2.0 | 6 votes |
def detail(self, request): result = self._is_login(request) if result[0] : username = result[1] else : return HttpResponseRedirect(reverse('login')) vault_password = request.session['vault_password'] name = request.GET.get('name') result = self.inventory_api.detail(username, vault_password, name) if result[0] : self.logger.info(self.username + ' 查看用户' + username + '的名为' + name + '的主机,查询成功') return render(request, 'inve_detail.html', {'name':name, 'detail_dict':result[1] , 'login_user':username, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : error_message = self.username + ' 查看用户' + username + '的名为' + name + '的主机,查询时发生错误,原因:' + result[1] self.logger.error(error_message) return HttpResponseRedirect(reverse('inventory_list'))
Example #3
Source File: inventory.py From lykops with Apache License 2.0 | 6 votes |
def delete(self, request): result = self._is_login(request) if result[0] : username = result[1] else : return HttpResponseRedirect(reverse('login')) name = request.GET.get('name') result = self.inventory_api.delete(username, name) http_referer = self.uri_api.get_httpreferer(username, no=-1) if not result[0] : error_message = self.username + ' 删除用户' + username + '的名为' + name + '的主机失败,提交保存时发生错误,原因:' + result[1] self.logger.error(error_message) return render(request, 'result.html', {'name':name , 'login_user':username, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : self.logger.info(self.username + ' 删除用户' + username + '的名为' + name + '的主机,提交保存成功') return HttpResponseRedirect(reverse('inventory_list'))
Example #4
Source File: views.py From django-shopify-auth with MIT License | 6 votes |
def finalize(request, *args, **kwargs): shop = request.POST.get('shop', request.GET.get('shop')) try: shopify_session = shopify.Session(shop, getattr(settings, 'SHOPIFY_APP_API_VERSION', 'unstable'), token=kwargs.get('token')) shopify_session.request_token(request.GET) except: login_url = reverse(login) return HttpResponseRedirect(login_url) # Attempt to authenticate the user and log them in. user = auth.authenticate(request=request, myshopify_domain=shopify_session.url, token=shopify_session.token) if user: auth.login(request, user) return_address = get_return_address(request) return HttpResponseRedirect(return_address)
Example #5
Source File: views.py From mooder with GNU Lesser General Public License v3.0 | 6 votes |
def form_valid(self, form): if form.cleaned_data['rank'] <= 0: form.add_error('rank', 'Rank不能为0') return self.form_invalid(form) self.object = form.save(commit=False) self.object.verify = 'pass' self.object.author.rank += self.object.rank self.object.author.coin += self.object.rank self.object.save() self.object.author.save() models.log_coin(self.object.rank, self.object.author.coin, None, self.object.author) return HttpResponseRedirect(self.get_success_url())
Example #6
Source File: user.py From lykops with Apache License 2.0 | 6 votes |
def summary(self, request): ''' 用户列表 ''' result = self._is_login(request) if not result[0] : return HttpResponseRedirect(reverse('login')) else : username = result[1] result = self.usermanager_api.summary() list_title_list = ['用户', '真实名', '是否激活' , '上次登录时间'] if result[0] : self.logger.info(self.username + ' 获取所有用户信息时成功') return render(request, 'user_list.html', {'list_title_list':list_title_list, 'query_list':result[1], 'login_user':username, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : error_message = self.username + ' 获取所有用户信息时失败,原因:' + result[1] self.logger.error(error_message) return HttpResponseRedirect(reverse('index'))
Example #7
Source File: user.py From lykops with Apache License 2.0 | 6 votes |
def detail(self, request): ''' 查看用户详细信息 ''' result = self._is_login(request) if not result[0] : return HttpResponseRedirect(reverse('login')) else : login_name = result[1] username = request.GET['username'] result = self.usermanager_api.detail(username) if result[0] : self.logger.info(self.username + ' 查看用户' + username + '的详细数据成功') return render(request, 'user_detail.html', {'username':username, 'detail_dict':result[1] , 'login_user':login_name, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : error_message = self.username + ' 查看用户' + username + '的详细数据,查询失败,原因:' + result[1] self.logger.error(error_message) return HttpResponseRedirect(reverse('index'))
Example #8
Source File: user.py From lykops with Apache License 2.0 | 6 votes |
def delete(self, request): ''' 删除用户 ''' result = self._is_login(request) if result[0] : editer = result[1] else : return HttpResponseRedirect(reverse('login')) username = request.GET.get('username') result = self.usermanager_api.delete(username , editer=editer) if not result[0] : error_message = self.username + ' 删除用户' + username + ',提交失败,原因:' + result[1] self.logger.error(error_message) http_referer = self.uri_api.get_httpreferer(username, no=-1) return render(request, 'result.html', {'error_message' : error_message, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : self.logger.info(self.username + ' 删除用户' + username + '成功,注:实际只是标记为删除并非真实删除') return HttpResponseRedirect(reverse('user_list'))
Example #9
Source File: views.py From django-mfa with MIT License | 6 votes |
def index(request): if request.user and request.user.is_authenticated: return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) if request.method == 'POST': form = LoginForm(request.POST, request.FILES) if form.is_valid(): user = form.user if is_u2f_enabled(user): request.session['u2f_pre_verify_user_pk'] = user.pk request.session['u2f_pre_verify_user_backend'] = user.backend login(request, form.user) return JsonResponse({"error": False}) else: return JsonResponse({"error": True, "errors": form.errors}) context = { "registration_form": RegistrationForm, "login_form": LoginForm } return render(request, 'login.html', context)
Example #10
Source File: options.py From lykops with Apache License 2.0 | 6 votes |
def detail(self, request): ''' 查看用户的ansible的option数据 ''' result = self._is_login(request) if result[0] : username = result[1] else : return HttpResponseRedirect(reverse('login')) vault_password = request.session['vault_password'] result = self.ansible_option_api.detail(username, vault_password) if result[0] : data = result[1] error_message = '' self.logger.info(self.username + ' 查看用户' + username + '的ansible配置成功') else : data = {} error_message = self.username + ' 查看用户' + username + '的ansible配置失败,查询时发生错误,原因:' + result[1] self.logger.error(error_message) error_message = result[1] return render_to_response('option_detail.html', {'data':data, 'login_user':username, 'error_message':error_message, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html})
Example #11
Source File: views.py From fossevents.in with MIT License | 6 votes |
def event_review(request, pk, token, slug=None, event_detail_template='events/event_detail.html'): # TODO: Add reference in email for analytics # TODO: Add history of reviews in review page event = get_object_or_404(models.Event, pk=pk) if event.slug != slug: return redirect(event.get_absolute_url()) form = EventReviewForm(data=request.POST) if form.is_valid(): review = services.create_event_review(request.user, event, form.cleaned_data) services.update_event_visibility(review) services.send_event_review_mail(review, request.user) return HttpResponseRedirect(reverse('home')) ctx = { 'event': event, 'review_url': services.get_event_review_url(event), 'form': form } return render(request, event_detail_template, ctx)
Example #12
Source File: multiform.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
def _process_all_forms(self, form_classes): """ Perform the is_valid() check for all forms. """ forms = self.get_forms(form_classes, None, True) # only proceed if all forms are valid if all([form.is_valid() for form in forms.values()]): for form_name in forms: # for every form call the valid method self.forms_valid(forms, form_name) # redirect to the success URL return HttpResponseRedirect(self.get_success_url()) else: for form_name in [form for form in forms if not forms[form].is_valid()]: # for every invalid form call the invalid method self.forms_invalid(forms, form_name) # show errors instead return self.render_to_response(self.get_context_data(forms=forms))
Example #13
Source File: multiform.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
def _process_grouped_forms(self, group_name, form_classes): """ Perform the is_valid() check for a group of forms. """ form_names = self.grouped_forms[group_name] forms = self.get_forms(form_classes, form_names) # check if all forms are valid if all([forms[formName].is_valid() for formName in forms if formName in form_names]): # process the group valid method self.forms_valid(forms, group_name, isGroup=True) # redirect to success url if at least one form was valid return HttpResponseRedirect(self.get_success_url()) else: # process the group invalid method self.forms_invalid(forms, group_name, isGroup=True) # show errors instead return self.render_to_response(self.get_context_data(forms=forms))
Example #14
Source File: views.py From lykops with Apache License 2.0 | 6 votes |
def create_admin(self, request): if request.method == 'GET' : result = self.usermanager_api.is_has(adminuser) if result : return HttpResponseRedirect(reverse('login')) else : return render(request, 'user_create_admin.html') else : form = Form_Login(request.POST) if form.is_valid(): post_key_list = ['name', 'contact', 'password', 'password-confirm', 'vaultpassword', 'vaultpassword-confirm'] user_mess_dict = {} for key in post_key_list : user_mess_dict[key] = request.POST.get(key) user_mess_dict['username'] = adminuser user_mess_dict['creater'] = adminuser result = self.usermanager_api.create(user_mess_dict) if not result[0] : self.logger.info('超级管理员' + adminuser + '创建失败,原因:' + result[1]) return render(request, 'user_create_admin.html', {'error_message' : result[1]}) else : self.logger.info('超级管理员' + adminuser + '创建成功') return HttpResponseRedirect(reverse('index'))
Example #15
Source File: user.py From lykops with Apache License 2.0 | 6 votes |
def enable(self, request): ''' 允许用户登陆 ''' result = self._is_login(request) if result[0] : editer = result[1] else : return HttpResponseRedirect(reverse('login')) username = request.GET.get('username') result = self.usermanager_api.enable(username , editer=editer) if not result[0] : error_message = self.username + ' 启用用户' + username + ',提交失败,原因:' + result[1] self.logger.error(error_message) http_referer = self.uri_api.get_httpreferer(username, no=-1) return render(request, 'result.html', {'error_message' : error_message, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : self.logger.info(self.username + ' 启用用户' + username + '成功') return HttpResponseRedirect(reverse('user_list'))
Example #16
Source File: test_multiform.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
def test_post(self): requestObj = self.tempForm.__class__.__dict__['request'] actionParam = (fClassesNames[1], groupName, '') for i in range(0, 6): setattr(requestObj, 'POST', {'action': actionParam[i % 3]}) response = self.tempForm.post(requestObj) if isinstance(response, HttpResponseRedirect): self.assertEqual(response.url, self.tempForm.success_url) else: self.assertEqual(response.status_code, 200) if i == 2: global form_valid form_valid = True setattr(requestObj, 'POST', requestMethodNames[0])
Example #17
Source File: inventory.py From lykops with Apache License 2.0 | 6 votes |
def summary(self, request): result = self._is_login(request) if result[0] : username = result[1] else : return HttpResponseRedirect(reverse('login')) result = self.inventory_api.summary(username) if result[0] : title_list = result[1] query_list = result[2] http_referer = self.uri_api.get_httpreferer(username, no=-1) self.logger.info(self.username + ' 查看用户' + username + '的主机列表,查询数据成功') return render(request, 'inve_list.html', {'title_list':title_list, 'query_list':query_list, 'login_user':username, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : error_message = self.username + ' 查看用户' + username + '的主机列表失败,查询时发生错误,原因:' + result[1] self.logger.error(error_message) http_referer = self.uri_api.get_httpreferer(username, no=-1) return render(request, 'result.html', {'error_message' : error_message, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html})
Example #18
Source File: CRUD.py From djreservation with GNU General Public License v3.0 | 6 votes |
def get_create_view_class(self): class UCreateView(CreateView): def form_valid(self, form): self.object = form.save(commit=False) self.object.user = self.request.user self.object.save() return HttpResponseRedirect(self.get_success_url()) return UCreateView
Example #19
Source File: inventory.py From lykops with Apache License 2.0 | 6 votes |
def add(self, request): result = self._is_login(request) if result[0] : username = result[1] else : return HttpResponseRedirect(reverse('login')) if request.method == 'GET' : html_code = self.inventory_api.add_get(username) return render(request, 'inve_add.html', {'html_code': html_code, 'login_user':username, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else: form = Form_Login(request.POST) if form.is_valid(): user_mess_dict = self.post_handle(request) vault_password = request.session['vault_password'] result = self.inventory_api.add_post(username, vault_password, user_mess_dict) if not result[0] : error_message = self.username + ' 为用户' + username + '新增主机时失败,提交保存时发生错误,原因:' + result[1] self.logger.error(error_message) http_referer = self.uri_api.get_httpreferer(username, no=-1) return render(request, 'result.html', {'error_message' : error_message, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : self.logger.info(self.username + ' 为用户' + username + '新增主机,提交保存成功') return HttpResponseRedirect(reverse('inventory_list'))
Example #20
Source File: user.py From lykops with Apache License 2.0 | 6 votes |
def disable(self, request): ''' 禁用用户登陆 ''' result = self._is_login(request) if result[0] : editer = result[1] else : return HttpResponseRedirect(reverse('login')) username = request.GET.get('username') result = self.usermanager_api.disable(username , editer=editer) if not result[0] : error_message = self.username + ' 禁用用户' + username + ',提交失败,原因:' + result[1] self.logger.error(error_message) http_referer = self.uri_api.get_httpreferer(username, no=-1) return render(request, 'result.html', {'error_message' : error_message, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) else : self.logger.info(self.username + ' 禁用用户' + username + '成功') return HttpResponseRedirect(reverse('user_list'))
Example #21
Source File: view_partials.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def render_last(self): return HttpResponseRedirect(self.steps.last_url)
Example #22
Source File: views.py From django-shopify-auth with MIT License | 5 votes |
def authenticate(request, *args, **kwargs): shop = request.POST.get('shop', request.GET.get('shop')) if settings.SHOPIFY_APP_DEV_MODE: return finalize(request, token='00000000000000000000000000000000', *args, **kwargs) if shop: # Store return adress so merchant gets where they intended to. return_address_parameter = request.GET.get(auth.REDIRECT_FIELD_NAME) if return_address_parameter: request.session[SESSION_REDIRECT_FIELD_NAME] = return_address_parameter redirect_uri = request.build_absolute_uri(reverse(finalize)) scope = settings.SHOPIFY_APP_API_SCOPE permission_url = shopify.Session(shop.strip(), getattr(settings, 'SHOPIFY_APP_API_VERSION', 'unstable')).create_permission_url(scope, redirect_uri) if settings.SHOPIFY_APP_IS_EMBEDDED: # Embedded Apps should use a Javascript redirect. return render(request, "shopify_auth/iframe_redirect.html", { 'shop': shop, 'redirect_uri': permission_url }) else: # Non-Embedded Apps should use a standard redirect. return HttpResponseRedirect(permission_url) return_address = get_return_address(request) return HttpResponseRedirect(return_address)
Example #23
Source File: mixin.py From django-admin-easy with MIT License | 5 votes |
def easy_list_view(self, request, action): method_name = 'easy_view_%s' % action view = getattr(self, method_name, None) if view: return view(request) self.message_user(request, 'Easy view %s not founded' % method_name, messages.ERROR) redirect = reverse('admin:%s_%s_changelist' % self._get_info(),) return HttpResponseRedirect(redirect)
Example #24
Source File: mixin.py From django-admin-easy with MIT License | 5 votes |
def easy_object_view(self, request, pk, action): method_name = 'easy_view_%s' % action view = getattr(self, method_name, None) if view: return view(request, pk) self.message_user(request, 'Easy view %s not found' % method_name, messages.ERROR) redirect = reverse('admin:%s_%s_change' % self._get_info(), args=(pk,)) return HttpResponseRedirect(redirect)
Example #25
Source File: multiform.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def form_valid(self, forms, form): """ If the form is valid, redirect to the supplied URL. """ return HttpResponseRedirect(self.get_success_url())
Example #26
Source File: views.py From ldap-oauth2 with GNU General Public License v3.0 | 5 votes |
def get(self, request): logout(request) next_ = request.GET.get('next') if next_ is None: return redirect('index') next_ = quote_plus(next_) login_url = reverse('account:login') redirect_to = '%s?next=%s' % (login_url, next_) if next_ else login_url return HttpResponseRedirect(redirect_to)
Example #27
Source File: view_partials.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def render_current(self): return HttpResponseRedirect(self.steps.current_url)
Example #28
Source File: mixins.py From django-blog-it with MIT License | 5 votes |
def dispatch(self, request, *args, **kwargs): user = request.user if not (user.is_authenticated and user.is_active): return HttpResponseRedirect('/dashboard/') # if not user.is_superuser: # return HttpResponseRedirect("/") return super(AdminMixin, self).dispatch(request, *args, **kwargs)
Example #29
Source File: views.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def post(self, request, *args, **kwargs): user = self.request.user filter_string = self.request.POST.get('string') delete = self.request.POST.get('delete', 'false') if delete == 'true': # even if the queryset is empty there are no problems Filter.objects.filter(user=user, queryset=filter_string).delete() return HttpResponseRedirect(self.get_success_url()) if filter_string: name = self.request.POST.get('name') if not re.match(r"^[\w\s,.]+$", name) or len(name) > 99: messages.add_message(request, messages.WARNING, _("""Filter name can only contain letters, numbers, commas or periods. Maximum length is 99 characters""") ) return HttpResponseRedirect(self.get_success_url()[:-10]) typ = self.request.POST.get('typ') check = Filter.objects.filter(user=user, typ=typ, queryset=filter_string) if check.exists(): messages.add_message(request, messages.WARNING, _("You already have a saved filter for that querystring") + ": " + check.first().name) return HttpResponseRedirect(self.get_success_url()) if Filter.objects.filter(user=user, name=name, typ=typ).exists(): messages.add_message(request, messages.WARNING, _("You already have a saved filter with the name") + ": " + name) return HttpResponseRedirect(self.get_success_url()) Filter(user=user, queryset=filter_string, typ=typ, name=name).save() return HttpResponseRedirect(self.get_success_url())
Example #30
Source File: views.py From django-slack-oauth with MIT License | 5 votes |
def response(self, redirect=settings.SLACK_SUCCESS_REDIRECT_URL): return HttpResponseRedirect(redirect)