def applyChanges(self, data): changes = super(HostingCtlSettingsEditForm, self).applyChanges(data) if not 'node_name' in data or \ not 'chef_server_url' in data or \ not 'client_key' in data: logger.warning( "Unable to extract data from Hosting Settings form: \ unexpected field names") return changes node_name = data.get('node_name') chef_server_url = data.get('chef_server_url') client_key = data.get('client_key') prefix = data.get('prefix_filter') chef_tool = queryUtility(IChefTool) if chef_tool is not None: chef_tool.setup(node_name, chef_server_url, client_key, prefix) if chef_tool.authenticated: api.portal.show_message( _(u'Chef API authentication: SUCCESS'), request=self.request) else: api.portal.show_message( _(u'Chef API authentication: FAILURE'), request=self.request) else: logger.warning("Chef utility is not correctly registered") return changes
def update(self): super(AddDomainItemForm, self).update() if self._finishedAdd: self.request.response.redirect(self.nextURL()) if self.parent is None: self._valid = False api.portal.show_message( _(u"Databag item must be added to a specific parent databag"), request=self.request, type="error" )
def getContent(self): if self.parent and self.item_name: chef_tool = queryUtility(IChefTool) if chef_tool: data = chef_tool.get_dict_from_item(self.parent, self.item_name) if data: item_id = data.get("id") split_id = item_id.split("__") if len(split_id) == 2: data["subdomain"] = split_id[1] data["domain"] = split_id[0].replace("_", ".") return data self._valid = False api.portal.show_message(_(u"Databag item not found."), request=self.request, type="error") return {}
def breadcrumbs(self): add_blank = False crumbs = () base_url = self.context.absolute_url().rstrip('/') url = self.request.getURL() path = url.split('/') # we are in our main view if 'applications' in path: path_pos = path.index('applications') elif 'create-domain' in path: path_pos = path.index('create-domain') add_blank = True elif 'edit-domain' in path: path_pos = path.index('edit-domain') add_blank = True else: return crumbs base_url += '/applications' crumbs += ( {'absolute_url': base_url, 'Title': _(u'Applications')}, ) titles = path[path_pos + 1:] urls = ['/'.join(titles[:i + 1]) for i in range(len(titles))] urls = [base_url + '/' + end_url for end_url in urls] crumbs += tuple( {'absolute_url': abs_url, 'Title': title} for (abs_url, title) in zip(urls, titles) ) if add_blank: crumbs += ({'absolute_url': '', 'Title': ''},) return crumbs