add login_required to all views

This commit is contained in:
Sanj 2012-03-05 10:34:49 +05:30
parent 379b448bb4
commit 83f1d36043
2 changed files with 21 additions and 3 deletions

View File

@ -16,11 +16,13 @@ from os.path import join
from settings import MEDIA_ROOT from settings import MEDIA_ROOT
import os import os
@login_required
def index(request): def index(request):
items = Item.objects.all() #FIXME: check perms, etc items = Item.objects.all() #FIXME: check perms, etc
context = RequestContext(request, {'items': items}) context = RequestContext(request, {'items': items})
return render_to_response("index.html", context) return render_to_response("index.html", context)
@login_required
def new_item(request): def new_item(request):
if request.POST: if request.POST:
form = ItemForm(request.POST) form = ItemForm(request.POST)
@ -91,13 +93,13 @@ def save_item_as(request):
new_item.save() new_item.save()
return HttpResponse("/edit_item/?id=%d" % new_item.id) return HttpResponse("/edit_item/?id=%d" % new_item.id)
@login_required
def render_item(request): def render_item(request):
id = request.GET.get("id", 0) id = request.GET.get("id", 0)
item = get_object_or_404(Item, pk=id) item = get_object_or_404(Item, pk=id)
return HttpResponse(item.render()) return HttpResponse(item.render())
@login_required
def print_item(request): def print_item(request):
id = request.GET.get("id", 0) id = request.GET.get("id", 0)
item = get_object_or_404(Item, pk=id) item = get_object_or_404(Item, pk=id)

View File

@ -63,7 +63,23 @@ MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/admin/media/' ADMIN_MEDIA_PREFIX = '/admin/media/'
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
SECRET_KEY = '@(#h=8&#23spfwzzhtbw%$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. # List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (