Scenario Import + Gitea PR Test (#1)

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#1
This commit is contained in:
2025-06-24 23:56:45 +12:00
parent 843e8e6f07
commit 7c3bc69b38
4 changed files with 66 additions and 33 deletions

View File

@ -3,7 +3,7 @@ import json
import logging import logging
import os import os
from collections import defaultdict from collections import defaultdict
from datetime import datetime, timedelta from datetime import datetime, timedelta, date
from typing import Union, List, Optional from typing import Union, List, Optional
from uuid import uuid4 from uuid import uuid4
@ -1343,14 +1343,38 @@ class PluginModel(EPModel):
# # # TODO consider Scenario, BaseScenario, RelatedScenario # # # TODO consider Scenario, BaseScenario, RelatedScenario
class Scenario(EnviPathModel): class Scenario(EnviPathModel):
package = models.ForeignKey('epdb.Package', verbose_name='Package', on_delete=models.CASCADE, db_index=True) package = models.ForeignKey('epdb.Package', verbose_name='Package', on_delete=models.CASCADE, db_index=True)
date = models.DateField(null=True, verbose_name='Study date') 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') type = models.CharField(max_length=256, null=False, blank=False, default='Not specified')
additional_information = models.JSONField(verbose_name='Additional Information') additional_information = models.JSONField(verbose_name='Additional Information')
@property
def url(self): def url(self):
return '{}/scenario/{}'.format(self.package.url, self.uuid) return '{}/scenario/{}'.format(self.package.url, self.uuid)
@staticmethod
@transaction.atomic
def create(package, name, description, date, type, additional_information):
s = Scenario()
s.package = package
s.name = name
s.description = description
s.date = date
s.type = type
s.additional_information = additional_information
s.save()
return s
def add_additional_information(self, data):
pass
def remove_additional_information(self, data):
pass
def set_additional_information(self, data):
pass
example = { example = {
"additionalInformationCollection": { "additionalInformationCollection": {

View File

@ -59,8 +59,8 @@ urlpatterns = [
# re_path(rf'^package/(?P<package_uuid>{UUID})/pathway(?P<pathway_uuid>{UUID})/edge$', v.package_pathway_edges, name='package pathway edge list'), # re_path(rf'^package/(?P<package_uuid>{UUID})/pathway(?P<pathway_uuid>{UUID})/edge$', v.package_pathway_edges, name='package pathway edge list'),
# re_path(rf'^package/(?P<package_uuid>{UUID})/pathway(?P<pathway_uuid>{UUID})/edge/(?P<edge_uuid>{UUID})$', v.package_pathway_edge, name='package pathway edge detail'), # re_path(rf'^package/(?P<package_uuid>{UUID})/pathway(?P<pathway_uuid>{UUID})/edge/(?P<edge_uuid>{UUID})$', v.package_pathway_edge, name='package pathway edge detail'),
# Scenario # Scenario
# re_path(rf'^package/(?P<package_uuid>{UUID})/scenario', v.package_scenarios, name='package scenario list'), re_path(rf'^package/(?P<package_uuid>{UUID})/scenario$', v.package_scenarios, name='package scenario list'),
# re_path(rf'^package/(?P<package_uuid>{UUID})/scenario/(?P<scenario_uuid>{UUID})$', v.package_scenarios, name='package scenario detail'), re_path(rf'^package/(?P<package_uuid>{UUID})/scenario/(?P<scenario_uuid>{UUID})$', v.package_scenario, name='package scenario detail'),
# Model # Model
re_path(rf'^package/(?P<package_uuid>{UUID})/model$', v.package_models, name='package model list'), re_path(rf'^package/(?P<package_uuid>{UUID})/model$', v.package_models, name='package model list'),
re_path(rf'^package/(?P<package_uuid>{UUID})/model/(?P<model_uuid>{UUID})$', v.package_model,name='package model detail'), re_path(rf'^package/(?P<package_uuid>{UUID})/model/(?P<model_uuid>{UUID})$', v.package_model,name='package model detail'),

View File

@ -1007,35 +1007,44 @@ def package_pathway_node(request, package_uuid, pathway_uuid, node_uuid):
# # pass # # pass
# # # #
# # # #
# # https://envipath.org/package/<id>/scenario # https://envipath.org/package/<id>/scenario
# def package_scenarios(request, package_id): def package_scenarios(request, package_uuid):
# current_user = _anonymous_or_real(request) current_user = _anonymous_or_real(request)
# current_package = PackageManager.get_package_by_id(current_user, package_uuid)
# if request.method == 'GET':
# context = get_base_context(request)
# current_package = PackageManager.get_package_by_id(current_user, package_id)
# context['meta']['current_package'] = current_package
# context['object_type'] = 'scenario'
#
# reviewed_scenario_qs = Scenario.objects.none()
# unreviewed_scenario_qs = Scenario.objects.none()
#
# current_package = PackageManager.get_package_by_id(current_user, package_id)
# if current_package.reviewed:
# reviewed_scenario_qs = Scenario.objects.filter(package=current_package).order_by('name')
# else:
# unreviewed_scenario_qs = Scenario.objects.filter(package=current_package).order_by('name')
#
# context['reviewed_objects'] = reviewed_scenario_qs
# context['unreviewed_objects'] = unreviewed_scenario_qs
#
# return render(request, 'collections/objects_list.html', context)
# #
# #
# # # https://envipath.org/package/<id>/scenario/<id>
# # def package_scenario(request, package_id, scenario_id):
# # pass
if request.method == 'GET':
context = get_base_context(request)
context['title'] = f'enviPath - {current_package.name} - Scenarios'
context['meta']['current_package'] = current_package
context['object_type'] = 'scenario'
context['breadcrumbs'] = breadcrumbs(current_package, 'pathway')
reviewed_scenario_qs = Scenario.objects.none()
unreviewed_scenario_qs = Scenario.objects.none()
if current_package.reviewed:
reviewed_scenario_qs = Scenario.objects.filter(package=current_package).order_by('name')
else:
unreviewed_scenario_qs = Scenario.objects.filter(package=current_package).order_by('name')
if request.GET.get('all'):
return JsonResponse({
"objects": [
{"name": pw.name, "url": pw.url, "reviewed": current_package.reviewed}
for pw in (reviewed_scenario_qs if current_package.reviewed else unreviewed_scenario_qs)
]
})
context['reviewed_objects'] = reviewed_scenario_qs
context['unreviewed_objects'] = unreviewed_scenario_qs
return render(request, 'collections/objects_list.html', context)
# https://envipath.org/package/<id>/scenario/<id>
def package_scenario(request, package_uuid, scenario_uuid):
pass
### END UNTESTED ### END UNTESTED

View File

@ -5,7 +5,7 @@
{% if reviewed_objects.count > 50 or unreviewed_objects.count > 50 %} {% if reviewed_objects.count > 50 or unreviewed_objects.count > 50 %}
{% if object_type != 'package' %} {% if object_type != 'package' %}
<div id="load-remaining-button-div"> <div id="load-remaining-button-div">
<button class="btn btn-secondary btn-lg btn-block" type="button" id="load-remaining">Load all {{ reviewed_objects.count }} {{ object_type }}s <button class="btn btn-secondary btn-lg btn-block" type="button" id="load-remaining">Load all {% if reviewed_objects.count > 0 %} {{ reviewed_objects.count }} {% else %} {{ unreviewed_objects.count }} {% endif %} {{ object_type }}s
</button> </button>
<p></p> <p></p>
<div id="load-all-loading"></div> <div id="load-all-loading"></div>