Пример #1
0
def edit_application(request, application_document_id=None, template='aplicaciones/application.html'):
    # all these application things ought likely be combined into a smaller number of views
    application_document = get_object_or_404(ApplicationDocument, id=application_document_id)

    # submitted applications can't be edited anymore, redirect to the view page
    if not application_document.status == "INCOMPLETE":
        return view_application(request, application_document_id=application_document_id)

    if not application_document.applicant.user == request.user:
        # TODO: what should we do if the user doesn't have permission to access this page?
        return HttpResponse("You do not have permission to edit this application.")
    application_document_form = ApplicationDocumentForm(instance=application_document)
    broker = application_document.broker
    applicant = application_document.applicant
    rental = application_document.rental

    if request.method == "POST":
        application_document_form = ApplicationDocumentForm(request.POST, instance=application_document)
        if application_document_form.is_valid():
            application_document_form.save()
            if request.POST['submit'] == "Submit to landlord":
            # TODO: DRY. hardcoding "submit to landlord" text comparison will break if we change
            # the button value in the template.
                """point here is to change the status flag if we submit to landlord"""
                application_document.status = "SUBMITTED"
                application_document.save()
                messages.info(request, "Your application has been submitted.  You can track your application status through your dashboard.")
                return HttpResponseRedirect(reverse("dashboard"))
    return direct_to_template(request, template, locals())
Пример #2
0
def application(request, rental_id=None, broker_id=None, printable=False, \
                template='aplicaciones/application.html'):
    """ApplicationDocuments are created in this view.

       Only use case is an applicant filling out a form to apply.
       This page should be the first point of contact for most tenants -- a
       broker gives the applicant a URL and they land here.
    """
    try:
        rental = Rental.objects.get(id=rental_id)
    except Rental.DoesNotExist:
        rental = None
    try:
        broker = Broker.objects.get(id=broker_id)
    except Broker.DoesNotExist:
        broker = None
    if not rental or not broker:
        # as per discussion with rz, this action will probably
        # be different later
        return HttpResponseRedirect(reverse("start_application",
                                    kwargs={'rental_id': rental_id,
                                            'broker_id': broker_id}))

    if request.method == 'POST':
        if not request.user.is_authenticated():
            return HttpResponse("You must log in to save or submit.")
        application_document_form = ApplicationDocumentForm(request.POST)
        if application_document_form.is_valid():
            application_document = application_document_form.save(commit=False)
            application_document.applicant = Applicant.objects.get(user=request.user)
            application_document.broker = broker
            application_document.rental = rental
            application_document.save()
            if request.POST['submit'] == "Submit to landlord":
            # TODO: DRY. hardcoding "submit to landlord" text comparison will break if we change
            # the button value in the template.  Also I just copied this logic from the edit_application view.
                """point here is to change the status flag if we submit to landlord"""
                application_document.status = "SUBMITTED"
                application_document.save()
                messages.info(request, "Your application has been submitted.  You can track your application status through your dashboard.")
                return HttpResponseRedirect(reverse("dashboard"))
            else: # the applicant saved, but didn't submit
                messages.info(request, "Your application was successfully saved.  You can continue to edit or [return to your dashboard].")
                return HttpResponseRedirect(reverse("edit_application",
                                             kwargs={'application_document_id': \
                                                     application_document.id}))
        else:
            return direct_to_template(request, template, locals())

    if request.method == 'GET':
        if not request.user.is_authenticated():
            messages.info(request, """You must be logged in to save or submit a rental application.  Please [log in] or [sign up].  [Click here] to learn more about Leasely before making a decision or check out the sidebar for a short summary of the benefits you'll receive by joining Leasely.""")
        application_document_form = ApplicationDocumentForm()
        return direct_to_template(request, template, locals())