fixed a few bugs anoop
authornishanth
Mon, 07 Jun 2010 16:49:31 +0530
branchanoop
changeset 72 3673ed3ca27c
parent 71 c736873f35cb
child 73 dab739f4381a
fixed a few bugs
sdi/forms.py
sdi/views.py
--- a/sdi/forms.py	Mon Jun 07 16:00:42 2010 +0530
+++ b/sdi/forms.py	Mon Jun 07 16:49:31 2010 +0530
@@ -157,12 +157,13 @@
 
     def clean_username(self):
         username = self.cleaned_data['username']
-        password = self.clean_password()
+        try:
+            password = self.data['password']
+        except KeyError:
+            raise forms.ValidationError("Invalid username or password")
 
         if not authenticate(username=username, password=password):
             raise forms.ValidationError("Invalid username or password")
 
         return username
 
-    def clean_password(self):
-        return self.cleaned_data['password']
--- a/sdi/views.py	Mon Jun 07 16:00:42 2010 +0530
+++ b/sdi/views.py	Mon Jun 07 16:49:31 2010 +0530
@@ -7,6 +7,7 @@
 from sage_days.sdi.models import Registrant
 from sage_days.sdi.forms import RegisterForm, SearchForm, EmailForm, LoginForm
 from sage_days.sdi.events import send_reg_complete_mail, mail_invi
+from sage_days.settings import APACHE_URL_PREFIX as aup
 
 def register(request):
     """ The user register page.
@@ -105,17 +106,23 @@
     """ basic login.
     """
 
+    redirect_url = "/%s/registration/stats"%aup
+
+    user = request.user
+    if user.is_authenticated():
+        return redirect(redirect_url)
+
     if request.method == "POST":
         form = LoginForm(request.POST)
         if form.is_valid():
-            data = form.cleaned_data()
+            data = form.cleaned_data
 
             username = data['username']
             password = data['password']
 
             user = authenticate(username=username, password=password)
             login(request, user)
-            return redirect("/registration/stats")
+            return redirect(redirect_url)
         else:
             return render_to_response("login.html", {"form":form})
     else: