def lookups(self, request, model_admin): return supported_formats_choices()
from mcod import settings from mcod.regions.fields import RegionsMultipleChoiceField from mcod.lib.field_validators import ContainsLetterValidator from mcod.lib.widgets import ( CKEditorWidget, ResourceDataRulesWidget, ResourceDataSchemaWidget, ResourceMapsAndPlotsWidget, ) from mcod.resources.archives import ARCHIVE_EXTENSIONS from mcod.resources.models import Resource, supported_formats_choices from mcod.special_signs.models import SpecialSign from mcod.unleash import is_enabled SUPPORTED_FILE_EXTENSIONS = [f'.{x[0]}' for x in supported_formats_choices()] SUPPORTED_FILE_EXTENSIONS.extend([f'.{x}' for x in ARCHIVE_EXTENSIONS]) class ResourceSourceSwitcher(forms.widgets.HiddenInput): input_type = 'hidden' template_name = 'admin/forms/widgets/resources/switcher.html' class ResourceSwitcherField(forms.Field): def validate(self, value): if value not in ('file', 'link'): return ValidationError('No option choosed') class ResourceFileWidget(forms.widgets.FileInput):
import random import uuid import factory from mcod.datasets.factories import DatasetFactory from mcod.resources import models _SUPPORTED_FORMATS = [i[0] for i in models.supported_formats_choices()] _RESOURCE_TYPES = [i[0] for i in models.RESOURCE_TYPE] class ResourceFactory(factory.django.DjangoModelFactory): title = factory.Faker('text', max_nb_chars=100, locale='pl_PL') description = factory.Faker('paragraph', nb_sentences=3, variable_nb_sentences=True, locale='pl_PL') views_count = random.randint(0, 500) downloads_count = random.randint(0, 500) file = factory.django.FileField( filename='{}.csv'.format(str(uuid.uuid4()))) link = factory.LazyAttribute( lambda obj: 'http://falconframework.org/media/resources/{}'.format( obj.file.name)) dataset = factory.SubFactory(DatasetFactory) format = factory.Faker('random_element', elements=_SUPPORTED_FORMATS) type = factory.Faker('random_element', elements=_RESOURCE_TYPES) openness_score = random.randint(1, 5) class Meta:
import datetime from django.conf import settings from django.utils.translation import gettext_lazy as _, override from django.utils.timezone import is_naive, make_aware from marshmallow import Schema as BaseSchema, EXCLUDE, pre_load, post_load, validate from marshmallow import ValidationError, validates_schema from marshmallow.fields import Bool, Date, DateTime, Int, List, Nested, Str, URL, UUID, Method from mcod.core.api.rdf.profiles.dcat_ap import DCATDatasetDeserializer from mcod.datasets.models import Dataset from mcod.resources.models import Resource, supported_formats_choices from mcod.resources.archives import ARCHIVE_EXTENSIONS from mcod.unleash import is_enabled SUPPORTED_RESOURCE_FORMATS = [i[0] for i in supported_formats_choices()] SUPPORTED_RESOURCE_FORMATS.extend(ARCHIVE_EXTENSIONS) SUPPORTED_RESOURCE_FORMATS.append('api') class Schema(BaseSchema): @post_load def modify_data(self, data, **kwargs): for key, value in data.items(): if isinstance(value, datetime.datetime): data[key] = make_aware( value, is_dst=False) if is_naive(value) else value return data class ExtraSchema(Schema):