Esempio n. 1
0
    def delete_component(self, user, app, id, transaction=False):
        '''Delete specified component'''

        logger.info('delete component')
        try:
            component = Components.get(Components.build_id(id, app, 'nobody'))
        except:
            raise Exception('component \'%s\' not found' % id)

        # if it's a transaction, save component state before deletion in case of a rollback
        if transaction:
            self.components_deleted.append(copy.copy(component))

        if not component.delete():
            raise Exception('failed to delete component \'%s\'' % id)

        return True
Esempio n. 2
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
Esempio n. 3
0
    def update_component(self, json_data, user, app, id, transaction=False):
        '''Update specified component with attributes set in json_data'''

        logger.info('update component')
        try:
            component = Components.get(Components.build_id(id, app, 'nobody'))
        except:
            logger.exception(e)
            return self.create_component(json_data, user, app)

        # if it's a transaction, save component state before update in case of a rollback
        if transaction:
            #backup = Components(app, user, component.name)
            #backup.set_entity_fields(component.entity)
            backup = copy.copy(component)
            self.components_updated.append(backup)

        # update component members based on json data
        component.fromJsonable(json_data)
        if not component.passive_save(app):
            raise Exception('error updating component %s: %s' %
                            (id, component.errors[0]))
        else:
            return component
Esempio n. 4
0
    def list(self, action, **kwargs):
        '''Return list of saved components'''

        output = []
        user = cherrypy.session['user']['name']
        app = cherrypy.request.path_info.split('/')[3]

        components = Components.all()
        components = components.filter_by_app(app)

        logger.info("number of components found: %d" % len(components))

        for component in components:
            h = component.toJsonable()
            output.append(h)

        return self.render_json(output)