示例#1
0
def machine__login_user(request, user_token=""):
    machine = get_machine_from_session(request)
    if machine is None:
        return find_session_redirect(machine)
    if machine.current_session is not None:
        return find_session_redirect(machine)

    user_profile, error = get_profile_from_post(request)

    if user_profile is None and user_token != "":
        user_profile, error = get_profile_from_url_token(user_token)

    if user_profile is not None:
        if machine.user_is_allowed(user_profile.user):
            machinesession = models.MachineSession()
            machinesession.machine = machine
            machinesession.user = user_profile.user
            machinesession.save()
            machine.current_session = machinesession
            machine.save()
            return find_session_redirect(machine)
        else:
            error = "user_not_allowed"

    return HttpResponse(
        loader.get_template('machine/login_user.html').render(
            {
                "machine": machine,
                "last_error": error,
            }, request))
示例#2
0
文件: info.py 项目: makerhafen/MAAPS
def pos__info(request):
    user_profile, error = get_profile_from_post(request)
    template = loader.get_template('pos/info.html')
    return HttpResponse(template.render({
        "user_profile": user_profile,
        "last_error": error,
    }, request))
示例#3
0
def pos__deposit(request):
    admin_profile = get_profile_from_session(request)
    if admin_profile is None:
        return redirect('pos__index')
    if not admin_profile.user.is_staff:  # this page is only allowed by admin
        request.session["profile_id"] = None
        return redirect('pos__index')

    transaction = None
    value_before_payment = None
    error = None
    deposit_value = request.POST.get("deposit_value", None)
    if deposit_value is not None:
        deposit_value = float(deposit_value)
        if deposit_value <= 0:
            error = "invalid_deposit_value"
        else:
            user_profile, error = get_profile_from_post(request)
            if user_profile is not None:
                value_before_payment = user_profile.prepaid_deposit
                transaction, invoice = pay_prepaid_deposit(user_profile, deposit_value, models.TransactionType.from_cash_for_deposit)

    template = loader.get_template('pos/deposit.html')
    return HttpResponse(template.render({
        "transaction": transaction,
        "last_error": error,
        "value_before_payment": value_before_payment
    }, request))
示例#4
0
def pos__payment(request):
    payment, transaction = None, None
    error = None
    value_before_payment = None

    payment_value = request.POST.get("payment_value", None)
    if payment_value is not None:
        payment_value = float(payment_value)
        if payment_value <= 0:
            error = "invalid_payment_value"
        else:
            user_profile, error = get_profile_from_post(request)
            if user_profile is not None:
                paying_user_profile = user_profile
                if user_profile.paying_user is not None:  # read user via card, his paying user pays
                    paying_user_profile = user_profile.paying_user
                payment, transaction = create_material_payment(
                    payment_value, paying_user_profile, user_profile, None)

    template = loader.get_template('pos/payment.html')
    return HttpResponse(
        template.render(
            {
                "payment": payment,
                "transaction": transaction,
                "last_error": error,
                "value_before_payment": value_before_payment
            }, request))
示例#5
0
def machine__tutor_required(request):
    machine = get_machine_from_session(request)
    if machine is None:
        return find_session_redirect(machine)

    tutor_profile, error = get_profile_from_post(request)
    if tutor_profile is not None:
        if machine.user_can_tutor(tutor_profile.user):
            machine.current_session.tutor = tutor_profile.user
            machine.current_session.save()
            return find_session_redirect(machine)
        else:
            error = "tutor_not_allowed"

    machine_usage_count = machine.count_usages(machine.current_session.user)

    return HttpResponse(
        loader.get_template('machine/tutor_required.html').render(
            {
                "machine":
                machine,
                "machine_usage_count":
                machine_usage_count,
                "tutor_required":
                machine.user_requires_tutor(machine.current_session.user),
                "tutor_required_once":
                machine.user_requires_tutor_once(machine.current_session.user),
                "last_error":
                error,
            }, request))
示例#6
0
def machine__pay_material(request, user_token=""):
    machine = get_machine_from_session(request)
    if machine is None:
        return find_session_redirect(machine)

    payment, transaction = None, None
    error = None
    value_before_payment = None

    payment_value = request.POST.get("payment_value", None)
    if payment_value is not None:
        payment_value = float(payment_value)
        if payment_value > 0.001:
            user_profile, error = get_profile_from_post(request)
            if user_profile is not None:
                if user_profile.paying_user is not None:
                    paying_user_profile = user_profile.paying_user
                else:
                    paying_user_profile = user_profile

                value_before_payment = paying_user_profile.prepaid_deposit
                payment, transaction = create_material_payment(
                    payment_value, paying_user_profile, user_profile, machine)

    template = loader.get_template('machine/pay_material.html')
    return HttpResponse(
        template.render(
            {
                "machine": machine,
                "payment": payment,
                "transaction": transaction,
                "last_error": error,
                "value_before_payment": value_before_payment
            }, request))
示例#7
0
def pos__login_staff(request, user_token=""):
    admin_profile = get_profile_from_session(request)
    error = None
    if admin_profile is None:
        profile, error = get_profile_from_post(request)
        if profile is None and user_token != "":
            profile, error = get_profile_from_url_token(user_token)

        if profile is not None:
            if profile.user.is_staff:
                request.session["profile_id"] = profile.id
                return redirect('pos__index')
            else:
                error = "user_is_not_staff"
    else:
        return redirect('pos__index')

    template = loader.get_template('pos/login_staff.html')
    return HttpResponse(
        template.render({
            "admin_profile": admin_profile,
            "last_error": error
        }, request))
示例#8
0
def machine__other_user_pays(request, user_token=""):
    machine = get_machine_from_session(request)
    if machine is None:
        return find_session_redirect(machine)

    payer_user_profile, error = get_profile_from_post(request)
    if payer_user_profile is not None:
        error = create_payment_session(machine, payer_user_profile)
        if error is None:
            return find_session_redirect(machine)

    if payer_user_profile is None and user_token != "":
        payer_user_profile, error = get_profile_from_url_token(user_token)
        if user_token is not None:
            error = create_payment_session(machine, payer_user_profile)
        if error is None:
            return find_session_redirect(machine)

    return HttpResponse(
        loader.get_template('machine/other_user_pays.html').render(
            {
                "machine": machine,
                "last_error": error,
            }, request))
示例#9
0
def pos__login_user(request, user_token=""):
    profile, error = get_profile_from_post(request)
    if profile is None and user_token != "":
        profile, error = get_profile_from_url_token(user_token)

    if profile is not None:
        paying_user = profile.user
        if profile.paying_user is not None:
            paying_user = profile.paying_user

        if paying_user.profile.monthly_payment is True:
            try:
                current_spaceRentPayment = models.SpaceRentPayment.objects.filter(
                    for_user=profile.user,
                    user=paying_user,
                    start__lt=timezone.now(),
                    end__gt=timezone.now())[0]
            except:
                current_spaceRentPayment = None
        else:
            try:
                current_spaceRentPayment = models.SpaceRentPayment.objects.filter(
                    for_user=profile.user,
                    user=paying_user,
                    end__gt=timezone.now())[0]
            except:
                current_spaceRentPayment = None
            if current_spaceRentPayment is not None:  # benuzer ist anwesend
                pass
                #spaceAccessTracking.spaceRentPayment = current_spaceRentPayment
                #spaceAccessTracking.save()
            else:
                spaceRentPayment = models.SpaceRentPayment()
                spaceRentPayment.start = timezone.now(
                )  # spaceAccessTracking.start
                spaceRentPayment.end = spaceRentPayment.start + timedelta(
                    hours=24)
                spaceRentPayment.user = paying_user
                spaceRentPayment.for_user = profile.user
                spaceRentPayment.price = _get_price(
                    paying_user.profile, identifier="spaceRentPayment.daily")
                spaceRentPayment.type = models.SpaceRentPaymentType.daily
                spaceRentPayment.save()
                if paying_user.profile.allow_postpaid is False:
                    transaction = models.Transaction()
                    transaction.user = paying_user
                    transaction.value = spaceRentPayment.price
                    transaction.type = models.TransactionType.from_deposit_for_rent
                    transaction.save()
                    paying_user.profile.prepaid_deposit -= transaction.value
                    paying_user.profile.save()
                    spaceRentPayment.transaction = transaction
                    spaceRentPayment.save()
                #spaceAccessTracking.spaceRentPayment = spaceRentPayment
                #spaceAccessTracking.save()
    #else:
    #    return redirect('pos__index')

    template = loader.get_template('pos/login_user.html')
    return HttpResponse(
        template.render({
            "profile": profile,
            "last_error": error
        }, request))