Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
 def test_calls_remove_pdf_task_when_opened(self, remove_application_pdfs):
     profile = UserProfileFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[profile.organization], answers={})
     AppsService.handle_apps_opened(Mock(**{'request.user': profile.user}),
                                    sub.applications.all())
     remove_application_pdfs.assert_called_with(sub.applications.first().id)
 def test_calls_remove_pdf_task_when_opened(self, remove_application_pdfs):
     profile = UserProfileFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[profile.organization], answers={})
     AppsService.handle_apps_opened(
         Mock(**{'request.user': profile.user}),
         sub.applications.all())
     remove_application_pdfs.assert_called_with(
         sub.applications.first().id)
Ejemplo n.º 5
0
 def test_mark_only_users_app_opened(self):
     fake_org_1 = FakeOrganizationFactory()
     fake_org_2 = FakeOrganizationFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[fake_org_1, fake_org_2], answers={})
     org_1_user = UserProfileFactory(organization=fake_org_1).user
     AppsService.handle_apps_opened(Mock(**{'request.user': org_1_user}),
                                    sub.applications.all())
     org_1_apps = sub.applications.filter(organization=fake_org_1)
     org_2_apps = sub.applications.filter(organization=fake_org_2)
     self.assertTrue(all([app.has_been_opened for app in org_1_apps]))
     self.assertFalse(any([app.has_been_opened for app in org_2_apps]))
 def test_mark_only_users_app_opened(self):
     fake_org_1 = FakeOrganizationFactory()
     fake_org_2 = FakeOrganizationFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[fake_org_1, fake_org_2], answers={})
     org_1_user = UserProfileFactory(organization=fake_org_1).user
     AppsService.handle_apps_opened(
         Mock(**{'request.user': org_1_user}),
         sub.applications.all())
     org_1_apps = sub.applications.filter(organization=fake_org_1)
     org_2_apps = sub.applications.filter(organization=fake_org_2)
     self.assertTrue(all([app.has_been_opened for app in org_1_apps]))
     self.assertFalse(any([app.has_been_opened for app in org_2_apps]))
Ejemplo n.º 7
0
 def get(self, request, submission_id):
     submission = get_object_or_404(
         models.FormSubmission, pk=int(submission_id))
     if not request.user.is_staff:
         if not submission.organizations.filter(
                 id=request.user.profile.organization_id).exists():
             return not_allowed(request)
     apps = AppsService.filter_to_org_if_not_staff(
         submission.applications.all(), request.user)
     AppsService.handle_apps_opened(self, apps)
     filename, pdf_bytes = PDFService.get_printout_for_submission(
         request.user, submission)
     response = HttpResponse(pdf_bytes, content_type='application/pdf')
     response['Content-Disposition'] = 'filename="{}"'.format(filename)
     return response
Ejemplo n.º 8
0
 def get(self, request, submission_id):
     submission = get_object_or_404(models.FormSubmission,
                                    pk=int(submission_id))
     if not request.user.is_staff:
         if not submission.organizations.filter(
                 id=request.user.profile.organization_id).exists():
             return not_allowed(request)
     apps = AppsService.filter_to_org_if_not_staff(
         submission.applications.all(), request.user)
     AppsService.handle_apps_opened(self, apps)
     filename, pdf_bytes = PDFService.get_printout_for_submission(
         request.user, submission)
     response = HttpResponse(pdf_bytes, content_type='application/pdf')
     response['Content-Disposition'] = 'filename="{}"'.format(filename)
     return response
 def get_context_data(self):
     context = super().get_context_data()
     context['organization'] = self.organization
     context['app_count'] = AppsService.get_valid_application_ids_from_set(
         self.app_ids).count()
     # check for fillable pdfs
     needs_prebuilt = self.organization.pdfs.count() > 0
     if needs_prebuilt:
         context['pdf_url'] = query_params.get_url_for_ids(
             'intake-pdf_bundle_file_view', self.app_ids)
     else:
         context['pdf_url'] = query_params.get_url_for_ids(
             'intake-pdf_printout_for_apps', self.app_ids)
     AppsService.handle_apps_opened(self, self.app_ids)
     MessagesService.flash_success(
         self.request, get_multiple_apps_read_flash(context['app_count']))
     return context
 def get_context_data(self):
     context = super().get_context_data()
     context['organization'] = self.organization
     context['app_count'] = AppsService.get_valid_application_ids_from_set(
         self.app_ids).count()
     # check for fillable pdfs
     needs_prebuilt = self.organization.pdfs.count() > 0
     if needs_prebuilt:
         context['pdf_url'] = query_params.get_url_for_ids(
             'intake-pdf_bundle_file_view', self.app_ids)
     else:
         context['pdf_url'] = query_params.get_url_for_ids(
             'intake-pdf_printout_for_apps', self.app_ids)
     AppsService.handle_apps_opened(self, self.app_ids)
     MessagesService.flash_success(
         self.request, get_multiple_apps_read_flash(context['app_count']))
     return context
Ejemplo n.º 11
0
 def get(self, request, submission_id):
     submission = get_object_or_404(models.FormSubmission,
                                    pk=int(submission_id))
     if not request.user.profile.should_have_access_to(submission):
         return self.not_allowed()
     pdf = submission.filled_pdfs.first()
     if not pdf:
         no_pdf_str = \
             "No prefilled pdf was made for submission: %s" % submission.pk
         notifications.slack_simple.send(no_pdf_str)
         fillables = models.FillablePDF.objects
         if not request.user.is_staff:
             org = request.user.profile.organization
             fillables = fillables.filter(organization=org)
         fillable_pdf = fillables.first()
         pdf = fillable_pdf.fill_for_submission(submission)
     apps = AppsService.filter_to_org_if_not_staff(
         submission.applications.all(), request.user)
     AppsService.handle_apps_opened(self, apps)
     response = HttpResponse(pdf.pdf, content_type='application/pdf')
     return response
Ejemplo n.º 12
0
 def get(self, request, submission_id):
     submission = get_object_or_404(
         models.FormSubmission, pk=int(submission_id))
     if not request.user.profile.should_have_access_to(submission):
         return self.not_allowed()
     pdf = submission.filled_pdfs.first()
     if not pdf:
         no_pdf_str = \
             "No prefilled pdf was made for submission: %s" % submission.pk
         notifications.slack_simple.send(no_pdf_str)
         fillables = models.FillablePDF.objects
         if not request.user.is_staff:
             org = request.user.profile.organization
             fillables = fillables.filter(
                 organization=org)
         fillable_pdf = fillables.first()
         pdf = fillable_pdf.fill_for_submission(submission)
     apps = AppsService.filter_to_org_if_not_staff(
         submission.applications.all(), request.user)
     AppsService.handle_apps_opened(self, apps)
     response = HttpResponse(pdf.pdf, content_type='application/pdf')
     return response