From 83f1d360437d7451e0b04d4fcfa4011dee8671b8 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 5 Mar 2012 10:34:49 +0530 Subject: [PATCH] add login_required to all views --- printaform/formaprint/views.py | 6 ++++-- printaform/settings.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/printaform/formaprint/views.py b/printaform/formaprint/views.py index a49da3a..f87813b 100755 --- a/printaform/formaprint/views.py +++ b/printaform/formaprint/views.py @@ -16,11 +16,13 @@ from os.path import join from settings import MEDIA_ROOT import os +@login_required def index(request): items = Item.objects.all() #FIXME: check perms, etc context = RequestContext(request, {'items': items}) return render_to_response("index.html", context) +@login_required def new_item(request): if request.POST: form = ItemForm(request.POST) @@ -91,13 +93,13 @@ def save_item_as(request): new_item.save() return HttpResponse("/edit_item/?id=%d" % new_item.id) - +@login_required def render_item(request): id = request.GET.get("id", 0) item = get_object_or_404(Item, pk=id) return HttpResponse(item.render()) - +@login_required def print_item(request): id = request.GET.get("id", 0) item = get_object_or_404(Item, pk=id) diff --git a/printaform/settings.py b/printaform/settings.py index b8f54c4..17d2612 100755 --- a/printaform/settings.py +++ b/printaform/settings.py @@ -63,7 +63,23 @@ MEDIA_URL = '/static/' ADMIN_MEDIA_PREFIX = '/admin/media/' # Make this unique, and don't share it with anybody. -SECRET_KEY = '@(#h=8spfwzzhtbw%$5n$wfyz5jt7ym#x8vx-ajfwn_a(1' +try: + SECRET_KEY +except NameError: + SECRET_FILE = os.path.join(PROJECT_ROOT, 'secret.txt') + try: + SECRET_KEY = open(SECRET_FILE).read().strip() + except IOError: + try: + from random import choice + SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) + secret = file(SECRET_FILE, 'w') + secret.write(SECRET_KEY) + secret.close() + except IOError: + Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE) + + # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = (