Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dispatch(self, request, submission_id, *args, **kwargs):
self.next_url = request.GET.get(
'next', reverse_lazy('intake-app_index'))
self.author = request.user
self.from_organization = request.user.profile.organization
self.to_organization = \
request.user.profile.organization.transfer_partners.first()
submission_id = int(submission_id)
self.submission = models.FormSubmission.objects.get(
id=submission_id)
self.application = self.submission.applications.filter(
organization=self.from_organization).first()
if not self.to_organization or not self.application:
return not_allowed(request)
return super().dispatch(request, *args, **kwargs)
def request_valid(self, request, *args, **kwargs):
apps = models.Application.objects.filter(id__in=self.app_ids)
filename, pdf_bytes = \
PDFService.get_concatenated_printout_for_applications(apps)
response = HttpResponse(pdf_bytes, content_type="application/pdf")
response['Content-Disposition'] = 'filename="{}"'.format(filename)
return response
def form_valid(self, form):
self.update_session_data(**form.parsed_data)
models.ApplicationEvent.log_app_started(
self.get_applicant_id(),
counties=form.parsed_data['counties'],
referrer=self.request.session.get('referrer'),
ip=self.request.ip_address,
user_agent=self.request.META.get('HTTP_USER_AGENT'),
)
return super().form_valid(form)
@admin.register(models.County)
class CountyAdmin(admin.ModelAdmin):
pass
@admin.register(models.StatusType)
class StatusTypeAdmin(admin.ModelAdmin):
pass
@admin.register(models.NextStep)
class NextStepAdmin(admin.ModelAdmin):
pass
@admin.register(models.StatusUpdate)
class StatusUpdateAdmin(admin.ModelAdmin):
pass
@admin.register(models.StatusNotification)
class StatusNotificationAdmin(admin.ModelAdmin):
pass
def log_event(self, name, data=None):
data = data or {}
return intake.models.ApplicationEvent.create(
name=name,
applicant_id=self.id,
**data
)
def get_or_create_app_bundle_if_needed(self):
"""If there are new submissions, make a new bundle
If the submissions are the same as the last bundle, use the last bundle
"""
return intake_models.ApplicationBundle.create_with_submissions(
submissions=self.submissions,
organization=self.organization,
)
def from_logs(cls, logs):
LogEntry = intake.models.ApplicationLogEntry
FormSubmission = intake.models.FormSubmission
applicationLogEntryReference = {
LogEntry.OPENED: cls.OPENED,
LogEntry.REFERRED: cls.REFERRED,
LogEntry.PROCESSED: cls.PROCESSED,
LogEntry.DELETED: cls.DELETED,
LogEntry.CONFIRMATION_SENT: cls.CONFIRMATION_SENT,
LogEntry.REFERRED_BETWEEN_ORGS: cls.REFERRED_BETWEEN_ORGS,
}
events = []
applicant_ids = dict(FormSubmission.objects.filter(
pk__in=[log.submission_id for log in logs]
).values_list('id', 'applicant_id'))
for log in logs:
being_charged = serializer_fields.YesNoAnswerField(
'being_charged', source='answers')
serving_sentence = serializer_fields.YesNoAnswerField(
'serving_sentence', source='answers')
on_probation_parole = serializer_fields.YesNoAnswerField(
'on_probation_parole', source='answers')
currently_employed = serializer_fields.YesNoAnswerField(
'currently_employed', source='answers')
city = serializer_fields.CityField(source='answers')
age = serializer_fields.AgeField(source='answers')
where_they_heard = serializer_fields.DictKeyField(
'how_did_you_hear', source='answers')
url = serializers.CharField(source='get_absolute_url', read_only=True)
class Meta:
model = models.FormSubmission
fields = [
'id',
'date_received',
'organizations',
'contact_preferences',
'monthly_income',
'us_citizen',
'being_charged',
'serving_sentence',
'on_probation_parole',
'currently_employed',
'city',
'age',
'url',
'where_they_heard'
]
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