コード例 #1
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def EditService(request, serviceId):

    from .forms import EditServiceForm

    service = Service.objects.all().get(id=serviceId)

    if request.method == 'GET':

        form = EditServiceForm(service)

        return render_with_user(request, 'services/edit_service.html',
                                {"form": form, "serviceId": serviceId})

    if request.method == 'POST':

        form = EditServiceForm(service, request.POST)

        form_valid = False

        if form.is_valid():
            form_valid = True
            form.save()

        return render_with_user(request, 'services/edit_service.html',
                                {"form": form, "form_valid": form_valid,
                                 "serviceId": serviceId})
コード例 #2
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def AddService(request):

    from .forms import ServiceForm

    is_submit = False

    if request.method == 'GET':

        form = ServiceForm()

        return render_with_user(request, 'services/add_service.html',
                                {"form": form, "is_submit": is_submit})

    if request.method == 'POST':

        form = ServiceForm(request.POST)
        form_valid = False
        is_submit = True

        if form.is_valid():
            form_valid = True
            form.save(request.user)

        return render_with_user(request, 'services/add_service.html',
                                {"form": form, "is_submit": is_submit,
                                 "form_valid": form_valid, })
コード例 #3
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def ServicesPayment(request, serviceId, csrf, payStatus, date_created):

    import datetime
    import time

    service = Service.objects.all().get(id=int(serviceId))
    user = request.user
    if date_created == "0":
        date_created = str(time.time())
    invoice_number = date_created + '-service-' + str(serviceId) + "-" \
                     + str(user.id)

    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": service.service_cost,
        "item_name": service.name,
        "invoice": invoice_number,
        "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')),
        "return_url": settings.SITE_NAME + "/paypal/payment/service/"
                      + serviceId + "/1/" + csrf + "/" + date_created + "/",
        "cancel_return": settings.SITE_NAME + "/paypal/payment/service/"
                         + serviceId + "/0/" + csrf + "/" + date_created + "/",
    }

    if payStatus == "2":
        if len(Invoice.objects.all().filter(number=invoice_number)) > 0:
            payStatus = "3"
        else:
            dateTime = datetime.datetime.\
                fromtimestamp(float(date_created)/1000)
            i = Invoice.objects.create(date_created=dateTime, service=service,
                                       buyer=user, amount=1, is_paid=False,
                                       number=invoice_number)
            i.save()
    if payStatus == "1":
        if len(Invoice.objects.all().filter(number=invoice_number)) == 0:
            payStatus = "3"
        else:
            i = Invoice.objects.all().get(number=invoice_number)
            i.is_paid = True
            i.save()
    if payStatus == "0":
        if len(Invoice.objects.all().filter(number=invoice_number)) == 0:
            payStatus = "3"
        else:
            i = Invoice.objects.all().get(number=invoice_number)
            i.is_paid = False
            i.save()

    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form.sandbox(), "service": service,
               "payStatus": payStatus, "invoice_number": invoice_number,
               "date_created": date_created, "serviceId": serviceId, }

    return render_with_user(request, "paypal/payment.html", context)
コード例 #4
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def account_settings(request):
    """
    *GET*
    Allows a user to change an account.
    *POST*
    Saves account with selected attributes
    *TEMPLATES*
    'accounts/settings.html'
    """

    from accounts.forms import SettingsForm

    if request.method == "GET":

        form = SettingsForm(request.user)

        redirect_to = "/home/#settings"

        if "next" in request.GET:
            redirect_to = request.GET["next"]

        return render_with_user(request, "accounts/settings.html", {"form": form, "redirect_to": redirect_to})

    if request.method == "POST":

        form = SettingsForm(request.user, request.POST)

        form_valid = False

        redirect_to = request.GET.get("next", "/home/#settings")

        if form.is_valid():
            # FORM IS VALID, CREATE USER

            form_valid = True
            form.save()

            return redirect(redirect_to)

        return render_with_user(
            request, "accounts/settings.html", {"form": form, "form_valid": form_valid, "redirect_to": redirect_to}
        )
コード例 #5
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def create_account(request):
    """
    *GET*
    Allows a user to create an account.
    *POST*
    Saves account with selected attributes
    *TEMPLATES*
    'accounts/sign_up.html'
    """

    from accounts.forms import UserForm

    if request.method == "GET":

        form = UserForm()

        redirect_to = "/login/#create"

        if "next" in request.GET:
            redirect_to = request.GET["next"]

        return render_with_user(request, "accounts/sign_up.html", {"form": form, "redirect_to": redirect_to})

    if request.method == "POST":

        form = UserForm(request.POST)
        form_valid = False

        redirect_to = request.GET.get("next", "/login/#create")

        if form.is_valid():
            # FORM IS VALID, CREATE USER

            form_valid = True
            form.save()

            return redirect(redirect_to)

        return render_with_user(
            request, "accounts/sign_up.html", {"form": form, "form_valid": form_valid, "redirect_to": redirect_to}
        )
コード例 #6
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def ServicesList(request):

    post = request.POST
    try:
        searchValue = post["searchValue"]
    except:
        searchValue = " "
    searchValue = searchValue.strip()
    url = 'api/services?search=' + searchValue

    return render_with_user(request, 'services/index.html',
                            {'searchValue': searchValue, 'url': url})
コード例 #7
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
    def post(self, request):
        from django.contrib.auth import login
        from .forms import AuthenticationForm

        form = AuthenticationForm(request, request.POST)

        redirect_to = request.GET.get("next", "/home/")

        if form.is_valid():
            request.session.delete_test_cookie()

            login(request, form.get_user())
            request.session["uid"] = form.get_user_id()

            return redirect(redirect_to)

        return render_with_user(request, "accounts/login.html", {"form": form, "redirect_to": redirect_to})
コード例 #8
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
    def get(self, request):
        from django.contrib.auth import logout
        from .forms import AuthenticationForm

        form = AuthenticationForm(request)

        logout(request)
        request.User = None

        request.session.set_test_cookie()

        redirect_to = "/home/"

        if "next" in request.GET:
            redirect_to = request.GET["next"]

        return render_with_user(request, "accounts/login.html", {"form": form, "redirect_to": redirect_to})
コード例 #9
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def view_that_asks_for_money(request):

    # What you want the button to do.
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": "1.00",
        "item_name": "name of the item",
        "invoice": "unique-invoice-id",
        "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')),
        "return_url": "http://0.0.0.0:8008/hello/",
        "cancel_return": "http://0.0.0.0:8008/hello/",
    }

    # Create the instance.
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form.sandbox(), "productID": request.POST["productID"]}
    return render_with_user(request, "paypal/payment.html", context)
コード例 #10
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def products_list(request):

    from service.models import Service
    from choiceNet.models import Invoice

    user = request.user

    services = Service.objects.all().filter(owner=user)
    count = len(services)

    for s in services:
        invoices = Invoice.objects.all().filter(service=s, is_active=True, is_paid=True)
        s_count = len(invoices)
        s.count = s_count

    context = {"services": services, "count": count}

    return render_with_user(request, "accounts/products.html", context)
コード例 #11
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def sales(request):

    from choiceNet.models import Invoice, Income

    refund_approved = 2

    if request.method == "POST":
        try:
            orderId = request.POST["orderId"]
            order = Invoice.objects.all().get(id=orderId)
            order.refund_status = "approved"
            order.save()
            refund_approved = 1
        except:
            refund_approved = 0

    orders = Invoice.objects.all().filter(service__owner=request.user, is_active=True).exclude(service_id=56)
    count = len(orders)
    paid_sales = 0
    unpaid_sales = 0

    for o in orders:
        if o.is_paid:
            paid_sales += o.amount * o.service.service_cost
        else:
            unpaid_sales += o.amount * o.service.service_cost

    incomes = Income.objects.all().filter(provider=request.user)
    if len(incomes) == 0:
        income = 0
    else:
        income = Income.objects.all().get(provider=request.user)

    context = {
        "orders": orders,
        "count": count,
        "paid_sales": paid_sales,
        "unpaid_sales": unpaid_sales,
        "income": income,
        "refund_approved": refund_approved,
    }

    return render_with_user(request, "accounts/sales.html", context)
コード例 #12
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def refund_request(request):

    refund_status = 2

    if request.method == "POST":
        try:
            orderId = request.POST["orderId"]
            order = Invoice.objects.all().get(id=orderId)
            order.refund_status = "refunded"
            order.is_paid = False
            order.save()
            refund_status = 1
        except:
            refund_status = 0

    orders = Invoice.objects.all().filter(refund_status="approved")
    count = len(orders)

    context = {"orders": orders, "refund_status": refund_status, "count": count}

    return render_with_user(request, "accounts/refund_request.html", context)
コード例 #13
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def orders(request):

    from choiceNet.models import Invoice

    isDeleted = 2

    if request.method == "POST":
        try:
            orderId = request.POST["orderId"]
            order = Invoice.objects.all().get(id=orderId)
            order.is_active = False
            order.save()
            isDeleted = 1
        except:
            isDeleted = 0

    orders = Invoice.objects.all().filter(buyer=request.user, is_active=True).exclude(service_id=56)
    count = len(orders)
    context = {"orders": orders, "isDeleted": isDeleted, "count": count}

    return render_with_user(request, "accounts/orders.html", context)
コード例 #14
0
ファイル: views.py プロジェクト: qysnolan/ChoiceNet
def withdraw_request(request):

    import datetime

    withdraw_status = 2

    if request.method == "POST":
        try:
            incomeId = request.POST["incomeId"]
            income = Income.objects.all().get(id=incomeId)
            income.withdraw_status = None
            income.income = 0
            income.withdraw_date = datetime.datetime.now()
            income.save()
            withdraw_status = 1
        except:
            withdraw_status = 0

    incomes = Income.objects.all().filter(withdraw_status="request")
    count = len(incomes)

    context = {"incomes": incomes, "withdraw_status": withdraw_status, "count": count}

    return render_with_user(request, "accounts/withdraw_request.html", context)