def create(self, tg_errors=None, **kwargs):
        if not kwargs.has_key('siteid'):
            turbogears.flash("Error: form didn't provide siteid")
            raise redirect("/")
        siteid = kwargs['siteid']

        try:
            site = Site.get(siteid)
        except sqlobject.SQLObjectNotFound:
            turbogears.flash("Error: Site %s does not exist" % siteid)
            raise redirect("/")

        errordict = dict(form=site_to_site_form, values=None, action=submit_action, page_title="Create Site to Site", site=site)

        # handle the validation error
        if tg_errors:
            turbogears.flash("Error creating SiteToSite: %s" % (createErrorString(tg_errors)))
            return errordict


        siteadmin_check(site, identity)
        sites = kwargs['sites']
        username = kwargs.get('username')
        password = kwargs.get('password')
        for dssite in sites:
            if dssite == site.id:
                continue
            try:
                site2site = SiteToSite(upstream_site=site, downstream_site=dssite, username=username, password=password)
            except: 
                pass
        turbogears.flash("SiteToSite created.")
        raise turbogears.redirect("/site/%s" % siteid)
    def update(self, hostcategory, tg_errors=None, **kwargs):
        siteadmin_check(hostcategory.my_site(), identity)
        del kwargs['category']

        if tg_errors is not None:
            turbogears.flash("Error updating HostCategory: %s" % createErrorString(tg_errors))
            submit_action = "/host_category/%s/update" % hostcategory.id
            return dict(form=host_category_form_read, values=hostcategory, action=submit_action,
                        disabled_fields=self.disabled_fields(), host=hostcategory.host)
        
        
        hostcategory.set(**kwargs)
        hostcategory.sync()
        turbogears.flash("HostCategory Updated")
        raise turbogears.redirect("/")
    def update(self, site, tg_errors=None, **kwargs):
        siteadmin_check(site, identity)

        if tg_errors is not None:
            submit_action = "/site/%s/update" % site.id
            turbogears.flash("Error updating Site: %s" % createErrorString(tg_errors))
            return dict(form=site_form, values=site, action=submit_action,
                        disabled_fields=self.disabled_fields())

        if not identity.in_group(admin_group) and kwargs.has_key('admin_active'):
            del kwargs['admin_active']
        site.set(**kwargs)
        site.sync()
        turbogears.flash("Site Updated")
        raise turbogears.redirect("/site/%s" % site.id)
    def update(self, host, tg_errors=None, **kwargs):
        siteadmin_check(host.my_site(), identity)

        if tg_errors is not None:
            submit_action = "/host/%s/update" % host.id
            turbogears.flash("Error updating Host: %s" % createErrorString(tg_errors))
            return dict(form=host_form, values=host, action=submit_action,
                        disabled_fields=self.disabled_fields(host=host), page_title="Host", site=host.site)


        if not identity.in_group(admin_group) and kwargs.has_key('admin_active'):
            del kwargs['admin_active']

        host.set(**kwargs)
        host.sync()
        turbogears.flash("Host Updated")
        raise turbogears.redirect("/host/%s" % host.id)
    def create(self, tg_errors=None, **kwargs):
        if not identity.in_group(admin_group) and kwargs.has_key('admin_active'):
            del kwargs['admin_active']
        kwargs['createdBy'] = identity.current.user_name

        if tg_errors is not None:
            turbogears.flash("Error creating Site: %s" % createErrorString(tg_errors))
            raise turbogears.redirect("/site/0/create")

        try:
            site = Site(**kwargs)
            SiteAdmin(site=site, username=identity.current.user_name)
        except: # probably sqlite IntegrityError but we can't catch that for some reason... 
            turbogears.flash("Error:Site %s already exists" % kwargs['name'])
            raise turbogears.redirect("/site/0/create")
        else:
            turbogears.flash("Site created.")
            raise turbogears.redirect("/site/%s" % site.id)
    def create(self, siteid=None, tg_errors=None, **kwargs):
        if not identity.in_group(admin_group) and kwargs.has_key('admin_active'):
            del kwargs['admin_active']
        site = Site.get(siteid)
        submit_action = "/host/0/create?siteid=%s" % site.id
        errordict = dict(form=host_form, values=None, action=submit_action, disabled_fields=self.disabled_fields(),
                         page_title="Create Host", site=site)

        # handle the validation error
        if tg_errors:
            turbogears.flash("Error creating Host: %s" % (createErrorString(tg_errors)))
            return errordict

        try:
            host = Host(site=site, **kwargs)
        except: # probably sqlite IntegrityError but we can't catch that for some reason... 
            turbogears.flash("Error:Host %s already exists" % kwargs['name'])
            return errordict
        
        
        turbogears.flash("Host created.")
        raise turbogears.redirect("/host/%s" % host.id)
 def register(self, username="", display_name="", email_address="", tg_errors=None):
     if tg_errors:
         turbogears.flash(createErrorString(tg_errors))
         username, display_name, email_address = map(cherrypy.request.input_values.get, ["username", "display_name", "email_address"])
                 
     return dict(username=username, display_name=display_name, email_address=email_address)