* Add tools package, with some custom forms. Code borrowed from the Amelie project.
authorMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 18:07:29 +0000 (19:07 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 18:07:29 +0000 (19:07 +0100)
tools/__init__.py [new file with mode: 0644]
tools/forms.py [new file with mode: 0644]

diff --git a/tools/__init__.py b/tools/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tools/forms.py b/tools/forms.py
new file mode 100644 (file)
index 0000000..b3171e3
--- /dev/null
@@ -0,0 +1,37 @@
+# Mostly based on code from Amelie, a project by Inter-Actief.
+
+from django.newforms.util import ErrorList
+from django.newforms.models import BaseModelForm, ModelFormMetaclass
+from django.newforms.forms import BaseForm, DeclarativeFieldsMetaclass
+
+class BaseContextForm(BaseForm):
+    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
+                 initial=None, request=None, error_class=ErrorList, label_suffix=':'):
+        self.request = request
+        if request and request.method == "POST":
+            if not data:
+                data = request.POST
+            if not files:
+                files = request.FILES
+        super(BaseContextForm, self).__init__(data, files, auto_id, prefix,
+                                       initial, request, error_class, label_suffix)
+
+class ContextForm(BaseContextForm):
+    __metaclass__ = DeclarativeFieldsMetaclass
+
+class BaseContextModelForm(BaseModelForm):
+    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
+                 initial=None, request=None, error_class=ErrorList, label_suffix=':', instance=None):
+        self.request = request
+        if request and request.method == "POST":
+            if not data:
+                data = request.POST
+            if not files:
+                files = request.FILES
+        super(BaseContextModelForm, self).__init__(data, files, auto_id, prefix, initial, 
+                                            error_class, label_suffix, instance)
+
+class ContextModelForm(BaseContextModelForm):
+    __metaclass__ = ModelFormMetaclass
+
+# vim:set sts=4 ts=4 sw=4 ai et: