Example #1
0
class DatasetApiAttrs(ObjectAttrs):
    title = TranslatedStr()
    slug = TranslatedStr()
    notes = TranslatedStr()
    category = fields.Nested(DatasetCategoryAttr, many=False)
    formats = fields.List(fields.String)
    tags = TranslatedTagsList(TranslatedStr(), attr='tags_list')
    openness_scores = fields.List(fields.Int())
    license_condition_db_or_copyrighted = fields.String()
    license_condition_modification = fields.Boolean()
    license_condition_original = fields.Boolean()
    license_condition_responsibilities = fields.String()
    license_condition_source = fields.Boolean()
    license_condition_timestamp = fields.Boolean()
    license_name = fields.String()
    license_description = fields.String()
    update_frequency = TransUpdateFreqField()
    views_count = fields.Integer()
    url = fields.String()
    followed = fields.Boolean()
    modified = fields.DateTime()
    resource_modified = fields.DateTime()
    created = fields.DateTime()
    verified = fields.DateTime()

    class Meta:
        relationships_schema = DatasetApiRelationships
        object_type = 'dataset'
        url_template = '{api_url}/datasets/{ident}'
Example #2
0
class Category(ExtSchema):
    id = fields.String()
    name = TranslatedStr()
    title = TranslatedStr()
    description = TranslatedStr()
    image_url = fields.String()
    code = fields.String()
Example #3
0
class InstitutionApiAttrs(ObjectAttrs):
    slug = TranslatedStr()
    title = TranslatedStr()
    description = TranslatedStr()
    image_url = fields.Str()
    postal_code = fields.Str()
    city = fields.Str()
    street_type = fields.Str()
    street = fields.Str()
    street_number = fields.Str()
    flat_number = fields.Str()
    email = fields.Str()
    epuap = fields.Str()
    fax = fields.Str(attribute='fax_display')
    tel = fields.Str(attribute='phone_display')
    regon = fields.Str()
    website = fields.Str()
    institution_type = fields.Str()
    followed = fields.Boolean()
    modified = fields.Str()
    created = fields.Str()

    class Meta:
        relationships_schema = InstitutionApiRelationships
        object_type = 'institution'
        url_template = '{api_url}/institutions/{ident}'
Example #4
0
class InstitutionsSerializer(BasicSerializer):
    id = ma.fields.Int()
    slug = TranslatedStr()
    title = TranslatedStr()
    description = TranslatedStr()
    image_url = ma.fields.Str()
    postal_code = ma.fields.Str()
    city = ma.fields.Str()
    street_type = ma.fields.Str()
    street = ma.fields.Str()
    street_number = ma.fields.Str()
    flat_number = ma.fields.Str()
    email = ma.fields.Str()
    epuap = ma.fields.Str()
    fax = ma.fields.Str(attribute='fax_display')
    tel = ma.fields.Str(attribute='phone_display')
    regon = ma.fields.Str()
    website = ma.fields.Str()
    institution_type = ma.fields.Str()
    datasets = OldRelationship(
        related_url='/institutions/{inst_id}/datasets',
        related_url_kwargs={'inst_id': '<id>'},
        schema=DatasetSchema,
        many=True,
        type_='dataset'
    )
    followed = ma.fields.Boolean()
    modified = ma.fields.Str()
    created = ma.fields.Str()

    class Meta:
        type_ = "institutions"
        self_url_many = "/institutions"
        self_url = '/institutions/{inst_id}'
        self_url_kwargs = {"inst_id": "<id>"}
Example #5
0
class ArticlesSerializer(BasicSerializer):
    id = ma.fields.Int(dump_only=True)
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    author = ma.fields.Str()
    datasets = OldRelationship(
        related_url='/articles/{article_id},{article_slug}/datasets',
        related_url_kwargs={'article_id': '<id>', 'article_slug': '<slug>'},
        schema=DatasetSchema,
        many=True,
        type_='dataset'
    )
    tags = TranslatedTagsList(ma.fields.String)
    views_count = ma.fields.Integer()
    followed = ma.fields.Boolean()

    modified = ma.fields.Str()
    created = ma.fields.Str()
    license = ma.fields.Nested(ArticleLicense, many=False)
    category = ma.fields.Nested(ArticleCategory, many=False)

    class Meta:
        type_ = "articles"
        self_url_many = "/articles"
        self_url = '/articles/{article_id},{article_slug}'
        self_url_kwargs = {"article_id": "<id>", "article_slug": "<slug>"}
Example #6
0
class ResourceSchema(ja.Schema):
    id = ma.fields.Int(dump_only=True)
    uuid = ma.fields.Str()
    title = TranslatedStr()
    description = TranslatedStr()
    category = ma.fields.Str()
    format = ma.fields.Str()
    type = ma.fields.Str()
    downloads_count = ma.fields.Integer()
    openness_score = ma.fields.Integer()
    views_count = ma.fields.Integer()
    modified = ma.fields.Str()
    created = ma.fields.Str()
    verified = ma.fields.Str()
    data_date = ma.fields.Date()
    file_url = ma.fields.Str()
    download_url = ma.fields.Str()
    link = ma.fields.Str()
    file_size = ma.fields.Integer()

    class Meta:
        type_ = 'resource'
        strict = True
        self_url_many = "/resources"
        self_url = '/resources/{resource_id}'
        self_url_kwargs = {"resource_id": "<id>"}
Example #7
0
class ApplicationsSerializer(BasicSerializer):
    id = ma.fields.Int(dump_only=True, faker_type='integer')
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    author = ma.fields.Str(faker_type='firstname')
    url = ma.fields.Str(faker_type='url')
    image_url = ma.fields.Str(faker_type='image_url')
    image_thumb_url = ma.fields.Str(faker_type='image_thumb_url')
    datasets = OldRelationship(
        related_url='/applications/{app_id},{app_slug}/datasets',
        related_url_kwargs={
            'app_id': '<id>',
            'app_slug': f'<slug>'
        },
        many=True,
        type_='dataset',
        faker_count=10,
        faker_schema=DatasetSchema)
    followed = ma.fields.Boolean(faker_type='boolean')
    tags = TranslatedTagsList(TranslatedStr(), faker_type='tagslist')
    views_count = ma.fields.Integer(faker_type='integer')
    modified = ma.fields.Str(faker_type='datetime')
    created = ma.fields.Str(faker_type='datetime')

    class Meta:
        type_ = "applications"
        self_url_many = "/applications"
        self_url = '/applications/{app_id},{app_slug}'
        self_url_kwargs = {"app_id": "<id>", "app_slug": f"<slug>"}
Example #8
0
class ResourceApiAttrs(ObjectAttrs, HighlightObjectMixin):
    title = TranslatedStr()
    description = TranslatedStr()
    category = fields.Str()
    format = fields.Str()
    media_type = fields.Str(
        attribute='type'
    )  # https://jsonapi.org/format/#document-resource-object-fields
    visualization_types = ListWithoutNoneStrElement(fields.Str())
    downloads_count =\
        fields.Function(
            lambda obj: obj.computed_downloads_count if is_enabled('S16_new_date_counters.be') else obj.downloads_count)
    openness_score = fields.Integer()
    views_count =\
        fields.Function(
            lambda obj: obj.computed_views_count if is_enabled('S16_new_date_counters.be') else obj.views_count)
    modified = fields.DateTime()
    created = fields.DateTime()
    verified = fields.DateTime()
    data_date = fields.Date()
    file_url = fields.Str()
    file_size = fields.Integer()
    csv_file_url = fields.Str()
    csv_file_size = fields.Integer()
    jsonld_file_url = fields.Str()
    jsonld_file_size = fields.Integer()
    jsonld_download_url = fields.Str()
    download_url = fields.Str()
    csv_download_url = fields.Str()
    link = fields.Str()
    data_special_signs = fields.Nested(SpecialSignSchema,
                                       data_key='special_signs',
                                       many=True)
    is_chart_creation_blocked = fields.Bool()
    if is_enabled('S35_high_value_data.be'):
        has_high_value_data = fields.Boolean()
    if is_enabled('S37_resources_admin_region_data.be'):
        regions = fields.Method('get_regions')
    if is_enabled('S40_new_file_model.be'):
        files = fields.Method('get_files')

    class Meta:
        relationships_schema = ResourceApiRelationships
        object_type = 'resource'
        api_path = 'resources'
        url_template = '{api_url}/resources/{ident}'
        model = 'resources.Resource'

    def get_regions(self, res):
        return RegionSchema(many=True).dump(
            getattr(res, 'all_regions', res.regions))

    def get_files(self, res):
        return ResourceFileSchema(many=True).dump(
            getattr(res, 'all_files', res.files))
class LaboratoryApiAttrs(ObjectAttrs):
    title = TranslatedStr()
    notes = TranslatedStr()
    event_type = fields.String()
    execution_date = fields.Date()
    reports = fields.Nested(ReportSchema, many=True)

    class Meta:
        object_type = 'Laboratory'
        url_template = '{api_url}/laboratories/{ident}'
        model = 'laboratory.LabEvent'
Example #10
0
class DatasetInstitution(ja.Schema):
    id = ma.fields.Int()
    title = TranslatedStr()
    slug = TranslatedStr()

    class Meta:
        type_ = 'institution'
        strict = True
        self_url = '/institutions/{institution_id}'
        self_url_kwargs = {"institution_id": "<id>",
                           "institution_slug": "<slug>"}
Example #11
0
class DatasetXMLSerializer(ExtSchema):
    id = fields.Integer()
    url = fields.Url(attribute='frontend_absolute_url')
    title = TranslatedStr()
    notes = TranslatedStr()
    keywords = fields.Function(lambda dataset: (
        tag.name for tag in getattr(dataset, f'tags_{get_language()}')))
    categories = fields.Nested(DatasetCategoryAttr, many=True)
    update_frequency = TransUpdateFreqField()
    created = fields.DateTime()
    verified = fields.DateTime()
    views_count = fields.Int(attribute='computed_views_count')
    downloads_count = fields.Int(attribute='computed_downloads_count')
    published_resources_count = fields.Int(
        attribute='published_resources__count')
    license = fields.Str(attribute='license_name')
    conditions = fields.Method('get_conditions')
    organization = fields.Method('get_organization')
    resources = fields.Method('get_resources')

    source = fields.Nested(SourceXMLSchema)

    def get_conditions(self, dataset):
        conditions = _(
            'This dataset is public information, it can be reused under the following conditions: '
        )
        terms = [
            str(
                dataset._meta.get_field(
                    'license_condition_modification').verbose_name)
            if dataset.license_condition_modification else '',
            str(
                dataset._meta.get_field('license_condition_source').
                verbose_name) if dataset.license_condition_source else '',
            dataset.license_condition_db_or_copyrighted,
            dataset.license_condition_personal_data
        ]
        return conditions + '\n'.join([term for term in terms if term])

    def get_organization(self, dataset):
        context = {
            'published_datasets_count':
            dataset.organization_published_datasets__count,
            'published_resources_count':
            dataset.organization_published_resources__count,
        }
        return InstitutionXMLSerializer(many=False, context=context).dump(
            dataset.organization)

    def get_resources(self, dataset):
        return ResourceXMLSerializer(many=True).dump(
            dataset.published_resources)
Example #12
0
class ResourceCSVMetadataSerializer(schemas.ExtSchema):
    frontend_absolute_url = fields.Url(data_key=_('Resource URL'))
    title = TranslatedStr(data_key=_('Resource title'), default='')
    description = TranslatedStr(data_key=_('Resource description'))
    created = fields.DateTime(data_key=_('Resource created'), format='iso8601')
    data_date = fields.Date(data_key=_('Data date'))
    openness_score = fields.Int(data_key=_('Openness score'))
    resource_type = fields.Function(lambda obj: obj.get_type_display(),
                                    data_key=_('Type'))
    format = fields.Str(data_key=_('File format'), default='')
    file_size = fields.Function(lambda obj: sizeof_fmt(obj.file_size)
                                if obj.file_size else '',
                                data_key=_('File size'))
    views_count = fields.Int(attribute='computed_views_count',
                             data_key=_("Resource views count"))
    downloads_count = fields.Int(attribute='computed_downloads_count',
                                 data_key=_("Resource downloads count"))
    has_table = fields.Function(lambda obj: _('YES')
                                if obj.has_table else _('NO'),
                                data_key=_('Table'))
    has_chart = fields.Function(lambda obj: _('YES')
                                if obj.has_chart else _('NO'),
                                data_key=_('Map'))
    has_map = fields.Function(lambda obj: _('YES') if obj.has_map else _('NO'),
                              data_key=_('Chart'))
    download_url = fields.Url(data_key=_('Download URL'))
    data_special_signs = fields.Nested(SpecialSignSchema,
                                       data_key=_('special signs'),
                                       many=True)

    @ma.post_dump(pass_many=False)
    def prepare_nested_data(self, data, **kwargs):
        special_signs = data.get(_('special signs'))
        signs_str = '\n'.join([
            '{name_label}: {name}, {symbol_label}: "{symbol}", {desc_label}: {desc}'
            .format(name=sign['name'],
                    name_label=_('name'),
                    symbol=sign['symbol'],
                    symbol_label=_('symbol'),
                    desc=sign['description'],
                    desc_label=_('description')) for sign in special_signs
        ])
        data[_('special signs')] = signs_str
        values_with_html = [_('Resource title'), _('Resource description')]
        for attribute in values_with_html:
            data[attribute] = strip_tags(data[attribute])
        return data

    class Meta:
        ordered = True
class InstitutionCSVMetadataSerializer(ExtSchema):
    organization_url = fields.Url(attribute='frontend_absolute_url',
                                  data_key=_('Organization URL'))
    organization_type = fields.Function(
        lambda obj: obj.get_institution_type_display(),
        data_key=_('Institution type'))
    organization_title = TranslatedStr(attribute='title', data_key=_('Name'))
    organization_abbr_title = TranslatedStr(attribute='abbreviation',
                                            data_key=_('Abbreviation'),
                                            default='')
    organization_regon = fields.Str(data_key=_('REGON'), attribute='regon')
    organization_epuap = fields.Str(attribute='epuap',
                                    data_key=_('EPUAP'),
                                    default='')
    organization_website = fields.Url(attribute='website',
                                      data_key=_('Website'))
    organization_created = fields.DateTime(attribute='created',
                                           data_key=_('Organization created'),
                                           format='iso8601')
    organization_modified = fields.DateTime(
        attribute='modified',
        data_key=_('Organization modified'),
        format='iso8601')
    organization_datasets_count = fields.Method(
        'get_published_datasets_count', data_key=_('Number of datasets'))
    organization_resources_count = fields.Method(
        'get_published_resources_count',
        data_key=_('Number of organization resources'))
    organization_postal_code = fields.Str(attribute='postal_code',
                                          data_key=_('Postal code'))
    organization_city = fields.Str(attribute='city', data_key=_('City'))
    organization_street_type = fields.Str(attribute='street_type',
                                          data_key=_('Street type'))
    organization_street = fields.Str(attribute='street', data_key=_('Street'))
    organization_street_number = fields.Str(attribute='street_number',
                                            data_key=_('Street number'))
    organization_flat_number = fields.Str(attribute='flat_number',
                                          data_key=_('Flat number'))
    organization_email = fields.Email(attribute='email', data_key=_('Email'))
    organization_phone_number = fields.Str(attribute='tel',
                                           data_key=_('Phone'))

    class Meta:
        ordered = True

    def get_published_datasets_count(self, organization):
        return self.context['published_datasets_count']

    def get_published_resources_count(self, organization):
        return self.context['published_resources_count']
class InstitutionXMLSerializer(ExtSchema):
    id = fields.Integer()
    url = fields.Url(attribute='frontend_absolute_url')
    type = fields.Function(
        lambda organization: organization.get_institution_type_display())
    title = TranslatedStr()
    abbreviation = fields.Str()
    epuap = fields.Str()
    website = fields.Url()
    created = fields.DateTime(format='iso8601')
    modified = fields.DateTime(format='iso8601')

    postal_code = fields.Str()
    city = fields.Str()
    street = fields.Str()
    street_number = fields.Str()
    street_type = fields.Str()
    flat_number = fields.Str()

    email = fields.Str()
    tel = fields.Str(data_key='phone_number')

    regon = fields.Str()

    published_datasets_count = fields.Method('get_published_datasets_count')
    published_resources_count = fields.Method('get_published_resources_count')

    def get_published_datasets_count(self, organization):
        return self.context['published_datasets_count']

    def get_published_resources_count(self, organization):
        return self.context['published_resources_count']
Example #15
0
class DatasetApiAttrs(ObjectAttrs, HighlightObjectMixin):
    title = TranslatedStr()
    slug = TranslatedStr()
    notes = TranslatedStr()
    categories = fields.Nested(DatasetCategoryAttr, many=True)
    category = fields.Nested(DatasetCategoryAttr, many=False)
    formats = fields.List(fields.String())
    types = fields.List(fields.String())
    keywords = KeywordsList(TranslatedStr())
    openness_scores = fields.List(fields.Int())
    license_chosen = fields.Integer()
    license_condition_db_or_copyrighted = fields.String()
    license_condition_personal_data = fields.String()
    license_condition_modification = fields.Boolean()
    license_condition_original = fields.Boolean()
    license_condition_responsibilities = fields.String()
    license_condition_source = fields.Boolean()
    license_condition_timestamp = fields.Boolean()
    license_name = fields.String()
    license_description = fields.String()
    update_frequency = TransUpdateFreqField()
    views_count =\
        fields.Function(
            lambda obj: obj.computed_views_count if is_enabled('S16_new_date_counters.be') else obj.views_count)
    downloads_count =\
        fields.Function(
            lambda obj: obj.computed_downloads_count if is_enabled('S16_new_date_counters.be') else obj.downloads_count)
    url = fields.String()
    followed = fields.Boolean()
    modified = fields.DateTime()
    resource_modified = fields.DateTime()
    created = fields.DateTime()
    verified = fields.DateTime()
    visualization_types = ListWithoutNoneStrElement(fields.Str())
    source = fields.Nested(SourceSchema)
    image_url = fields.Str()
    image_alt = TranslatedStr()
    if is_enabled('S35_high_value_data.be'):
        has_high_value_data = fields.Boolean()
    if is_enabled('S37_resources_admin_region_data.be'):
        regions = fields.Nested(RegionSchema, many=True)

    class Meta:
        relationships_schema = DatasetApiRelationships
        object_type = 'dataset'
        url_template = '{api_url}/datasets/{ident}'
        model = 'datasets.Dataset'
class GuideItemApiAttrs(ObjectAttrs):
    title = TranslatedStr(data_key='name')
    content = TranslatedStr()
    route = fields.Str()
    css_selector = fields.Str()
    position = fields.Str()
    order = fields.Int()
    is_optional = fields.Bool()
    is_clickable = fields.Bool()
    is_expandable = fields.Bool()

    class Meta:
        relationships_schema = GuideItemApiRelationships
        object_type = 'item'
        url_template = '{api_url}/guides/{ident}'
        ordered = True
        model = 'guides.GuideItem'
class GuideApiAttrs(ObjectAttrs):
    title = TranslatedStr(data_key='name')

    class Meta:
        relationships_schema = GuideApiRelationships
        object_type = 'guide'
        url_template = '{api_url}/guides/{ident}'
        ordered = True
        model = 'guides.Guide'
Example #18
0
class ApplicationApiAttrs(ObjectAttrs):
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    author = fields.Str(faker_type='firstname')
    url = fields.Str(faker_type='url')
    image_url = fields.Str(faker_type='image_url')
    image_thumb_url = fields.Str(faker_type='image_thumb_url')
    followed = fields.Boolean(faker_type='boolean')
    tags = TranslatedTagsList(TranslatedStr(), faker_type='tagslist')
    views_count = fields.Integer(faker_type='integer')
    modified = fields.Str(faker_type='datetime')
    created = fields.Str(faker_type='datetime')

    class Meta:
        relationships_schema = ApplicationApiRelationships
        object_type = 'application'
        url_template = '{api_url}/applications/{ident}'
class ArticleApiAttrs(ObjectAttrs, HighlightObjectMixin):
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    author = fields.Str(faker_type='firstname')
    keywords = KeywordsList(TranslatedStr(), faker_type='tagslist')
    views_count = fields.Integer(faker_type='integer')
    followed = fields.Boolean()
    modified = fields.Str(faker_type='datetime')
    created = fields.Str(faker_type='datetime')
    license = fields.Nested(ArticleLicense, many=False)
    category = fields.Nested(ArticleCategory, many=False)

    class Meta:
        relationships_schema = ArticleApiRelationships
        object_type = 'article'
        url_template = '{api_url}/articles/{ident}'
        model = 'articles.Article'
Example #20
0
class DatasetCategoryAttr(ExtSchema):
    id = fields.Str()
    title = TranslatedStr()
    code = fields.Str()

    @ma.pre_dump(pass_many=True)
    def prepare_data(self, data, many, **kwargs):
        if isinstance(data, Manager):
            data = data.all()
        return data
Example #21
0
class ResourceXMLSerializer(schemas.ExtSchema):
    id = fields.Integer()
    access_url = fields.Url(attribute='frontend_absolute_url')
    title = TranslatedStr()
    description = TranslatedStr()
    openness_score = fields.Integer()
    format = fields.Str()
    views_count = fields.Int(attribute='computed_views_count')
    downloads_count = fields.Int(attribute='computed_downloads_count')
    created = fields.DateTime(format='iso8601')
    data_date = fields.Date()
    type = fields.Function(lambda resource: resource.get_type_display())
    file_size = fields.Function(lambda obj: sizeof_fmt(obj.file_size)
                                if obj.file_size else '')

    visualization_types = ListWithoutNoneStrElement(fields.Str())
    download_url = fields.Str()
    data_special_signs = fields.Nested(SpecialSignSchema,
                                       data_key='special_signs',
                                       many=True)
Example #22
0
class ApplicationApiAttrs(ObjectAttrs, HighlightObjectMixin):
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    author = fields.Str(faker_type='firstname')
    url = fields.Str(faker_type='url')
    image_url = fields.Str(faker_type='image_url')
    image_thumb_url = fields.Str(faker_type='image_thumb_url')
    image_alt = TranslatedStr()
    illustrative_graphics_url = fields.Str()
    illustrative_graphics_alt = TranslatedStr()
    followed = fields.Boolean(faker_type='boolean')
    keywords = KeywordsList(TranslatedStr(), faker_type='tagslist')
    views_count = fields.Integer(faker_type='integer')
    modified = fields.Str(faker_type='datetime')
    created = fields.Str(faker_type='datetime')
    has_image_thumb = fields.Bool()
    main_page_position = fields.Int()
    external_datasets = fields.Nested(ExternalDataset, many=True)

    class Meta:
        relationships_schema = ApplicationApiRelationships
        object_type = 'application'
        url_template = '{api_url}/applications/{ident}'
        model = 'applications.Application'
Example #23
0
class DatasetSchema(ja.Schema):
    id = ma.fields.Int(dump_only=True, faker_type='integer')
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    formats = ma.fields.List(ma.fields.Str(), attr='formats')
    category = ma.fields.Nested(DatasetCategory, many=False)
    downloads_count = ma.fields.Integer()
    tags = TranslatedTagsList(TranslatedStr(), attr='tags_list')
    openness_scores = ma.fields.List(ma.fields.Int())
    license_condition_db_or_copyrighted = ma.fields.String()
    license_condition_modification = ma.fields.Boolean()
    license_condition_original = ma.fields.Boolean()
    license_condition_responsibilities = ma.fields.String()
    license_condition_source = ma.fields.Boolean()
    license_condition_timestamp = ma.fields.Boolean()
    license_name = ma.fields.String()
    license_description = ma.fields.String()
    update_frequency = ma.fields.Method('update_frequency_translated')
    views_count = ma.fields.Integer()
    url = ma.fields.String()
    modified = ma.fields.Str('last_modified_resource_date')
    created = ma.fields.Str()
    verified = ma.fields.Str()

    def last_modified_resource_date(self, obj):
        return str(obj.last_modified_resource) if obj.last_modified_resource else None

    def update_frequency_translated(self, obj):
        if obj.update_frequency and obj.update_frequency in UPDATE_FREQUENCY:
            return _(UPDATE_FREQUENCY[obj.update_frequency])
        return None

    class Meta:
        type_ = 'dataset'
        strict = True
        self_url_many = "/datasets"
        self_url = '/datasets/{dataset_id},{dataset_slug}'
        self_url_kwargs = {"dataset_id": "<id>", "dataset_slug": "<slug>"}
Example #24
0
class ResourceApiAttrs(ObjectAttrs):
    title = TranslatedStr()
    description = TranslatedStr()
    category = fields.Str()
    format = fields.Str()
    media_type = fields.Str()
    downloads_count = fields.Integer()
    openness_score = fields.Integer()
    views_count = fields.Integer()
    modified = fields.DateTime()
    created = fields.DateTime()
    verified = fields.DateTime()
    data_date = fields.Date()
    file_url = fields.Str()
    download_url = fields.Str()
    link = fields.Str()
    file_size = fields.Integer()

    class Meta:
        relationships_schema = ResourceApiRelationships
        object_type = 'resource'
        api_path = 'resources'
        url_template = '{api_url}/resources/{ident}'
class InstitutionApiAttrs(ObjectAttrs, HighlightObjectMixin):
    abbreviation = fields.Str()
    city = fields.Str()
    created = fields.Str()
    datasets_count = fields.Int(attribute='published_datasets_count')
    email = fields.Str()
    epuap = fields.Str()
    fax = fields.Str()
    flat_number = fields.Str()
    followed = fields.Boolean()
    image_url = fields.Str()
    institution_type = fields.Str()
    modified = fields.Str()
    description = TranslatedStr()
    postal_code = fields.Str()
    regon = fields.Str()
    resources_count = fields.Int(attribute='published_resources_count')
    slug = TranslatedStr()
    sources = fields.Nested(DataSourceAttr, many=True)
    street = fields.Str()
    street_number = fields.Str()
    street_type = fields.Str()
    tel = fields.Str()
    title = TranslatedStr()
    website = fields.Str()

    class Meta:
        relationships_schema = InstitutionApiRelationships
        object_type = 'institution'
        url_template = '{api_url}/institutions/{ident}'
        model = 'organizations.Organization'

    @post_dump(pass_many=False)
    def prepare_notes(self, data, **kwargs):
        data["notes"] = data.get("description")
        return data
Example #26
0
class ShowcaseApiAttrs(ObjectAttrs, HighlightObjectMixin):
    category = fields.Str()
    category_name = fields.Method('get_category_name')
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    author = fields.Str(faker_type='firstname')
    url = fields.Str(faker_type='url')
    image_url = fields.Str(faker_type='image_url')
    image_thumb_url = fields.Str(faker_type='image_thumb_url')
    image_alt = TranslatedStr()
    illustrative_graphics_url = fields.Str()
    illustrative_graphics_alt = TranslatedStr()
    followed = fields.Boolean(faker_type='boolean')
    keywords = KeywordsList(TranslatedStr(), faker_type='tagslist')
    views_count = fields.Integer(faker_type='integer')
    modified = fields.Str(faker_type='datetime')
    created = fields.Str(faker_type='datetime')
    has_image_thumb = fields.Bool()
    main_page_position = fields.Int()
    external_datasets = fields.Nested(ExternalDataset, many=True)
    # application showcase fields:
    is_mobile_app = fields.Bool()
    is_mobile_app_name = fields.Method('get_is_mobile_app_name')
    is_desktop_app = fields.Bool()
    is_desktop_app_name = fields.Method('get_is_desktop_app_name')
    mobile_apple_url = fields.URL()
    mobile_google_url = fields.URL()
    desktop_linux_url = fields.URL()
    desktop_macos_url = fields.URL()
    desktop_windows_url = fields.URL()

    license_type = fields.Str()
    license_type_name = fields.Method('get_license_type_name')
    # api use showcase fields:
    file_url = fields.Str()

    class Meta:
        relationships_schema = ShowcaseApiRelationships
        object_type = 'showcase'
        url_template = '{api_url}/showcases/{ident}'
        model = 'showcases.Showcase'
        ordered = True

    def get_is_desktop_app_name(self, obj):
        return str(_('Desktop App')) if obj.is_desktop_app else ''

    def get_is_mobile_app_name(self, obj):
        return str(_('Mobile App')) if obj.is_mobile_app else ''

    def get_category_name(self, obj):
        return str(Showcase.CATEGORY_NAMES.get(obj.showcase_category, ''))

    def get_license_type_name(self, obj):
        return str(Showcase.LICENSE_TYPE_NAMES.get(obj.license_type, ''))
Example #27
0
class DatasetCategoryAttr(ExtSchema):
    id = fields.Str()
    title = TranslatedStr()
Example #28
0
class CommonObjectApiAttrs(ObjectAttrs, HighlightObjectMixin):
    model = fields.Str()

    # common
    slug = TranslatedStr()
    title = TranslatedStr()
    notes = TranslatedStr()
    keywords = KeywordsList(TranslatedStr(), faker_type='tagslist')
    modified = fields.DateTime()
    created = fields.DateTime()
    verified = fields.DateTime()
    categories = fields.Nested(Category, many=True)
    category = fields.Nested(Category)
    if is_enabled('S35_high_value_data.be'):
        has_high_value_data = fields.Boolean()

    # datasets
    source = fields.Nested(SourceSchema)

    # resources
    data_date = fields.Date()
    visualization_types = fields.List(fields.Str())

    # applications, showcases
    author = fields.Str()
    illustrative_graphics_alt = TranslatedStr()
    illustrative_graphics_url = fields.Str()
    image_alt = TranslatedStr()
    image_thumb_url = fields.Str()
    if is_enabled('S39_showcases.be'):
        showcase_category = fields.Str()
        showcase_category_name = fields.Method('get_showcase_category_name')
        showcase_types = fields.List(fields.Str())
        showcase_platforms = fields.List(fields.Str())

    # institutions
    abbreviation = fields.Str()
    institution_type = fields.Str()
    datasets_count = fields.Int(attribute='published_datasets_count')
    resources_count = fields.Int(attribute='published_resources_count')
    fax = fields.Str()
    tel = fields.Str()
    sources = fields.Nested(DataSourceAttr, many=True)

    # cms pages
    html_url = fields.Str()

    if is_enabled('S39_filter_by_geodata.be'):
        # regions
        region_id = fields.Int()
        hierarchy_label = TranslatedStr()
        bbox = fields.List(fields.List(fields.Float),
                           attribute='bbox.coordinates')
        regions = fields.Nested(RegionSchema, many=True)

    def get_showcase_category_name(self, obj):
        val = getattr(obj, 'showcase_category', None)
        if val:
            model = apps.get_model('showcases.Showcase')
            return str(model.CATEGORY_NAMES[val])
        return missing

    @staticmethod
    def self_api_url(data):
        try:
            api_url = getattr(settings, 'API_URL', 'https://api.dane.gov.pl')
            model = data.model
            obj_id = data.id
            slug = data['slug'][get_language()]
            full_url = f'{api_url}/{model}s/{obj_id},{slug}'
        except AttributeError:
            full_url = None
        return full_url

    class Meta:
        relationships_schema = CommonObjectRelationships
        object_type = 'common'
        api_path = 'search'
Example #29
0
class ArticleCategory(ma.Schema):
    id = ma.fields.Int()
    name = TranslatedStr()
    description = TranslatedStr()
class ArticleCategory(ExtSchema):
    id = fields.String()
    name = TranslatedStr()
    description = TranslatedStr()