def get_context_data(self, **kwargs): app_id = int(self.request.GET.get("app")) visible_containers = Container.filter_by_user(self.request.user) app_qs = ContainerApp.objects.filter(pk=app_id, container__in=visible_containers) app = app_qs.first() if app is None: raise Http404("ID {} is not accessible".format(app_id)) context = super(ContainerInputList, self).get_context_data(**kwargs) context['app'] = app context['app_url'] = rest_framework.reverse.reverse( str('containerapp-detail'), kwargs=dict(pk=app.pk), request=self.request) context['batch_form'] = BatchForm() context['inputs'] = [ dict(name=arg.name, url=rest_framework.reverse.reverse( str('containerargument-detail'), kwargs=dict(pk=arg.pk), request=self.request)) for arg in app.arguments.filter( type=ContainerArgument.INPUT).order_by('position') ] context['priolist'] = [t[0] for t in settings.SLURM_QUEUES] return context
def get_context_data(self, **kwargs): app_id = int(self.request.GET.get("app")) visible_containers = Container.filter_by_user(self.request.user) app_qs = ContainerApp.objects.filter(pk=app_id, container__in=visible_containers) app = app_qs.first() if app is None: raise Http404("ID {} is not accessible".format(app_id)) context = super(ContainerInputList, self).get_context_data(**kwargs) context['app'] = app context['app_url'] = rest_framework.reverse.reverse( str('containerapp-detail'), kwargs=dict(pk=app.pk), request=self.request) context['batch_form'] = BatchForm() context['inputs'] = [ dict(name=arg.name, url=rest_framework.reverse.reverse( str('containerargument-detail'), kwargs=dict(pk=arg.pk), request=self.request)) for arg in app.arguments.filter( type=ContainerArgument.INPUT).order_by('position')] context['priolist'] = [t[0] for t in settings.SLURM_QUEUES] return context
def filter_granted(self, queryset): """ Args don't have permissions, so filter by parent containers. """ granted_containers = Container.filter_by_user(self.request.user) return queryset.filter(app__container_id__in=granted_containers)
def method_revise(request, pk): """ Add a revision of an existing Method. revision_parent is defined by the previous version. """ t = loader.get_template('method/method.html') c = {} creating_user = request.user # Retrieve the most recent member of this Method's family. parent_method = Method.check_accessible(pk, creating_user) family = parent_method.family # Retrieve the most recent revision of the corresponding CR. parent_revision = parent_method.driver if not parent_revision: this_code_resource = None all_revisions = [] else: this_code_resource = parent_revision.coderesource # Filter the available revisions by user. all_revisions = CodeResourceRevision.filter_by_user( creating_user, queryset=this_code_resource.revisions.all()).order_by( '-revision_DateTime') parent_container = parent_method.container if not parent_container: this_container_family = None all_containers = [] else: this_container_family = parent_container.family all_containers = Container.filter_by_user( creating_user, queryset=this_container_family.containers.all()) if request.method == 'POST': # Because there is no CodeResource specified, the second value is of type MethodReviseForm. family_form, method_revise_form,\ dep_forms, input_form_tuples,\ output_form_tuples, _ = create_method_forms(request.POST, creating_user, family=family) if not _method_forms_check_valid(family_form, method_revise_form, dep_forms, input_form_tuples, output_form_tuples): # Bail out now if there are any problems. c.update({ 'coderesource': this_code_resource, 'containerfamily': this_container_family, 'method_revise_form': method_revise_form, 'dep_forms': dep_forms, 'input_forms': input_form_tuples, 'output_forms': output_form_tuples, 'family': family, 'family_form': family_form, 'parent': parent_method, 'docker_default': DockerImage.DEFAULT_IMAGE }) return HttpResponse(t.render(c, request)) # Next, attempt to build the Method and add it to family. create_method_from_forms(family_form, method_revise_form, dep_forms, input_form_tuples, output_form_tuples, creating_user, family=family, parent_method=parent_method) if _method_forms_check_valid(family_form, method_revise_form, dep_forms, input_form_tuples, output_form_tuples): # Success! return HttpResponseRedirect('/methods/{}'.format(family.pk)) else: # Initialize forms with values of parent Method. family_form = MethodFamilyForm({ "name": family.name, "description": family.description }) parent_users_allowed = [ x.username for x in parent_method.users_allowed.all() ] parent_groups_allowed = [ x.name for x in parent_method.groups_allowed.all() ] method_revise_form = MethodReviseForm( initial={ "revision_desc": parent_method.revision_desc, "driver_revisions": parent_revision and parent_revision.pk, "docker_image": parent_method.docker_image_id, "reusable": parent_method.reusable, "threads": parent_method.threads, "memory": parent_method.memory, "permissions": [parent_users_allowed, parent_groups_allowed] }) dependencies = parent_method.dependencies.all() dep_forms = [] for i, dependency in enumerate(dependencies): its_crv = dependency.requirement its_cr = its_crv.coderesource dep_form = MethodDependencyForm(user=creating_user, auto_id='id_%s_' + str(i), initial={ 'coderesource': its_cr.pk, 'revisions': its_crv.pk, 'path': dependency.path, 'filename': dependency.filename }) dep_forms.append(dep_form) # If the parent Method has no dependencies, add a blank form. if len(dep_forms) == 0: dep_forms.append( MethodDependencyForm(user=creating_user, auto_id='id_%s_0')) xput_forms = [] inputs = parent_method.inputs.order_by("dataset_idx") outputs = parent_method.outputs.order_by("dataset_idx") for xput_type, xputs in (("in", inputs), ("out", outputs)): forms = [] for xput in xputs: tx_form = TransformationXputForm(auto_id='id_%s_{}_{}'.format( xput_type, len(forms)), initial={ 'dataset_name': xput.dataset_name, 'dataset_idx': xput.dataset_idx }) if xput.has_structure: structure = xput.structure xs_form = XputStructureForm( user=creating_user, auto_id='id_%s_{}_{}'.format(xput_type, len(forms)), initial={ 'compounddatatype': structure.compounddatatype.id, 'min_row': structure.min_row, 'max_row': structure.max_row }) else: xs_form = XputStructureForm( user=creating_user, auto_id='id_%s_{}_{}'.format(xput_type, len(forms)), initial={'compounddatatype': '__raw__'}) forms.append((tx_form, xs_form)) xput_forms.append(forms) input_form_tuples, output_form_tuples = xput_forms # if previous Method has no inputs, provide blank forms if len(input_form_tuples) == 0: tx_form = TransformationXputForm(auto_id='id_%s_in_0') xs_form = XputStructureForm(user=creating_user, auto_id='id_%s_in_0') input_form_tuples.append((tx_form, xs_form)) method_revise_form.fields['driver_revisions'].widget.choices = [ (str(x.id), '{}: {}'.format(x.revision_number, x.revision_name)) for x in all_revisions ] method_revise_form.fields['container'].widget.choices = [ (str(x.id), x.tag) for x in all_containers ] c.update({ 'coderesource': this_code_resource, 'containerfamily': this_container_family, 'method_form': method_revise_form, 'dep_forms': dep_forms, 'input_forms': input_form_tuples, 'output_forms': output_form_tuples, 'family': family, 'family_form': family_form, 'parent': parent_method, 'docker_default': DockerImage.DEFAULT_IMAGE }) return HttpResponse(t.render(c, request))
def filter_granted(self, queryset): """ Args don't have permissions, so filter by parent containers. """ granted_containers = Container.filter_by_user(self.request.user) return queryset.filter(app__container_id__in=granted_containers)
def method_revise(request, pk): """ Add a revision of an existing Method. revision_parent is defined by the previous version. """ t = loader.get_template('method/method.html') c = {} creating_user = request.user # Retrieve the most recent member of this Method's family. parent_method = Method.check_accessible(pk, creating_user) family = parent_method.family # Retrieve the most recent revision of the corresponding CR. parent_revision = parent_method.driver if not parent_revision: this_code_resource = None all_revisions = [] else: this_code_resource = parent_revision.coderesource # Filter the available revisions by user. all_revisions = CodeResourceRevision.filter_by_user( creating_user, queryset=this_code_resource.revisions.all()).order_by('-revision_DateTime') parent_container = parent_method.container if not parent_container: this_container_family = None all_containers = [] else: this_container_family = parent_container.family all_containers = Container.filter_by_user( creating_user, queryset=this_container_family.containers.all()) if request.method == 'POST': # Because there is no CodeResource specified, the second value is of type MethodReviseForm. family_form, method_revise_form,\ dep_forms, input_form_tuples,\ output_form_tuples, _ = create_method_forms(request.POST, creating_user, family=family) if not _method_forms_check_valid(family_form, method_revise_form, dep_forms, input_form_tuples, output_form_tuples): # Bail out now if there are any problems. c.update( { 'coderesource': this_code_resource, 'containerfamily': this_container_family, 'method_revise_form': method_revise_form, 'dep_forms': dep_forms, 'input_forms': input_form_tuples, 'output_forms': output_form_tuples, 'family': family, 'family_form': family_form, 'parent': parent_method, 'docker_default': DockerImage.DEFAULT_IMAGE }) return HttpResponse(t.render(c, request)) # Next, attempt to build the Method and add it to family. create_method_from_forms( family_form, method_revise_form, dep_forms, input_form_tuples, output_form_tuples, creating_user, family=family, parent_method=parent_method ) if _method_forms_check_valid(family_form, method_revise_form, dep_forms, input_form_tuples, output_form_tuples): # Success! return HttpResponseRedirect('/methods/{}'.format(family.pk)) else: # Initialize forms with values of parent Method. family_form = MethodFamilyForm({"name": family.name, "description": family.description}) parent_users_allowed = [x.username for x in parent_method.users_allowed.all()] parent_groups_allowed = [x.name for x in parent_method.groups_allowed.all()] method_revise_form = MethodReviseForm( initial={ "revision_desc": parent_method.revision_desc, "driver_revisions": parent_revision and parent_revision.pk, "docker_image": parent_method.docker_image_id, "reusable": parent_method.reusable, "threads": parent_method.threads, "memory": parent_method.memory, "permissions": [parent_users_allowed, parent_groups_allowed] }) dependencies = parent_method.dependencies.all() dep_forms = [] for i, dependency in enumerate(dependencies): its_crv = dependency.requirement its_cr = its_crv.coderesource dep_form = MethodDependencyForm( user=creating_user, auto_id='id_%s_'+str(i), initial={ 'coderesource': its_cr.pk, 'revisions': its_crv.pk, 'path': dependency.path, 'filename': dependency.filename } ) dep_forms.append(dep_form) # If the parent Method has no dependencies, add a blank form. if len(dep_forms) == 0: dep_forms.append(MethodDependencyForm(user=creating_user, auto_id='id_%s_0')) xput_forms = [] inputs = parent_method.inputs.order_by("dataset_idx") outputs = parent_method.outputs.order_by("dataset_idx") for xput_type, xputs in (("in", inputs), ("out", outputs)): forms = [] for xput in xputs: tx_form = TransformationXputForm(auto_id='id_%s_{}_{}'.format(xput_type, len(forms)), initial={'dataset_name': xput.dataset_name, 'dataset_idx': xput.dataset_idx}) if xput.has_structure: structure = xput.structure xs_form = XputStructureForm(user=creating_user, auto_id='id_%s_{}_{}'.format(xput_type, len(forms)), initial={'compounddatatype': structure.compounddatatype.id, 'min_row': structure.min_row, 'max_row': structure.max_row}) else: xs_form = XputStructureForm(user=creating_user, auto_id='id_%s_{}_{}'.format(xput_type, len(forms)), initial={'compounddatatype': '__raw__'}) forms.append((tx_form, xs_form)) xput_forms.append(forms) input_form_tuples, output_form_tuples = xput_forms # if previous Method has no inputs, provide blank forms if len(input_form_tuples) == 0: tx_form = TransformationXputForm(auto_id='id_%s_in_0') xs_form = XputStructureForm(user=creating_user, auto_id='id_%s_in_0') input_form_tuples.append((tx_form, xs_form)) method_revise_form.fields['driver_revisions'].widget.choices = [ (str(x.id), '{}: {}'.format(x.revision_number, x.revision_name)) for x in all_revisions ] method_revise_form.fields['container'].widget.choices = [ (str(x.id), x.tag) for x in all_containers] c.update( { 'coderesource': this_code_resource, 'containerfamily': this_container_family, 'method_form': method_revise_form, 'dep_forms': dep_forms, 'input_forms': input_form_tuples, 'output_forms': output_form_tuples, 'family': family, 'family_form': family_form, 'parent': parent_method, 'docker_default': DockerImage.DEFAULT_IMAGE } ) return HttpResponse(t.render(c, request))