Exemple #1
0
def location_check_submit(request, application_id):
    if request.method == 'POST':
        application_status = ApplicationStatus.objects.get(id=application_id)
        user = request.user
        block = request.POST.get('block')
        redirect_path = create_redirect_path_from_session(request)

        # Check if application has already been denied.
        if application_status.current_step == None:
            return HttpResponseRedirect('/double-submit/%s/' %
                                        application_status.id)
        # Check if application has moved past step 2.
        elif application_status.current_step.step != 3:
            return HttpResponseRedirect('/double-submit/%s/' %
                                        application_status.id)
        elif block == 'yes':
            # Create a new review for completing this step.
            review = Review(reviewer=user,
                            email_sent=False,
                            application=application_status,
                            step_completed=3)
            review.save()

            # Are there other applicants who applied to this property?
            lot_pin = application_status.lot.pin
            other_applicants = ApplicationStatus.objects.filter(lot=lot_pin,
                                                                denied=False)
            applicants_list = list(other_applicants)

            if (len(applicants_list) > 1):
                # If there are other applicants: move application to Step 4.
                step, _ = ApplicationStep.objects.get_or_create(
                    description=APPLICATION_STATUS['multi'],
                    public_status='valid',
                    step=4)
                application_status.current_step = step
                application_status.save()

                return HttpResponseRedirect('/applications/all/%s' %
                                            redirect_path)
            else:
                # Move to Step 5: Adlerman letter.
                step, _ = ApplicationStep.objects.get_or_create(
                    description=APPLICATION_STATUS['letter'],
                    public_status='valid',
                    step=5)
                application_status.current_step = step
                application_status.save()

                return HttpResponseRedirect('/applications/all/%s' %
                                            redirect_path)
        # Send admin to denial confirmation page.
        else:
            reason = 'block'

            return HttpResponseRedirect(
                '/deny-application/{app_id}/?reason={reason}'.format(
                    app_id=application_status.id, reason=reason))
Exemple #2
0
def deed_check_submit(request, application_id):
    if request.method == 'POST':
        application_status = ApplicationStatus.objects.get(id=application_id)
        user = request.user

        document = request.POST.get('document')
        name = request.POST.get('name', 'off')
        address = request.POST.get('address', 'off')
        church = request.POST.get('church')
        '''
        The first two conditions prevent a LargeLots admin from re-evaluating an application that:
        (1) has already been denied;
        (2) advanced past Step 2. 
        '''
        if application_status.current_step == None:
            return HttpResponseRedirect('/double-submit/%s/' %
                                        application_status.id)
        elif application_status.current_step.step != 2:
            return HttpResponseRedirect('/double-submit/%s/' %
                                        application_status.id)
        # Move to step 3 of review process.
        elif (name == 'on' and address == 'on' and church == 'no'
              and document == 'yes'):
            step, _ = ApplicationStep.objects.get_or_create(
                description=APPLICATION_STATUS['location'],
                public_status='valid',
                step=3)
            application_status.current_step = step
            application_status.save()

            review = Review(reviewer=user,
                            email_sent=False,
                            application=application_status,
                            step_completed=2)
            review.save()

            return HttpResponseRedirect('/application-review/step-3/%s/' %
                                        application_status.id)
        # Send admin to denial confirmation page.
        else:
            if (document == 'no'):
                reason = 'document'
            elif (church == 'yes'):
                reason = 'church'
            elif (name == 'off' and address == 'on'):
                reason = 'name'
            elif (name == 'on' and address == 'off'):
                reason = 'address'
            else:
                reason = 'nameaddress'

            return HttpResponseRedirect(
                '/deny-application/{app_id}/?reason={reason}'.format(
                    app_id=application_status.id, reason=reason))
Exemple #3
0
def multiple_location_check_submit(request, application_id):
    if request.method == 'POST':
        user = request.user
        applications = request.POST.getlist('multi-check')
        application_ids = [int(i) for i in applications]
        applications = ApplicationStatus.objects.filter(id__in=application_ids)

        # Did the admin check multiple applicants? If so, tag them with lottery boolean.
        if (len(applications) > 1):
            for a in applications:
                a.lottery = True
                a.save()

        # Applicant(s) with a check should advance to step 5.
        for a in applications:
            step, _ = ApplicationStep.objects.get_or_create(
                description=APPLICATION_STATUS['letter'],
                public_status='valid',
                step=5)
            a.current_step = step
            a.save()
            review = Review(reviewer=user,
                            email_sent=False,
                            application=a,
                            step_completed=4)
            review.save()

        # Deny unchecked applications, and send them emails.
        application_status = ApplicationStatus.objects.get(id=application_id)
        lot_pin = application_status.lot.pin
        applicants_to_deny = ApplicationStatus.objects.filter(
            lot=lot_pin, denied=False).exclude(id__in=application_ids)
        email_error_app_ids = []

        for a in applicants_to_deny:
            reason, _ = DenialReason.objects.get_or_create(
                value=DENIAL_REASONS['adjacent'])
            review = Review(reviewer=user,
                            email_sent=True,
                            denial_reason=reason,
                            application=a,
                            step_completed=4)
            review.save()
            a.denied = True
            a.current_step = None
            a.save()

            try:
                send_denial_email(request, a)
            except SMTPException as stmp_e:
                email_error_app_ids.append(a.id)
        # If any emails raised an error, redirect to the email-error page.
        if email_error_app_ids:
            request.session['email_error_app_ids'] = email_error_app_ids
            return HttpResponseRedirect(reverse('email_error'))

        redirect_path = create_redirect_path_from_session(request)

        return HttpResponseRedirect('/applications/all/%s' % redirect_path)
Exemple #4
0
    def _deny(self, app_status, denial_reason):
        '''
        Deny the given application and create a corresponding review object.

        :app_status - ApplicationStatus object
        :denial_reason - DenialReason object
        '''
        app_status.denied = True
        app_status.current_step = None
        app_status.save()

        review = Review(reviewer=self.admin,
                        denial_reason=denial_reason,
                        application=app_status,
                        email_sent=True)

        review.save()
Exemple #5
0
def applicant_duplicate_submit(request, application_id):
    if request.method == 'POST':
        application_status = ApplicationStatus.objects.get(id=application_id)
        user = request.user

        reason, _ = DenialReason.objects.get_or_create(
            value=DENIAL_REASONS['duplicate'])
        review = Review(reviewer=user,
                        email_sent=True,
                        denial_reason=reason,
                        application=application_status,
                        step_completed=2)
        review.save()

        application_status.denied = True
        application_status.save()

        return HttpResponseRedirect('/deny-application/%s/' %
                                    application_status.id)
Exemple #6
0
def bulk_deny_submit(request):
    user = request.user
    denial_reasons = request.POST.getlist('denial-reason')
    no_deny_ids = request.POST.getlist('remove')
    apps = request.POST.getlist('application')
    app_ids = [int(i) for i in apps]

    dictionary = dict(zip(app_ids, denial_reasons))
    apps_to_deny = ApplicationStatus.objects.filter(id__in=app_ids).exclude(
        id__in=no_deny_ids)
    email_error_app_ids = []

    for a in apps_to_deny:
        dict_reason = dictionary[a.id]
        reason, _ = DenialReason.objects.get_or_create(
            value=DENIAL_REASONS[dict_reason])

        review = Review(reviewer=user,
                        email_sent=True,
                        denial_reason=reason,
                        application=a)
        review.save()
        a.denied = True
        a.current_step = None
        a.save()

        try:
            send_denial_email(request, a)
        except SMTPException as stmp_e:
            email_error_app_ids.append(a.id)
    # If any emails raised an error, redirect to the email-error page.
    if email_error_app_ids:
        request.session['email_error_app_ids'] = email_error_app_ids
        return HttpResponseRedirect(reverse('email_error'))

    return HttpResponseRedirect(reverse('applications', args=['all']))
    def handle(self, *args, **options):
        pins_with_denials = json.loads(options['pins_with_denials'])
        user_email = options['user_email']
        user = User.objects.get(email=user_email)

        self.stdout.write('Begin: Denying applications!')

        for pin, reason_text in pins_with_denials.items():
            applications = ApplicationStatus.objects.filter(lot=pin)
            for app in applications:
                reason, _ = DenialReason.objects.get_or_create(
                    value=reason_text)
                review = Review(reviewer=user,
                                email_sent=True,
                                denial_reason=reason,
                                application=app)
                review.save()
                app.denied = True
                app.current_step = None
                app.save()

                self.stdout.write(
                    ('{0} {1} | {2}').format(app.application.first_name,
                                             app.application.last_name, pin))
Exemple #8
0
def lottery_submit(request, lot_pin):
    if request.method == 'POST':
        user = request.user
        winner_id = int(request.POST['winner-select'])
        winning_app = ApplicationStatus.objects.get(id=winner_id)

        # Move lottery winner to Step 7.
        step, _ = ApplicationStep.objects.get_or_create(
            description=APPLICATION_STATUS['EDS_waiting'],
            public_status='valid',
            step=7)
        winning_app.current_step = step
        winning_app.save()
        # Create a review.
        review = Review(reviewer=user,
                        email_sent=True,
                        application=winning_app,
                        step_completed=6)
        review.save()
        # Send winner an email.
        context = {'app': winning_app.application, 'lot': winning_app.lot}

        msg = create_email_msg('lotto_winner_email',
                               'LargeLots application - Lottery winner',
                               winning_app.application.email, context)

        email_error_app_ids = []

        try:
            msg.send()
            winning_app.lottery_email_sent = True
            winning_app.save()
        except SMTPException as stmp_e:
            email_error_app_ids.append(winning_app.id)

        # Deny lottery losers: find all applications on Step 5.
        losing_apps = ApplicationStatus.objects.filter(
            current_step__step=6).filter(lot=lot_pin)
        for a in losing_apps:
            # Deny each application.
            reason, _ = DenialReason.objects.get_or_create(
                value=DENIAL_REASONS['lottery'])
            review = Review(reviewer=user,
                            email_sent=True,
                            denial_reason=reason,
                            application=a,
                            step_completed=6)
            review.save()
            a.denied = True
            a.current_step = None
            a.save()

            # Send loser an email.
            context = {
                'app': a.application,
                'lot': a.lot,
                'review': review,
                'today': datetime.now().date(),
                'DENIAL_REASONS': DENIAL_REASONS
            }

            msg = create_email_msg('denial_email',
                                   'LargeLots application - Lottery results',
                                   a.application.email, context)

            try:
                msg.send()
                a.lottery_email_sent = True
                a.save()
            except SMTPException as stmp_e:
                email_error_app_ids.append(a)

        if email_error_app_ids:
            request.session['email_error_app_ids'] = email_error_app_ids
            return HttpResponseRedirect(reverse('email_error'))

        return HttpResponseRedirect(reverse('lotteries'))