Example #1
0
    def create(self, validated_data):
        item = super(ItemSerializer, self).create(validated_data)

        if item.schema is None:
            sample = item.owner_sample
            project = sample.spider.project
            schema_names = map(attrgetter('name'), project.schemas)
            schema_name = unique_name(sample.name,
                                      schema_names,
                                      initial_suffix=1)
            schema = Schema(self.storage,
                            id=AUTO_PK,
                            name=schema_name,
                            project=project,
                            auto_created=True)
            schema.items.add(item)
            schema.save()

        if item.parent and item.name is None:
            sample = item.owner_sample
            item_names = map(attrgetter('name'), sample.ordered_items)
            item.name = unique_name('subitem', item_names, initial_suffix=1)
            item.save(only=('name', ))

        return item
Example #2
0
    def create(self, validated_data):
        item = super(ItemSerializer, self).create(validated_data)

        if item.schema is None:
            sample = item.owner_sample
            project = sample.spider.project
            schema_names = map(attrgetter('name'), project.schemas)
            schema_name = unique_name(sample.name, schema_names,
                                      initial_suffix=1)
            schema = Schema(self.storage, id=AUTO_PK, name=schema_name,
                            project=project, auto_created=True)
            schema.items.add(item)
            schema.save()

        if item.parent and item.name is None:
            sample = item.owner_sample
            item_names = map(attrgetter('name'), sample.ordered_items)
            item.name = unique_name('subitem', item_names, initial_suffix=1)
            item.save(only=('name',))

        return item
Example #3
0
    def create(self, validated_data):
        sample = super(SampleSerializer, self).create(validated_data)

        project = sample.spider.project
        schema_names = map(attrgetter('name'), project.schemas)
        schema_name = unique_name(sample.name, schema_names)
        schema = Schema(self.storage, id=AUTO_PK, name=schema_name,
                        project=project, auto_created=True)
        schema.save()

        item = Item(self.storage, id=AUTO_PK, sample=sample, schema=schema)
        item.save()

        return sample
Example #4
0
    def create(self, validated_data):
        sample = super(SampleSerializer, self).create(validated_data)

        project = sample.spider.project
        schema_names = map(attrgetter('name'), project.schemas)
        schema_name = unique_name(sample.name, schema_names)
        schema = Schema(self.storage,
                        id=AUTO_PK,
                        name=schema_name,
                        project=project,
                        auto_created=True)
        schema.save()

        item = Item(self.storage, id=AUTO_PK, sample=sample, schema=schema)
        item.save()

        return sample
Example #5
0
    def create(self, validated_data):
        annotation = super(AnnotationSerializer, self).create(validated_data)

        if annotation.field is None:
            project = annotation.owner_sample.spider.project
            project.schemas  # preload schemas and fields
            item = annotation.parent
            schema = item.schema
            field_names = map(attrgetter('name'), schema.fields)
            field_name = unique_name('field', field_names, initial_suffix=1)
            field = Field(self.storage, id=AUTO_PK, name=field_name,
                          type=choose_field_type(annotation), schema=schema,
                          auto_created=True)
            field.annotations.add(annotation)
            field.save()

        return annotation
Example #6
0
    def create(self, validated_data):
        annotation = super(AnnotationSerializer, self).create(validated_data)

        if annotation.field is None:
            project = annotation.owner_sample.spider.project
            project.schemas  # preload schemas and fields
            item = annotation.parent
            schema = item.schema
            field_names = map(attrgetter('name'), schema.fields)
            field_name = unique_name('field', field_names, initial_suffix=1)
            field = Field(self.storage,
                          id=AUTO_PK,
                          name=field_name,
                          schema=schema,
                          auto_created=True)
            field.annotations.add(annotation)
            field.save()

        return annotation