def load(self, request, project_id, model_id): HasProject.load(self, request, project_id) try: model = LogicalModel.objects.get(id=model_id) if model.project != self.project: raise PermissionDenied self.model = model except LogicalModel.DoesNotExist: raise NotFound
def load(self, request, project_id, simulation_id): HasProject.load(self, request, project_id) try: simulation = MaBoSSSimulation.objects.get(id=simulation_id) if simulation.project != self.project: raise PermissionDenied self.simulation = simulation except MaBoSSSimulation.DoesNotExist: raise NotFound
def delete(self, request, project_id, model_id): HasProject.load(self, request, project_id) try: model = LogicalModel.objects.get(id=model_id) if model.project != self.project: raise PermissionDenied model.delete() except LogicalModel.DoesNotExist: raise NotFound return Response(status=status.HTTP_200_OK)
def load(self, request, project_id, analysis_id): if request.user.is_anonymous: raise PermissionDenied HasProject.load(self, request, project_id) try: analysis = MaBoSSSensitivityAnalysis.objects.get(id=analysis_id) if analysis.project != self.project: raise PermissionDenied self.analysis = analysis except MaBoSSSensitivityAnalysis.DoesNotExist: raise NotFound
def get(self, request, project_id, model_id=None): HasProject.load(self, request, project_id) try: if model_id is None: models = LogicalModel.objects.filter(project=self.project) serializer = LogicalModelSerializer(models, many=True) return Response(serializer.data) else: model = LogicalModel.objects.get(id=model_id) if model.project != self.project: raise PermissionDenied serializer = LogicalModelSerializer(model) return Response(serializer.data) except LogicalModel.DoesNotExist: raise NotFound
def post(self, request, project_id): HasProject.load(self, request, project_id) # try: if 'url' in request.data.keys(): print(request.data['url']) if request.data['url'].startswith("https://www.ebi.ac.uk"): zip_filename = tempfile.mkstemp(suffix=".zip") os.close(zip_filename[0]) urlretrieve(request.data['url'], zip_filename[1]) with zipfile.ZipFile(zip_filename[1], 'r') as zip_file: temp_dir = tempfile.mkdtemp() zip_file.extract(zip_file.namelist()[0], temp_dir) (bnd_file, cfg_file, layout_file) = sbml_to_maboss( os.path.join(temp_dir, zip_file.namelist()[0]), request.data['use_sbml_names'].lower() == "true") new_model = LogicalModel( project=self.project, name=request.data['name'], bnd_file=File(open(bnd_file, 'rb'), name=os.path.basename(bnd_file)), cfg_file=File(open(cfg_file, 'rb'), name=os.path.basename(cfg_file)), layout_file=File(open(layout_file, 'rb'), name=os.path.basename(layout_file)) if layout_file is not None else None, format=LogicalModel.MABOSS).save() os.remove(bnd_file) os.remove(cfg_file) if layout_file is not None: os.remove(layout_file) shutil.rmtree(temp_dir) os.remove(zip_filename[1]) else: sbml_file = tempfile.mkstemp(suffix=".sbml") os.close(sbml_file[0]) urlretrieve(request.data['url'], sbml_file[1]) (bnd_file, cfg_file, layout_file) = sbml_to_maboss( sbml_file[1], request.data['use_sbml_names'].lower() == "true") new_model = LogicalModel( project=self.project, name=request.data['name'], bnd_file=File(open(bnd_file, 'rb'), name=os.path.basename(bnd_file)), cfg_file=File(open(cfg_file, 'rb'), name=os.path.basename(cfg_file)), layout_file=File(open(layout_file, 'rb'), name=os.path.basename(layout_file)) if layout_file is not None else None, format=LogicalModel.MABOSS).save() os.remove(bnd_file) os.remove(cfg_file) if layout_file is not None: os.remove(layout_file) os.remove(sbml_file[1]) elif 'file2' in request.data.keys(): LogicalModel(project=self.project, name=request.data['name'], bnd_file=request.data['file'], cfg_file=request.data['file2'], format=LogicalModel.MABOSS).save() elif request.data['file'].name.endswith(".zginml"): ginsim_file = tempfile.mkstemp(suffix=".zginml") with open(ginsim_file[0], 'wb') as f: f.write(request.data['file'].read()) bnd_file, cfg_file = ginsim_to_maboss(ginsim_file[1]) LogicalModel(project=self.project, name=request.data['name'], bnd_file=File(open(bnd_file, 'rb'), name=os.path.basename(bnd_file)), cfg_file=File(open(cfg_file, 'rb'), name=os.path.basename(cfg_file)), format=LogicalModel.MABOSS).save() elif request.data['file'].name.endswith(".bnet"): bnet_file = tempfile.mkstemp(suffix=".bnet") with open(bnet_file[0], 'wb') as f: f.write(request.data['file'].read()) bnd_file, cfg_file = bnet_to_maboss(bnet_file[1]) LogicalModel(project=self.project, name=request.data['name'], bnd_file=File(open(bnd_file, 'rb'), name=os.path.basename(bnd_file)), cfg_file=File(open(cfg_file, 'rb'), name=os.path.basename(cfg_file)), format=LogicalModel.MABOSS).save() else: sbml_file = tempfile.mkstemp(suffix=".sbml") with open(sbml_file[0], 'wb') as f: f.write(request.data['file'].read()) bnd_file, cfg_file, layout_file = sbml_to_maboss( sbml_file[1], request.data['use_sbml_names'].lower() == "true") LogicalModel(project=self.project, name=request.data['name'], bnd_file=File(open(bnd_file, 'rb'), name=os.path.basename(bnd_file)), cfg_file=File(open(cfg_file, 'rb'), name=os.path.basename(cfg_file)), layout_file=File(open(layout_file, 'rb'), name=os.path.basename(layout_file)) if layout_file is not None else None, format=LogicalModel.MABOSS).save() os.remove(bnd_file) os.remove(cfg_file) if layout_file is not None: os.remove(layout_file) os.remove(sbml_file[1]) return Response(status=status.HTTP_200_OK)
def __init__(self, *args, **kwargs): HasProject.__init__(self, *args, **kwargs) self.model = None
def __init__(self, *args, **kwargs): HasProject.__init__(self, *args, **kwargs) self.analysis = None
def __init__(self, *args, **kwargs): HasProject.__init__(self, *args, **kwargs) self.simulation = None