Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/opentheso #189

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18,139 changes: 18,139 additions & 0 deletions app/export/telemeta.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/scripts/opentheso.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

chmod 777 "export/telemeta.xml" && echo "The file is now writable"
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ worker:
env_file:
- env/prod.env
command: /bin/bash scripts/worker.sh
command: /bin/bash scripts/opentheso.sh
links:
- broker
- db
Expand Down
1 change: 1 addition & 0 deletions telemeta/templates/telemeta/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<li><a href="{% url "telemeta-users" %}" class="red">{% trans "Users" %}</a></li>
{% endif %}
{% endif %}
<li><a href="{% url "telemeta-opentheso" %}" class="darkblue">{% trans "Opentheso" %}</a></li>
{% if user.is_staff %}
<li><a href="#admin#" class="violet">{% trans "Admin" %}</a>
<ul>
Expand Down
91 changes: 50 additions & 41 deletions telemeta/templates/telemeta/instrument_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,59 @@
{% block head_title %}{% trans "Instruments" %} - {{ block.super }}{% endblock %}

{% block title %}
<h1><img src="{{ STATIC_URL }}telemeta/images/admin_red.png" style="vertical-align:middle" /> {% trans "Administration" %} > {% trans "Instruments" %}</h1>
<h1><img src="{{ STATIC_URL }}telemeta/images/admin_red.png" style="vertical-align:middle" /> {% trans "Administration" %} > {% trans "Instruments" %}</h1>
{% endblock %}

{% block tabcontents %}
<form class="addnew" id="_addinstru" method="POST"
action="{% url "telemeta-instrument-add" %}">{% csrf_token %}
<fieldset>
<legend>{% trans "Add entry" %}</legend>
<div class="field">
<label>{% trans "Name" %}: <input type="text" name="value"></label>
<form class="addnew" id="_addinstru" method="POST"
action="{% url "telemeta-instrument-add" %}">{% csrf_token %}
<fieldset>
<legend>{% trans "Add entry" %}</legend>
<div class="field">
<label>{% trans "Name" %}: <input type="text" name="value"></label>

</div>
<div class="buttons">
<br />
<a href="#" class="component_icon button icon_add"
onclick="document.getElementById('_addinstru').submit(); return false;">{% trans "Add" %}</a>
</div>
</fieldset>
</form>
{% if instruments %}
<form id="_updateinstru" method="POST" action="{% url "telemeta-instrument-update" %}">{% csrf_token %}
<table class="listing">
<thead>
<tr><th class="sel">&nbsp;</th><th>{% trans "Name"%}</th><th>{% trans "Associated items" %}</th></tr>
</thead><tbody>
{% for record in instruments %}
<tr>
<td><input type="checkbox" name="sel" value="{{record.id}}" /></td>
<td><a href="{% url "telemeta-instrument-record-edit" record.id %}">
{{record.name}}</a></td>
<td><a href="{% url "telemeta-instrument-item-list" record.id %}">{{ record.num_items }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="buttons">
<br />
<a href="#" class="component_icon button icon_cancel"
onclick="document.getElementById('_updateinstru').submit(); return false;">{% trans "Remove selected items" %}</a>
</div>
</form>
{% else %}
<p class="help">{% trans "This instrument list is empty" %}</p>
{% endif %}
</div>
<div class="buttons">
<br />
<a href="#" class="component_icon button icon_add"
onclick="document.getElementById('_addinstru').submit(); return false;">{% trans "Add" %}</a>
</div>
</fieldset>
</form>
<form class="addnew" id="_export" method="POST"
action="{% url "telemeta-instrument-export" %}" >{% csrf_token %}
<div class="buttons">
<br />
<a href="#" class="component_icon button icon_copy"
onclick="document.getElementById('_export').submit(); return false;">{% trans "Export Skos" %}</a>
</div>

<br style="clear: right"/>
</form>
{% if instruments %}
<form id="_updateinstru" method="POST" action="{% url "telemeta-instrument-update" %}">{% csrf_token %}
<table class="listing">
<thead>
<tr><th class="sel">&nbsp;</th><th>{% trans "Name"%}</th><th>{% trans "Associated items" %}</th></tr>
</thead><tbody>
{% for record in instruments %}
<tr>
<td><input type="checkbox" name="sel" value="{{record.id}}" /></td>
<td><a href="{% url "telemeta-instrument-record-edit" record.id %}">
{{record.name}}</a></td>
<td><a href="{% url "telemeta-instrument-item-list" record.id %}">{{ record.num_items }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="buttons">
<br />
<a href="#" class="component_icon button icon_cancel"
onclick="document.getElementById('_updateinstru').submit(); return false;">{% trans "Remove selected items" %}</a>
</div>
</form>
{% else %}
<p class="help">{% trans "This instrument list is empty" %}</p>
{% endif %}

<br style="clear: right"/>
{% endblock %}
71 changes: 71 additions & 0 deletions telemeta/templates/telemeta/opentheso.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

{% extends "telemeta/base.html" %}
{% load telemeta_tags %}
{% load i18n %}
{% load bootstrap_pagination %}
{% block content %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
{% if not opentheso %}
<h1>recherche par nom</h1>
<form method="GET" action="{% url "telemeta-opentheso" %} ">
<input id="search" type="text" name="name"/><br/>
<input type="submit" value="rechercher">
</form>
<h1>recherche par id</h1>
<form method="GET" action="{% url "telemeta-opentheso" %} ">
<input id="search" type="text" name="id"/><br/>

<input type="submit" value="rechercher">
</form>
{% else %}
{% if recherche_by_id %}
<h1>{{ terme|capfirst }}</h1><br/><br/>
<h1>Terme(s) générique(s)</h1>
{% for t in termeGen %}
<br/>
<a target="_blank" href='{{ t.link }}'>{{ t.valeur }}</a>
{% endfor %}
<br/>
<h1>Terme(s) spécifique(s)</h1>
{% for t in termeSpe %}
<br/>
<a target="_blank" href='{{ t.link }}'>{{ t.valeur }}</a>
{% endfor %}
<br/>
<h1>Terme(s) associé(s)</h1>
{% for t in termeAsso %}
<br/>
<a target="_blank" href='{{ t.link }}'>{{ t.valeur }}</a>
{% endfor %}
<br/>
<h1>Synonyme</h1>
{% for t in termeSyn %}
<br/>
{{ t }}
{% endfor %}
<br/>
<h1>Alignement</h1>
{% for t in align%}
<br/>
{% if t != "aucun alignement" %}
<a href={{ t }}>{{ t }}</a>
{% else %}
{{ t }}
{% endif %}
{% endfor %}
<br/>
{% endif %}
{% if not recherche_by_id %}
<h1>resultat de la recherche par nom</h1>
{% for t in result%}
<br/>
{% if t != "erreur recherche" %}
<a href={{ t.id }}>{{ t.value }}</a>
{% else %}
{{ t }}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}

{% endblock %}
5 changes: 5 additions & 0 deletions telemeta/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from jsonrpc import jsonrpc_site
import os.path
import telemeta.config
from telemeta.views.export import ExportView
from telemeta.views.opentheso import OpenthesoView

telemeta.config.check()

Expand All @@ -45,6 +47,7 @@
profile_view = ProfileView()
geo_view = GeoView()
resource_view = ResourceView()
opentheso_view = OpenthesoView()
#boolean_view = BooleanSearchView()

# ID's regular expressions
Expand Down Expand Up @@ -236,6 +239,8 @@

url(r'^', include('jqchat.urls')),

url(r'^opentheso/$',opentheso_view.opentheso,name='telemeta-opentheso'),
url(r'^export_instrument/$',ExportView().export_instrument,name="telemeta-instrument-export")
# Timeside
#url(r'^timeside/', include('timeside.server.urls')),

Expand Down
140 changes: 140 additions & 0 deletions telemeta/views/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# coding: utf8
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse
from django.utils.encoding import smart_str


from telemeta.models.instrument import *
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
import os
from telemeta.views.core import *
from telemeta.views.core import serve_media
from django.template import RequestContext, Template

import os
import sys
from lxml import etree
from datetime import datetime
import unicodedata
class ExportView(object):

def skos(self):
Instruments = Instrument.objects.all()
Alias = InstrumentAlias.objects.all()
Instrument_relation =InstrumentRelation.objects.all()
Instrument_alias_relation = InstrumentAliasRelation.objects.all()
today = datetime.today()
# en tête du xml
f = open("export/telemeta.xml", 'w')

s = '<?xml version="1.0" encoding="UTF-8"?>\n\
<rdf:RDF\
xmlns:skos="http://www.w3.org/2004/02/skos/core#"\n\
xmlns:dc="http://purl.org/dc/elements/1.1/"\n\
xmlns:dcterms="http://purl.org/dc/terms/"\n\
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"\n\
xmlns:iso-thes="http://purl.org/iso25964/skos-thes#"\n\
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n\
'
f.write(s.encode('utf-8'))
# description du concept de schéma

s = '<rdf:Description rdf:about="http://localhost:8080/opentheso-4.3.0/101">\n\
<rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#ConceptScheme"/>\n\
<skos:prefLabel xml:lang="fr">instrumentDJANGO</skos:prefLabel>\n\
<iso-thes:microThesaurusOf rdf:resource="http://localhost:8080/opentheso-4.3.0/1"/>\n\
<dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:created>\n\
<dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:modified>\n\
</rdf:Description>\n'

# description de la collection instrument
f.write(s.encode('utf-8'))
s = '<rdf:Description rdf:about="http://localhost:8080/opentheso-4.3.0/MT101">\n\
<rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Collection"/>\n\
<skos:prefLabel xml:lang="fr">instrument</skos:prefLabel>\n\
<iso-thes:microThesaurusOf rdf:resource="http://localhost:8080/opentheso-4.3.0/101"/>\n'
f.write(s.encode('utf-8'))
for instru in Instruments:# parcours de toutes les valeurs de la table instrument
# ajout des membres dans la collection
s = ' <skos:member rdf:resource="http://localhost:8080/opentheso-4.3.0/IM_' + str(instru.id) + '"/>\n'
f.write(s.encode('utf-8'))
for alias in Alias: # parcours de toutes les valeurs de la table alias_instrument
# ajout des membres dans la collection
s = ' <skos:member rdf:resource="http://localhost:8080/opentheso-4.3.0/A_' + str(alias.id)+ '"/>\n'
f.write(s.encode('utf-8'))
s = ' <dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:created>\n\
<dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:modified>\n\
</rdf:Description>\n'
f.write(s.encode('utf-8'))
for instru in Instruments : # parcours de toutes les valeurs de la table instrument
isenfant = False
s = '<rdf:Description rdf:about="http://localhost:8080/opentheso-4.3.0/IM_' + str(instru.id) + '">\n\
<rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>\n\
<skos:prefLabel xml:lang="fr">' + unicodedata.normalize('NFD',instru.name).encode('ascii','ignore') + '</skos:prefLabel>\n\
<skos:inScheme rdf:resource="http://localhost:8080/opentheso-4.3.0/101"/>\n '
f.write(s.encode('utf-8'))
for relation in Instrument_relation: # parcours de toutes les relations entre les instruments

if relation.instrument.id == instru.id: # si l'id de l'instrument actuellement parcouru correspond à l'id de l'instruement fils de la relation
isenfant = True
s = ' <skos:broader rdf:resource = "http://localhost:8080/opentheso-4.3.0/IM_' + str(relation.parent_instrument.id) + '"/>\n'
f.write(s.encode('utf-8'))
elif relation.parent_instrument.id == instru.id: # si l'id de l'instrument actuellement parcouru correspond à l'id de l'instruement_parent de la relation
s = ' <skos:narrower rdf:resource = "http://localhost:8080/opentheso-4.3.0/IM_' +str(relation.instrument.id) + '"/>\n'
f.write(s.encode('utf-8'))
if not isenfant:
s = '<skos:topConceptOf rdf:resource = "http://localhost:8080/opentheso-4.3.0/101"/>\n'
f.write(s.encode('utf-8'))
for alias_relation in Instrument_alias_relation: # parcours de toutes les relations entre les instruments et les alias
if alias_relation.instrument.id == instru.id: # si l'id de l'instrument dans la relation entre les instrument et les alias correspond à l'id de l'instrument actuellement parcouru
s = ' <skos:narrower rdf:resource = "http://localhost:8080/opentheso-4.3.0/A_' + str(alias_relation.instrument.id) + '"/>\n'
f.write(s.encode('utf-8'))

s = ' <dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:created>\n\
<dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) \
+ '</dcterms:modified>\n'
f.write(s.encode('utf-8'))
s = '</rdf:Description>\n'
f.write(s.encode('utf-8'))
for alias in Alias: # parcours de toutes les valeurs de la table alias_instrument
s = '<rdf:Description rdf:about="http://localhost:8080/opentheso-4.3.0/A_' + str(alias.id) + '">\n\
<rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>\n\
<skos:prefLabel xml:lang="fr">' +unicodedata.normalize('NFD', alias.name).encode('ascii', 'ignore') + '</skos:prefLabel>\n\
<skos:inScheme rdf:resource="http://localhost:8080/opentheso-4.3.0/101"/>\n'
f.write(s.encode('utf-8'))
for alias_relation in Instrument_alias_relation: # parcours de toutes les relations entre les instruments et les alias
if alias_relation.alias.id == alias.id: # si l'id de l'alias dans la relation entre les instrument et les alias correspond à l'id de l'alias actuellement parcouru
s = ' <skos:broader rdf:resource = "http://localhost:8080/opentheso-4.3.0/IM_' + \
str(alias_relation.instrument.id) + '"/>\n'
f.write(s.encode('utf-8'))

s = ' <dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:created>\n\
<dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#date">' \
+ str(today.year) + '-' + str(today.month) + '-' + str(today.day) + '</dcterms:modified>\n\
</rdf:Description>\n\
'
f.write(s.encode('utf-8'))
f.write('</rdf:RDF>')


# overture du fichier xml

def export_instrument(self,request):
self.skos()
# It's usually a good idea to set the 'Content-Length' header too.
# You can also set any other required headers: Cache-Control, etc.
xml = open("export/telemeta.xml", "r").read()

c = RequestContext(request,{'result':xml})
t = Template("{{result}}")

return HttpResponse(xml, content_type='application/force-download')

Loading