How to use the intake.models.FormSubmission.objects 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 / application_form_views.py View on Github external
def get_last_submission_of_applicant_if_exists(applicant_id):
    subs = models.FormSubmission.objects.filter(
        applicant_id=applicant_id)
    if subs.count():
        return subs.latest('date_received')
    return None
github codeforamerica / intake / features / steps / pdf_steps.py View on Github external
def test_prefilled_pdf_for_applicant(context, applicant_name):
    first_name, last_name = applicant_name.split(' ')
    sub = models.FormSubmission.objects.filter(
        first_name=first_name, last_name=last_name).first()
    context.test.assertTrue(sub.filled_pdfs.count() >= 1)
github codeforamerica / intake / intake / serializers / note_serializer.py View on Github external
from rest_framework import serializers
from django.contrib.auth.models import User
from intake import models
from intake.serializers.fields import FormattedLocalDateField


class ApplicationNoteSerializer(serializers.ModelSerializer):
    created = FormattedLocalDateField(format='%b %-d', required=False)
    submission = serializers.PrimaryKeyRelatedField(
        queryset=models.FormSubmission.objects.all())
    user = serializers.PrimaryKeyRelatedField(
        queryset=User.objects.filter(is_staff=True))

    class Meta:
        model = models.ApplicationNote
        fields = [
            'id',
            'submission',
            'body',
            'created',
            'user'
        ]

    def to_representation(self, obj):
        name = obj.user.first_name
        base = super().to_representation(obj)
github codeforamerica / intake / intake / management / data_import.py View on Github external
def import_submissions(self, delete_existing=False):
        self.delete_existing(models.FormSubmission, delete_existing)
        self._cursor.execute(SUBMISSIONS_SQL)
        result = models.FormSubmission.objects.bulk_create(
            self.parse_submission(r) for r in self._cursor
        )
        success_message = "Successfully imported {} form submissions{}".format(
                len(result), self.from_string())
        saved_submissions = models.FormSubmission.objects.all()
        for sub in saved_submissions:
            self._uuid_pk_map[sub.old_uuid] = sub.id
        self.messages.append(success_message)
github codeforamerica / intake / intake / services / followups.py View on Github external
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 / 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 / views / session_view_base.py View on Github external
def send_notifications(self, submission):
        number = models.FormSubmission.objects.count()
        # TODO: say which orgs this is going to in notification
        notifications.slack_new_submission.send(
            submission=submission, request=self.request,
            submission_count=number)
        self.create_confirmations_for_user(submission)
github codeforamerica / intake / intake / views.py View on Github external
def build_redirect_url(self, request, submission_id):
        submission = models.FormSubmission.objects.get(old_uuid=submission_id)
        return reverse_lazy(self.redirect_view_name,
                            kwargs=dict(submission_id=submission.id)
                            )
github codeforamerica / intake / intake / views.py View on Github external
def send_notifications(self, submission):
        number = models.FormSubmission.objects.count()
        # TODO: say which orgs this is going to in notification
        notifications.slack_new_submission.send(
            submission=submission, request=self.request,
            submission_count=number)
        self.create_confirmations_for_user(submission)