raise 404 error if organization doesn't exit

This commit is contained in:
Serghei Mihai 2015-06-01 18:53:16 +02:00
parent 75a981d928
commit 30af3088bc
1 changed files with 5 additions and 3 deletions

View File

@ -5,7 +5,7 @@ from xml.etree import ElementTree
from django.views.generic.base import TemplateView
from django.views.generic import FormView
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render_to_response
from django.shortcuts import render_to_response, get_object_or_404
from django.core import signing
from django.http.request import QueryDict
from django.contrib.auth import authenticate
@ -75,8 +75,9 @@ class OrganizationPageView(LoginMixin, FormView):
def get_context_data(self, **kwargs):
context = super(OrganizationPageView, self).get_context_data(**kwargs)
organization = get_object_or_404(Organization,
slug=self.kwargs['organization_slug'])
idps = get_idp_list()
organization = Organization.objects.get(slug=self.kwargs['organization_slug'])
self.request.session['organization'] = organization.slug
self.request.session[organization.slug] = self.request.GET.urlencode()
relay = signing.dumps({'organization': organization.slug})
@ -90,7 +91,8 @@ class OrganizationPageView(LoginMixin, FormView):
def form_valid(self, form):
data = form.cleaned_data
organization = Organization.objects.get(slug=self.kwargs['organization_slug'])
organization = get_object_or_404(Organization,
slug=self.kwargs['organization_slug'])
data.update({'organization': organization})
user = authenticate(**data)
if user: