server/mirrormanager/controllers.py | 88 +++++++-------
server/mirrormanager/model.py | 6
server/mirrormanager/templates/adminview.kid | 2
server/mirrormanager/templates/boringlocationhostform.kid | 16 ++
4 files changed, 68 insertions(+), 44 deletions(-)
New commits:
commit dedc01805578e879c0582c5fe35ec0e392c34bf7
Author: Matt Domsch <Matt_Domsch(a)dell.com>
Date: Mon Jan 17 00:21:54 2011 -0600
add boringlocationhostform
diff --git a/server/mirrormanager/templates/boringlocationhostform.kid
b/server/mirrormanager/templates/boringlocationhostform.kid
new file mode 100644
index 0000000..edc92f4
--- /dev/null
+++ b/server/mirrormanager/templates/boringlocationhostform.kid
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#"
+ py:extends="'master.kid'">
+<head>
+<meta content="text/html; charset=utf-8" http-equiv="Content-Type"
py:replace="''"/>
+<title>${page_title}</title>
+</head>
+<body>
+<p>
+Back to <a href="${tg.url('/location/' +
str(location.id))}"><span
+py:replace="location.name">Location Name</span></a>
+</p>
+
+${form(value=values, action=tg.url(action))}
+</body>
+</html>
commit 54f349bbf877900ac4fc116306bea0e8de0ab98a
Author: Matt Domsch <Matt_Domsch(a)dell.com>
Date: Mon Jan 17 00:21:31 2011 -0600
fix adminview locationhost deletion
diff --git a/server/mirrormanager/templates/adminview.kid
b/server/mirrormanager/templates/adminview.kid
index 12bc558..2669398 100644
--- a/server/mirrormanager/templates/adminview.kid
+++ b/server/mirrormanager/templates/adminview.kid
@@ -117,7 +117,7 @@ Nothing to see here, move along.
<UL>
<li py:for="h in l.hosts">
<a href="${tg.url('/host/' + str(h.id))}"><span
py:replace="h.name">Host name</span></a>
- <a href="${tg.url('/location/%s/%s/delete' %
(l.id,h.id))}">[Delete]</a>
+ <a href="${tg.url('/locationhost/%s/%s/delete' %
(l.id,h.id))}">[Delete]</a>
</li>
</UL>
</li>
commit 19ca12147629b74cad373498dd93afa67924d8c2
Author: Matt Domsch <Matt_Domsch(a)dell.com>
Date: Mon Jan 17 00:21:09 2011 -0600
add destroySelf() to Location
diff --git a/server/mirrormanager/model.py b/server/mirrormanager/model.py
index bd56890..1fe2b97 100644
--- a/server/mirrormanager/model.py
+++ b/server/mirrormanager/model.py
@@ -888,6 +888,12 @@ class Location(SQLObject):
name = UnicodeCol(alternateID=True, length=UnicodeColKeyLength)
hosts = SQLRelatedJoin('Host')
+ def destroySelf(self):
+ """Cascade the delete operation"""
+ for h in self.hosts:
+ self.removeHost(h)
+ SQLObject.destroySelf(self)
+
class FileGroup(SQLObject):
class sqlmeta:
cacheValues = False
commit eba044f5c865b849f0e19c456d038fd1d72eed40
Author: Matt Domsch <Matt_Domsch(a)dell.com>
Date: Mon Jan 17 00:20:32 2011 -0600
minor fixups to controllers, Location stuff untested
diff --git a/server/mirrormanager/controllers.py b/server/mirrormanager/controllers.py
index 2f432e7..b4e005b 100644
--- a/server/mirrormanager/controllers.py
+++ b/server/mirrormanager/controllers.py
@@ -170,14 +170,6 @@ class SiteController(controllers.Controller, identity.SecureResource,
content):
site.del_downstream_site(dsite)
raise turbogears.redirect("/site/%s" % site.id)
- @expose(format='json')
- def search(self, name):
- """Called by the LocationHost controller
AutoCompleteWidget."""
- if not name: return dict()
- results = Site.select(LIKE(Site.q.name, "%"+name+"%"))
- sites = [ s.name for s in results ]
- return dict(sites=sites)
-
##############################################
class SiteAdminFields(widgets.WidgetsList):
username =
widgets.TextField(validator=validators.All(validators.UnicodeString,validators.NotEmpty,
help_text="FAS username you wish to have be an admin for this site"))
@@ -309,7 +301,7 @@ class SiteToSiteController(controllers.Controller,
identity.SecureResource, cont
##############################################
class HostFields(widgets.WidgetsList):
name =
widgets.TextField(validator=validators.All(validators.UnicodeString,validators.NotEmpty),
attrs=dict(size='30'), label="Host Name",
- help_text="* Name of server as seen by a public end
user")
+ help_text="* FQDN of server as seen by a public end
user")
admin_active = widgets.CheckBox("admin_active", default=True,
help_text="Uncheck this box to temporarily disable this host, it will be removed from
public listings.")
user_active = widgets.CheckBox("user_active", default=True,
help_text="Uncheck this box to temporarily disable this host, it will be removed from
public listings.")
country =
widgets.TextField(validator=validators.All(validators.Regex(r'^[a-zA-Z][a-zA-Z]$'),validators.NotEmpty),
@@ -876,7 +868,7 @@ class CategoryFields(widgets.WidgetsList):
publiclist = widgets.CheckBox()
GeoDNSDomain = widgets.TextField(validator=validators.UnicodeString,
attrs=dict(size='30'))
-category_form = Widgets.TableForm(fields=CategoryFields(), submit_text="Create
Category")
+category_form = widgets.TableForm(fields=CategoryFields(), submit_text="Create
Category")
class CategoryController(SimpleDbObjectController):
page_title="Category"
@@ -905,6 +897,7 @@ class CategoryController(SimpleDbObjectController):
class ArchFields(widgets.WidgetsList):
name = widgets.TextField(validator=validators.UnicodeString,
attrs=dict(size='30'))
+ primaryArch = widgets.CheckBox(label="Primary Arch (not secondary)")
arch_form = widgets.TableForm(fields=ArchFields(), submit_text="Create Arch")
@@ -1140,45 +1133,54 @@ class LocationController(SimpleDbObjectController):
#########################################################
class LocationHostFields(widgets.WidgetsList):
locationName = widgets.Label(label="Location Name")
- siteName = widgets.AutoCompleteField(label="Site Name",
-
search_controller=tg.url('/site/search'),
- search_param='name',
result_name='sites',
- validator=validators.AutoCompleteValidator())
+ hostid =
widgets.TextField(validator=validators.Int, label="Host ID")
location_host_form = widgets.TableForm(fields=LocationHostFields(),
submit_text="Create Location / Host Mapping")
-class LocationHostController(SimpleDbObjectController):
- page_title = "Location / Host"
- myClass = Location
- url_prefix="locationhosts"
- form = location_host_form
-
- @expose(template="mirrormanager.templates.boringform")
- @validate(form=form)
- @error_handler(SimpleDbObjectController.new)
- def create(self, tg_errors=None, **kwargs):
- SimpleDbObjectController.create(self, tg_errors, **kwargs)
+class LocationHostController(controllers.Controller, identity.SecureResource, content):
+ require = identity.in_group(admin_group)
+
+ @expose(template="mirrormanager.templates.boringlocationhostform")
+ def new(self, locationid, **kwargs):
+ try:
+ location = Location.get(locationid)
+ except sqlobject.SQLObjectNotFound:
+ raise redirect("/adminview")
- @expose(template="mirrormanager.templates.boringform")
- @validate(form=form)
- @error_handler()
- def update(self, obj, tg_errors=None, **kwargs):
- return SimpleDbObjectController.update(self, obj, tg_errors, **kwargs)
+ submit_action = "/locationhost/create?locationid=%s" % locationid
+ return dict(form=location_host_form, values=None, action=submit_action,
page_title="New Location / Host", location=location)
+
+ @expose(template="mirrormanager.templates.boringlocationhostform")
+ @error_handler(new)
+ @validate(form=location_host_form)
+ def create(self, locationid, **kwargs):
+ try:
+ location = Location.get(locationid)
+ except sqlobject.SQLObjectNotFound:
+ turbogears.flash("Error: Location %s does not exist" % locationid)
+ raise redirect("/")
- @expose(template="mirrormanager.templates.boringdeleteform")
- def delete(self, obj, tg_errors=None, **kwargs):
- confirmed = kwargs.get('confirmed', None)
- confirm_delete_form = widgets.TableForm(fields=ConfirmDeleteFields(),
submit_text="Yes, really delete it!")
- if confirmed:
- turbogears.flash("%s has been deleted." % obj.name)
- obj.destroySelf()
- turbogears.redirect("/adminview")
- else:
- form = confirm_delete_form
- page_title = "Item Deletion"
- submit_action = "/%s/%s/delete?confirmed=1" % (self.url_prefix,
obj.id)
- return dict(form=form, values=obj, action=submit_action,
page_title=page_title)
+ try:
+ hostid = kwargs['hostid']
+ location.addHost(hostid)
+ except: # probably sqlite IntegrityError but we can't catch that for some
reason...
+ turbogears.flash("Error:LocationHost already exists")
+ turbogears.flash("Location/Host created.")
+ raise turbogears.redirect("/location/%s" % location.id)
+ @expose(template="mirrormanager.templates.boringlocationhostform")
+ def delete(self, locationid, hostid, **kwargs):
+ try:
+ location = Location.get(locationid)
+ except sqlobject.SQLObjectNotFound:
+ turbogears.flash("Error: Location %s does not exist" % locationid)
+ raise redirect("/")
+ try:
+ location.removeHost(hostid)
+ except:
+ turbogears.flash("Error: Location does not have Host %s" % hostid)
+
+ raise turbogears.redirect("/location/%s" % location.id)
class Root(controllers.RootController):