Esempio n. 1
0
    def _fill_form_list(form_list, metadata: Metadata, dataset: Dataset,
                        user: MrMapUser):
        """ Iterates over all forms and applies the metadata changes on the objects

        Args:
            form_list: The list of forms
            metadata: The metadata record
            dataset: The dataset record
            user: The performing user
        Returns:

        """
        function_map = {
            "DatasetIdentificationForm":
            DatasetWizard._fill_metadata_dataset_identification_form,
            "DatasetResponsiblePartyForm":
            DatasetWizard._fill_metadata_dataset_responsible_party_form,
            "DatasetClassificationForm":
            DatasetWizard._fill_metadata_dataset_classification_form,
            "DatasetSpatialExtentForm":
            DatasetWizard._fill_metadata_dataset_spatial_extent_form,
            "DatasetLicenseConstraintsForm":
            DatasetWizard._fill_metadata_dataset_licence_form,
            "DatasetQualityForm":
            DatasetWizard._fill_metadata_dataset_quality_form,
        }

        for form in form_list:
            form_class = type(form).__name__
            function_map[form_class](form.cleaned_data, metadata, dataset,
                                     user)

        dataset.save()
        metadata.is_custom = True
        metadata.save()

        try:
            doc = Document.objects.get(
                metadata__id=metadata.id,
                document_type=DocumentEnum.METADATA.value,
                is_original=False,
            )
            doc.is_active = metadata.is_active
            DatasetWizard._overwrite_dataset_document(metadata, doc)
        except ObjectDoesNotExist:
            DatasetWizard._create_dataset_document(metadata)
Esempio n. 2
0
class NewDatasetWizard(PermissionRequiredMixin, DatasetWizard):
    permission_required = PermissionEnum.CAN_ADD_DATASET_METADATA.value
    raise_exception = True
    permission_denied_message = NO_PERMISSION

    def __init__(self, *args, **kwargs):
        super().__init__(action_url=reverse(
            'editor:dataset-metadata-wizard-new', ),
                         title=_(format_html('<b>Add New Dataset</b>')),
                         *args,
                         **kwargs)

    def get_form_kwargs(self, step=None):
        return {'request': self.request}

    def done(self, form_list, **kwargs):
        """ Iterates over all forms and fills the Metadata/Dataset records accordingly

        Args:
            form_list (FormList): An iterable list of forms
            kwargs:
        Returns:

        """
        # Create instances
        self.metadata = Metadata()
        self.metadata.metadata_type = MetadataEnum.DATASET.value
        self.metadata.is_active = True

        self.dataset = Dataset()
        self.dataset.is_active = True
        self.dataset.md_identifier_code = self.metadata.identifier
        self.dataset.metadata_standard_name = "ISO 19115 Geographic information - Metadata"
        self.dataset.metadata_standard_version = "ISO 19115:2003(E)"

        # Pre-save objects to be able to add M2M relations
        self.metadata.save()
        self.metadata.identifier = self.metadata.id
        self.dataset.metadata = self.metadata
        self.dataset.save()
        self.metadata.metadata_url = reverse("resource:get-dataset-metadata",
                                             args=(self.dataset.id, ))

        return super().done(form_list=form_list, **kwargs)