def save(self, app, action, **params): ''' save the posted headline ''' user = cherrypy.session['user']['name'] host_app = cherrypy.request.path_info.split('/')[3] key = params.get('name') try: if key == '_new': headline = Headlines(app, user, uuid4()) else: headline = Headlines.get(Headlines.build_id(key, app, user)) except: headline = Headlines(app, user, uuid4()) headline.label = params.get('label') if not headline.label: headline.errors = ['label cannot be blank'] else: headline.message = params.get('message') headline.description = params.get('description') headline.alert_name = params.get('alert_name') headline.metadata.sharing = 'app' if headline.errors or not headline.passive_save(): logger.error('Error saving headline %s: %s' % (headline.name, headline.errors[0])) alerts = SavedSearch.all() alerts = alerts.filter_by_app(app) alerts = alerts.search('is_scheduled=True') if key != '_new': return self.render_template( '/%s:/templates/unixHeadlines/headlines_detail.html' % host_app, dict(host_app=host_app, app=app, headline=headline, alerts=alerts)) else: headline.name = key return self.render_template( '/%s:/templates/unixHeadlines/headlines_new.html' % host_app, dict(host_app=host_app, app=app, headline=headline, alerts=alerts)) else: raise cherrypy.HTTPRedirect( self._redirect(host_app, app, 'success'), 303)
def new(self, app, action, **kwargs): ''' render the _new template ''' user = cherrypy.session['user']['name'] host_app = cherrypy.request.path_info.split('/')[3] headline = Headlines(app, user, '_new') alerts = SavedSearch.all() alerts = alerts.filter_by_app(app) alerts = alerts.search('is_scheduled=True') return self.render_template('/%s:/templates/unixHeadlines/headlines_new.html' \ % host_app, dict(host_app=host_app, app=app, headline=headline, alerts=alerts))