commit 176023aaf72179dddcfa4a2f045b145743ef6e4e
Author: Kostas Papadimitriou <kpap@grnet.gr>
Date:   Fri Apr 6 16:08:15 2012 +0300

    Redirect to index if no approval terms found

diff --git a/snf-astakos-app/astakos/im/views.py b/snf-astakos-app/astakos/im/views.py
index ca1f61c..b247f9c 100644
--- a/snf-astakos-app/astakos/im/views.py
+++ b/snf-astakos-app/astakos/im/views.py
@@ -1,18 +1,18 @@
 # Copyright 2011-2012 GRNET S.A. All rights reserved.
-# 
+#
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
 # conditions are met:
-# 
+#
 #   1. Redistributions of source code must retain the above
 #      copyright notice, this list of conditions and the following
 #      disclaimer.
-# 
+#
 #   2. Redistributions in binary form must reproduce the above
 #      copyright notice, this list of conditions and the following
 #      disclaimer in the documentation and/or other materials
 #      provided with the distribution.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -25,7 +25,7 @@
 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
-# 
+#
 # The views and conclusions contained in the software and
 # documentation are those of the authors and should not be
 # interpreted as representing official policies, either expressed
@@ -112,24 +112,24 @@ def signed_terms_required(func):
 def index(request, login_template_name='im/login.html', profile_template_name='im/profile.html', extra_context={}):
     """
     If there is logged on user renders the profile page otherwise renders login page.
-    
+
     **Arguments**
-    
+
     ``login_template_name``
         A custom login template to use. This is optional; if not specified,
         this will default to ``im/login.html``.
-    
+
     ``profile_template_name``
         A custom profile template to use. This is optional; if not specified,
         this will default to ``im/profile.html``.
-    
+
     ``extra_context``
         An dictionary of variables to add to the template context.
-    
+
     **Template:**
-    
+
     im/profile.html or im/login.html or ``template_name`` keyword argument.
-    
+
     """
     template_name = login_template_name
     formclass = 'LoginForm'
@@ -146,33 +146,33 @@ def index(request, login_template_name='im/login.html', profile_template_name='i
 def invite(request, template_name='im/invitations.html', extra_context={}):
     """
     Allows a user to invite somebody else.
-    
+
     In case of GET request renders a form for providing the invitee information.
     In case of POST checks whether the user has not run out of invitations and then
     sends an invitation email to singup to the service.
-    
+
     The view uses commit_manually decorator in order to ensure the number of the
     user invitations is going to be updated only if the email has been successfully sent.
-    
+
     If the user isn't logged in, redirects to settings.LOGIN_URL.
-    
+
     **Arguments**
-    
+
     ``template_name``
         A custom template to use. This is optional; if not specified,
         this will default to ``im/invitations.html``.
-    
+
     ``extra_context``
         An dictionary of variables to add to the template context.
-    
+
     **Template:**
-    
+
     im/invitations.html or ``template_name`` keyword argument.
-    
+
     **Settings:**
-    
+
     The view expectes the following settings are defined:
-    
+
     * LOGIN_URL: login uri
     * ASTAKOS_DEFAULT_CONTACT_EMAIL: service support email
     * ASTAKOS_DEFAULT_FROM_EMAIL: from email
@@ -180,11 +180,11 @@ def invite(request, template_name='im/invitations.html', extra_context={}):
     status = None
     message = None
     inviter = AstakosUser.objects.get(username = request.user.username)
-    
+
     if request.method == 'POST':
         username = request.POST.get('uniq')
         realname = request.POST.get('realname')
-        
+
         if inviter.invitations > 0:
             try:
                 invite_func(inviter, username, realname)
@@ -203,7 +203,7 @@ def invite(request, template_name='im/invitations.html', extra_context={}):
             status = messages.ERROR
             message = _('No invitations left')
     messages.add_message(request, status, message)
-    
+
     sent = [{'email': inv.username,
              'realname': inv.realname,
              'is_consumed': inv.is_consumed}
@@ -219,30 +219,30 @@ def invite(request, template_name='im/invitations.html', extra_context={}):
 def edit_profile(request, template_name='im/profile.html', extra_context={}):
     """
     Allows a user to edit his/her profile.
-    
+
     In case of GET request renders a form for displaying the user information.
     In case of POST updates the user informantion and redirects to ``next``
     url parameter if exists.
-    
+
     If the user isn't logged in, redirects to settings.LOGIN_URL.
-    
+
     **Arguments**
-    
+
     ``template_name``
         A custom template to use. This is optional; if not specified,
         this will default to ``im/profile.html``.
-    
+
     ``extra_context``
         An dictionary of variables to add to the template context.
-    
+
     **Template:**
-    
+
     im/profile.html or ``template_name`` keyword argument.
-    
+
     **Settings:**
-    
+
     The view expectes the following settings are defined:
-    
+
     * LOGIN_URL: login uri
     """
     form = ProfileForm(instance=request.user)
@@ -272,38 +272,38 @@ def edit_profile(request, template_name='im/profile.html', extra_context={}):
 def signup(request, on_failure='im/signup.html', on_success='im/signup_complete.html', extra_context={}, backend=None):
     """
     Allows a user to create a local account.
-    
+
     In case of GET request renders a form for providing the user information.
     In case of POST handles the signup.
-    
+
     The user activation will be delegated to the backend specified by the ``backend`` keyword argument
     if present, otherwise to the ``astakos.im.backends.InvitationBackend``
     if settings.ASTAKOS_INVITATIONS_ENABLED is True or ``astakos.im.backends.SimpleBackend`` if not
     (see backends);
-    
+
     Upon successful user creation if ``next`` url parameter is present the user is redirected there
     otherwise renders the same page with a success message.
-    
+
     On unsuccessful creation, renders ``on_failure`` with an error message.
-    
+
     **Arguments**
-    
+
     ``on_failure``
         A custom template to render in case of failure. This is optional;
         if not specified, this will default to ``im/signup.html``.
-    
-    
+
+
     ``on_success``
         A custom template to render in case of success. This is optional;
         if not specified, this will default to ``im/signup_complete.html``.
-    
+
     ``extra_context``
         An dictionary of variables to add to the template context.
-    
+
     **Template:**
-    
+
     im/signup.html or ``on_failure`` keyword argument.
-    im/signup_complete.html or ``on_success`` keyword argument. 
+    im/signup_complete.html or ``on_success`` keyword argument.
     """
     if request.user.is_authenticated():
         return HttpResponseRedirect(reverse('astakos.im.views.index'))
@@ -344,27 +344,27 @@ def signup(request, on_failure='im/signup.html', on_success='im/signup_complete.
 def send_feedback(request, template_name='im/feedback.html', email_template_name='im/feedback_mail.txt', extra_context={}):
     """
     Allows a user to send feedback.
-    
+
     In case of GET request renders a form for providing the feedback information.
     In case of POST sends an email to support team.
-    
+
     If the user isn't logged in, redirects to settings.LOGIN_URL.
-    
+
     **Arguments**
-    
+
     ``template_name``
         A custom template to use. This is optional; if not specified,
         this will default to ``im/feedback.html``.
-    
+
     ``extra_context``
         An dictionary of variables to add to the template context.
-    
+
     **Template:**
-    
+
     im/signup.html or ``template_name`` keyword argument.
-    
+
     **Settings:**
-    
+
     * LOGIN_URL: login uri
     * ASTAKOS_DEFAULT_CONTACT_EMAIL: List of feedback recipients
     """
@@ -373,7 +373,7 @@ def send_feedback(request, template_name='im/feedback.html', email_template_name
     if request.method == 'POST':
         if not request.user:
             return HttpResponse('Unauthorized', status=401)
-        
+
         form = FeedbackForm(request.POST)
         if form.is_valid():
             subject = _("Feedback from %s alpha2 testing" % SITENAME)
@@ -383,7 +383,7 @@ def send_feedback(request, template_name='im/feedback.html', email_template_name
                         'message': form.cleaned_data['feedback_msg'],
                         'data': form.cleaned_data['feedback_data'],
                         'request': request})
-            
+
             try:
                 send_mail(subject, content, from_email, recipient_list)
                 message = _('Feedback successfully sent')
@@ -422,7 +422,7 @@ def activate(request, email_template_name='im/welcome_email.txt', on_failure='')
     """
     Activates the user identified by the ``auth`` request parameter, sends a welcome email
     and renews the user token.
-    
+
     The view uses commit_manually decorator in order to ensure the user state will be updated
     only if the email will be send successfully.
     """
@@ -432,7 +432,7 @@ def activate(request, email_template_name='im/welcome_email.txt', on_failure='')
         user = AstakosUser.objects.get(auth_token=token)
     except AstakosUser.DoesNotExist:
         return HttpResponseBadRequest(_('No such user'))
-    
+
     user.is_active = True
     user.email_verified = True
     user.save()
@@ -460,12 +460,12 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html'
              term = ApprovalTerms.objects.get(id=term_id)
         except ApprovalTermDoesNotExist, e:
             pass
-    
+
     if not term:
-        return HttpResponseBadRequest(_('No approval terms found.'))
+        return HttpResponseRedirect(reverse('astakos.im.views.index'))
     f = open(term.location, 'r')
     terms = f.read()
-    
+
     if request.method == 'POST':
         next = request.POST.get('next')
         if not next:
@@ -489,4 +489,4 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html'
 
 @signed_terms_required
 def change_password(request):
-    return password_change(request, post_change_redirect=reverse('astakos.im.views.edit_profile'))
\ No newline at end of file
+    return password_change(request, post_change_redirect=reverse('astakos.im.views.edit_profile'))
