forked from enviPath/enviPy
wip
This commit is contained in:
@ -8,9 +8,12 @@ from django.shortcuts import redirect
|
||||
|
||||
from bayer.models import PESCompound
|
||||
from epdb.logic import PackageManager
|
||||
from epdb.models import Pathway, Node
|
||||
from epdb.views import _anonymous_or_real
|
||||
from utilities.decorators import package_permission_required
|
||||
|
||||
Package = s.GET_PACKAGE_MODEL()
|
||||
|
||||
|
||||
@package_permission_required()
|
||||
def create_pes(request, package_uuid):
|
||||
@ -18,6 +21,10 @@ def create_pes(request, package_uuid):
|
||||
current_package = PackageManager.get_package_by_id(current_user, package_uuid)
|
||||
|
||||
if request.method == "POST":
|
||||
|
||||
if current_package.classification_level == Package.Classification.INTERNAL:
|
||||
raise BadRequest("Cannot create PESs for internal packages.")
|
||||
|
||||
compound_name = request.POST.get('compound-name')
|
||||
compound_description = request.POST.get('compound-description')
|
||||
pes_link = request.POST.get('pes-link')
|
||||
@ -28,6 +35,14 @@ def create_pes(request, package_uuid):
|
||||
except ValueError as e:
|
||||
return BadRequest(f"Could not fetch PES data for {pes_link}")
|
||||
|
||||
classification = pes_data.get("classificationLevel", "")
|
||||
if "secret" == classification.lower():
|
||||
data_pools = pes_data.get("dataPools")
|
||||
if data_pools:
|
||||
if s.DATA_POOL_MAPPING[current_package.data_pool.name] not in data_pools:
|
||||
return BadRequest(
|
||||
f"PES data pool {s.DATA_POOL_MAPPING[current_package.data_pool.name]} not found in PES data")
|
||||
|
||||
pes = PESCompound.create(current_package, pes_data, compound_name, compound_description)
|
||||
|
||||
return redirect(pes.url)
|
||||
@ -37,6 +52,55 @@ def create_pes(request, package_uuid):
|
||||
pass
|
||||
|
||||
|
||||
@package_permission_required()
|
||||
def create_pes_node(request, package_uuid, pathway_uuid):
|
||||
current_user = _anonymous_or_real(request)
|
||||
current_package = PackageManager.get_package_by_id(current_user, package_uuid)
|
||||
current_pathway = Pathway.objects.get(package=current_package, uuid=pathway_uuid)
|
||||
|
||||
if request.method == "POST":
|
||||
|
||||
if current_package.classification_level == Package.Classification.INTERNAL:
|
||||
raise BadRequest("Cannot create PESs for internal packages.")
|
||||
|
||||
compound_name = request.POST.get('compound-name')
|
||||
compound_description = request.POST.get('compound-description')
|
||||
pes_link = request.POST.get('pes-link')
|
||||
|
||||
if pes_link:
|
||||
try:
|
||||
pes_data = fetch_pes(request, pes_link)
|
||||
except ValueError as e:
|
||||
return BadRequest(f"Could not fetch PES data for {pes_link}")
|
||||
|
||||
classification = pes_data.get("classificationLevel", "")
|
||||
if "secret" == classification.lower():
|
||||
data_pools = pes_data.get("dataPools")
|
||||
if data_pools:
|
||||
if s.DATA_POOL_MAPPING[current_package.data_pool.name] not in data_pools:
|
||||
return BadRequest(
|
||||
f"PES data pool {s.DATA_POOL_MAPPING[current_package.data_pool.name]} not found in PES data")
|
||||
|
||||
pes = PESCompound.create(current_package, pes_data, compound_name, compound_description)
|
||||
|
||||
n = Node()
|
||||
n.stereo_removed = False
|
||||
n.pathway = current_pathway
|
||||
n.depth = 0
|
||||
|
||||
n.default_node_label = pes.default_structure
|
||||
n.save()
|
||||
|
||||
n.node_labels.add(pes.default_structure)
|
||||
n.save()
|
||||
|
||||
return redirect(current_pathway.url)
|
||||
|
||||
else:
|
||||
return BadRequest("Please provide a PES link.")
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
def fetch_pes(request, pes_url) -> dict:
|
||||
proxies = {
|
||||
|
||||
Reference in New Issue
Block a user