コード例 #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
    def save(self, user, report, request):
        invited = []
        already_invited = []
        for email in self.cleaned_data['emails']:
            if Invite.create(email=email,
                             report=report,
                             inviter=user,
                             message=self.cleaned_data.get('body'),
                             request=request):
                invited.append(email)
            else:
                already_invited.append(email)

        # make the invite into a comment
        Comment(body=self.cleaned_data.get("body"),
                created_by=user,
                visibility=Comment.PRIVATE,
                report=report).save()
        return namedtuple("InviteReport",
                          "invited already_invited")(invited, already_invited)
コード例 #4
0
        report.county = County.objects.filter(the_geom__intersects=report.point).first()
        report.is_archived = row['closed'] and not row['issue_id']
        report.is_public = row['closed'] and row['issue_id']
        try:
            report.save()
        except Exception as e:
            print(str(e))
            continue

        # create a private comment for the private_note field
        # the PK should be large to avoid colliding with the comments that are imported later
        if row['private_note']:
            Comment(
                pk=100000+report.pk,
                report_id=report.pk,
                body=row['private_note'],
                created_on=row['created_at'],
                visibility=Comment.PRIVATE,
                created_by=User.objects.filter(is_staff=True).first()
            ).save()

    # add comments
    old.execute("""
    SELECT private, id, report_id, annotator_id, annotator_type, body, created_at FROM annotations
    """)
    for row in dictfetchall(old):
        comment = Comment.objects.filter(pk=row['id']).first()
        if not comment:
            comment = Comment(pk=row['id'])

        comment.body = row['body'] or ""
        comment.created_on = row['created_at']