Commit 15ceff77 authored by eliott's avatar eliott
Browse files

Modified render_template and renamed it to render_response (consistent with

archweb_pub conventions).
Moved pkgmaint_guide to a template.
parent d1cc0f54
......@@ -2,7 +2,7 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core import validators
from archweb_dev.utils import render_template
from archweb_dev.utils import render_response
from archweb_dev.packages.models import Package
from archweb_dev.todolists.models import Todolist, TodolistPkg
from archweb_dev.settings import DATA_DIR
......@@ -27,7 +27,7 @@ def index(request):
else:
pkgs = None
return render_template('devel/index.html', request,
return render_response(request, 'devel/index.html',
{'stats':stats, 'pkgs':pkgs, 'todos':todos, 'maint':thismaint})
@login_required
......@@ -59,9 +59,10 @@ def change_profile(request):
request.user.set_password(passwd1)
request.user.save()
return HttpResponseRedirect('/devel/')
return render_template('devel/profile.html', request, {'errors':errors,'email':request.user.email})
return render_response(request, 'devel/profile.html', {'errors':errors,'email':request.user.email})
@login_required
def guide(request):
return render_response(request, 'devel/pkgmaint_guide.txt', {'errors':errors,'email':request.user.email})
return HttpResponse(file(DATA_DIR + '/pkgmaint_guide.txt').read(),
mimetype='text/plain')
from django.core import validators
from django.conf import settings
from django.core.cache import cache
from django.shortcuts import render_to_response
from django.template import RequestContext
def validate(errdict, fieldname, fieldval, validator, blankallowed, request):
"""
A helper function that allows easy access to Django's validators without
going through a Manipulator object. Will return a dict of all triggered
errors.
"""
if blankallowed and not fieldval:
return
alldata = ' '.join(request.POST.values()) + ' '.join(request.GET.values())
try:
validator(fieldval, alldata)
except validators.ValidationError, e:
if not errdict.has_key(fieldname):
errdict[fieldname] = []
errdict[fieldname].append(e)
def prune_cache(django_page_url):
if not settings.CACHE:
return
cache_prefix = 'views.decorators.cache.cache_page.'
cache_prefix += settings.CACHE_MIDDLEWARE_KEY_PREFIX + '.'
cache_postfix = '.d41d8cd98f00b204e9800998ecf8427e'
cache.delete('%s%s%s' % (cache_prefix,django_page_url,cache_postfix))
def render_response(req, *args, **kwargs):
kwargs['context_instance'] = RequestContext(req)
return render_to_response(*args, **kwargs)
......@@ -3,24 +3,24 @@
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})
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})
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,
return render_response(request, 'error_page.html',
{'errmsg': 'Cannot find a maintainer record for you! No posting allowed.'})
manipulator = News.AddManipulator()
......@@ -38,24 +38,24 @@ def add(request):
data = {}
form = forms.FormWrapper(manipulator, data, errors)
return render_template('news/add.html', request, {'form': form})
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'})
# 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_template('news/delete.html', request)
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,
return render_response(request, 'error_page.html',
{'errmsg': 'Cannot find a maintainer record for you! No posting allowed.'})
try:
manipulator = News.ChangeManipulator(newsid)
......@@ -64,7 +64,7 @@ def edit(request, newsid):
news = manipulator.original_object
# if news.author != m:
# return render_template('error_page.html', request, {'errmsg': 'You do not own this news item'})
# 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
......@@ -79,4 +79,4 @@ def edit(request, newsid):
data = news.__dict__
form = forms.FormWrapper(manipulator, data, errors)
return render_template('news/add.html', request, {'form': form, 'news':news})
return render_response(request, 'news/add.html', {'form': form, 'news':news})
......@@ -5,7 +5,7 @@
from django.core import validators
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from archweb_dev.utils import validate, render_template
from archweb_dev.lib.utils import validate, render_response
from datetime import datetime
from archweb_dev.packages.models import Package, PackageFile, Repo, Category
......@@ -19,7 +19,7 @@ def update(request):
try:
maint = User.objects.get(username=request.user.username)
except User.DoesNotExist:
return render_template('error_page.html', request, {'errmsg':'No maintainer record found! Are you a maintainer?'})
return render_response(request, 'error_page.html', {'errmsg':'No maintainer record found! Are you a maintainer?'})
ids = request.POST.getlist('pkgid')
for id in ids:
pkg = Package.objects.get(id=id)
......@@ -30,7 +30,7 @@ def update(request):
else:
message = "You are not the current maintainer"
pkg.save()
return render_template('status_page.html', request, {'message':message})
return render_response(request, 'status_page.html', {'message':message})
def details(request, pkgid=0, name='', repo=''):
if pkgid == 0:
......@@ -38,12 +38,12 @@ def details(request, pkgid=0, name='', repo=''):
if repo: p = p.filter(repo__name__exact=repo)
# if more then one result, send to the search view
if len(p) > 1: return search(request, name)
if len(p) < 1: return render_template('error_page.html', request,
if len(p) < 1: return render_response(request, 'error_page.html',
{'errmsg': 'No matching packages.'})
pkgid = p[0].id
pkg = get_object_or_404(Package, id=pkgid)
return render_template('packages/details.html', request, {'pkg':pkg})
return render_response(request, 'packages/details.html', {'pkg':pkg})
def search(request, query=''):
if request.GET.has_key('q'):
......@@ -78,7 +78,7 @@ def search(request, query=''):
validate(errors, 'Page Skip', str(skip), validators.isOnlyDigits, True, request)
if errors:
c['errors'] = errors
return render_template('packages/search.html', request, c)
return render_response(request, 'packages/search.html', c)
if query:
res1 = Package.objects.filter(pkgname__icontains=query)
......@@ -117,15 +117,15 @@ def search(request, query=''):
if limit > 0: results = results[skip:(skip+limit)]
c['results'] = results
return render_template('packages/search.html', request, c)
return render_response(request, 'packages/search.html', c)
def files(request, pkgid):
pkg = get_object_or_404(Package, id=pkgid)
files = PackageFile.objects.filter(pkg=pkgid)
return render_template('packages/files.html', request, {'pkg':pkg,'files':files})
return render_response(request, 'packages/files.html', {'pkg':pkg,'files':files})
def flaghelp(request):
return render_template('packages/flaghelp.html', request)
return render_response(request, 'packages/flaghelp.html')
def flag(request, pkgid):
pkg = get_object_or_404(Package, id=pkgid)
......@@ -141,7 +141,7 @@ def flag(request, pkgid):
validate(errors, 'Email Address', email, validators.isValidEmail, False, request)
if errors:
context['errors'] = errors
return render_template('packages/flag.html', request, context)
return render_response(request, 'packages/flag.html', context)
context['confirmemail'] = email
pkg.needupdate = 1
......@@ -160,13 +160,13 @@ def flag(request, pkgid):
'Arch Website Notification <nobody@archlinux.org>',
[pkg.maintainer.email],
fail_silently=True)
return render_template('packages/flag.html', request, context)
return render_response(request, 'packages/flag.html', context)
@login_required
def unflag(request, pkgid):
pkg = get_object_or_404(Package, id=pkgid)
if pkg.maintainer.username != request.user.username:
return render_template('error_page.html', request, {'errmsg': 'You do not own this package.'})
return render_response(request, 'error_page.html', {'errmsg': 'You do not own this package.'})
pkg.needupdate = 0
pkg.save()
return HttpResponseRedirect('/packages/%d/' % (pkg.id))
from django.http import HttpResponse
from archweb_dev.utils import render_template
from archweb_dev.lib.utils import render_response
from django.contrib.auth.models import User
from archweb_dev.packages.models import Package, Repo
from archweb_dev.news.models import News
......@@ -11,20 +11,20 @@ def index(request):
news = News.objects.order_by('-postdate', '-id')[:10]
pkgs = Package.objects.exclude(repo__name__exact='Testing').order_by('-last_update')[:15]
repos = Repo.objects.order_by('name')
return render_template('public/index.html', request, {'news_updates':news,'pkg_updates':pkgs,'repos':repos})
return render_response(request, 'public/index.html', {'news_updates':news,'pkg_updates':pkgs,'repos':repos})
def about(request):
return render_template('public/about.html', request)
return render_response(request, 'public/about.html')
def art(request):
return render_template('public/art.html', request)
return render_response(request, 'public/art.html')
def cvs(request):
return render_template('public/cvs.html', request)
return render_response(request, 'public/cvs.html')
def developers(request):
devs = User.objects.order_by('username')
return render_template('public/developers.html', request, {'devs':devs})
return render_response(request, 'public/developers.html', {'devs':devs})
def donate(request):
donor_count = Donator.objects.count()
......@@ -33,27 +33,27 @@ def donate(request):
slice2 = Donator.objects.all()[(splitval):(splitval*2)]
slice3 = Donator.objects.all()[(splitval*2):(donor_count-splitval)]
slice4 = Donator.objects.all()[(donor_count-splitval):donor_count]
return render_template('public/donate.html', request,
return render_response(request, 'public/donate.html',
{'slice1':slice1,'slice2':slice2,'slice3':slice3,'slice4':slice4})
def download(request):
mirrors = Mirror.objects.order_by('country', 'domain')
return render_template('public/download.html', request, {'mirrors':mirrors})
return render_response(request, 'public/download.html', {'mirrors':mirrors})
def irc(request):
return render_template('public/irc.html', request)
return render_response(request, 'public/irc.html')
def moreforums(request):
return render_template('public/moreforums.html', request)
return render_response(request, 'public/moreforums.html')
def press(request):
return render_template('public/press.html', request)
return render_response(request, 'public/press.html')
def projects(request):
return render_template('public/projects.html', request)
return render_response(request, 'public/projects.html')
def robots(request):
return HttpResponse("User-agent: *\nDisallow: /\n", mimetype="text/plain")
def denied(request):
return render_template('public/denied.html', request)
return render_response(request, 'public/denied.html')
......@@ -2,7 +2,7 @@
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from archweb_dev.utils import render_template
from archweb_dev.lib.utils import render_response
from archweb_dev.todolists.models import Todolist, TodolistPkg
from archweb_dev.packages.models import Package
......@@ -23,14 +23,14 @@ def flag(request, listid, pkgid):
def view(request, listid):
list = get_object_or_404(Todolist, id=listid)
pkgs = TodolistPkg.objects.filter(list=list.id).order_by('pkg')
return render_template('todolists/view.html', request, {'list':list,'pkgs':pkgs})
return render_response(request, 'todolists/view.html', {'list':list,'pkgs':pkgs})
@login_required
def list(request):
lists = Todolist.objects.order_by('-date_added')
for l in lists:
l.complete = TodolistPkg.objects.filter(list=l.id,complete=False).count() == 0
return render_template('todolists/list.html', request, {'lists':lists})
return render_response(request, 'todolists/list.html', {'lists':lists})
@login_required
#@is_maintainer
......@@ -40,7 +40,7 @@ def add(request):
try:
m = User.objects.get(username=request.user.username)
except User.DoesNotExist:
return render_template('error_page.html', request,
return render_response(request, 'error_page.html',
{'errmsg': 'Cannot find a maintainer record for you!'})
# create the list
todo = Todolist(
......@@ -60,5 +60,4 @@ def add(request):
if num == 1062: # duplicate entry aka dupe package on list
pass
return HttpResponseRedirect('/todo/')
return render_template('todolists/add.html', request)
return render_response(request, 'todolists/add.html')
from django.core import validators
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from string import *
import sgmllib
#from archweb_dev.packages.models import Maintainer
#from archweb_dev.settings import BADPRIVS_URL
#def is_maintainer(view_func, badprivs_url=BADPRIVS_URL):
# """
# Decorator for views that checks that the logged-in user has a corresponding
# record in the Maintainers table. If not, the user is forwarded to a
# "bad-privileges" page.
# """
# def _dec(view_func):
# def _checkuser(request, *args, **kwargs):
# try:
# m = Maintainer.objects.get(username=request.user.username)
# except Maintainer.DoesNotExist:
# return HttpResponseRedirect(badprivs_url)
# return view_func(request, *args, **kwargs)
#
# return _checkuser
# return _dec(view_func)
def render_template(template, request, context=None):
"""
A shortcut to render_to_response with a RequestContext. Also includes
request.path in the context, so both 'path' and 'user' are accessible to
the template.
"""
if context:
context['path'] = request.path
return render_to_response(template, context_instance=RequestContext(request, context))
else:
return render_to_response(template, context_instance=RequestContext(request))
def validate(errdict, fieldname, fieldval, validator, blankallowed, request):
"""
A helper function that allows easy access to Django's validators without
going through a Manipulator object. Will return a dict of all triggered
errors.
"""
if blankallowed and not fieldval:
return
alldata = ' '.join(request.POST.values()) + ' '.join(request.GET.values())
try:
validator(fieldval, alldata)
except validators.ValidationError, e:
if not errdict.has_key(fieldname): errdict[fieldname] = []
errdict[fieldname].append(e)
# XXX: unused right now, probably not needed
class Stripper(sgmllib.SGMLParser):
"""Helper class to strip HTML tags"""
def __init__(self):
sgmllib.SGMLParser.__init__(self)
def strip(self, some_html):
"""Strips all HTML tags and leading/trailing whitespace"""
self.theString = ""
self.feed(some_html)
self.close()
return self.theString
def handle_data(self, data):
self.theString += data
......@@ -3,14 +3,14 @@
#
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from archweb_dev.utils import render_template
from archweb_dev.lib.utils import render_response
from archweb_dev.wiki.models import Wikipage
@login_required
def index(request):
"""Return a list of all wiki pages"""
pages = Wikipage.objects.all().order_by('title')
return render_template('wiki/home.html', request, {'pages':pages})
return render_response(request, 'wiki/home.html', {'pages':pages})
def main(request):
"""Return the Index wiki page"""
......@@ -21,7 +21,7 @@ def page(request, title):
"""Display page, or redirect to root if page doesn't exist yet"""
try:
page = Wikipage.objects.get(title__exact=title)
return render_template('wiki/page.html', request, {'page':page})
return render_response(request, 'wiki/page.html', {'page':page})
except Wikipage.DoesNotExist:
return HttpResponseRedirect("/wiki/edit/%s/" % title)
......@@ -46,7 +46,7 @@ def edit(request, title):
# create a dummy page object -- note that it is not saved!
page = Wikipage(title=title)
page.body = "<!-- Enter content here -->"
return render_template('wiki/edit.html', request, {'page':page})
return render_response(request, 'wiki/edit.html', {'page':page})
@login_required
def delete(request):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment