[cig-commits] r7844 - in cs/pythia/trunk/opal: components core forms views

leif at geodynamics.org leif at geodynamics.org
Fri Aug 17 20:02:53 PDT 2007


Author: leif
Date: 2007-08-17 20:02:52 -0700 (Fri, 17 Aug 2007)
New Revision: 7844

Modified:
   cs/pythia/trunk/opal/components/WebComponent.py
   cs/pythia/trunk/opal/core/responders.py
   cs/pythia/trunk/opal/forms/__init__.py
   cs/pythia/trunk/opal/views/ListView.py
Log:
Wrote class Form.  Moved towards list-as-model, avoiding querysets.


Modified: cs/pythia/trunk/opal/components/WebComponent.py
===================================================================
--- cs/pythia/trunk/opal/components/WebComponent.py	2007-08-17 21:41:11 UTC (rev 7843)
+++ cs/pythia/trunk/opal/components/WebComponent.py	2007-08-18 03:02:52 UTC (rev 7844)
@@ -57,8 +57,16 @@
         return self
 
 
+    def response(self, request):
+        return self.responder.response(request)
+
+
+    def isLeaf(self):
+        return False
+
+
     def subResponder(self, name):
-        raise http.Http404
+        return self.responder.subResponder(name)
 
 
     # urlpatterns support
@@ -90,17 +98,8 @@
         return controller.response(request)
 
 
-    def genericObjectDetail(self, request, queryset, query, **kwds):
-        # NYI: Unlike Django's object_detail() function, this discards
-        # 'queryset'.  This may not be appropriate, even though this
-        # is a view of a single object: e.g., if the queryset is a
-        # per-user query, then perhaps 'Http404' should be raised.
-        # OTOH, in Django's create_update functions (replicated in the
-        # CRUD stuff below), 'model' seems to be good enough; which
-        # begs the question as to why this method doesn't take a
-        # 'model' instead of a 'queryset'.
-        model = queryset.model
-        view = views.DetailView(model, query, **kwds)
+    def genericObjectDetail(self, request, model, **kwds):
+        view = views.DetailView(model, **kwds)
         controller = view.controller
         return controller.response(request)
 

Modified: cs/pythia/trunk/opal/core/responders.py
===================================================================
--- cs/pythia/trunk/opal/core/responders.py	2007-08-17 21:41:11 UTC (rev 7843)
+++ cs/pythia/trunk/opal/core/responders.py	2007-08-18 03:02:52 UTC (rev 7844)
@@ -69,12 +69,16 @@
 
 class QueryDirectoryResponder(Responder):
 
-    def __init__(self, Model, Inquirer, subResponderFactory):
+    def __init__(self, index, Model, Inquirer, subResponderFactory):
+        self.index = index
         self.Model = Model
         self.Inquirer = Inquirer
         self.subResponderFactory = subResponderFactory
         return
 
+    def response(self, request):
+        return self.index.response(request)
+
     def subResponder(self, name):
         from opal.core.exceptions import ObjectDoesNotExist
         query = self.newQuery(name)

Modified: cs/pythia/trunk/opal/forms/__init__.py
===================================================================
--- cs/pythia/trunk/opal/forms/__init__.py	2007-08-17 21:41:11 UTC (rev 7843)
+++ cs/pythia/trunk/opal/forms/__init__.py	2007-08-18 03:02:52 UTC (rev 7844)
@@ -1013,3 +1013,78 @@
             v(field_data, all_data)
         except validators.ValidationError, e:
             raise validators.CriticalValidationError, e.messages
+
+
+#------------------------------------------------------------------------
+
+
+
+class FormClass(type):
+
+
+    def __init__(cls, name, bases, dct):
+
+        type.__init__(cls, name, bases, dct)
+
+        fields = []
+
+        # register inherited fields
+        bases = list(bases)
+        bases.reverse()
+        for base in bases:
+            try:
+                fields.extend(base._fields)
+            except AttributeError:
+                pass
+
+        # examine the class record for additional fields
+        _fields = dct.get('fields', [])
+        fields.extend(_fields)
+        
+        # install the field list into the class record
+        cls.fields = fields
+        cls._fields = _fields
+
+        # create and install the manipulator
+        manipulator = Manipulator()
+        manipulator.fields = fields
+        cls.manipulator = manipulator
+
+        return
+
+
+
+class Form(object):
+
+    __metaclass__ = FormClass
+
+    fields = []
+    _fields = []
+
+    manipulator = Manipulator()
+
+
+    def __init__(self, data, errors):
+        self.wrapper = FormWrapper(self.manipulator, data, errors)
+        self.data = data
+        self.errors = errors
+        return
+
+
+    #@classmethod
+    def blank(cls):
+        return cls({}, {})
+    blank = classmethod(blank)
+
+
+    #@classmethod
+    def fromRequest(cls, request):
+        data = request.POST.copy()
+        errors = cls.manipulator.get_validation_errors(data)
+        cls.manipulator.do_html2python(data)
+        return cls(data, errors)
+    fromRequest = classmethod(fromRequest)
+
+
+
+# end of file

Modified: cs/pythia/trunk/opal/views/ListView.py
===================================================================
--- cs/pythia/trunk/opal/views/ListView.py	2007-08-17 21:41:11 UTC (rev 7843)
+++ cs/pythia/trunk/opal/views/ListView.py	2007-08-18 03:02:52 UTC (rev 7844)
@@ -48,7 +48,7 @@
 
 
     def __init__(self, queryset, allow_empty=True, **kwds):
-        View.__init__(self, queryset.model, **kwds)
+        View.__init__(self, queryset, **kwds)
         self.queryset = queryset
         self.allow_empty = allow_empty
         return



More information about the cig-commits mailing list