#31 API protected visibility
* reworks most internal API methods for de/serializing from public to protected visibility * moves test_api_sharing.py into /share subfolder of tests
This commit is contained in:
@@ -21,7 +21,7 @@ from konova.utils.message_templates import DATA_UNSHARED
|
||||
|
||||
|
||||
class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
||||
def model_to_geo_json(self, entry):
|
||||
def _model_to_geo_json(self, entry):
|
||||
""" Adds the basic data, which all elements hold
|
||||
|
||||
Args:
|
||||
@@ -36,14 +36,14 @@ class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
||||
"id": entry.id,
|
||||
"identifier": entry.identifier,
|
||||
"title": entry.title,
|
||||
"created_on": self.created_on_to_json(entry),
|
||||
"modified_on": self.modified_on_to_json(entry),
|
||||
"created_on": self._created_on_to_json(entry),
|
||||
"modified_on": self._modified_on_to_json(entry),
|
||||
}
|
||||
self.extend_properties_data(entry)
|
||||
self._extend_properties_data(entry)
|
||||
geo_json["properties"] = self.properties_data
|
||||
return geo_json
|
||||
|
||||
def konova_code_to_json(self, konova_code: KonovaCode):
|
||||
def _konova_code_to_json(self, konova_code: KonovaCode):
|
||||
""" Serializes KonovaCode model into json
|
||||
|
||||
Args:
|
||||
@@ -60,7 +60,7 @@ class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
||||
"short_name": konova_code.short_name,
|
||||
}
|
||||
|
||||
def konova_code_from_json(self, json_str, code_list_identifier):
|
||||
def _konova_code_from_json(self, json_str, code_list_identifier):
|
||||
""" Returns a konova code instance
|
||||
|
||||
Args:
|
||||
@@ -78,7 +78,7 @@ class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
||||
)
|
||||
return code
|
||||
|
||||
def created_on_to_json(self, entry):
|
||||
def _created_on_to_json(self, entry):
|
||||
""" Serializes the created_on into json
|
||||
|
||||
Args:
|
||||
@@ -89,7 +89,7 @@ class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
||||
"""
|
||||
return entry.created.timestamp if entry.created is not None else None
|
||||
|
||||
def modified_on_to_json(self, entry):
|
||||
def _modified_on_to_json(self, entry):
|
||||
""" Serializes the modified_on into json
|
||||
|
||||
Args:
|
||||
@@ -112,7 +112,7 @@ class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
entry = self.get_obj_from_db(id, user)
|
||||
entry = self._get_obj_from_db(id, user)
|
||||
is_shared = entry.is_shared_with(user)
|
||||
if not is_shared:
|
||||
raise PermissionError(DATA_UNSHARED)
|
||||
@@ -128,7 +128,7 @@ class DeductableAPISerializerV1Mixin:
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def deductions_to_json(self, qs: QuerySet):
|
||||
def _deductions_to_json(self, qs: QuerySet):
|
||||
""" Serializes eco account deductions into json
|
||||
|
||||
Args:
|
||||
@@ -160,7 +160,7 @@ class ResponsibilityAPISerializerV1Mixin:
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def responsible_to_json(self, responsible: Responsibility):
|
||||
def _responsible_to_json(self, responsible: Responsibility):
|
||||
""" Serializes Responsibility model into json
|
||||
|
||||
Args:
|
||||
@@ -170,14 +170,14 @@ class ResponsibilityAPISerializerV1Mixin:
|
||||
serialized_json (dict)
|
||||
"""
|
||||
return {
|
||||
"registration_office": self.konova_code_to_json(responsible.registration_office),
|
||||
"registration_office": self._konova_code_to_json(responsible.registration_office),
|
||||
"registration_file_number": responsible.registration_file_number,
|
||||
"conservation_office": self.konova_code_to_json(responsible.conservation_office),
|
||||
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
||||
"conservation_file_number": responsible.conservation_file_number,
|
||||
"handler": responsible.handler,
|
||||
}
|
||||
|
||||
def set_responsibility(self, obj, responsibility_data: dict):
|
||||
def _set_responsibility(self, obj, responsibility_data: dict):
|
||||
""" Sets the responsible data contents to the provided responsibility_data dict
|
||||
|
||||
Args:
|
||||
@@ -189,12 +189,12 @@ class ResponsibilityAPISerializerV1Mixin:
|
||||
"""
|
||||
if responsibility_data is None:
|
||||
return obj
|
||||
obj.responsible.registration_office = self.konova_code_from_json(
|
||||
obj.responsible.registration_office = self._konova_code_from_json(
|
||||
responsibility_data["registration_office"],
|
||||
CODELIST_REGISTRATION_OFFICE_ID
|
||||
)
|
||||
obj.responsible.registration_file_number = responsibility_data["registration_file_number"]
|
||||
obj.responsible.conservation_office = self.konova_code_from_json(
|
||||
obj.responsible.conservation_office = self._konova_code_from_json(
|
||||
responsibility_data["conservation_office"],
|
||||
CODELIST_CONSERVATION_OFFICE_ID,
|
||||
)
|
||||
@@ -207,7 +207,7 @@ class LegalAPISerializerV1Mixin:
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def legal_to_json(self, legal: Legal):
|
||||
def _legal_to_json(self, legal: Legal):
|
||||
""" Serializes Legal model into json
|
||||
|
||||
Args:
|
||||
@@ -219,11 +219,11 @@ class LegalAPISerializerV1Mixin:
|
||||
return {
|
||||
"registration_date": legal.registration_date,
|
||||
"binding_date": legal.binding_date,
|
||||
"process_type": self.konova_code_to_json(legal.process_type),
|
||||
"laws": [self.konova_code_to_json(law) for law in legal.laws.all()],
|
||||
"process_type": self._konova_code_to_json(legal.process_type),
|
||||
"laws": [self._konova_code_to_json(law) for law in legal.laws.all()],
|
||||
}
|
||||
|
||||
def set_legal(self, obj, legal_data):
|
||||
def _set_legal(self, obj, legal_data):
|
||||
""" Sets the legal data contents to the provided legal_data dict
|
||||
|
||||
Args:
|
||||
@@ -237,11 +237,11 @@ class LegalAPISerializerV1Mixin:
|
||||
return obj
|
||||
obj.legal.registration_date = legal_data.get("registration_date", None)
|
||||
obj.legal.binding_date = legal_data.get("binding_date", None)
|
||||
obj.legal.process_type = self.konova_code_from_json(
|
||||
obj.legal.process_type = self._konova_code_from_json(
|
||||
legal_data.get("process_type", None),
|
||||
CODELIST_PROCESS_TYPE_ID,
|
||||
)
|
||||
laws = [self.konova_code_from_json(law, CODELIST_LAW_ID) for law in legal_data.get("laws", [])]
|
||||
laws = [self._konova_code_from_json(law, CODELIST_LAW_ID) for law in legal_data.get("laws", [])]
|
||||
obj.legal.laws.set(laws)
|
||||
return obj
|
||||
|
||||
@@ -250,7 +250,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def set_deadlines(self, obj, deadline_data):
|
||||
def _set_deadlines(self, obj, deadline_data):
|
||||
""" Sets the linked deadline data according to the given deadline_data
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
obj.deadlines.set(deadlines)
|
||||
return obj
|
||||
|
||||
def set_compensation_states(self, obj, states_data, states_manager):
|
||||
def _set_compensation_states(self, obj, states_data, states_manager):
|
||||
""" Sets the linked compensation state data according to the given states_data
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
else:
|
||||
# Create and add id to list
|
||||
new_state = CompensationState.objects.create(
|
||||
biotope_type=self.konova_code_from_json(biotope_type, CODELIST_BIOTOPES_ID),
|
||||
biotope_type=self._konova_code_from_json(biotope_type, CODELIST_BIOTOPES_ID),
|
||||
surface=surface
|
||||
)
|
||||
states.append(new_state.id)
|
||||
@@ -335,7 +335,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
states_manager.set(states)
|
||||
return obj
|
||||
|
||||
def set_compensation_actions(self, obj, actions_data):
|
||||
def _set_compensation_actions(self, obj, actions_data):
|
||||
""" Sets the linked compensation action data according to the given actions_data
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
else:
|
||||
# Create and add id to list
|
||||
new_action = CompensationAction.objects.create(
|
||||
action_type=self.konova_code_from_json(action, CODELIST_COMPENSATION_ACTION_ID),
|
||||
action_type=self._konova_code_from_json(action, CODELIST_COMPENSATION_ACTION_ID),
|
||||
amount=amount,
|
||||
unit=unit,
|
||||
comment=comment,
|
||||
@@ -383,7 +383,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
obj.actions.set(actions)
|
||||
return obj
|
||||
|
||||
def compensation_state_to_json(self, qs: QuerySet):
|
||||
def _compensation_state_to_json(self, qs: QuerySet):
|
||||
""" Serializes compensation states into json
|
||||
|
||||
Args:
|
||||
@@ -394,13 +394,13 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
"""
|
||||
return [
|
||||
{
|
||||
"biotope": self.konova_code_to_json(entry.biotope_type),
|
||||
"biotope": self._konova_code_to_json(entry.biotope_type),
|
||||
"surface": entry.surface,
|
||||
}
|
||||
for entry in qs
|
||||
]
|
||||
|
||||
def compensation_actions_to_json(self, qs: QuerySet):
|
||||
def _compensation_actions_to_json(self, qs: QuerySet):
|
||||
""" Serializes CompensationActions into json
|
||||
|
||||
Args:
|
||||
@@ -411,7 +411,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
"""
|
||||
return [
|
||||
{
|
||||
"action": self.konova_code_to_json(entry.action_type),
|
||||
"action": self._konova_code_to_json(entry.action_type),
|
||||
"amount": entry.amount,
|
||||
"unit": entry.unit,
|
||||
"comment": entry.comment,
|
||||
@@ -419,7 +419,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
||||
for entry in qs
|
||||
]
|
||||
|
||||
def deadlines_to_json(self, qs: QuerySet):
|
||||
def _deadlines_to_json(self, qs: QuerySet):
|
||||
""" Serializes deadlines into json
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user