How to use the intake.models.FormSubmission 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 / tests / acceptance / test_screenshots.py View on Github external
]
        counties = models.County.objects.all()
        for county in counties:
            if county.slug == constants.Counties.SAN_FRANCISCO:
                self.sfcounty = county
            elif county.slug == constants.Counties.CONTRA_COSTA:
                self.cccounty = county
        self.submissions = []
        for org_set in org_sets:
            answers = {
                **intake_mock.fake.cleaned_sf_county_form_answers(),
                **intake_mock.fake.contra_costa_county_form_answers(),
                **intake_mock.fake.alameda_county_form_answers(),
                **intake_mock.fake.declaration_letter_answers(),
            }
            sub = models.FormSubmission.create_for_organizations(
                organizations=org_set, answers=answers)
            self.submissions.append(sub)
            for org in org_set:
                if org.slug != 'cfa':
                    attr_name = org.slug + '_submissions'
                    org_subs = getattr(self, attr_name)
                    org_subs.append(sub)
                    setattr(self, attr_name, org_subs)
        self.pdf = intake_mock.useable_pdf(self.sf_pubdef)
        self.superuser = auth_mock.fake_superuser()
        accounts_models.UserProfile.objects.create(
            user=self.superuser,
            organization=self.cfa)
github codeforamerica / intake / intake / serializers / form_submission_serializer.py View on Github external
from intake import models
from .application_serializers import ApplicationFollowupListSerializer
from .note_serializer import ApplicationNoteSerializer
from .tag_serializer import TagSerializer


class FormSubmissionFollowupListSerializer(serializers.ModelSerializer):
    local_date_received = fields.LocalDateField(source='date_received')
    full_name = serializers.CharField(source='get_full_name', read_only=True)
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    applications = ApplicationFollowupListSerializer(many=True)
    notes = ApplicationNoteSerializer(many=True)
    tags = TagSerializer(many=True)

    class Meta:
        model = models.FormSubmission
        fields = [
            'id',
            'local_date_received',
            'full_name',
            'url',
            'phone_number',
            'email',
            'applications',
            'notes',
            'tags'
        ]
github codeforamerica / intake / features / steps / applications_steps.py View on Github external
def create_fake_applications(context, count, org_slug=None, status=None):
    count = int(count)
    if org_slug:
        org = Organization.objects.get(slug=org_slug)
        factories.FormSubmissionWithOrgsFactory.create_batch(
            count, organizations=[org])
        if status:
            for sub in FormSubmission.objects.all():
                app = sub.applications.first()
                app.has_been_opened = True
                app.save()
            if status == "read and updated":
                profile = UserProfileFactory(organization=org)
                for sub in FormSubmission.objects.all():
                    factories.StatusUpdateFactory(
                        application=sub.applications.first(),
                        author=profile.user)

    else:
        factories.FormSubmissionWithOrgsFactory.create_batch(count)
github codeforamerica / intake / intake / services / submissions.py View on Github external
def create_for_organizations(organizations, **kwargs):
    submission = models.FormSubmission(**kwargs)
    submission.save()
    submission.organizations.add_orgs_to_sub(*organizations)
    return submission
github codeforamerica / intake / intake / management / data_import.py View on Github external
def parse_submission(self, record):
        return models.FormSubmission(
            old_uuid=record['uuid'],
            date_received=gmt.localize(record['date_received']),
            answers=record['answers']
            )
github codeforamerica / intake / intake / models.py View on Github external
instance.save()
        return instance

    def get_absolute_url(self):
        """This is unique _to each submission_.

        URLs will need to be changed when multiple pdfs can pertain to one
        submission
        """
        return reverse(
            'intake-filled_pdf',
            kwargs=dict(submission_id=self.submission.id))


class ApplicationBundle(models.Model):
    submissions = models.ManyToManyField(FormSubmission,
                                         related_name='bundles')
    organization = models.ForeignKey('user_accounts.Organization',
                                     on_delete=models.PROTECT,
                                     related_name='bundles')
    bundled_pdf = models.FileField(upload_to='pdf_bundles/', null=True,
                                   blank=True)

    @classmethod
    def create_with_submissions(cls, submissions, skip_pdf=False, **kwargs):
        instance = cls(**kwargs)
        instance.save()
        if submissions:
            instance.submissions.add(*submissions)
        if not skip_pdf and not instance.bundled_pdf:
            instance.build_bundled_pdf_if_necessary()
        return instance
github codeforamerica / intake / intake / models.py View on Github external
(REFERRED, "referred"),
        (PROCESSED, "processed"),
        (DELETED, "deleted"),
        (CONFIRMATION_SENT, "sent confirmation"),
        (REFERRED_BETWEEN_ORGS, "referred to another org"),
    )

    time = models.DateTimeField(default=timezone_utils.now)
    user = models.ForeignKey(User,
                             on_delete=models.SET_NULL, null=True,
                             related_name='application_logs')
    organization = models.ForeignKey(
        'user_accounts.Organization',
        on_delete=models.SET_NULL, null=True,
        related_name='logs')
    submission = models.ForeignKey(FormSubmission,
                                   on_delete=models.SET_NULL, null=True,
                                   related_name='logs')
    event_type = models.PositiveSmallIntegerField(
        choices=EVENT_TYPES)

    class Meta:
        ordering = ['-time']

    @classmethod
    def log_multiple(cls, event_type, submission_ids,
                     user, time=None, organization=None,
                     organization_id=None):
        if not time:
            time = timezone_utils.now()
        org_kwarg = dict(organization=organization)
        if not organization: