aboutsummaryrefslogtreecommitdiff
path: root/sgdfi/_dbs
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-10-29 16:54:39 +0100
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-10-29 16:54:39 +0100
commit3b308c48415811ffcefef62be8a9c6439f556a5c (patch)
tree10d35bcb4062d74b69f09f2db0be6f00a0e01111 /sgdfi/_dbs
parent33fa1bacec308d9eb65a645fcbd92c95dfc7c86a (diff)
Starts to work, but I have to add the request optimization for structure paging to work.
Diffstat (limited to 'sgdfi/_dbs')
-rwxr-xr-xsgdfi/_dbs/_dept.py27
-rwxr-xr-xsgdfi/_dbs/_st.py4
-rwxr-xr-xsgdfi/_dbs/_stspe.py2
-rwxr-xr-xsgdfi/_dbs/_ststatus.py10
4 files changed, 27 insertions, 16 deletions
diff --git a/sgdfi/_dbs/_dept.py b/sgdfi/_dbs/_dept.py
index b33c212..5c55ce7 100755
--- a/sgdfi/_dbs/_dept.py
+++ b/sgdfi/_dbs/_dept.py
@@ -343,6 +343,9 @@ class Department(_Enum):
MONDE = 999
_DepartmentData = {
+ Department.UNKNOWN: \
+ (None, "Tous", -1),
+
Department.NONE: \
("00", "Non précisé", 9023),
Department.AIN: \
@@ -567,7 +570,7 @@ def _normalize(value):
""" Normalize a string for comparison. """
return ''.join(c for c in _udnormalize('NFD', value.casefold()) \
- if c in 'abcdefghijklmnopqrstuvwxyz')
+ if c in 'abcdefghijklmnopqrstuvwxyz0123456789')
# Leads are the following:
# - intranet internal identifier.
@@ -579,14 +582,16 @@ def _normalize(value):
_DepartmentLeads = {}
_DepartmentLeads.update({_normalize(name): i for i, (dcode, name, ii) \
in _DepartmentData.items()})
-_DepartmentLeads.update({dcode: i for i, (dcode, name, ii) \
- in _DepartmentData.items()})
+_DepartmentLeads.update({_normalize(dcode): i for i, (dcode, name, ii) \
+ in _DepartmentData.items() if dcode is not None})
_DepartmentLeads.update({ii: i for i, (dcode, name, ii) \
in _DepartmentData.items()})
_DepartmentLeads.update({str(ii): i for i, (dcode, name, ii) \
in _DepartmentData.items()})
_DepartmentLeads.update({_normalize(f"{dcode} - {name}"): i \
- for i, (dcode, name, ii) in _DepartmentData.items()})
+ for i, (dcode, name, ii) in _DepartmentData.items() if dcode is not None})
+_DepartmentLeads.update({_normalize(f"{name} - {dcode}"): i \
+ for i, (dcode, name, ii) in _DepartmentData.items() if dcode is not None})
class DepartmentData:
""" Department data (id, name, …). """
@@ -605,29 +610,29 @@ class DepartmentData:
self.__ii = None
data = None
- if isinstance(value, StructureTypeData):
+ if isinstance(value, DepartmentData):
self.__id = value.id
self.__ii = value.iid
self.__dcode = value.displayed_code
self.__name = value.name
elif isid(value):
- value = StructureType(value)
+ value = Department(value)
self.__id = value
- data = _StructureTypeData.get(value, None)
+ data = _DepartmentData.get(value, None)
else:
lead = value
if type(lead) == str:
lead = _normalize(lead)
try:
- self.__id = _StructureTypeLeads[lead]
- data = _StructureTypeData.get(self.__id, None)
+ self.__id = _DepartmentLeads[lead]
+ data = _DepartmentData.get(self.__id, None)
except KeyError:
if type(value) == str:
self.__name = value
else:
- raise ValueError("Could not determine a structure type.") \
+ raise ValueError("Could not determine a department.") \
from None
if data is not None:
@@ -644,7 +649,7 @@ class DepartmentData:
if self.__name is not None:
p.append(f"name = {repr(self.__name)}")
if self.__ii is not None:
- p.append(f"iid = {repr(self.__iid)}")
+ p.append(f"iid = {repr(self.__ii)}")
return f"{self.__class__.__name__}({', '.join(p)})"
diff --git a/sgdfi/_dbs/_st.py b/sgdfi/_dbs/_st.py
index 0b9e92c..e5f669a 100755
--- a/sgdfi/_dbs/_st.py
+++ b/sgdfi/_dbs/_st.py
@@ -61,6 +61,8 @@ class StructureType(_Enum):
# - internal code.
_StructureTypeData = {
+ StructureType.UNKNOWN: ("Tous", -1),
+
StructureType.AUTRES: ("Autres", 1211),
StructureType.SOMMET: ("Sommet", 1205),
@@ -138,7 +140,7 @@ class StructureTypeData:
if self.__name is not None:
p.append(f"name = {repr(self.__name)}")
if self.__ii is not None:
- p.append(f"iid = {repr(self.__iid)}")
+ p.append(f"iid = {repr(self.__ii)}")
return f"{self.__class__.__name__}({', '.join(p)})"
diff --git a/sgdfi/_dbs/_stspe.py b/sgdfi/_dbs/_stspe.py
index 55da554..f85001a 100755
--- a/sgdfi/_dbs/_stspe.py
+++ b/sgdfi/_dbs/_stspe.py
@@ -28,6 +28,8 @@ class StructureSpeciality(_Enum):
# - internal code.
_StructureSpecialityData = {
+ StructureSpeciality.UNKNOWN: ("Toutes", -1),
+
StructureSpeciality.WITHOUT: ("sans spécialité", 624),
StructureSpeciality.MARINE: ("Marine", 622),
StructureSpeciality.VENT_DU_LARGE: ("Vent du Large", 623),
diff --git a/sgdfi/_dbs/_ststatus.py b/sgdfi/_dbs/_ststatus.py
index d77df05..192c0fe 100755
--- a/sgdfi/_dbs/_ststatus.py
+++ b/sgdfi/_dbs/_ststatus.py
@@ -12,22 +12,24 @@ __all__ = ["StructureStatus", "StructureStatusData"]
@_unique
class StructureStatus(_Enum):
""" The default status (unknown). """
- UNKNOWN = 0
+ UNKNOWN = -1
""" Ouverte. """
- OPEN = 1
+ OPEN = 0
""" Fermée. """
- CLOSED = 2
+ CLOSED = 1
""" Suspendue. """
- SUSPENDED = 3
+ SUSPENDED = 2
# Structure status data.
# - name.
# - internal identifier on the intranet.
_StructureStatusData = {
+ StructureStatus.UNKNOWN: ("Tous", -1),
+
StructureStatus.OPEN: ("Ouverte", 0),
StructureStatus.CLOSED: ("Fermée", 1),
StructureStatus.SUSPENDED: ("Suspendue", 2)