How to use the intake.models.Application.objects.filter function in intake

To help you get started, we’ve selected a few intake examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codeforamerica / intake / intake / views / app_detail_views.py View on Github external
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(
github codeforamerica / intake / intake / services / applications_service.py View on Github external
def get_all_applications_for_users_org(user):
    """Fetches all applications (unpaginated) for the organization of the given
        user.
        Prefetches form submissions, status updates, status types, status
        authors for use in intake/views/data_export_views
    """
    preselect_tables = [
        'form_submission'
    ]
    prefetch_tables = [
        'status_updates',
        'status_updates__status_type',
        'status_updates__author',
        'organization__county'
    ]
    qset = models.Application.objects.filter(
        organization__profiles__user=user
    ).select_related(*preselect_tables).prefetch_related(*prefetch_tables)
    return qset.order_by('-created').distinct()
github codeforamerica / intake / intake / services / followups.py View on Github external
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
github codeforamerica / intake / intake / services / applications_service.py View on Github external
def get_unread_apps_per_org_count(organization):
    return models.Application.objects.filter(
        organization=organization, **UNREAD_APPLICATIONS_FILTER_KWARGS).count()
github codeforamerica / intake / intake / services / applications_service.py View on Github external
def get_needs_update_apps_per_org_count(organization):
    return models.Application.objects.filter(
        organization=organization, **NEEDS_STATUS_UPDATE_FILTER_KWARGS).count()