commit 6ff7a7caaa57751788e41a600f37e1dd5dc01a4f
Author: Sofia Papagiannaki <papagian@gmail.com>
Date:   Fri Aug 3 13:02:02 2012 +0300

    named reverse urls

diff --git a/snf-astakos-app/astakos/im/api/__init__.py b/snf-astakos-app/astakos/im/api/__init__.py
index 3d61edc..71dd97c 100644
--- a/snf-astakos-app/astakos/im/api/__init__.py
+++ b/snf-astakos-app/astakos/im/api/__init__.py
@@ -161,27 +161,24 @@ def get_menu(request, with_extra_links=False, with_signout=True):
         pass
     else:
         l = []
-        l.append({ 'url': absolute(reverse('astakos.im.views.index')),
-                  'name': user.email})
-        l.append({ 'url': absolute(reverse('astakos.im.views.edit_profile')),
-                  'name': "My account" })
+        l.append(dict(url=absolute(reverse('index')), name=user.email))
+        l.append(dict(url=absolute(reverse('edit_profile')), name="My account"))
         if with_extra_links:
             if user.has_usable_password() and user.provider == 'local':
-                l.append({ 'url': absolute(reverse('password_change')),
-                          'name': "Change password" })
+                l.append(dict(url=absolute(reverse('password_change')), name="Change password"))
             if EMAILCHANGE_ENABLED:
-                l.append({'url':absolute(reverse('email_change')),
-                          'name': "Change email"})
+                l.append(dict(url=absolute(reverse('email_change')), name="Change email"))
             if INVITATIONS_ENABLED:
-                l.append({ 'url': absolute(reverse('astakos.im.views.invite')),
-                          'name': "Invitations" })
-            l.append({ 'url': absolute(reverse('astakos.im.views.feedback')),
-                      'name': "Feedback" })
-            l.append({ 'url': absolute(reverse('group_add')),
-                      'name': "Add group" })
+                l.append(dict(url=absolute(reverse('invite')), name="Invitations"))
+            l.append(dict(url=absolute(reverse('feedback')), name="Feedback"))
+            if request.user.has_perm('im.add_astakosgroup'):
+                l.append(dict(url=absolute(reverse('group_add')), name="Add group"))
+            url = absolute(reverse('group_list'))
+            l.append(dict(url=url, name="Subscribed groups"))
+            url = '%s?relation=owner' % url
+            l.append(dict(url=url, name="My groups"))
         if with_signout:
-            l.append({ 'url': absolute(reverse('astakos.im.views.logout')),
-                      'name': "Sign out"})
+            l.append(dict(url=absolute(reverse('logout')), name="Sign out"))
 
     callback = request.GET.get('callback', None)
     data = json.dumps(tuple(l))
diff --git a/snf-astakos-app/astakos/im/functions.py b/snf-astakos-app/astakos/im/functions.py
index 9d21e22..363372b 100644
--- a/snf-astakos-app/astakos/im/functions.py
+++ b/snf-astakos-app/astakos/im/functions.py
@@ -81,9 +81,9 @@ def send_verification(user, template_name='im/activation_email.txt'):
     
     Raises SendVerificationError
     """
-    url = '%s?auth=%s&next=%s' % (urljoin(BASEURL, reverse('astakos.im.views.activate')),
+    url = '%s?auth=%s&next=%s' % (urljoin(BASEURL, reverse('activate')),
                                     quote(user.auth_token),
-                                    quote(urljoin(BASEURL, reverse('astakos.im.views.index'))))
+                                    quote(urljoin(BASEURL, reverse('index'))))
     message = render_to_string(template_name, {
             'user': user,
             'url': url,
@@ -158,7 +158,7 @@ def send_invitation(invitation, template_name='im/invitation.txt'):
     Raises SendInvitationError
     """
     subject = _('Invitation to %s alpha2 testing' % SITENAME)
-    url = '%s?code=%d' % (urljoin(BASEURL, reverse('astakos.im.views.index')), invitation.code)
+    url = '%s?code=%d' % (urljoin(BASEURL, reverse('index')), invitation.code)
     message = render_to_string('im/invitation.txt', {
                 'invitation': invitation,
                 'url': url,
@@ -184,7 +184,7 @@ def send_greeting(user, email_template_name='im/welcome_email.txt'):
     subject = _('Welcome to %s alpha2 testing' % SITENAME)
     message = render_to_string(email_template_name, {
                 'user': user,
-                'url': urljoin(BASEURL, reverse('astakos.im.views.index')),
+                'url': urljoin(BASEURL, reverse('index')),
                 'baseurl': BASEURL,
                 'site_name': SITENAME,
                 'support': DEFAULT_CONTACT_EMAIL})
diff --git a/snf-astakos-app/astakos/im/target/redirect.py b/snf-astakos-app/astakos/im/target/redirect.py
index 3c59c21..33fd922 100644
--- a/snf-astakos-app/astakos/im/target/redirect.py
+++ b/snf-astakos-app/astakos/im/target/redirect.py
@@ -118,7 +118,7 @@ def login(request):
         next = urlunsplit(parts)
         
         # build url location
-        parts[2] = reverse('astakos.im.views.index')
+        parts[2] = reverse('index')
         params = {'next':next}
         parts[3] = urlencode(params)
         url = urlunsplit(parts)
diff --git a/snf-astakos-app/astakos/im/templates/im/account_base.html b/snf-astakos-app/astakos/im/templates/im/account_base.html
index f61414f..30d9981 100644
--- a/snf-astakos-app/astakos/im/templates/im/account_base.html
+++ b/snf-astakos-app/astakos/im/templates/im/account_base.html
@@ -18,7 +18,7 @@
 
 {% block page.quicknav.items %}
         <li class="{% block signup_class %}{% endblock %}">
-            <a href="{% url astakos.im.views.logout %}">LOGOUT</a>
+            <a href="{% url logout %}">LOGOUT</a>
         </li>
 {% endblock %}
 
diff --git a/snf-astakos-app/astakos/im/templates/im/feedback.html b/snf-astakos-app/astakos/im/templates/im/feedback.html
index fc512e0..ca0a88b 100644
--- a/snf-astakos-app/astakos/im/templates/im/feedback.html
+++ b/snf-astakos-app/astakos/im/templates/im/feedback.html
@@ -1,7 +1,7 @@
 {% extends "im/account_base.html" %}
 
 {% block body %}
-<form action="{% url astakos.im.views.feedback %}" method="post"
+<form action="{% url feedback %}" method="post"
     class="withlabels">{% csrf_token %}
     
     {% with feedback_form as form %}
diff --git a/snf-astakos-app/astakos/im/templates/im/invitations.html b/snf-astakos-app/astakos/im/templates/im/invitations.html
index 5d75ef3..029e068 100644
--- a/snf-astakos-app/astakos/im/templates/im/invitations.html
+++ b/snf-astakos-app/astakos/im/templates/im/invitations.html
@@ -31,7 +31,7 @@
 
 <div class="rightcol">
  {% if inviter.invitations %}
-  <form action="{% url astakos.im.views.invite %}" method="post"
+  <form action="{% url invite %}" method="post"
     class="innerlabels">{% csrf_token %}
     <h2>INVITE SOMEONE ELSE</h2>
     {% with invitation_form as form %}
diff --git a/snf-astakos-app/astakos/im/templates/im/login_base.html b/snf-astakos-app/astakos/im/templates/im/login_base.html
index 4cfce43..b4ea9e2 100644
--- a/snf-astakos-app/astakos/im/templates/im/login_base.html
+++ b/snf-astakos-app/astakos/im/templates/im/login_base.html
@@ -59,7 +59,7 @@ Login
         {% endfor %}
         <div class="bottom">
             {% block body.login.signup %}
-                new to okeanos ? <a href="{% url astakos.im.views.signup %}{% ifnotequal code "" %}?code={{ code|urlencode }}{% endifnotequal %}">CREATE ACCOUNT</a>
+                new to okeanos ? <a href="{% url signup %}{% ifnotequal code "" %}?code={{ code|urlencode }}{% endifnotequal %}">CREATE ACCOUNT</a>
             {% endblock %}
             </div>
         </div>
diff --git a/snf-astakos-app/astakos/im/templates/im/profile.html b/snf-astakos-app/astakos/im/templates/im/profile.html
index ffc0651..37a1591 100644
--- a/snf-astakos-app/astakos/im/templates/im/profile.html
+++ b/snf-astakos-app/astakos/im/templates/im/profile.html
@@ -2,7 +2,7 @@
 
 {% block body %}
 
-<form action={%url astakos.im.views.edit_profile %} method="post"
+<form action={%url edit_profile %} method="post"
     class="withlabels">{% csrf_token %}
     
     {% with profile_form as form %}
diff --git a/snf-astakos-app/astakos/im/templates/im/register.html b/snf-astakos-app/astakos/im/templates/im/register.html
index d3f57b9..d33383d 100644
--- a/snf-astakos-app/astakos/im/templates/im/register.html
+++ b/snf-astakos-app/astakos/im/templates/im/register.html
@@ -5,7 +5,7 @@
 {% endblock title%}
 
 {% block body %}
-<form action={%url astakos.im.views.register%} method="post">{% csrf_token %}
+<form action={%url register%} method="post">{% csrf_token %}
     {{ form.as_p }}
 <div>
     <button type="submit" class="btn primary">Register</button>
diff --git a/snf-astakos-app/astakos/im/templates/im/signup.html b/snf-astakos-app/astakos/im/templates/im/signup.html
index c7194b1..0fc4e6d 100644
--- a/snf-astakos-app/astakos/im/templates/im/signup.html
+++ b/snf-astakos-app/astakos/im/templates/im/signup.html
@@ -25,7 +25,7 @@
 {% block body.right %}
     {% if "local" in im_modules %}
       <div class="form-stacked">
-        <form action="{% url astakos.im.views.signup %}" method="post"
+        <form action="{% url signup %}" method="post"
             class="innerlabels signup">{% csrf_token %}
           <h2><span>SIGN UP</span></h2>
             <input type="hidden" name="next" value="{{ next }}">
diff --git a/snf-astakos-app/astakos/im/templates/im/signup_complete.html b/snf-astakos-app/astakos/im/templates/im/signup_complete.html
index 4ac7c12..bf98755 100644
--- a/snf-astakos-app/astakos/im/templates/im/signup_complete.html
+++ b/snf-astakos-app/astakos/im/templates/im/signup_complete.html
@@ -10,7 +10,7 @@
     </div>
 
 <div class="section">
-    <form action="{% url astakos.im.views.signup %}" method="post" class="login innerlabels">{% csrf_token %}
+    <form action="{% url signup %}" method="post" class="login innerlabels">{% csrf_token %}
                 {% with thirdparty_signup_form as form %}
                 {% include "im/form_render.html" %}
                 {% endwith %}
diff --git a/snf-astakos-app/astakos/im/templates/im/third_party_registration.html b/snf-astakos-app/astakos/im/templates/im/third_party_registration.html
index 8cc7a0a..0fb678a 100644
--- a/snf-astakos-app/astakos/im/templates/im/third_party_registration.html
+++ b/snf-astakos-app/astakos/im/templates/im/third_party_registration.html
@@ -15,7 +15,7 @@
 {% block body.right %}
     {% if "local" in im_modules %}
       <div class="form-stacked">
-        <form action="{% url astakos.im.views.signup %}" method="post"
+        <form action="{% url signup %}" method="post"
             class="innerlabels signup">{% csrf_token %}
           <h2><span>Provide an email address to complete the registration:</span></h2>
             <input type="hidden" name="next" value="{{ next }}">
diff --git a/snf-astakos-app/astakos/im/templates/registration/email_change_form.html b/snf-astakos-app/astakos/im/templates/registration/email_change_form.html
index a18e05b..eace8a1 100644
--- a/snf-astakos-app/astakos/im/templates/registration/email_change_form.html
+++ b/snf-astakos-app/astakos/im/templates/registration/email_change_form.html
@@ -1,7 +1,7 @@
 {% extends "im/account_base.html" %}
 
 {% block body %}
-<form action="{% url astakos.im.views.change_email %}" method="post"
+<form action="{% url email_change %}" method="post"
     class="withlabels">{% csrf_token %}
 
     {% include "im/form_render.html" %}
diff --git a/snf-astakos-app/astakos/im/templates/registration/logged_out.html b/snf-astakos-app/astakos/im/templates/registration/logged_out.html
index af0f864..520896e 100644
--- a/snf-astakos-app/astakos/im/templates/registration/logged_out.html
+++ b/snf-astakos-app/astakos/im/templates/registration/logged_out.html
@@ -3,6 +3,6 @@
 {%block page.title %}Logout{% endblock %}
 {% block body %}
 <div class="section">
-    <h2>You have successfully logged out. <a href="{% url astakos.im.views.index %}">Login</a>.</h2>
+    <h2>You have successfully logged out. <a href="{% url index %}">Login</a>.</h2>
 </div>
 {% endblock %}
diff --git a/snf-astakos-app/astakos/im/urls.py b/snf-astakos-app/astakos/im/urls.py
index 55e1473..0780e74 100644
--- a/snf-astakos-app/astakos/im/urls.py
+++ b/snf-astakos-app/astakos/im/urls.py
@@ -41,16 +41,16 @@ from astakos.im.settings import IM_MODULES, INVITATIONS_ENABLED, EMAILCHANGE_ENA
 urlpatterns = patterns('astakos.im.views',
     url(r'^$', 'index', {}, name='index'),
     url(r'^login/?$', 'index', {}, name='login'),
-    url(r'^profile/?$', 'edit_profile'),
-    url(r'^feedback/?$', 'feedback'),
-    url(r'^signup/?$', 'signup', {'on_success':'im/login.html', 'extra_context':{'login_form':LoginForm()}}),
-    url(r'^logout/?$', 'logout', {'template':'im/login.html', 'extra_context':{'login_form':LoginForm()}}),
-    url(r'^activate/?$', 'activate'),
+    url(r'^profile/?$', 'edit_profile', {}, name='edit_profile'),
+    url(r'^feedback/?$', 'feedback', {}, name='feedback'),
+    url(r'^signup/?$', 'signup', {'on_success':'im/login.html', 'extra_context':{'login_form':LoginForm()}}, name='signup'),
+    url(r'^logout/?$', 'logout', {'template':'im/login.html', 'extra_context':{'login_form':LoginForm()}}, name='logout'),
+    url(r'^activate/?$', 'activate', {}, name='activate'),
     url(r'^approval_terms/?$', 'approval_terms', {}, name='latest_terms'),
     url(r'^approval_terms/(?P<term_id>\d+)/?$', 'approval_terms'),
     url(r'^password/?$', 'change_password', {}, name='password_change'),
     url(r'^group/add/?$', 'group_add', {}, name='group_add'),
-    url(r'^group/list?$', 'user_group_list', {}, name='user_group_list'),
+    url(r'^group/list/?$', 'group_list', {}, name='group_list'),
     url(r'^group/(?P<group_id>\d+)/?$', 'group_detail', {}, name='group_detail'),
     url(r'^group/(?P<group_id>\d+)/policies/list/?$', 'group_policies_list', {}, name='group_policies_list'),
     url(r'^group/(?P<group_id>\d+)/policies/add/?$', 'group_policies_add', {}, name='group_policies_add'),
@@ -86,7 +86,7 @@ if 'local' in IM_MODULES:
 
 if INVITATIONS_ENABLED:
     urlpatterns += patterns('astakos.im.views',
-        url(r'^invite/?$', 'invite')
+        url(r'^invite/?$', 'invite', {}, name='invite')
     )
 
 if 'shibboleth' in IM_MODULES:
diff --git a/snf-astakos-app/astakos/im/util.py b/snf-astakos-app/astakos/im/util.py
index 4aea9c2..4b0c2a6 100644
--- a/snf-astakos-app/astakos/im/util.py
+++ b/snf-astakos-app/astakos/im/util.py
@@ -119,7 +119,7 @@ def prepare_response(request, user, next='', renew=False):
         params = ''
         if next:
             params = '?' + urlencode({'next': next})
-        next = reverse('astakos.im.views.edit_profile') + params
+        next = reverse('edit_profile') + params
     
     response = HttpResponse()
     
@@ -130,7 +130,7 @@ def prepare_response(request, user, next='', renew=False):
     request.session.set_expiry(user.auth_token_expires)
     
     if not next:
-        next = reverse('astakos.im.views.index')
+        next = reverse('index')
     
     response['Location'] = next
     response.status_code = 302
diff --git a/snf-astakos-app/astakos/im/views.py b/snf-astakos-app/astakos/im/views.py
index e347071..cf84f1b 100644
--- a/snf-astakos-app/astakos/im/views.py
+++ b/snf-astakos-app/astakos/im/views.py
@@ -138,7 +138,7 @@ def index(request, login_template_name='im/login.html', profile_template_name='i
     """
     template_name = login_template_name
     if request.user.is_authenticated():
-        return HttpResponseRedirect(reverse('astakos.im.views.edit_profile'))
+        return HttpResponseRedirect(reverse('edit_profile'))
     return render_response(template_name,
                            login_form = LoginForm(request=request),
                            context_instance = get_context(request, extra_context))
@@ -315,7 +315,7 @@ def signup(request, template_name='im/signup.html', on_success='im/signup_comple
     im/signup_complete.html or ``on_success`` keyword argument. 
     """
     if request.user.is_authenticated():
-        return HttpResponseRedirect(reverse('astakos.im.views.edit_profile'))
+        return HttpResponseRedirect(reverse('edit_profile'))
     
     provider = get_query(request).get('provider', 'local')
     try:
@@ -512,14 +512,14 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html'
             pass
 
     if not term:
-        return HttpResponseRedirect(reverse('astakos.im.views.index'))
+        return HttpResponseRedirect(reverse('index'))
     f = open(term.location, 'r')
     terms = f.read()
 
     if request.method == 'POST':
         next = request.POST.get('next')
         if not next:
-            next = reverse('astakos.im.views.index')
+            next = reverse('index')
         form = SignApprovalTermsForm(request.POST, instance=request.user)
         if not form.is_valid():
             return render_response(template_name,
@@ -540,7 +540,7 @@ 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'),
+                            post_change_redirect=reverse('edit_profile'),
                             password_change_form=ExtendedPasswordChangeForm)
 
 @signed_terms_required
@@ -570,7 +570,7 @@ def change_email(request, activation_key=None,
     
     if not request.user.is_authenticated():
         path = quote(request.get_full_path())
-        url = request.build_absolute_uri(reverse('astakos.im.views.index'))
+        url = request.build_absolute_uri(reverse('index'))
         return HttpResponseRedirect(url + '?next=' + path)
     form = EmailChangeForm(request.POST or None)
     if request.method == 'POST' and form.is_valid():
@@ -619,7 +619,7 @@ def group_detail(request, group_id):
     try:
         group = AstakosGroup.objects.select_related().get(id=group_id)
     except AstakosGroup.DoesNotExist:
-        raise HttpResponseBadRequest(_('Invalid group.'))
+        return HttpResponseBadRequest(_('Invalid group.'))
     d = {}
     for resource in group.policy.all():
         d[resource.name] = group.policy.through.objects.get(resource__id=resource.id,
