Example #1
0
    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)
Example #2
0
    def get_uuid(self, action, count, **kwargs):

        count = int(count)
        if count > UUID_LIMIT:
            count = UUID_LIMIT
        response = []
        for i in range(count):
            response.append(util.uuid4())
        return self.render_json(response)
Example #3
0
    def get_uuid(self, action, count, **kwargs):

        count = int(count)
        if count > UUID_LIMIT:
            count = UUID_LIMIT
        response = []
        for i in range(count): 
            response.append(util.uuid4())
        return self.render_json(response)
    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/headlines_detail.html' % host_app,
                                             dict(app=app, headline=headline, alerts=alerts))
            else:
                headline.name = key
                return self.render_template('/%s:/templates/headlines_new.html' % host_app,
                                             dict(app=app, headline=headline, alerts=alerts))
        else:
            raise cherrypy.HTTPRedirect(self._redirect(host_app, app, 'success'), 303)
Example #5
0
    def create_component(self, json_data, user, app, transaction=False):
        '''Create new component using attributes set in json_data'''

        logger.info('create component')
        component = Components(app, user, uuid4())
        component.created_at = self.get_current_timestamp()

        # update component members based on json data
        component.fromJsonable(json_data)
        if not component.passive_save(app):
            raise Exception('error creating component %s: %s' %
                            (component.get_unique_key(), component.errors[0]))
        else:
            # if it's a transaction, save new component in case of a rollback
            if transaction:
                # NOTE: manually set id as create doesn't update model
                component.id = Components.build_id(component.name, app,
                                                   'nobody')
                self.components_created.append(component)
            return component
Example #6
0
 def createUUID(self):
     return util.uuid4()
Example #7
0
 def createUUID(self):
     return util.uuid4()