show my page link to unlogged, hide admin links,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 17 Oct 2011 13:40:05 +0000 (15:40 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 17 Oct 2011 13:40:05 +0000 (15:40 +0200)
properly redirect on logout from protected pages

apps/catalogue/templatetags/catalogue.py
apps/catalogue/views.py
redakcja/templates/registration/head_login.html

index bfb900b..2ce4add 100644 (file)
@@ -24,14 +24,15 @@ def main_tabs(context):
 
     tabs = []
     user = context['user']
 
     tabs = []
     user = context['user']
-    if user.is_authenticated():
-        tabs.append(Tab('my', _('My page'), reverse("catalogue_user")))
+    tabs.append(Tab('my', _('My page'), reverse("catalogue_user")))
 
     tabs.append(Tab('activity', _('Activity'), reverse("catalogue_activity")))
     tabs.append(Tab('all', _('All'), reverse("catalogue_document_list")))
     tabs.append(Tab('users', _('Users'), reverse("catalogue_users")))
 
     tabs.append(Tab('activity', _('Activity'), reverse("catalogue_activity")))
     tabs.append(Tab('all', _('All'), reverse("catalogue_document_list")))
     tabs.append(Tab('users', _('Users'), reverse("catalogue_users")))
-    tabs.append(Tab('create', _('Add'), reverse("catalogue_create_missing")))
-    tabs.append(Tab('upload', _('Upload'), reverse("catalogue_upload")))
+
+    if user.has_perm('catalogue.add_book'):
+        tabs.append(Tab('create', _('Add'), reverse("catalogue_create_missing")))
+        tabs.append(Tab('upload', _('Upload'), reverse("catalogue_upload")))
 
     if user.is_staff:
         tabs.append(Tab('admin', _('Admin'), reverse("admin:index")))
 
     if user.is_staff:
         tabs.append(Tab('admin', _('Admin'), reverse("admin:index")))
index fad8a69..72cf63d 100644 (file)
@@ -56,6 +56,8 @@ def my(request):
     return render(request, 'catalogue/my_page.html', {
         'last_books': sorted(request.session.get("wiki_last_books", {}).items(),
                         key=lambda x: x[1]['time'], reverse=True),
     return render(request, 'catalogue/my_page.html', {
         'last_books': sorted(request.session.get("wiki_last_books", {}).items(),
                         key=lambda x: x[1]['time'], reverse=True),
+
+        "logout_to": '/',
         })
 
 
         })
 
 
@@ -110,6 +112,8 @@ def create_missing(request, slug=None):
     return direct_to_template(request, "catalogue/document_create_missing.html", extra_context={
         "slug": slug,
         "form": form,
     return direct_to_template(request, "catalogue/document_create_missing.html", extra_context={
         "slug": slug,
         "form": form,
+
+        "logout_to": '/',
     })
 
 
     })
 
 
@@ -165,12 +169,16 @@ def upload(request):
                 "ok_list": ok_list,
                 "skipped_list": skipped_list,
                 "error_list": error_list,
                 "ok_list": ok_list,
                 "skipped_list": skipped_list,
                 "error_list": error_list,
+
+                "logout_to": '/',
             })
     else:
         form = forms.DocumentsUploadForm()
 
     return direct_to_template(request, "catalogue/document_upload.html", extra_context={
         "form": form,
             })
     else:
         form = forms.DocumentsUploadForm()
 
     return direct_to_template(request, "catalogue/document_upload.html", extra_context={
         "form": form,
+
+        "logout_to": '/',
     })
 
 
     })
 
 
@@ -326,6 +334,8 @@ def book_append(request, slug):
     return direct_to_template(request, "catalogue/book_append_to.html", extra_context={
         "book": book,
         "form": form,
     return direct_to_template(request, "catalogue/book_append_to.html", extra_context={
         "book": book,
         "form": form,
+
+        "logout_to": '/',
     })
 
 
     })
 
 
index f051213..64bd3e7 100644 (file)
@@ -2,7 +2,7 @@
 
 {% if user.is_authenticated %}
 <span class="user_name">{{ user.username }}</span> |
 
 {% if user.is_authenticated %}
 <span class="user_name">{{ user.username }}</span> |
-<a href='{% url logout %}'>{% trans "Log Out" %}</a>
+<a href='{% url logout %}{% if logout_to %}?next={{ logout_to }}{% endif %}'>{% trans "Log Out" %}</a>
 {% else %}
 {% url login as login_url %}
 {% ifnotequal login_url request.path %}
 {% else %}
 {% url login as login_url %}
 {% ifnotequal login_url request.path %}