[cig-commits] r7807 - in cs/pythia/trunk/opal: components db/models
sites views
leif at geodynamics.org
leif at geodynamics.org
Fri Aug 10 18:19:30 PDT 2007
Author: leif
Date: 2007-08-10 18:19:24 -0700 (Fri, 10 Aug 2007)
New Revision: 7807
Modified:
cs/pythia/trunk/opal/components/WebComponent.py
cs/pythia/trunk/opal/db/models/base.py
cs/pythia/trunk/opal/sites/WebSite.py
cs/pythia/trunk/opal/views/DetailView.py
Log:
Django's poor design (cycles in the module dependency graph, __init__
code, global variables, etc.) causes pain. Fixed the "you can't have
a model named 'Model'" bug introduced by Django v0.96. Fixed
DetailView/CreationController combo. (Over in the other repository,
SeismoWebPortal is working again.)
Modified: cs/pythia/trunk/opal/components/WebComponent.py
===================================================================
--- cs/pythia/trunk/opal/components/WebComponent.py 2007-08-11 00:09:36 UTC (rev 7806)
+++ cs/pythia/trunk/opal/components/WebComponent.py 2007-08-11 01:19:24 UTC (rev 7807)
@@ -28,8 +28,10 @@
# urlpatterns support
- include = lambda urlconf_module: [urlconf_module]
+ def include(self, urlconf_module):
+ return [urlconf_module]
+
def patterns(self, *tuples):
from opal.core.urlresolvers import RegexURLPattern, RegexURLResolver
pattern_list = []
Modified: cs/pythia/trunk/opal/db/models/base.py
===================================================================
--- cs/pythia/trunk/opal/db/models/base.py 2007-08-11 00:09:36 UTC (rev 7806)
+++ cs/pythia/trunk/opal/db/models/base.py 2007-08-11 01:19:24 UTC (rev 7807)
@@ -22,7 +22,11 @@
"Metaclass for all models"
def __new__(cls, name, bases, attrs):
# If this isn't a subclass of Model, don't do anything special.
- if name == 'Model' or not filter(lambda b: issubclass(b, Model), bases):
+
+ # This Django v0.96 change causes problems if a model subclass
+ # happens to be called 'Model'. Reverted to v0.95 code.
+ #if name == 'Model' or not filter(lambda b: issubclass(b, Model), bases):
+ if not bases or bases == (object,):
return super(ModelBase, cls).__new__(cls, name, bases, attrs)
# Create the class.
Modified: cs/pythia/trunk/opal/sites/WebSite.py
===================================================================
--- cs/pythia/trunk/opal/sites/WebSite.py 2007-08-11 00:09:36 UTC (rev 7806)
+++ cs/pythia/trunk/opal/sites/WebSite.py 2007-08-11 01:19:24 UTC (rev 7807)
@@ -351,8 +351,8 @@
#########
SITE_ID = pyre.int("site-id", default=1)
- #rootUrlconf = pyre.str("root-urlconf", default=None)
- rootUrlconf = pyre.facility("root", default=None)
+ rootUrlconf = pyre.str("root", default=None)
+ #rootUrlconf = pyre.facility("root", default=None)
def _configure(self):
@@ -388,7 +388,19 @@
from opal.core import urlresolvers
if self.ROOT_URLCONF is None:
- self.ROOT_URLCONF = self.rootUrlconf
+ # This can't be configured as a normal facility because of
+ # Django's poor design (cycles in the module dependency
+ # graph, global variables, etc.).
+ urlconf = self.retrieveComponent(self.rootUrlconf, factory='root')
+ if urlconf is None:
+ raise RuntimeError("no urlconf")
+ context = self.configureComponent(urlconf)
+ if not context.verifyConfiguration(urlconf, 'strict'):
+ raise RuntimeError("%s: configuration error(s)" % urlconf.name)
+ urlconf.init()
+
+ self.ROOT_URLCONF = urlconf
+
return urlresolvers.RegexURLResolver(r'^/', self.ROOT_URLCONF)
Modified: cs/pythia/trunk/opal/views/DetailView.py
===================================================================
--- cs/pythia/trunk/opal/views/DetailView.py 2007-08-11 00:09:36 UTC (rev 7806)
+++ cs/pythia/trunk/opal/views/DetailView.py 2007-08-11 01:19:24 UTC (rev 7807)
@@ -31,7 +31,7 @@
defaultTemplateNameTag = "detail"
- def __init__(self, model, query, template_name_field=None, **kwds):
+ def __init__(self, model, query=None, template_name_field=None, **kwds):
View.__init__(self, model, **kwds)
self.query = query
self.obj = None
@@ -40,7 +40,8 @@
def response(self, request):
- self.obj = self.getObject()
+ if self.query:
+ self.obj = self.getObject()
# Give the controller a chance to respond to this request.
return self.controller.response(request)
@@ -62,7 +63,7 @@
def loadTemplate(self):
- if self.template_name_field:
+ if self.obj and self.template_name_field:
template_name_list = [getattr(self.obj, self.template_name_field), self.template_name]
t = self.template_loader.select_template(template_name_list)
else:
@@ -78,7 +79,8 @@
def globalContext(self):
context = super(DetailView, self).globalContext()
- context[self.template_object_name] = self.obj
+ if self.obj:
+ context[self.template_object_name] = self.obj
return context
More information about the cig-commits
mailing list