예제 #1
0
    def save(self, *args, request, **kwargs):
        # first thing we need to do is create or find the right User object
        try:
            user = User.objects.get(email__iexact=self.cleaned_data['email'])
        except User.DoesNotExist:
            user = User(email=self.cleaned_data['email'],
                        first_name=self.cleaned_data['first_name'],
                        last_name=self.cleaned_data['last_name'],
                        prefix=self.cleaned_data.get('prefix', ""),
                        suffix=self.cleaned_data.get('suffix', ""),
                        is_active=False)
            user.save()

        self.instance.created_by = user
        self.instance.county = County.objects.filter(
            the_geom__intersects=self.instance.point).first()
        super().save(*args, **kwargs)

        # if the submitter left a question, add it as a comment
        if self.cleaned_data.get("questions"):
            c = Comment(report=self.instance,
                        created_by=user,
                        body=self.cleaned_data['questions'],
                        visibility=Comment.PROTECTED)
            c.save()

        send_mail(
            "OregonInvasivesHotline.org - Thank you for your submission",
            render_to_string(
                "reports/_submission.txt", {
                    "user":
                    user,
                    "url":
                    user.get_authentication_url(request,
                                                next=reverse(
                                                    "reports-detail",
                                                    args=[self.instance.pk]))
                }), "*****@*****.**", [user.email])

        UserNotificationQuery.notify(self.instance, request)

        return self.instance
예제 #2
0
    def save(self, *args, request, **kwargs):
        # first thing we need to do is create or find the right User object
        try:
            user = User.objects.get(email__iexact=self.cleaned_data['email'])
        except User.DoesNotExist:
            user = User(
                email=self.cleaned_data['email'],
                first_name=self.cleaned_data['first_name'],
                last_name=self.cleaned_data['last_name'],
                prefix=self.cleaned_data.get('prefix', ""),
                suffix=self.cleaned_data.get('suffix', ""),
                phone=self.cleaned_data.get('phone', ""),
                has_completed_ofpd=self.cleaned_data.get("has_completed_ofpd"),
                is_active=False
            )
            user.save()

        self.instance.created_by = user
        self.instance.county = County.objects.filter(the_geom__intersects=self.instance.point).first()
        super().save(*args, **kwargs)

        # if the submitter left a question, add it as a comment
        if self.cleaned_data.get("questions"):
            c = Comment(report=self.instance, created_by=user, body=self.cleaned_data['questions'], visibility=Comment.PROTECTED)
            c.save()

        send_mail(
            "OregonInvasivesHotline.org - Thank you for your submission",
            render_to_string("reports/_submission.txt", {
                "user": user,
                "url": user.get_authentication_url(request, next=reverse("reports-detail", args=[self.instance.pk]))
            }),
            "*****@*****.**",
            [user.email]
        )

        UserNotificationQuery.notify(self.instance, request)

        return self.instance
예제 #3
0
            print(row['id'])
            continue

        if row['private']:
            comment.visibility = Comment.PRIVATE

        if row['annotator_type'] == "User":
            comment.created_by_id = user_id_to_user_id[row['annotator_id']]
        elif row['annotator_type'] == "Submitter":
            comment.created_by_id = comment.report.created_by_id
        elif row['annotator_type'] == "Expert":
            comment.created_by_id = key_to_user_id[(row['annotator_type'], row['annotator_id'])]
        else:
            comment.created_by_id = comment.report.created_by_id

        comment.save()

    # add images
    old.execute("""
    SELECT id, imageable_id, imageable_type, filename, created_at, label FROM images
    WHERE imageable_type = 'Report'
    """)
    for row in dictfetchall(old):
        try:
            report = Report.objects.get(pk=row['imageable_id'])
        except Report.DoesNotExist:
            continue

        Image(
            image_id=row['id'],
            image=os.path.relpath(os.path.join(settings.MEDIA_ROOT, "images", ("%04d-" % row['id']) + row['filename']), settings.MEDIA_ROOT),