Author: justi9
Date: 2008-03-26 12:51:38 -0400 (Wed, 26 Mar 2008)
New Revision: 1797
Modified:
mgmt/cumin/python/cumin/brokergroup.py
mgmt/cumin/python/cumin/widgets.py
mgmt/cumin/python/wooly/__init__.py
mgmt/mint/python/mint/__init__.py
mgmt/mint/sql/schema.sql
Log:
Makes broker group name unique in the schema.
Introduces a field, UniqueNameField, that checks the database for
objects that already have the given name.
Introduces an init() pass to Widget (I thought I would need this), so
that it's possible link widgets to the state of other widgets. This
can't be accomplished in the __init__ pass because the whole tree of
widgets doesn't exist yet.
Modified: mgmt/cumin/python/cumin/brokergroup.py
===================================================================
--- mgmt/cumin/python/cumin/brokergroup.py 2008-03-26 15:28:34 UTC (rev 1796)
+++ mgmt/cumin/python/cumin/brokergroup.py 2008-03-26 16:51:38 UTC (rev 1797)
@@ -148,9 +148,14 @@
def __init__(self, app, name):
super(BrokerGroupForm, self).__init__(app, name)
- self.group_name = NameField(app, "name", self)
+ self.group_name = UniqueNameField(app, "name", self, BrokerGroup)
self.add_field(self.group_name)
+ def init(self):
+ super(BrokerGroupForm, self).init()
+
+ self.group_name.set_object_attr(self.frame().get_object_parameter())
+
class BrokerGroupAdd(BrokerGroupForm):
def process_cancel(self, session):
branch = session.branch()
@@ -158,7 +163,7 @@
self.page().pop_current_frame(branch)
self.page().get_current_frame(branch).show_view(branch)
self.page().set_redirect_url(session, branch.marshal())
-
+
def process_submit(self, session):
errors = self.validate(session)
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2008-03-26 15:28:34 UTC (rev 1796)
+++ mgmt/cumin/python/cumin/widgets.py 2008-03-26 16:51:38 UTC (rev 1797)
@@ -31,9 +31,14 @@
else:
return ()
+ # XXX these should be object_attr, not _parameter
def set_object_parameter(self, param):
self.__param = param
+ return param
+ def get_object_parameter(self):
+ return self.__param
+
def get_object(self, session):
if self.__param:
return self.__param.get(session)
@@ -593,6 +598,40 @@
break
+class UniqueNameField(NameField):
+ def __init__(self, app, name, form, cls, fld="name"):
+ super(UniqueNameField, self).__init__(app, name, form)
+
+ self.__class = cls
+ self.__field = fld
+ self.__object = None
+
+ def set_object_attr(self, attr):
+ self.__object = attr
+
+ def do_validate(self, session, errors):
+ name = self.get(session)
+
+ args = {self.__field: name, }
+ results = self.__class.selectBy(**args)
+
+ if self.__object:
+ object = self.__object.get(session)
+ if object:
+ results = results.filter(self.__class.q.id != object.id)
+
+ if results.count() > 0:
+ errors.append(DuplicateValueError())
+
+class DuplicateValueError(Error):
+ def __init__(self, fld="name"):
+ super(Error, self).__init__()
+
+ self.__field = fld
+
+ def get_message(self, session):
+ return "An item with this %s already exists" % self.__field
+
class DurabilityField(RadioField):
def __init__(self, app, name, form):
super(DurabilityField, self).__init__(app, name, form)
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2008-03-26 15:28:34 UTC (rev 1796)
+++ mgmt/cumin/python/wooly/__init__.py 2008-03-26 16:51:38 UTC (rev 1797)
@@ -115,6 +115,10 @@
if cls is Widget:
break
+ def init(self):
+ for child in self.children:
+ child.init()
+
def ancestors(self):
if self.__ancestors is None:
if self.parent is None:
@@ -403,6 +407,8 @@
self.pages[page.name] = page
+ page.init()
+
def get_page(self, name):
#print "Looking for", name, "in", self.pages
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2008-03-26 15:28:34 UTC (rev 1796)
+++ mgmt/mint/python/mint/__init__.py 2008-03-26 16:51:38 UTC (rev 1797)
@@ -67,7 +67,7 @@
class sqlmeta:
lazyUpdate = True
- name = StringCol(length=1000, default=None)
+ name = StringCol(length=1000, default=None, unique=True, notNone=True)
brokers = SQLRelatedJoin("BrokerRegistration",
intermediateTable="broker_group_mapping",
createRelatedTable=False)
Modified: mgmt/mint/sql/schema.sql
===================================================================
--- mgmt/mint/sql/schema.sql 2008-03-26 15:28:34 UTC (rev 1796)
+++ mgmt/mint/sql/schema.sql 2008-03-26 16:51:38 UTC (rev 1797)
@@ -5,7 +5,7 @@
CREATE TABLE broker_group (
id SERIAL PRIMARY KEY,
- name VARCHAR(1000)
+ name VARCHAR(1000) NOT NULL UNIQUE
);
CREATE TABLE broker_group_mapping (