Esempio n. 1
0
def IDView(request, TEMPLATE_ID):

    events = request.user.loanrequest_set.all()
    context = {}
    # note that TEMPLATE_ID is a string variable and not an int
    if int(TEMPLATE_ID) <= len(events) and int(TEMPLATE_ID) > 0:

        display = None

        selectedData = events[int(TEMPLATE_ID)-1]

        if request.method == "POST":

            form = LoanRequestForm(request.POST, instance=selectedData)

            if form.is_valid():

                form.save()
                display = "You have successfully updated the event !"

                return HttpResponseRedirect(urlresolvers.reverse("ViewID", args=(TEMPLATE_ID,)))

        else:
            form = LoanRequestForm(instance=selectedData)

    else:
        return HttpResponseNotFound("<h1>Sorry page not found ! </h1>")


    context["form"] = form
    context["display"] = display
    context["TemplateID"] = TEMPLATE_ID

    return render(request, "growthstreetApp/templatesID.html", context)
Esempio n. 2
0
def dataAddView(request):

    context = {}
    context["wrongCredentials"] = 1

    context["whatData"] = "events"

    if request.method == "POST":

        form = LoanRequestForm(request.POST)

        if form.is_valid():
            # creating and saving the webform object.
            templateObject = form.save(commit=False)
            templateObject.user = request.user
            templateObject.save()

            return HttpResponseRedirect(urlresolvers.reverse("ViewData"))

        else:
            context["wrongCredentials"]= -1

    else:
        form = LoanRequestForm()

    context["form"] = form
    return render(request, "growthstreetApp/formTemplateAdd.html", context)