feature/additional_information (#30)

Fixes #12

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#30
This commit is contained in:
2025-07-19 08:10:40 +12:00
parent 4fff78541b
commit 49e02ed97d
11 changed files with 534 additions and 344 deletions

View File

@ -468,10 +468,10 @@ class Rule(PolymorphicModel, EnviPathModel, AliasMixin, ScenarioMixin):
# I think this only affects Django Admin which we are barely using
# # https://github.com/django-polymorphic/django-polymorphic/issues/229
_non_polymorphic = models.Manager()
class Meta:
base_manager_name = '_non_polymorphic'
# _non_polymorphic = models.Manager()
#
# class Meta:
# base_manager_name = '_non_polymorphic'
@abc.abstractmethod
def apply(self, *args, **kwargs):
@ -1431,14 +1431,13 @@ class PluginModel(EPModel):
pass
# #
# #
# # # TODO fully implement AdditionalInformation
# # # TODO consider Scenario, BaseScenario, RelatedScenario
class Scenario(EnviPathModel):
package = models.ForeignKey('epdb.Package', verbose_name='Package', on_delete=models.CASCADE, db_index=True)
type = models.CharField(max_length=256, null=False, blank=False, default='No date')
type = models.CharField(max_length=256, null=False, blank=False, default='Not specified')
scenario_date = models.CharField(max_length=256, null=False, blank=False, default='No date')
scenario_type = models.CharField(max_length=256, null=False, blank=False, default='Not specified')
# for Referring Scenarios this property will be filled
parent = models.ForeignKey('self', on_delete=models.CASCADE, default=None, null=True)
additional_information = models.JSONField(verbose_name='Additional Information')
@ -1470,47 +1469,15 @@ class Scenario(EnviPathModel):
def set_additional_information(self, data):
pass
example = {
"additionalInformationCollection": {
"additionalInformation": [
{
"addInfoName": "referringscenario",
"creationDate": "2017-12-15 11:46:07.993",
"data": "http://localhost:8080/package/5882df9c-dae1-4d80-a40e-db4724271456/scenario/11482bc1-8a0c-44a0-ae8b-5a02ae732559",
"id": "http://localhost:8080/package/5882df9c-dae1-4d80-a40e-db4724271456/infocollection/0f30d0ca-b2bd-4c85-a425-ed8b22d4fed6/referringscenario/41532eac-e04a-4474-937a-df1344c3dce7",
"identifier": "referringscenario",
"lastModified": "2017-12-15 11:46:07.993",
"name": "referringscenario"
},
{
"addInfoName": "halflife",
"creationDate": "2017-12-15 11:46:07.934",
"data": "First Order;;reported,no further information about the model;3690.0 - 3690.0;McCorquodale, G. & Wardrope, L. (2006)",
"id": "http://localhost:8080/package/5882df9c-dae1-4d80-a40e-db4724271456/infocollection/0f30d0ca-b2bd-4c85-a425-ed8b22d4fed6/halflife/8f44fdd9-f453-4ab1-8509-2ee5826faad7",
"identifier": "halflife",
"lastModified": "2020-05-05 17:26:14.753",
"name": "halflife"
}
],
"creationDate": "2017-12-15 11:46:07.608",
"id": "http://localhost:8080/package/5882df9c-dae1-4d80-a40e-db4724271456/infocollection/0f30d0ca-b2bd-4c85-a425-ed8b22d4fed6",
"identifier": "infocollection",
"lastModified": "2020-05-05 17:26:15.496",
"name": "no name"
},
"aliases": [],
"creationDate": "2017-12-15 11:46:08.221",
"date": "no date",
"description": "no description",
"id": "http://localhost:8080/package/5882df9c-dae1-4d80-a40e-db4724271456/scenario/e7089e49-e07d-4a2d-8045-e144b7eb5a5e",
"identifier": "scenario",
"lastModified": "2020-05-05 17:26:15.065",
"name": "McCorquodale, G. & Wardrope, L. (2006) - (00002) (Related Scenario) - (00000)",
"reviewStatus": "reviewed",
"scenarios": [],
"type": "Not specified"
}
def get_additional_information(self):
from envipy_additional_information import NAME_MAPPING
for k, vals in self.additional_information.items():
if k == 'enzyme':
continue
for v in vals:
yield NAME_MAPPING[k](**json.loads(v))
class UserSettingPermission(Permission):
uuid = models.UUIDField(null=False, blank=False, verbose_name='UUID of this object', primary_key=True,