diff options
author | eliott <eliott@cactuswax.net> | 2007-12-30 00:34:02 +0100 |
---|---|---|
committer | eliott <eliott@cactuswax.net> | 2007-12-30 00:34:02 +0100 |
commit | 15ceff77fef19819cba43e866938311aeffd0732 (patch) | |
tree | 16903554adbb32300aad9a5b3d647679710e9302 /news | |
parent | d1cc0f54a490e5eacf07107e461672979266f461 (diff) | |
download | archweb-15ceff77fef19819cba43e866938311aeffd0732.tar.gz archweb-15ceff77fef19819cba43e866938311aeffd0732.tar.xz |
Modified render_template and renamed it to render_response (consistent with
archweb_pub conventions).
Moved pkgmaint_guide to a template.
Diffstat (limited to 'news')
-rw-r--r-- | news/views.py | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/news/views.py b/news/views.py index 5ceb331..4e4b4f0 100644 --- a/news/views.py +++ b/news/views.py @@ -3,80 +3,80 @@ from django.shortcuts import get_object_or_404 from django.contrib.auth.decorators import user_passes_test from django.contrib.auth.models import User from django import forms -from archweb_dev.utils import render_template +from archweb_dev.lib.utils import render_response from archweb_dev.news.models import News from datetime import date def view(request, newsid): - news = get_object_or_404(News, id=newsid) - return render_template('news/view.html', request, {'news':news}) + news = get_object_or_404(News, id=newsid) + return render_response(request, 'news/view.html', {'news':news}) def list(request): - news = News.objects.order_by('-postdate', '-id') - return render_template('news/list.html', request, {'news':news}) + news = News.objects.order_by('-postdate', '-id') + return render_response(request, 'news/list.html', {'news':news}) @user_passes_test(lambda u: u.has_perm('news.add_news')) def add(request): - try: - m = User.objects.get(username=request.user.username) - except User.DoesNotExist: - return render_template('error_page.html', request, - {'errmsg': 'Cannot find a maintainer record for you! No posting allowed.'}) + try: + m = User.objects.get(username=request.user.username) + except User.DoesNotExist: + return render_response(request, 'error_page.html', + {'errmsg': 'Cannot find a maintainer record for you! No posting allowed.'}) - manipulator = News.AddManipulator() - if request.POST: - data = request.POST.copy() - # add in the author ID - data['author'] = m.id - errors = manipulator.get_validation_errors(data) - if not errors: - manipulator.do_html2python(data) - manipulator.save(data) - return HttpResponseRedirect('/news/') - else: - errors = {} - data = {} + manipulator = News.AddManipulator() + if request.POST: + data = request.POST.copy() + # add in the author ID + data['author'] = m.id + errors = manipulator.get_validation_errors(data) + if not errors: + manipulator.do_html2python(data) + manipulator.save(data) + return HttpResponseRedirect('/news/') + else: + errors = {} + data = {} - form = forms.FormWrapper(manipulator, data, errors) - return render_template('news/add.html', request, {'form': form}) + form = forms.FormWrapper(manipulator, data, errors) + return render_response(request, 'news/add.html', {'form': form}) @user_passes_test(lambda u: u.has_perm('news.delete_news')) def delete(request, newsid): - news = get_object_or_404(News, id=newsid) - #if news.author.id != request.user.id: - # return render_template('error_page.html', request, {'errmsg': 'You do not own this news item'}) - if request.POST: - news.delete() - return HttpResponseRedirect('/news/') - return render_template('news/delete.html', request) + news = get_object_or_404(News, id=newsid) + #if news.author.id != request.user.id: + # return render_response(request, 'error_page.html', {'errmsg': 'You do not own this news item'}) + if request.POST: + news.delete() + return HttpResponseRedirect('/news/') + return render_response(request, 'news/delete.html') @user_passes_test(lambda u: u.has_perm('news.change_news')) def edit(request, newsid): - try: - m = User.objects.get(username=request.user.username) - except User.DoesNotExist: - return render_template('error_page.html', request, - {'errmsg': 'Cannot find a maintainer record for you! No posting allowed.'}) - try: - manipulator = News.ChangeManipulator(newsid) - except News.DoesNotExist: - raise Http404 + try: + m = User.objects.get(username=request.user.username) + except User.DoesNotExist: + return render_response(request, 'error_page.html', + {'errmsg': 'Cannot find a maintainer record for you! No posting allowed.'}) + try: + manipulator = News.ChangeManipulator(newsid) + except News.DoesNotExist: + raise Http404 - news = manipulator.original_object -# if news.author != m: -# return render_template('error_page.html', request, {'errmsg': 'You do not own this news item'}) - if request.POST: - data = request.POST.copy() - # add in the author ID - data['author'] = news.author.id - errors = manipulator.get_validation_errors(data) - if not errors: - manipulator.do_html2python(data) - manipulator.save(data) - return HttpResponseRedirect('/news/') - else: - errors = {} - data = news.__dict__ + news = manipulator.original_object +# if news.author != m: +# return render_response(request, 'error_page.html', {'errmsg': 'You do not own this news item'}) + if request.POST: + data = request.POST.copy() + # add in the author ID + data['author'] = news.author.id + errors = manipulator.get_validation_errors(data) + if not errors: + manipulator.do_html2python(data) + manipulator.save(data) + return HttpResponseRedirect('/news/') + else: + errors = {} + data = news.__dict__ - form = forms.FormWrapper(manipulator, data, errors) - return render_template('news/add.html', request, {'form': form, 'news':news}) + form = forms.FormWrapper(manipulator, data, errors) + return render_response(request, 'news/add.html', {'form': form, 'news':news}) |