def delete(self, id): firewall = Firewalls.first(id=id) msg = "The firewall could not be deleted." if firewall: if Firewalls.delete(firewall): msg = "Firewall deleted." cherrypy.session['flash'] = msg raise cherrypy.HTTPRedirect('/firewalls')
def add(self, **post): firewall = Firewalls.new(data="", name="") if post: fields = ['data', 'name'] data = self._get_data('firewall', fields, post) self._set_data(firewall, data) if Firewalls.add(firewall): cherrypy.session['flash'] = "Firewall successfully added" raise cherrypy.HTTPRedirect("/firewalls/index") cherrypy.session['flash'] = "The firewall data contains errors." firewalls = Firewalls.all() return self.render("/firewalls/add.html", crumbs=self.crumbs, firewall=firewall)
def view(self, id): firewall = Firewalls.first(id=id) if not firewall: cherrypy.session['flash'] = '404 Firewall Not Found' raise cherrypy.HTTPRedirect('/firewalls/index') env = dict( firewall=firewall, ) return self.render("/firewalls/view.html", crumbs=self.crumbs, **env)
def edit(self, id, **post): firewall = Firewalls.first(id=id) if not firewall: raise cherrypy.HTTPRedirect('/firewalls') if post: fields = ['data', 'name'] data = self._get_data('firewall', fields, post) firewall.update(data, fields) raise cherrypy.HTTPRedirect('/firewalls/view/%s' % id) env = dict( firewall=firewall, ) return self.render("/firewalls/edit.html", crumbs=self.crumbs, **env)
def GET(self): firewalls = Firewalls.all() return [f.to_dict() for f in firewalls]
def index(self): env = dict( firewalls=Firewalls.all() ) return self.render("/firewalls/index.html", crumbs=self.crumbs[:-1], **env)