def filter(self, applications): today = get_todays_date() a_week_ago = today - datetime.timedelta(days=7) for app in truthy_values_filter(applications, 'where_they_heard', 'finished'): if app['finished'].date() > a_week_ago: yield app
def get_submissions_due_for_follow_ups(after_id=None): """ Pulls in submissions that are over a month old and which have not been sent followups """ today = utils.get_todays_date() thirty_days = datetime.timedelta(days=30) a_month_ago = today - thirty_days end_date_criteria = a_month_ago date_criteria = Q(date_received__lte=end_date_criteria) apps_that_need_followups = models.Application.objects.filter( status_updates=None, organization__needs_applicant_followups=True) has_at_least_one_app_w_no_update = Q( id__in=apps_that_need_followups.values_list( 'form_submission_id', flat=True)) if after_id: lower_bound = models.FormSubmission.objects.get( id=after_id).date_received start_date_criteria = Q(date_received__gte=lower_bound) date_criteria = date_criteria & start_date_criteria exclusion_criteria = ~Q(has_been_sent_followup=True) qset = models.FormSubmission.objects.filter( has_at_least_one_app_w_no_update & date_criteria & exclusion_criteria ) return qset
def get_concatenated_printout_for_bundle(user, bundle): # for each of the submissions, canvas = None pdf_file = None submissions = list(bundle.submissions.all()) count = len(submissions) if count == 1: return get_printout_for_submission(user, submissions[0]) for i, submission in enumerate(submissions): form, letter = submission.get_display_form_for_user(user) if i == 0: pdf_display = PDFFormDisplay(form, letter) canvas, pdf_file = pdf_display.render(save=False) elif i > 0 and i < (count - 1): pdf_display = PDFFormDisplay(form, letter, canvas=canvas) canvas, pdf = pdf_display.render(save=False) else: pdf_display = PDFFormDisplay(form, letter, canvas=canvas) canvas, pdf = pdf_display.render( save=True, title="{} Applications from Code for America".format(count)) today = utils.get_todays_date() filename = '{}-{}-Applications-CodeForAmerica.pdf'.format( today.strftime('%Y-%m-%d'), count) pdf_file.seek(0) return filename, pdf_file.read()
def get_lookup_structure(self): today = get_todays_date() duration = today - self.start_date number_of_days = duration.days structure = [(today - datetime.timedelta(days=i), []) for i in range(0, number_of_days, 7)] return structure
def get_concatenated_printout_for_bundle(user, bundle): # for each of the submissions, canvas = None pdf_file = None submissions = list(bundle.submissions.all()) count = len(submissions) if count == 1: return get_printout_for_submission(user, submissions[0]) for i, submission in enumerate(submissions): form, letter = submission.get_display_form_for_user(user) if i == 0: pdf_display = PDFFormDisplay(form, letter) canvas, pdf_file = pdf_display.render(save=False) elif i > 0 and i < (count - 1): pdf_display = PDFFormDisplay(form, letter, canvas=canvas) canvas, pdf = pdf_display.render(save=False) else: pdf_display = PDFFormDisplay(form, letter, canvas=canvas) canvas, pdf = pdf_display.render( save=True, title="{} Applications from Code for America".format(count)) today = utils.get_todays_date() filename = '{}-{}-Applications-CodeForAmerica.pdf'.format( today.strftime('%Y-%m-%d'), count ) pdf_file.seek(0) return filename, pdf_file.read()
def get_submissions_due_for_follow_ups(after_id=None): """ Pulls in submissions that are over a month old and which have not been sent followups """ today = utils.get_todays_date() thirty_days = datetime.timedelta(days=30) a_month_ago = today - thirty_days end_date_criteria = a_month_ago date_criteria = Q(date_received__lte=end_date_criteria) apps_that_need_followups = models.Application.objects.filter( status_updates=None, organization__needs_applicant_followups=True) has_at_least_one_app_w_no_update = Q( id__in=apps_that_need_followups.values_list('form_submission_id', flat=True)) if after_id: lower_bound = models.FormSubmission.objects.get( id=after_id).date_received start_date_criteria = Q(date_received__gte=lower_bound) date_criteria = date_criteria & start_date_criteria exclusion_criteria = ~Q( applicant__events__name=models.ApplicationEvent.FOLLOWUP_SENT) qset = models.FormSubmission.objects.filter( has_at_least_one_app_w_no_update & date_criteria & exclusion_criteria) return qset
def test_make_year_weeks_output(self): todays_date = utils.get_todays_date() next_week = todays_date + datetime.timedelta(days=7) last_year_week = statistics.as_year_week(todays_date) too_far_year_week = statistics.as_year_week(next_week) year_weeks = statistics.make_year_weeks() expected_last_yw, last_date, last_date_from_yw = year_weeks[-1] self.assertNotEqual(too_far_year_week, expected_last_yw) self.assertEqual(last_year_week, expected_last_yw)
def make_year_weeks(): start_date = utils.get_start_date() year_weeks = [] date_cursor = start_date last_date = utils.get_todays_date() while date_cursor <= last_date: year_week = as_year_week(date_cursor) year_weeks.append(year_week) date_cursor += timedelta(days=7) return year_weeks
def make_year_weeks(): start_date = utils.get_start_date() year_weeks = [] date_cursor = start_date last_date = utils.get_todays_date() while date_cursor <= last_date: year_week = as_year_week(date_cursor) year_weeks.append(year_week) date_cursor += timedelta(days=7) return year_weeks
def test_make_year_weeks_output(self): todays_date = utils.get_todays_date() weekday = todays_date.weekday() first_day_of_this_week = todays_date - datetime.timedelta(days=weekday) next_week = first_day_of_this_week + datetime.timedelta(days=7) last_year_week = statistics.as_year_week(first_day_of_this_week) too_far_year_week = statistics.as_year_week(next_week) year_weeks = statistics.make_year_weeks() expected_last_yw = year_weeks[-1] self.assertNotEqual(too_far_year_week, expected_last_yw) self.assertEqual(last_year_week, expected_last_yw)
def test_make_year_weeks_output(self): todays_date = utils.get_todays_date() weekday = todays_date.weekday() first_day_of_this_week = todays_date - datetime.timedelta(days=weekday) next_week = first_day_of_this_week + datetime.timedelta(days=7) last_year_week = statistics.as_year_week(first_day_of_this_week) too_far_year_week = statistics.as_year_week(next_week) year_weeks = statistics.make_year_weeks() expected_last_yw = year_weeks[-1] self.assertNotEqual(too_far_year_week, expected_last_yw) self.assertEqual(last_year_week, expected_last_yw)
def get_new_visitor_tally(self): with connection.cursor() as cursor: cursor.execute(self.visitor_tally_sql) rows = cursor.fetchall() totals = {} for referrer, total in rows: host = parse_url_host(referrer) if host not in totals: totals[host] = 0 totals[host] += total self.visitor_tally = totals self.last_visitor_tally_date = get_todays_date()
def get_submissions_due_for_follow_ups(after_id=None): """ Pulls in submissions that are over a month old and which have not been sent followups """ today = utils.get_todays_date() thirty_days = datetime.timedelta(days=30) a_month_ago = today - thirty_days end_date_criteria = a_month_ago date_criteria = Q(date_received__lte=end_date_criteria) if after_id: lower_bound = models.FormSubmission.objects.get( id=after_id).date_received start_date_criteria = Q(date_received__gte=lower_bound) date_criteria = date_criteria & start_date_criteria exclusion_criteria = ~Q( applicant__events__name=models.ApplicationEvent.FOLLOWUP_SENT) qset = models.FormSubmission.objects.filter(date_criteria & exclusion_criteria) return qset
def concatenated_printout(form_letter_tuples): canvas = None pdf_file = None count = len(form_letter_tuples) for i, form_letter_tuple in enumerate(form_letter_tuples): if i == 0: pdf_display = PDFFormDisplay(*form_letter_tuple) canvas, pdf_file = pdf_display.render(save=False) else: pdf_display = PDFFormDisplay(*form_letter_tuple, canvas=canvas) if i == (count - 1): canvas, pdf = pdf_display.render( save=True, title="{} Applications from Code for America".format( count)) else: canvas, pdf = pdf_display.render(save=False) today = utils.get_todays_date() filename = '{}-{}-Applications-CodeForAmerica.pdf'.format( today.strftime('%Y-%m-%d'), count) pdf_file.seek(0) return filename, pdf_file.read()
def get_submissions_due_for_follow_ups(after_id=None): """ Pulls in submissions that are over 5 weeks old and which have not been sent followups """ today = utils.get_todays_date() followup_time = datetime.timedelta(days=7 * 6) end_date_criteria = today - followup_time date_criteria = Q(date_received__lte=end_date_criteria) apps_that_need_followups = models.Application.objects.filter( status_updates=None, organization__needs_applicant_followups=True) has_at_least_one_app_w_no_update = Q( id__in=apps_that_need_followups.values_list('form_submission_id', flat=True)) if after_id: lower_bound = models.FormSubmission.objects.get( id=after_id).date_received start_date_criteria = Q(date_received__gte=lower_bound) date_criteria = date_criteria & start_date_criteria exclusion_criteria = ~Q(has_been_sent_followup=True) qset = models.FormSubmission.objects.filter( has_at_least_one_app_w_no_update & date_criteria & exclusion_criteria) return qset
def filter(self, applications): today = get_todays_date() a_week_ago = today - datetime.timedelta(days=7) for app in truthy_values_filter(applications, 'started'): if app['started'].date() > a_week_ago: yield app
def get_visitor_tally_if_needed(self): today = get_todays_date() tallied_today = self.last_visitor_tally_date == today if not tallied_today: self.get_new_visitor_tally() return self.visitor_tally