예제 #1
0
    def patch(self, request, *args, **kwargs):
        hostname = self.getParam(request, 'hostname', '')
        product = LogicProducts().get_product(request, False)
        new_status = self.getParam(request, 'status', '')
        instance_id = self.getParam(request, 'instance_id', '')

        if hostname and product and status and instance_id:
            instance = SaasInstance.objects. \
                filter(Q(identifier=instance_id)&Q(hostname=hostname)&Q(product=product)). \
                first()

        if not instance:
            raise Exception(
                'please specify hostname and product_name and instance_id and status'
            )

        if instance.status == instance.IN_PREPARATION and new_status == instance.READY:
            instance.status = new_status
            instance.save()
            return Response({'success': 'true'}, status=status.HTTP_200_OK)

        if instance.status == instance.READY and new_status == instance.AVAILABLE:
            instance.status = new_status
            instance.save()
            return Response({'success': 'true'}, status=status.HTTP_200_OK)

        if instance.status == instance.TO_BE_REMOVED and new_status == instance.REMOVED:
            instance.status = new_status
            instance.save()
            return Response({'success': 'true'}, status=status.HTTP_200_OK)

        raise Exception('unexpected behaviour')
예제 #2
0
def plan_select(request, plan_id):
    product = LogicProducts().get_product(request, False)
    if product is None:
        return redirect('/pricing')
    current_plan = LogicContracts().get_current_plan(request, product)
    if current_plan is None and not product.is_active:
        product = None
    plans = LogicPlans().get_plans(product)

    # the customer has selected a plan
    if plan_id != 'current':
        # check if this is a valid plan
        new_plan = LogicPlans().get_plan(product, plan_id)
        if new_plan.cost_per_period > 0:
            return show_paymentmethod(request, product, current_plan, new_plan)
        else:
            return show_contract(request, product, current_plan, new_plan)

    # load booked plan from the database
    if current_plan:
        plan_id = current_plan.slug
    else:
        plan_id = ''

    return render(request, 'plan.html', {
        'product': product,
        'plans': plans,
        'selected_plan': plan_id
    })
예제 #3
0
def instance_view(request):
    customer = SaasCustomer.objects.filter(user=request.user).first()
    product = LogicProducts().get_product(request, False)
    if product is None:
        return redirect('/pricing')
    contract = LogicContracts().get_contract(customer, product)
    if not contract or not contract.instance:
        return render(
            request, 'error.html',
            {'message': _("Error: no instance has been assigned yet.")})
    url = product.instance_url. \
            replace('#Prefix', product.prefix). \
            replace('#Identifier', contract.instance.identifier)
    pwd_reset_url = product.instance_password_reset_url
    if pwd_reset_url == 'password1':
        # Tryton does not have a password reset functionality for the admin user
        initialadminpassword = contract.instance.password1
        pwd_reset_url = None
    elif pwd_reset_url.startswith('/'):
        pwd_reset_url = url + pwd_reset_url[1:]
    adminuser = product.instance_admin_user
    adminemail = customer.email_address

    return render(
        request, 'instance.html', {
            'instance': contract.instance,
            'instance_url': url,
            'adminuser': adminuser,
            'adminemail': adminemail,
            'initialadminpassword': initialadminpassword,
            'pwd_reset_url': pwd_reset_url
        })
예제 #4
0
    def get(self, request, *args, **kwargs):
        hostname = self.getParam(request, 'hostname', '')
        product = LogicProducts().get_product(request, False)
        action = self.getParam(request, 'action', '')

        if action == "install":
            instance_status = [
                SaasInstance().IN_PREPARATION,
            ]
        elif action == "update" or action == "check" or action == "quota":
            instance_status = [
                SaasInstance().READY,
                SaasInstance().AVAILABLE,
                SaasInstance().RESERVED,
                SaasInstance().ASSIGNED,
                SaasInstance().EXPIRED,
                SaasInstance().TO_BE_REMOVED,
            ]
        elif action == "remove":
            instance_status = [
                SaasInstance().TO_BE_REMOVED,
            ]
        else:
            raise Exception('please specify valid action')

        if hostname and product:
            rows = SaasInstance.objects.filter(
                hostname=hostname, product=product,
                status__in=instance_status).order_by('id')
        else:
            raise Exception('please specify hostname and product_name')
        serializer = InstanceSerializer(rows, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #5
0
파일: views.py 프로젝트: tpokorra/saasadmin
def products(request):
    products = SaasProduct.objects.all()
    product = LogicProducts().get_product(request, False)

    return render(request, "products.html", {
        'products': products,
        'product': product
    })
예제 #6
0
def contract_view(request):
    customer = SaasCustomer.objects.filter(user=request.user).first()
    product = LogicProducts().get_product(request, False)
    contract = LogicContracts().get_contract(customer, product)
    if not contract:
        return redirect("/plan/current")

    return show_contract(request, product, contract.plan, None)
예제 #7
0
def display_pricing(request):
    product = LogicProducts().get_product(request)

    if product is None:
        products = LogicProducts().get_products()
        hostname = request.META['HTTP_HOST']
        if hostname.startswith("www."):
            hostname = hostname.replace('www.', '')
        return render(request, 'select_product.html', {
            'products': products,
            'hostname': hostname
        })

    plans = LogicPlans().get_plans(product)

    return render(request, 'pricing.html', {
        'product': product,
        'plans': plans
    })
예제 #8
0
 def get(self, request, *args, **kwargs):
     hostname = self.getParam(request, 'hostname', '')
     product = LogicProducts().get_product(request, False)
     if hostname and product:
         rows = SaasInstance.objects.filter(hostname=hostname,
                                            product=product).order_by('id')
     else:
         raise Exception('please specify hostname and product_name')
     serializer = InstanceSerializer(rows, many=True)
     return Response(serializer.data, status=status.HTTP_200_OK)
예제 #9
0
파일: views.py 프로젝트: tpokorra/saasadmin
def instance_view(request):
    logic = LogicCustomers()
    customer = SaasCustomer.objects.filter(user=request.user).first()
    product = LogicProducts().get_product(request)
    contract = logic.get_contract(customer, product)
    if not contract:
        return render(
            request, 'error.html',
            {'message': _("Error: no instance has been assigned yet.")})
    return render(request, 'instance.html', {'instance': contract.instance})
예제 #10
0
    def put(self, request, *args, **kwargs):
        hostname = self.getParam(request, 'hostname', '')
        product = LogicProducts().get_product(request, False)

        if hostname and product:
            success, new_data = LogicInstances().create_new_instance(
                hostname, product)
            if success:
                return Response(new_data, status=status.HTTP_201_CREATED)
        else:
            raise Exception('please specify hostname and product_name')

        raise Exception('could not create new instance')
예제 #11
0
def paymentmethod_select(request):
    product = LogicProducts().get_product(request, False)
    customer = SaasCustomer.objects.filter(user=request.user).first()

    if request.method == "POST":
        values = request.POST.copy()
        contract = LogicContracts().get_contract(customer, product)
        new_plan = LogicPlans().get_plan(product, values["plan"])
        if not contract:
            contract = LogicContracts().get_new_contract(
                customer, product, new_plan)

        contract.payment_method = values["payment_method"]
        contract.account_owner = values['account_owner']
        contract.account_iban = values['account_iban']
        if contract.payment_method == "SEPA_DIRECTDEBIT":
            if not contract.account_owner or not contract.account_iban:
                error = _("Please specify account owner and IBAN")
                return show_paymentmethod(request, product, None, None, error)

            contract.sepa_mandate_date = datetime.today()
            # TODO: something with prefixinstance_idyyyymmdd?
            contract.sepa_mandate = 'TODO'
        else:
            contract.sepa_mandate_date = None
            contract.sepa_mandate = ''
        contract.save()

        if not contract.is_confirmed or contract.plan.slug != new_plan.slug:
            return show_contract(request, product, contract.plan, new_plan)

        # confirm to user that storing worked
        return show_paymentmethod(request,
                                  product,
                                  contract.plan,
                                  None,
                                  successmessage=_("Changes Saved"))

    current_plan = LogicContracts().get_current_plan(request, product)
    if current_plan is None:
        return redirect('/plan/current')
    return show_paymentmethod(request, product, current_plan, None)
예제 #12
0
    def patch(self, request, *args, **kwargs):
        hostname = self.getParam(request, 'hostname', '')
        product = LogicProducts().get_product(request, False)
        new_status = self.getParam(request, 'status', '')
        instance_id = self.getParam(request, 'instance_id', '')

        if hostname and product and status and instance_id:
            instance = SaasInstance.objects. \
                filter(Q(identifier=instance_id)&Q(hostname=hostname)&Q(product=product)&Q(status='in_preparation')). \
                first()

        if not instance:
            raise Exception(
                'please specify hostname and product_name and instance_id and status'
            )

        if instance.status == 'in_preparation' and new_status == 'free':
            instance.status = 'free'
            instance.save()
            return Response({'success': 'true'}, status=status.HTTP_200_OK)

        raise Exception('unexpected behaviour')
예제 #13
0
파일: views.py 프로젝트: tpokorra/saasadmin
def select_plan(request, plan_id):
    product = LogicProducts().get_product(request)
    current_plan = LogicContracts().get_current_plan(request, product)
    plans = LogicPlans().get_plans(product)

    # the customer has selected a plan
    if plan_id != 'current':
        # check if this is a valid plan
        new_plan = LogicPlans().get_plan(product, plan_id)
        return show_payment(request, product, current_plan, new_plan)

    # load booked plan from the database
    if current_plan:
        plan_id = current_plan.name
    else:
        plan_id = ''

    return render(request, 'plan.html', {
        'product': product,
        'plans': plans,
        'selected_plan': plan_id
    })
예제 #14
0
파일: views.py 프로젝트: tpokorra/saasadmin
def select_payment(request):
    product = LogicProducts().get_product(request)
    current_plan = LogicContracts().get_current_plan(request, product)
    if current_plan is None:
        return redirect('/plan/current')
    return show_payment(request, product, current_plan, None)