diff options
-rw-r--r-- | main/middleware.py | 16 | ||||
-rw-r--r-- | main/models.py | 4 | ||||
-rw-r--r-- | news/views.py | 16 | ||||
-rw-r--r-- | settings.py | 1 |
4 files changed, 14 insertions, 23 deletions
diff --git a/main/middleware.py b/main/middleware.py index 4d343b4..f893c79 100644 --- a/main/middleware.py +++ b/main/middleware.py @@ -1,19 +1,3 @@ -import threading - -user_holder = threading.local() -user_holder.user = None - -# http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser -class AutoUserMiddleware(object): - '''Saves the current user so it can be retrieved by the admin''' - def process_request(self, request): - user_holder.user = request.user - - -def get_user(): - '''Get the currently logged in request.user''' - return user_holder.user - # begin copy of stock Django UpdateCacheMiddleware # this is to address feeds caching issue which makes it horribly # unperformant diff --git a/main/models.py b/main/models.py index 7eeec85..793407e 100644 --- a/main/models.py +++ b/main/models.py @@ -3,7 +3,6 @@ from django.db.models import Q from django.contrib.auth.models import User from django.contrib.sites.models import Site -from main.middleware import get_user from packages.models import PackageRelation ########################### @@ -121,8 +120,7 @@ class Donor(models.Model): class News(models.Model): id = models.AutoField(primary_key=True) - author = models.ForeignKey(User, related_name='news_author', - default=get_user) + author = models.ForeignKey(User, related_name='news_author') postdate = models.DateField(auto_now_add=True) title = models.CharField(max_length=255) content = models.TextField() 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): diff --git a/settings.py b/settings.py index 6c9a118..68eaaad 100644 --- a/settings.py +++ b/settings.py @@ -51,7 +51,6 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.http.ConditionalGetMiddleware', "django.middleware.common.CommonMiddleware", "django.middleware.doc.XViewMiddleware", - "main.middleware.AutoUserMiddleware", 'django.middleware.cache.FetchFromCacheMiddleware', ) |