Esempio n. 1
0
    def _fill_metadata_dataset_licence_form(data: dict, metadata: Metadata, dataset: Dataset, user: MrMapUser):
        """ Fills form data into Metadata/Dataset records

        Args:
            data (dict): Cleaned form data
            metadata (dict): The metadata record
            dataset (dict): The dataset record
            user: The performing user
        Returns:

        """
        metadata.licence = data.get("licence", None)
        metadata.access_constraints = data.get("access_constraints", None)
Esempio n. 2
0
def overwrite_metadata(original_md: Metadata, custom_md: Metadata,
                       editor_form):
    """ Overwrites the original data with the custom date

    Args:
        original_md (Metadata): The original Metadata object
        custom_md (Metadata): The custom Metadata object
        editor_form: The editor form which holds additional data
    Returns:
        nothing
    """
    original_md.title = custom_md.title
    original_md.abstract = custom_md.abstract
    original_md.access_constraints = custom_md.access_constraints
    # we need the metadata_url to reset dataset metadatas
    # original_md.metadata_url = custom_md.metadata_url
    original_md.licence = custom_md.licence
    # get db objects from values

    # Keyword updating
    keywords = editor_form.cleaned_data["keywords"]
    original_md.keywords.clear()
    for kw in keywords:
        keyword = Keyword.objects.get_or_create(keyword=kw)[0]
        original_md.keywords.add(keyword)

    # Language updating
    original_md.language_code = editor_form.cleaned_data["language_code"]

    # Categories updating
    # Categories are provided as id's to prevent language related conflicts
    try:
        categories = editor_form.cleaned_data["categories"]
        original_md.categories.clear()
        for category in categories:
            original_md.categories.add(category)
    except KeyError:
        pass

    # Categories are inherited by subelements
    subelements = original_md.get_described_element().get_subelements(
    ).select_related('metadata')
    for subelement in subelements:
        subelement.metadata.categories.clear()
        for category in categories:
            subelement.metadata.categories.add(category)

    # change capabilities document so that all sensitive elements (links) are proxied
    if original_md.use_proxy_uri != custom_md.use_proxy_uri:
        if custom_md.use_proxy_uri == 'on':
            original_md.set_proxy(True)
        else:
            original_md.set_proxy(False)

    # save metadata
    original_md.is_custom = True
    original_md.save()

    if original_md.is_dataset_metadata:
        overwrite_dataset_metadata_document(original_md)
    else:
        overwrite_capabilities_document(original_md)