コード例 #1
0
ファイル: test_model_controller.py プロジェクト: esho/spire
    def _create_examples(self):
        examples = []
        for i, name in enumerate(self.NAMES.split(' ')):
            examples.append({'id': uniqid(), 'name': name, 'value': i})

        with self.interface.get_engine().begin() as connection:
            connection.execute(Example.__table__.insert(), *examples)
コード例 #2
0
ファイル: request.py プロジェクト: siq/flux
    def initiate(self, session, data):
        Request = self.docket_entity.bind('docket.entity/1.0/flux/1.0/request')
        id = uniqid()

        attrs = data['input']
        try:
            attrs = self.operation['schema'].unserialize(attrs)
        except ValidationError:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='invalid-input')

        wait_for_completion = attrs.pop('wait_for_completion', True)
        if wait_for_completion:
            SubscribedTask.queue_http_task('complete-request-operation',
                self.flux.prepare('flux/1.0/request', 'task', None,
                    {'task': 'complete-request-operation', 'request_id': id,
                        'process_id': data['id']}),
                topic='request:completed',
                aspects={'id': id},
                timeout=259200)

        attrs['id'] = id
        try:
            request = Request.create(**attrs)
        except Exception:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='failed')

        if wait_for_completion:
            return self.executing()
        else:
            outcome = ('created' if request.status in ('pending', 'prepared') else 'failed')
            return self.outcome(outcome, {
                'request': surrogate.construct('flux.surrogates.request', request),})
コード例 #3
0
ファイル: test_model_controller.py プロジェクト: esho/spire
    def _create_examples(self):
        examples = []
        for name, value in self.EXAMPLES:
            examples.append({'id': uniqid(), 'name': name, 'value': value})

        with self.interface.get_engine().begin() as connection:
            connection.execute(Example.__table__.insert(), *examples)
コード例 #4
0
    def _create_examples(self):
        examples = []
        for i, name in enumerate(self.NAMES.split(' ')):
            examples.append({'id': uniqid(), 'name': name, 'value': i})

        with self.interface.get_engine().begin() as connection:
            connection.execute(Example.__table__.insert(), *examples)
コード例 #5
0
    def _create_examples(self):
        examples = []
        for name, value in self.EXAMPLES:
            examples.append({'id': uniqid(), 'name': name, 'value': value})

        with self.interface.get_engine().begin() as connection:
            connection.execute(Example.__table__.insert(), *examples)
コード例 #6
0
ファイル: entity.py プロジェクト: siq-legacy/docket
    def create(cls, session, **attrs):
        subject = cls(**attrs)
        if not subject.id:
            subject.id = uniqid()

        if subject.created:
            subject.modified = subject.created
        else:
            subject.created = subject.modified = current_timestamp()

        cls._check_duplicate_name(session, subject)
        session.add(subject)
        return subject
コード例 #7
0
ファイル: entity.py プロジェクト: siq-legacy/docket
    def create(cls, session, **attrs):
        subject = cls(**attrs)
        if not subject.id:
            subject.id = uniqid()

        if subject.created:
            subject.modified = subject.created
        else:
            subject.created = subject.modified = current_timestamp()

        cls._check_duplicate_name(session, subject)
        session.add(subject)
        return subject
コード例 #8
0
    def _dispatch_request(self, request, response):
        directory = self.configuration['upload_directory']
        if request.method == 'GET':
            return
        elif request.method != 'POST':
            raise MethodNotAllowed()

        mapping = {}
        for name, uploaded_file in request.files.iteritems():
            filename = mapping[name] = '%s_%s' % (
                uniqid(), secure_filename(uploaded_file.filename))
            uploaded_file.save(os.path.join(directory, filename))

        response.mimetype = 'text/html'
        response.data = Json.serialize(mapping)
コード例 #9
0
    def _dispatch_request(self, request, response):
        directory = self.configuration['upload_directory']
        if request.method == 'GET':
            return
        elif request.method != 'POST':
            raise MethodNotAllowed()

        mapping = {}
        for name, uploaded_file in request.files.iteritems():
            filename = mapping[name] = '%s_%s' % (
                uniqid(), secure_filename(uploaded_file.filename))
            uploaded_file.save(os.path.join(directory, filename))

        response.mimetype = 'text/html'
        response.data = Json.serialize(mapping)
コード例 #10
0
ファイル: request.py プロジェクト: siq/flux
    def initiate(self, session, data):
        Request = self.docket_entity.bind('docket.entity/1.0/flux/1.0/request')
        id = uniqid()

        attrs = data['input']
        try:
            attrs = self.operation['schema'].unserialize(attrs)
        except ValidationError:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='invalid-input')

        wait_for_completion = attrs.pop('wait_for_completion', True)
        if wait_for_completion:
            SubscribedTask.queue_http_task(
                'complete-request-operation',
                self.flux.prepare(
                    'flux/1.0/request', 'task', None, {
                        'task': 'complete-request-operation',
                        'request_id': id,
                        'process_id': data['id']
                    }),
                topic='request:completed',
                aspects={'id': id},
                timeout=259200)

        attrs['id'] = id
        try:
            request = Request.create(**attrs)
        except Exception:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='failed')

        if wait_for_completion:
            return self.executing()
        else:
            outcome = ('created' if request.status in ('pending', 'prepared')
                       else 'failed')
            return self.outcome(
                outcome, {
                    'request':
                    surrogate.construct('flux.surrogates.request', request),
                })