From 67f6bc546ec20bd1912aae385220855f9a41a93d Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 20 Jun 2010 23:31:34 -0500 Subject: Remove AutoUserMiddleware This was having some serious effects on caching as we would always have to access the user in the session, marking every page with a "Vary: Cookie" header. This is the start of stamping that out. The way we get the user for news item creation is now more similar to that from the todo lists, but not quite. That should be adjusted to be more like the news item creation. Signed-off-by: Dan McGee --- news/views.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'news') diff --git a/news/views.py b/news/views.py index d876f0b..e6a6d83 100644 --- a/news/views.py +++ b/news/views.py @@ -1,5 +1,7 @@ from django import forms from django.contrib.auth.decorators import permission_required +from django.shortcuts import render_to_response, redirect +from django.template import RequestContext from django.views.generic import list_detail, create_update from main.models import News @@ -22,9 +24,17 @@ class NewsForm(forms.ModelForm): @permission_required('main.add_news') def add(request): - return create_update.create_object(request, - form_class=NewsForm, - template_name='news/add.html') + if request.POST: + form = NewsForm(request.POST) + if form.is_valid(): + newsitem = form.save(commit=False) + newsitem.author = request.user + newsitem.save() + return redirect(newsitem.get_absolute_url()) + else: + form = NewsForm() + return render_to_response('news/add.html', + RequestContext(request, { 'form': form })) @permission_required('main.delete_news') def delete(request, newsid): -- cgit v1.2.3-24-g4f1b