Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mark_opened(bundle, user):
submission_ids = FormSubmission.objects.filter(
bundles=bundle).values_list('id', flat=True)
Application.objects.filter(
form_submission_id__in=submission_ids,
organization_id=user.profile.organization.id
).distinct().update(has_been_opened=True)
EventsService.bundle_opened(bundle, user)
def get_submissions_for_org_user(user):
return models.FormSubmission.objects.filter(
organizations=user.profile.organization
).prefetch_related(
'applications',
'applications__organization',
'applications__status_updates',
'applications__status_updates__status_type',
).distinct()
def handle(self, *args, **options):
subs = models.FormSubmission.objects.filter(
applicant_id__isnull=True)
backfilled = 0
for sub in subs:
if not sub.applicant_id:
applicant = models.Applicant()
applicant.save()
sub.applicant = applicant
sub.save()
event = models.ApplicationEvent(
applicant_id=applicant.id,
name=models.ApplicationEvent.APPLICATION_SUBMITTED,
time=sub.date_received,
data={})
event.save()
backfilled += 1
self.stdout.write(
def get(self, request):
submission_ids = self.get_ids_from_params(request)
submissions = models.FormSubmission.objects.filter(
pk__in=submission_ids)
if not request.user.is_staff:
submissions = submissions.filter(
organizations__profiles=request.user.profile)
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 = models.ApplicationBundle\
.get_or_create_for_submissions_and_user(submissions, request.user)
return redirect(bundle.get_pdf_bundle_url())
def get(self, request):
submission_ids = self.get_ids_from_params(request)
submissions = models.FormSubmission.objects.filter(
pk__in=submission_ids)
if not request.user.is_staff:
submissions = submissions.filter(
organizations__profiles=request.user.profile)
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)
return redirect(bundle.get_pdf_bundle_url())
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 = models.ApplicationBundle\
.get_or_create_for_submissions_and_user(submissions, request.user)
forms = [
submission.get_display_form_for_user(request.user)
for submission in submissions]
context = dict(
forms=forms,
count=len(submissions),
show_pdf=request.user.profile.should_see_pdf(),
app_ids=[sub.id for sub in submissions]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
county_totals = []
counties = models.County.objects.all()
for county in counties:
county_totals.append(dict(
count=models.FormSubmission.objects.filter(
organizations__county=county).count(),
county_name=county.name))
context['stats'] = {
'total_all_counties': models.FormSubmission.objects.count(),
'county_totals': county_totals
}
if self.request.user.is_authenticated():
two_months = datetime.timedelta(days=62)
two_months_ago = timezone.now() - two_months
applicants = models.Applicant.objects\
.annotate(first_event=Min('events__time'))\
.filter(first_event__gte=two_months_ago)\
.order_by('-first_event')
if not self.request.user.is_staff:
org = self.request.user.profile.organization
applicants = applicants.filter(
def set_request_scoping_properties(self, request, submission_id, **kwargs):
self.request = request
submission_id = int(submission_id)
self.application = models.Application.objects.filter(
form_submission=submission_id,
organization=request.user.profile.organization).first()
if self.application:
self.application.latest_status = \
models.StatusUpdate.objects.filter(
application_id=self.application.id
).order_by('-created').first()
self.submission = models.FormSubmission.objects.filter(
id=submission_id).first()