Skip to content

Commit

Permalink
Fix limitations formatting (#10)
Browse files Browse the repository at this point in the history
* more explicit names

* handle conditions in a table

* format conditions #7

* fix limitations formatting #8

* add ps script to build and upload Pypi package
  • Loading branch information
Guts committed Sep 5, 2019
1 parent 496e92c commit 8a3c940
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 149 deletions.
15 changes: 10 additions & 5 deletions isogeotodocx/isogeo2docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,15 @@ def md2docx(self, docx_template: DocxTemplate, md: Metadata, share: Share = None

# ---- CGUs # --------------------------------------------------------
if md.conditions:
print(md.conditions)
conditions_out = self.fmt.conditions(md_conditions=md.conditions)
else:
conditions_out = ""

# ---- LIMITATIONS # -------------------------------------------------
if md.limitations:
lims_out = self.fmt.limitations(md_limitations=md.limitations)
limitations_out = self.fmt.limitations(md_limitations=md.limitations)
else:
lims_out = ""
limitations_out = ""

# ---- METADATA # ----------------------------------------------------
md_created = utils.hlpr_datetimes(md._created).strftime(self.datetimes_fmt)
Expand Down Expand Up @@ -306,7 +305,7 @@ def md2docx(self, docx_template: DocxTemplate, md: Metadata, share: Share = None
"varTopologyInfo": self.fmt.clean_xml(md.topologicalConsistency),
"varInspireTheme": " ; ".join(li_theminspire),
"varInspireConformity": inspire_valid,
"varLimitations": lims_out,
"varLimitations": limitations_out,
"varConditions": conditions_out,
"varSpecifications": specifications_out,
"varContactsCount": len(md.contacts),
Expand Down Expand Up @@ -428,7 +427,13 @@ def missing_values(self, idx_type=0):
WORKGROUP_TEST_FIXTURE_UUID = environ.get("ISOGEO_WORKGROUP_TEST_UUID")

# ------------ Isogeo search --------------------------
search_results = isogeo.search(include="all")
search_results = isogeo.search(
include="all",
specific_md=(
"70f1192f67ac43e5987800ead18effb2",
"b140d9a92c20416d97c3cdc12dc12607",
),
)
isogeo.close() # close session

# ------------ REAL START ----------------------------
Expand Down
208 changes: 75 additions & 133 deletions isogeotodocx/utils/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from isogeo_pysdk import (
Condition,
Conformity,
Directive,
IsogeoTranslator,
IsogeoUtils,
License,
Expand Down Expand Up @@ -74,7 +75,8 @@ def conditions(self, md_conditions: list) -> list:
"""Render input metadata CGUs as a new list.
:param list md_conditions: input list extracted from an Isogeo metadata
:rtype: list(dict)
:rtype: tuple(dict)
"""
# output list
conditions_out = []
Expand Down Expand Up @@ -102,51 +104,45 @@ def conditions(self, md_conditions: list) -> list:
return tuple(conditions_out)

def limitations(self, md_limitations: list) -> list:
"""Render input metadata limitations as a new list.
"""Format input metadata limitations as a tuple of 2 tuples of dictionaries, ready to be exported:
one with limitations related to INSPIRE, one with other limitations.
:param list md_limitations: input list of metadata limitations
:param dict md_limitations: input dictionary extracted from an Isogeo metadata
:rtype: tuple(tuple(dict), tuple(dict))
"""
lims_out = []
for l_in in md_limitations:
limitation = {}
# ensure other fields
limitation["description"] = l_in.get("description", "")
limitation["type"] = self.isogeo_tr("limitations", l_in.get("type"))
# legal type
if l_in.get("type") == "legal":
limitation["restriction"] = self.isogeo_tr(
"restrictions", l_in.get("restriction")
)
else:
pass
# INSPIRE precision
if "directive" in l_in.keys():
limitation["inspire"] = l_in.get("directive").get("name")
limitations_out = []
for lim_in in md_limitations:
# load limitation object
limitation_in = Limitation(**lim_in)

# build out dict
limitation_out = {}

limitation["content"] = l_in.get("directive").get("description")
# fill it
limitation_out["description"] = limitation_in.description
limitation_out["restriction"] = self.isogeo_tr(
"restrictions", limitation_in.restriction
)
limitation_out["type"] = self.isogeo_tr("limitations", limitation_in.type)

else:
pass

# store into the final list
lims_out.append(
"{} {}. {} {} {}".format(
limitation.get("type"),
limitation.get("description", ""),
limitation.get("restriction", ""),
limitation.get("content", ""),
limitation.get("inspire", ""),
# split INSPIRE / others
if limitation_in.directive:
directive = Directive(**limitation_in.directive)
limitation_out["directive"] = "{} ({})".format(
directive.name, directive.description
)
)
limitations_out.append(limitation_out)

# return formatted result
return lims_out
return tuple(limitations_out)

def specifications(self, md_specifications: list) -> list:
"""Render input metadata specifications (conformity + specification) as a new list.
:param list md_specifications: input dictionary extracted from an Isogeo metadata
:rtype: list(dict)
:rtype: tuple(dict)
"""
# output list
specifications_out = []
Expand Down Expand Up @@ -230,119 +226,65 @@ def clean_xml(self, invalid_xml: str, mode: str = "soft", substitute: str = "_")
"""Try me"""
formatter = Formatter()

# # specifications
# fixture_specifications = [
# {
# "conformant": True,
# "specification": {
# "_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
# "_tag": "specification:isogeo:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
# "name": "CNIG CC v2014",
# "link": "http://cnig.gouv.fr/wp-content/uploads/2014/10/141002_Standard_CNIG_CC_diffusion.pdf",
# "published": "2014-10-02T00:00:00",
# },
# },
# {
# "conformant": False,
# "specification": {
# "_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m20z",
# "_tag": "specification:1a2b3c4d5e6f7g8h9i0j11k12l13m20z:1a2b3c4d5e6f7g8h9i0j11k12l13m20z",
# "name": "Spécification - GT",
# "link": "https://www.isogeo.com",
# "owner": {
# "_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m20z",
# "_tag": "owner:1a2b3c4d5e6f7g8h9i0j11k12l13m20z",
# "_created": "2019-01-30T17:39:21.8947459+00:00",
# "_modified": "2019-08-05T13:55:03.9109327+00:00",
# "contact": {
# "_id": "azerty7g8h9i0j11k12l13m20z",
# "_tag": "contact:group:azerty7g8h9i0j11k12l13m20z",
# "_deleted": False,
# "type": "group",
# "name": "Isogeo TEST - SDK Migration",
# "zipCode": "33140",
# "countryCode": "FR",
# "available": False,
# },
# "canCreateMetadata": True,
# "canCreateLegacyServiceLinks": True,
# "areKeywordsRestricted": False,
# "hasCswClient": True,
# "hasScanFme": False,
# "keywordsCasing": "lowercase",
# "metadataLanguage": "es",
# },
# },
# },
# ]
# print(formatter.specifications(fixture_specifications))

# CGUs - Conditions
fixture_conditions = [
# limitations
fixture_limitations = [
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "**Gras**\n*Italique*\t\n<del>Supprimé</del>\n<cite>Citation</cite>\n\n* Élément 1\n* Élément 2\n\n1. Élément 1\n2. Élément 2\n\n[Foo](http://foo.bar)",
"license": {
"restriction": "license",
"directive": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_tag": "license:isogeo:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"name": "ODbL 1.0 - Open Database Licence",
"link": "https://vvlibri.org/fr/licence/odbl-10/legalcode/unofficial",
"name": "Pas de restriction d’accès public selon INSPIRE",
"description": "Aucun des articles de la loi ne peut être invoqué pour justifier d’une restriction d’accès public.",
},
},
{
"_id": "abc2d5177d284fd5acc18046bb3dc076",
"description": "Hop hop hop",
"license": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_tag": "license:isogeo:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"name": "ODbL 1.0 - Open Database Licence",
"link": "https://vvlibri.org/fr/licence/odbl-10/legalcode/unofficial",
},
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "security",
"description": "**Gras**\n*Italique*\t\n<del>Supprimé</del>\n<cite>Citation</cite>\n\n* Élément 1\n* Élément 2\n\n1. Élément 1\n2. Élément 2\n\n[Foo](http://foo.bar)",
},
{"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n", "description": ""},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"license": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_tag": "license:1a2b3c4d5e6f7g8h9i0j11k12l13m14n:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"owner": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_tag": "owner:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_created": "2019-01-30T17:39:21.8947459+00:00",
"_modified": "2019-08-05T13:55:03.9109327+00:00",
"contact": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_tag": "contact:group:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_deleted": False,
"type": "group",
"name": "Isogeo TEST - SDK Migration",
"zipCode": "33140",
"countryCode": "FR",
"available": False,
},
"canCreateMetadata": True,
"canCreateLegacyServiceLinks": True,
"areKeywordsRestricted": False,
"hasCswClient": True,
"hasScanFme": False,
"keywordsCasing": "lowercase",
"metadataLanguage": "es",
},
"name": "TEST License",
"link": "https://www.isogeo;com",
"content": "**Description**\n\nLicence créée manuellement pour des tests automatiques.",
},
"restriction": "other",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"license": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"_tag": "license:isogeo:1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"name": "Licence ouverte ETALAB 2.0",
"link": "https://www.etalab.gouv.fr/wp-content/uploads/2017/04/ETALAB-Licence-Ouverte-v2.0.pdf",
},
"restriction": "patentPending",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "Ceci est un **copyright**",
"restriction": "copyright",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "trademark",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "patent",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "intellectualPropertyRights",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "restricted",
},
]
print(formatter.conditions(fixture_conditions))
print(formatter.limitations(fixture_limitations))
71 changes: 71 additions & 0 deletions tests/fixtures/fixture_limitations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
fixture_limitations = [
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "**Gras**\n*Italique*\t\n<del>Supprimé</del>\n<cite>Citation</cite>\n\n* Élément 1\n* Élément 2\n\n1. Élément 1\n2. Élément 2\n\n[Foo](http://foo.bar)",
"restriction": "license",
"directive": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"name": "Pas de restriction d’accès public selon INSPIRE",
"description": "Aucun des articles de la loi ne peut être invoqué pour justifier d’une restriction d’accès public.",
},
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "security",
"description": "**Gras**\n*Italique*\t\n<del>Supprimé</del>\n<cite>Citation</cite>\n\n* Élément 1\n* Élément 2\n\n1. Élément 1\n2. Élément 2\n\n[Foo](http://foo.bar)",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "other",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "patentPending",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "Ceci est un **copyright**",
"restriction": "copyright",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "trademark",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "patent",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "intellectualPropertyRights",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "",
"restriction": "restricted",
},
{
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"type": "legal",
"description": "Description complémentaire",
"restriction": "other",
"directive": {
"_id": "1a2b3c4d5e6f7g8h9i0j11k12l13m14n",
"name": "L124-5-II-2 du code de l’environnement (Directive 2007/2/CE (INSPIRE), Article 13.1.c)",
"description": "La bonne marche de la justice, la possibilité pour toute personne d’être jugée équitablement ou la capacité d’une autorité publique d’effectuer une enquête d’ordre pénal ou disciplinaire.",
},
},
]
Binary file modified tests/fixtures/template_Isogeo.docx
Binary file not shown.
Loading

0 comments on commit 8a3c940

Please sign in to comment.