1 from django
.core
import validators
2 from django
.template
import RequestContext
3 from django
.shortcuts
import render_to_response
4 from django
.http
import HttpResponseRedirect
8 #from archweb_dev.packages.models import Maintainer
9 #from archweb_dev.settings import BADPRIVS_URL
10 #def is_maintainer(view_func, badprivs_url=BADPRIVS_URL):
12 # Decorator for views that checks that the logged-in user has a corresponding
13 # record in the Maintainers table. If not, the user is forwarded to a
14 # "bad-privileges" page.
16 # def _dec(view_func):
17 # def _checkuser(request, *args, **kwargs):
19 # m = Maintainer.objects.get(username=request.user.username)
20 # except Maintainer.DoesNotExist:
21 # return HttpResponseRedirect(badprivs_url)
22 # return view_func(request, *args, **kwargs)
25 # return _dec(view_func)
27 def render_template(template
, request
, context
=None):
29 A shortcut to render_to_response with a RequestContext. Also includes
30 request.path in the context, so both 'path' and 'user' are accessible to
34 context
['path'] = request
.path
35 return render_to_response(template
, context_instance
=RequestContext(request
, context
))
37 return render_to_response(template
, context_instance
=RequestContext(request
))
39 def validate(errdict
, fieldname
, fieldval
, validator
, blankallowed
, request
):
41 A helper function that allows easy access to Django's validators without
42 going through a Manipulator object. Will return a dict of all triggered
45 if blankallowed
and not fieldval
:
47 alldata
= ' '.join(request
.POST
.values()) + ' '.join(request
.GET
.values())
49 validator(fieldval
, alldata
)
50 except validators
.ValidationError
, e
:
51 if not errdict
.has_key(fieldname
): errdict
[fieldname
] = []
52 errdict
[fieldname
].append(e
)
55 # XXX: unused right now, probably not needed
56 class Stripper(sgmllib
.SGMLParser
):
57 """Helper class to strip HTML tags"""
59 sgmllib
.SGMLParser
.__init
__(self
)
61 def strip(self
, some_html
):
62 """Strips all HTML tags and leading/trailing whitespace"""
68 def handle_data(self
, data
):
69 self
.theString
+= data