コード例 #1
0
ファイル: process.py プロジェクト: trb116/pythonanalyzer
 def is_completed(self):
     customer = customer_from_request(self.request)
     return (self.order.pk is not None
             or customer is not None and customer.is_authenticated())
コード例 #2
0
ファイル: views.py プロジェクト: adaptivdesign/django-sellmo
def _get_customer(request):
    customer = customer_from_request(request)
    if customer is None:
        raise PermissionDenied()
    return customer
コード例 #3
0
 def is_completed(self):
     customer = customer_from_request(self.request)
     return (
         self.order.pk is not None or customer is not None and
         customer.is_authenticated()
     )
コード例 #4
0
ファイル: views.py プロジェクト: trb116/pythonanalyzer
def _get_customer(request):
    customer = customer_from_request(request)
    if customer is None:
        raise PermissionDenied()
    return customer
コード例 #5
0
ファイル: views.py プロジェクト: adaptivdesign/django-sellmo
def registration(request, step=None, **kwargs):

    customer = customer_from_request(request)
    if request.user.is_authenticated():
        user = request.user
    else:
        user = apps.get_model(settings.AUTH_USER_MODEL)()
    customer.user = user

    data = request.POST if request.method == 'POST' else None

    process = get_registration_process(request, customer)

    # If a step is given, attempt to go to the given step
    if step:
        try:
            process.step_to(step)
        except ProcessStepNotFound:
            # If the step can not be found, fall back to
            # the latest step.
            step = None
        except ProcessError as error:
            raise Http404(error)

    # Go to the latest step
    if not step:
        try:
            process.step_to_latest()
        except ProcessError as error:
            raise Http404(error)

        # Create the redirection
        yield redirect(
            reverse(
                'account:registration',
                kwargs={'step': process.current_step.key},
                current_app=resolve(request.path).namespace
            )
        )

    elif data:
        # Perform atomic transactions at this point
        with transaction.atomic():
            if process.feed(data):
                # Update customer
                user = customer.user
                user.save()
                customer.user = user
                customer.save()

                # Process step was successfull, redirect to next
                # step
                if not process.is_completed():
                    # Go to the next step
                    yield redirect(
                        reverse(
                            'account:registration',
                            kwargs={'step': process.current_step.key},
                            current_app=resolve(request.path).namespace
                        )
                    )

        # See if we completed the process
        if process.is_completed():
            # Assign last completed order
            order = completed_order_from_request(request)
            if order is not None:
                order.customer = customer
                order.save()

            # Redirect to login view
            yield redirect(
                reverse(
                    request.POST.get(
                        'next',
                        request.GET.get('next', LOGIN_VIEW))
                )
            )

    yield chaining.update(
        customer=customer,
        process=process)

    if (yield chaining.forward).result is None:
        context = {'customer': customer}
        try:
            result = process.render(request, context=context)
        except ProcessError as error:
            raise Http404(error)

        if result is None:
            raise ViewNotImplemented