commit 1698da77c6ed2a08d5f3990e02d23fbfffe35d11
Author: Leonidas Poulopoulos <leopoul@noc.grnet.gr>
Date:   Thu Nov 22 13:53:21 2012 +0200

    Changed the user registration proccess. Admins now validate institution

diff --git a/accounts/views.py b/accounts/views.py
index c525964..e1b8119 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -5,24 +5,76 @@ from django.shortcuts import render_to_response
 from django.template.context import RequestContext
 from django.template.loader import render_to_string
 from django.utils.translation import ugettext_lazy as _
-
+from flowspy.accounts.models import *
+from flowspy.peers.models import *
+from flowspy.flowspec.forms import *
 from registration.models import RegistrationProfile
 from registration.views import activate as registration_activate
+from django.views.decorators.cache import never_cache
 
+@never_cache
 def activate(request, activation_key):
-    activation_key = activation_key.lower() # Normalize before trying anything with it.
-    account = RegistrationProfile.objects.activate_user(activation_key)
-    context = RequestContext(request)
-
-    if account:
-        # A user has been activated
-        email = render_to_string("registration/activation_complete.txt",
-                                 {"site": Site.objects.get_current(),
-                                  "user": account})
-        send_mail(_("%sUser account activated") % settings.EMAIL_SUBJECT_PREFIX,
+    account = None
+    if request.method == "GET":
+        activation_key = activation_key.lower() # Normalize before trying anything with it.
+        context = RequestContext(request)
+        try:
+            rp = RegistrationProfile.objects.get(activation_key=activation_key)
+            
+        except RegistrationProfile.DoesNotExist:
+            return render_to_response("registration/activate.html",
+                                  { 'account': account,
+                                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
+                                  context_instance=context)
+        try:
+            userProfile = rp.user.get_profile()
+        except UserProfile.DoesNotExist:
+            return render_to_response("registration/activate.html",
+                                  { 'account': account,
+                                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
+                                  context_instance=context)
+        
+        form = UserProfileForm(instance=userProfile)
+        form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=rp.user.pk), empty_label=None)
+        form.fields['peer'] = forms.ModelChoiceField(queryset=Peer.objects.all(), empty_label=None)
+        
+        return render_to_response("registration/activate_edit.html",
+                                  { 'account': account,
+                                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
+                                    'form': form },
+                                  context_instance=context)
+            
+    if request.method == "POST":
+        context = RequestContext(request)
+        request_data = request.POST.copy()
+        try:
+            user = User.objects.get(pk=request_data['user'])
+            up = user.get_profile()
+            up.peer = Peer.objects.get(pk=request_data['peer'])
+            up.save()
+            
+        except:
+            return render_to_response("registration/activate_edit.html",
+                                  { 'account': account,
+                                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS
+                                     },
+                                  context_instance=context)
+        activation_key = activation_key.lower() # Normalize before trying anything with it.
+        try:
+            rp = RegistrationProfile.objects.get(activation_key=activation_key)
+            account = RegistrationProfile.objects.activate_user(activation_key)
+        except Exception as e:
+            pass
+    
+        if account:
+            # A user has been activated
+            email = render_to_string("registration/activation_complete.txt",
+                                     {"site": Site.objects.get_current(),
+                                      "user": account})
+            send_mail(_("%sUser account activated") % settings.EMAIL_SUBJECT_PREFIX,
                   email, settings.SERVER_EMAIL, [account.email])
-
-    return render_to_response("registration/activate.html",
-                              { 'account': account,
-                                'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
-                              context_instance=context)
+        context = RequestContext(request)
+        return render_to_response("registration/activate.html",
+                                  { 'account': account,
+                                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
+                                  context_instance=context)
\ No newline at end of file
