Exemple #1
0
 def get_project(self, username, title, **kwargs):
     return get_project_or_404(
         Project.objects.all(),
         user=self.request.user,
         title__iexact=title,
         owner__user__username__iexact=username,
     )
    def get(self, request, *args, **kwargs):
        print("viz method=GET", request.GET)
        project = get_project_or_404(
            self.model.objects.all(),
            user=request.user,
            owner__user__username__iexact=kwargs["username"],
            title__iexact=kwargs["title"],
        )
        if project.tech == "python-paramtools":
            return redirect(f"/{project.owner}/{project.title}/new/")

        deployment_name = kwargs.get("rd_name", "default")
        if re.search(kubernetes_name_exp, deployment_name):
            raise Http404()
        context = self.project_context(request, project)
        if is_profile_active(request.user):
            owner = request.user.profile
        else:
            owner = None
        try:
            deployment, _ = Deployment.objects.get_or_create_deployment(
                project=project, name=deployment_name, owner=owner
            )
        except DeploymentException:
            raise Http404("Viz apps must have a sponsor.")
        context["show_readme"] = False
        context["tech"] = project.tech
        context["object"] = project
        context["deployment"] = deployment
        context["viz_host"] = project.cluster.viz_host or DEFAULT_VIZ_HOST
        context["protocol"] = "https"
        return render(request, self.template_name, context)
 def get(self, request, *args, **kwargs):
     print("method=GET", request.GET, kwargs)
     project = get_project_or_404(
         self.projects,
         user=request.user,
         owner__user__username__iexact=kwargs["username"],
         title__iexact=kwargs["title"],
     )
     context = self.project_context(request, project)
     context["show_readme"] = True
     return render(request, self.template_name, context)
 def post(self, request, *args, **kwargs):
     project = get_project_or_404(
         self.projects,
         user=request.user,
         owner__user__username__iexact=kwargs["username"],
         title__iexact=kwargs["title"],
     )
     sim = Simulation.objects.new_sim(user=request.user, project=project)
     context = {"request": request}
     data = {
         "inputs": InputsSerializer(sim.inputs, context=context).data,
         "sim": SimulationSerializer(sim, context=context).data,
     }
     return Response(data, status=status.HTTP_201_CREATED)
 def post(self, request, *args, **kwargs):
     project = get_project_or_404(
         self.queryset,
         user=request.user,
         owner__user__username__iexact=kwargs["username"],
         title__iexact=kwargs["title"],
     )
     # Setting inputs_status="PENDING" ensures that each request
     # creates a new simulation. This is necessary if a user is submitting
     # a batch of simulations.
     sim = Simulation.objects.new_sim(request.user,
                                      project,
                                      inputs_status="PENDING")
     return submit(request, status.HTTP_201_CREATED, project, sim)
 def handle(self, request, action, *args, **kwargs):
     print("router handle", args, kwargs)
     project = get_project_or_404(
         self.projects,
         user=request.user,
         owner__user__username__iexact=kwargs["username"],
         title__iexact=kwargs["title"],
     )
     if project.status == "running":
         if project.sponsor is None:
             return self.payment_view.as_view()(request, *args, **kwargs)
         else:
             return self.login_view.as_view()(request, *args, **kwargs)
     else:
         raise Http404()
 def get(self, request, *args, **kwargs):
     print("method=GET", request.GET, kwargs)
     project = get_project_or_404(
         self.projects,
         user=self.request.user,
         owner__user__username__iexact=kwargs["username"],
         title__iexact=kwargs["title"],
     )
     if project.status != "running":
         return redirect(project.app_url)
     context = self.project_context(request, project)
     context["show_readme"] = False
     context["tech"] = project.tech
     if request.user.is_authenticated and getattr(request.user, "profile", None):
         sim = Simulation.objects.new_sim(user=request.user, project=project)
         return redirect(sim.get_absolute_edit_url())
     else:
         return render(request, self.template_name, context)
    def get_inputs(self, kwargs, meta_parameters=None):
        project = get_project_or_404(
            self.queryset,
            user=self.request.user,
            owner__user__username__iexact=kwargs["username"],
            title__iexact=kwargs["title"],
        )
        ioutils = get_ioutils(project)
        try:
            defaults = ioutils.model_parameters.defaults(meta_parameters)
        except NotReady:
            print("NOT READY")
            return Response(status=202)
        except pt.ValidationError as e:
            return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
        if "year" in defaults["meta_parameters"]:
            defaults.update({"extend": True})

        return Response(defaults)