Exemplo n.º 1
0
 def test_create_profile(self, user):
     profile = Profile.objects.create(user=user, is_active=True)
     assert profile
     assert profile.user == user
     assert profile.is_active == True
     assert is_profile_active(user) == True
     profile.is_active = False
     assert profile.is_active == False
     assert is_profile_active(user) == False
Exemplo n.º 2
0
 def user_can_run(self, user, project):
     """
     The user_can_run method determines if the user has sufficient
     credentials for running this model. The result of this method is
     used to determine which buttons and information is displayed to the
     user regarding their credential status (not logged in v. logged in
     without payment v. logged in with payment). Note that this is actually
     enforced by RequiresLoginInputsView and RequiresPmtView.
     """
     # only requires login and active account.
     if project.sponsor is not None:
         return user.is_authenticated and is_profile_active(user)
     else:  # requires payment method too.
         return (user.is_authenticated and is_profile_active(user)
                 and has_payment_method(user))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def project_context(self, request, project):
        user = request.user
        can_run = user.is_authenticated and is_profile_active(user)
        provided_free = project.sponsor is not None
        can_run = can_run or provided_free
        rate = round(project.server_cost, 2)
        exp_cost, exp_time = project.exp_job_info(adjust=True)

        context = {
            "rate": f"${rate}/hour",
            "project_name": project.title,
            "owner": project.owner.user.username,
            "app_description": project.safe_description,
            "can_run": can_run,
            "exp_cost": f"${exp_cost}",
            "exp_time": f"{exp_time} seconds",
            "provided_free": provided_free,
            "app_url": project.app_url,
        }
        return context