summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoreliott <eliott@cactuswax.net>2007-12-29 15:34:02 -0800
committereliott <eliott@cactuswax.net>2007-12-29 15:34:02 -0800
commit15ceff77fef19819cba43e866938311aeffd0732 (patch)
tree16903554adbb32300aad9a5b3d647679710e9302 /lib
parentd1cc0f54a490e5eacf07107e461672979266f461 (diff)
Modified render_template and renamed it to render_response (consistent with
archweb_pub conventions). Moved pkgmaint_guide to a template.
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
new file mode 100644
index 00000000..59df963b
--- /dev/null
+++ b/lib/utils.py
@@ -0,0 +1,34 @@
+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)
+