示例#1
0
 def get_context_data(self, *args, **kwargs):
     context = super().get_context_data(*args, **kwargs)
     self.submission = self.submissions[0]
     display_form, letter_display = \
         DisplayFormService.get_display_form_for_user_and_submission(
             self.request.user, self.submission)
     applications = models.Application.objects.filter(
         form_submission=self.submission)
     if not self.request.user.is_staff:
         applications = applications.filter(
             organization=self.request.user.profile.organization)
         application = applications.first()
         if not application.has_been_opened:
             message = self.marked_read_flash_message.format(
                 applicant_name=self.submission.get_full_name())
             messages.success(self.request, message)
     for application in applications:
         if application.status_updates.exists():
             # latest_status is cached on the model instance
             # for easier template randering. It is not saved to the db
             application.latest_status = \
                 application.status_updates.latest('updated')
     context.update(
         form=display_form,
         submission=self.submission,
         declaration_form=letter_display,
         applications=applications,
         should_see_pdf=self.request.user.profile.should_see_pdf())
     AppsService.handle_apps_opened(self, applications)
     return context
示例#2
0
 def get_context_data(self, *args, **kwargs):
     context = super().get_context_data(*args, **kwargs)
     self.submission = self.submissions[0]
     display_form, letter_display = \
         DisplayFormService.get_display_form_for_user_and_submission(
             self.request.user, self.submission)
     applications = models.Application.objects.filter(
         form_submission=self.submission)
     if not self.request.user.is_staff:
         applications = applications.filter(
             organization=self.request.user.profile.organization)
         application = applications.first()
         if not application.has_been_opened:
             message = self.marked_read_flash_message.format(
                 applicant_name=self.submission.get_full_name())
             messages.success(self.request, message)
     for application in applications:
         if application.status_updates.exists():
             # latest_status is cached on the model instance
             # for easier template randering. It is not saved to the db
             application.latest_status = \
                 application.status_updates.latest('updated')
     context.update(
         form=display_form,
         submission=self.submission,
         declaration_form=letter_display,
         applications=applications,
         should_see_pdf=self.request.user.profile.should_see_pdf())
     AppsService.handle_apps_opened(self, applications)
     return context
示例#3
0
def get_concatenated_printout_for_bundle(user, bundle):
    submissions = list(bundle.submissions.all())
    count = len(submissions)
    if count == 1:
        return get_printout_for_submission(user, submissions[0])
    else:
        return concatenated_printout([
            DisplayFormService.get_display_form_for_user_and_submission(
                user, submission) for submission in submissions
        ])
示例#4
0
def get_printout_for_submission(user, submission):
    # get the correct form
    form, letter = DisplayFormService.get_display_form_for_user_and_submission(
        user, submission)
    # use the form to serialize the submission
    pdf_display = PDFFormDisplay(form, letter)
    canvas, pdf = pdf_display.render(title=get_applicant_name(form) +
                                     " - Case Details")
    filename = '{}-{}-{}-CaseDetails.pdf'.format(
        form.last_name.get_display_value(),
        form.first_name.get_display_value(), submission.id)
    pdf.seek(0)
    return filename, pdf.read()
示例#5
0
 def test_displays_all_fields(self):
     data = mock.fake.alameda_pubdef_answers()
     alameda = models.County.objects.get(slug='alameda')
     Form = county_form_selector.get_combined_form_class(
         counties=[alameda.slug])
     input_form = Form(data)
     input_form.is_valid()
     submission = SubmissionsService.create_for_counties(
         counties=[alameda], answers=input_form.cleaned_data)
     user = User.objects.get(username="******")
     display_form, letter_display = \
         DisplayFormService.get_display_form_for_user_and_submission(
             user, submission)
     page_data = str(display_form) + str(letter_display)
     for key in data:
         field = display_form.get_field_by_input_name(key)
         self.assertIn(field.get_html_class_name(), page_data,
                       "couldn't find " + field.get_html_class_name())
示例#6
0
 def get(self, request, bundle_id):
     bundle = get_object_or_404(models.ApplicationBundle, pk=int(bundle_id))
     has_access = request.user.profile.should_have_access_to(bundle)
     if not has_access:
         return not_allowed(request)
     submissions = list(
         request.user.profile.filter_submissions(bundle.submissions.all()))
     forms = [
         DisplayFormService.get_display_form_for_user_and_submission(
             request.user, submission) for submission in submissions
     ]
     context = dict(bundle=bundle,
                    forms=forms,
                    count=len(submissions),
                    show_pdf=bool(bundle.bundled_pdf),
                    app_ids=[sub.id for sub in submissions],
                    bundled_pdf_url=bundle.get_pdf_bundle_url())
     BundlesService.mark_opened(bundle, request.user)
     return TemplateResponse(request, "app_bundle.jinja", context)
示例#7
0
 def test_displays_all_fields(self):
     data = mock.fake.alameda_pubdef_answers()
     alameda = models.County.objects.get(slug='alameda')
     Form = county_form_selector.get_combined_form_class(
         counties=[alameda.slug])
     input_form = Form(data)
     input_form.is_valid()
     submission = SubmissionsService.create_for_counties(
         counties=[alameda], answers=input_form.cleaned_data)
     user = User.objects.get(username="******")
     display_form, letter_display = \
         DisplayFormService.get_display_form_for_user_and_submission(
             user, submission)
     page_data = str(display_form) + str(letter_display)
     for key in data:
         field = display_form.get_field_by_input_name(key)
         self.assertIn(
             field.get_html_class_name(), page_data,
             "couldn't find " + field.get_html_class_name())
示例#8
0
 def get(self, request, bundle_id):
     bundle = get_object_or_404(models.ApplicationBundle, pk=int(bundle_id))
     has_access = request.user.profile.should_have_access_to(bundle)
     if not has_access:
         return not_allowed(request)
     submissions = list(
         request.user.profile.filter_submissions(bundle.submissions.all()))
     forms = [
         DisplayFormService.get_display_form_for_user_and_submission(
             request.user, submission)
         for submission in submissions]
     context = dict(
         bundle=bundle,
         forms=forms,
         count=len(submissions),
         show_pdf=bool(bundle.bundled_pdf),
         app_ids=[sub.id for sub in submissions],
         bundled_pdf_url=bundle.get_pdf_bundle_url())
     BundlesService.mark_opened(bundle, request.user)
     return TemplateResponse(request, "app_bundle.jinja", context)
示例#9
0
 def get(self, request):
     submission_ids = self.get_ids_from_params(request)
     submissions = models.FormSubmission.objects.filter(
         pk__in=submission_ids)
     submissions = request.user.profile.filter_submissions(submissions)
     if len(submissions) < len(submission_ids):
         raise Http404(
             "Either those applications have been deleted or you don't "
             "have permission to view those applications")
     bundle = BundlesService\
         .get_or_create_for_submissions_and_user(submissions, request.user)
     forms = [
         DisplayFormService.get_display_form_for_user_and_submission(
             request.user, submission) for submission in submissions
     ]
     context = dict(bundle=bundle,
                    forms=forms,
                    count=len(submissions),
                    show_pdf=request.user.profile.should_see_pdf(),
                    app_ids=[sub.id for sub in submissions])
     BundlesService.mark_opened(bundle, request.user)
     return TemplateResponse(request, "app_bundle.jinja", context)
示例#10
0
 def get(self, request):
     submission_ids = self.get_ids_from_params(request)
     submissions = models.FormSubmission.objects.filter(
         pk__in=submission_ids)
     submissions = request.user.profile.filter_submissions(submissions)
     if len(submissions) < len(submission_ids):
         raise Http404(
             "Either those applications have been deleted or you don't "
             "have permission to view those applications")
     bundle = BundlesService\
         .get_or_create_for_submissions_and_user(submissions, request.user)
     forms = [
         DisplayFormService.get_display_form_for_user_and_submission(
             request.user, submission)
         for submission in submissions]
     context = dict(
         bundle=bundle,
         forms=forms,
         count=len(submissions),
         show_pdf=request.user.profile.should_see_pdf(),
         app_ids=[sub.id for sub in submissions]
     )
     BundlesService.mark_opened(bundle, request.user)
     return TemplateResponse(request, "app_bundle.jinja", context)