Skip to content

Commit

Permalink
Add HVD data tag for INSPIRE #61
Browse files Browse the repository at this point in the history
  • Loading branch information
geofranzi committed Aug 30, 2024
1 parent b71087e commit 7c54ba0
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 21 deletions.
19 changes: 14 additions & 5 deletions framework/inspire/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from layers.admin import LayersAdmin
from map.admin import MapAdmin

from .models import (InspireDataset, InspireMap, InspireTheme, ProcessingInline, SourceLayer,)
from .models import (InspireDataset, InspireHVD, InspireMap, InspireTheme, ProcessingInline, SourceLayer,)


def create_csw(self, request, queryset):
Expand Down Expand Up @@ -100,11 +100,11 @@ class InspireLayerAdmin(LayersAdmin):

(None, {
'classes': ('suit-tab', 'suit-tab-inspire',),
'fields': ('inspireidentified', 'opendata', 'inspire_theme')
'fields': ('inspireidentified', 'opendata', 'inspire_theme', 'inspire_hvd',),
}),
)
inlines = LayersAdmin.inlines + (ProcessingInlineTab,)
list_display = ('title', 'check_csw_published')
list_display = ('title', 'check_csw_published', 'inspire_hvd')
suit_form_tabs = LayersAdmin.suit_form_tabs + (
('inspire', 'INSPIRE'),)
search_fields = ('title', 'abstract', 'inspire_theme__name')
Expand All @@ -118,13 +118,14 @@ class InspireLayerAdmin(LayersAdmin):
class InspireMapAdmin(MapAdmin):
fieldsets = MapAdmin.fieldsets + (
(None, {
'classes': ('suit-tab', 'suit-tab-inspire',),
'fields': ('inspire_theme',)
'classes': ('suit-tab', 'suit-tab-inspire'),
'fields': ('inspire_theme', 'inspire_hvd')
}),

)
inlines = MapAdmin.inlines
# list_display=('title','publishable', 'downloadable', 'internal_contact')
list_display = ('full_name', 'ows_title_de', 'ows_title_en', 'ows_url_name', 'inspire_hvd')
suit_form_tabs = MapAdmin.suit_form_tabs + (('inspire', 'Inspire theme'),)
search_fields = ('abstract', 'inspire_theme__name')

Expand All @@ -144,7 +145,15 @@ def has_add_permission(self, request):
return False


class InspireHVDAdmin(admin.ModelAdmin):
list_display = ('uri', 'name_en', 'name_de')

def has_add_permission(self, request):
return False


admin.site.register(InspireMap, InspireMapAdmin)
admin.site.register(SourceLayer, SourceLayerAdmin)
admin.site.register(InspireDataset, InspireLayerAdmin)
admin.site.register(InspireTheme, InspireThemeAdmin)
admin.site.register(InspireHVD, InspireHVDAdmin)
27 changes: 14 additions & 13 deletions framework/inspire/csw.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os.path

from django.conf import settings
from django.contrib.gis.gdal import DataSource
from django.template.loader import get_template
from owslib.util import http_post

from inspire.models import (InspireMap, InspireMapSerializer, InspireMetadataSerializer, SourceMetadataSerializer,)
from layers.models import MetadataSerializer
from map.models import MapLayerInline
from webgis import settings


# Create insert and delete XML
Expand All @@ -31,6 +31,7 @@ def create_csw_xml(instance, type):
keywords_thesaurus.append(keywords)
else:
keywords_no_thesaurus.append(keywords)

# search for all maps
ows_list = MapLayerInline.objects.filter(map_layer_id=instance.id)
for ows_layer in ows_list:
Expand Down Expand Up @@ -65,12 +66,12 @@ def create_csw_xml(instance, type):
})

md_doc_meta = tpl.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/metadata/' + str(instance.id) + '_' + type + '_metadata.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/metadata/' + str(instance.id) + '_' + type + '_metadata.xml', 'wb')
f.write(md_doc_meta.encode('UTF-8'))

ctx["csw"] = "1"
md_doc_csw = tpl.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/' + str(instance.id) + '_' + type + '_insert.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/' + str(instance.id) + '_' + type + '_insert.xml', 'wb')
f.write(md_doc_csw.encode('UTF-8'))

print(ows_identifier)
Expand All @@ -82,7 +83,7 @@ def create_csw_xml(instance, type):
})

md_doc = tpl.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/' + str(instance.id) + '_' + type + '_delete.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/' + str(instance.id) + '_' + type + '_delete.xml', 'wb')
f.write(md_doc.encode('UTF-8'))

result["error"] = False
Expand All @@ -101,7 +102,7 @@ def create_csw_view_xml(instance, inspire):

if inspire:
map = InspireMapSerializer(instance)
# print(map.data)
# print(map.data)
ows_srs_list = map.data["ows_srs"].split(",")

for keywords in map.data["map_keywords"]:
Expand All @@ -128,16 +129,16 @@ def create_csw_view_xml(instance, inspire):
})

md_doc_meta = tpl_view.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/metadata/' + str(instance.id) + '_metadata_service.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/metadata/' + str(instance.id) + '_metadata_service.xml', 'wb')
f.write(md_doc_meta.encode('UTF-8'))

md_doc_meta = tpl_download.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/metadata/' + str(instance.id) + '_metadata_download.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/metadata/' + str(instance.id) + '_metadata_download.xml', 'wb')
f.write(md_doc_meta.encode('UTF-8'))

ctx["csw"] = "1"
md_doc_csw = tpl_view.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/' + str(instance.id) + '_insert_service.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/' + str(instance.id) + '_insert_service.xml', 'wb')
f.write(md_doc_csw.encode('UTF-8'))

tpl_view = get_template('CSW/delete.xml')
Expand All @@ -149,7 +150,7 @@ def create_csw_view_xml(instance, inspire):

ctx["csw"] = "1"
md_doc_csw = tpl_download.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/' + str(instance.id) + '_insert_download.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/' + str(instance.id) + '_insert_download.xml', 'wb')
f.write(md_doc_csw.encode('UTF-8'))

tpl_download = get_template('CSW/delete.xml')
Expand All @@ -158,7 +159,7 @@ def create_csw_view_xml(instance, inspire):
})

md_doc = tpl_download.render(ctx)
f = open(settings.MEDIA_ROOT + 'csw/' + str(instance.id) + '_delete_download.xml', 'wb')
f = open(settings.MEDIA_ROOT + '/csw/' + str(instance.id) + '_delete_download.xml', 'wb')
f.write(md_doc.encode('UTF-8'))

create_map_mapfile(instance, inspire)
Expand Down Expand Up @@ -220,18 +221,18 @@ def create_map_mapfile(instance, inspire):
})

md_doc_meta = tpl.render(ctx)
f = open(settings.MEDIA_ROOT + 'map/' + map.data["ows_url_name"] + '.map', 'wb')
f = open(settings.MEDIA_ROOT + '/map/' + map.data["ows_url_name"] + '.map', 'wb')
f.write(md_doc_meta.encode('UTF-8'))


def create_record(id):
response = http_post(settings.CSW_T_PATH, request=open(settings.MEDIA_ROOT + 'csw/' + str(id) + '_insert.xml').read())
response = http_post(settings.CSW_T_PATH, request=open(settings.MEDIA_ROOT + '/csw/' + str(id) + '_insert.xml').read())
print(response)


def delete_record(id):
if os.path.isfile(settings.MEDIA_ROOT + 'csw/' + str(id) + '_delete.xml'):
response = http_post(settings.CSW_T_PATH, request=open(settings.MEDIA_ROOT + 'csw/' + str(id) + '_delete.xml').read())
response = http_post(settings.CSW_T_PATH, request=open(settings.MEDIA_ROOT + '/csw/' + str(id) + '_delete.xml').read())
print(response)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.5 on 2024-08-25 14:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('inspire', '0003_alter_inspiretheme_topiccategory_and_more'),
]

operations = [
migrations.CreateModel(
name='InspireHDV',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uri', models.CharField(max_length=400, verbose_name='URI')),
('name_en', models.CharField(max_length=200, verbose_name='Name (en)')),
('name_de', models.CharField(max_length=200, verbose_name='Name (de)')),
],
),
migrations.AddField(
model_name='sourcelayer',
name='inspire_hdv',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='inspire_hdv', to='inspire.inspirehdv'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.5 on 2024-08-25 15:01

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('inspire', '0004_inspirehdv_sourcelayer_inspire_hdv'),
]

operations = [
migrations.RemoveField(
model_name='sourcelayer',
name='inspire_hdv',
),
migrations.AddField(
model_name='inspiredataset',
name='inspire_hdv',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='inspire_hdv', to='inspire.inspirehdv'),
),
]
19 changes: 19 additions & 0 deletions framework/inspire/migrations/0006_inspiremap_inspire_hdv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.5 on 2024-08-25 21:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('inspire', '0005_remove_sourcelayer_inspire_hdv_and_more'),
]

operations = [
migrations.AddField(
model_name='inspiremap',
name='inspire_hdv',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='inspire_hdv_map', to='inspire.inspirehdv'),
),
]
26 changes: 23 additions & 3 deletions framework/inspire/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ class Meta:
fields = ('uri', 'name_en', 'name_de', 'definition_en', 'definition_de', 'topicCategory')


class InspireHVD(models.Model):
uri = models.CharField(max_length=400, verbose_name="URI")
name_en = models.CharField(max_length=200, verbose_name="Name (en)")
name_de = models.CharField(max_length=200, verbose_name="Name (de)")

def __str__(self):
return u"%s" % self.name_en


class InspireHVDSerializer(serializers.ModelSerializer):
class Meta:
model = InspireHVD
fields = ('uri', 'name_en', 'name_de')


class SourceLayer(Layer):
internal_contact = models.ForeignKey(Contact, related_name="internal_contact", verbose_name="Internal Contact",
on_delete=models.PROTECT, blank=True, null=True)
Expand Down Expand Up @@ -62,6 +77,7 @@ def check_csw_published(self):

class InspireDataset(Layer):
inspire_theme = models.ManyToManyField(InspireTheme, blank=True, related_name="inspire_theme")
inspire_hvd = models.ForeignKey(InspireHVD, related_name="inspire_hvd", on_delete=models.PROTECT, blank=True, null=True)

opendata = models.BooleanField(default=False)
inspireidentified = models.BooleanField(default=False)
Expand Down Expand Up @@ -124,6 +140,7 @@ class Meta:

class InspireMap(Map):
inspire_theme = models.ManyToManyField(InspireTheme, blank=True, related_name="inspire_theme_map")
inspire_hvd = models.ForeignKey(InspireHVD, related_name="inspire_hvd_map", on_delete=models.PROTECT, blank=True, null=True)

inspire_wms_published = models.BooleanField(default=False)
inspire_wms_first_publication_date = models.DateTimeField(verbose_name="First publication date", blank=True, null=True)
Expand All @@ -150,26 +167,29 @@ def check_csw_published(self):

class InspireMetadataSerializer(MetadataSerializer):
inspire_theme = InspireThemesSerializer(many=True)
inspire_hvd = InspireHVDSerializer(read_only=True)

class Meta(MetadataSerializer.Meta):
model = InspireDataset
fields = MetadataSerializer.Meta.fields + ('inspire_theme',)
fields = MetadataSerializer.Meta.fields + ('inspire_theme', 'inspire_hvd')


class SourceMetadataSerializer(MetadataSerializer):
inspire_theme = InspireThemesSerializer(many=True)
inspire_hvd = InspireHVDSerializer(read_only=True)

class Meta(MetadataSerializer.Meta):
model = SourceLayer
fields = MetadataSerializer.Meta.fields + ('inspire_theme',)
fields = MetadataSerializer.Meta.fields + ('inspire_theme', 'inspire_hvd')


class InspireMapSerializer(MapSerializer):
inspire_theme = InspireThemesSerializer(many=True)
inspire_hvd = InspireHVDSerializer(read_only=True)

class Meta(MapSerializer.Meta):
model = InspireMap
fields = MapSerializer.Meta.fields + ('inspire_theme',)
fields = MapSerializer.Meta.fields + ('inspire_theme', 'inspire_hvd')


def check_csw_published(identifier):
Expand Down

0 comments on commit 7c54ba0

Please sign in to comment.