def create(cls, *, email, report, inviter, message, request): """ Create and send an invitation to the person with the given email address Returns True if the invite was sent, otherwise False (meaning the user has already been invited before) """ try: user = User.objects.get(email__iexact=email) except User.DoesNotExist: user = User(email=email, is_active=False) user.save() if Invite.objects.filter(user=user, report=report).exists(): return False invite = Invite(user=user, created_by=inviter, report=report) send_mail( "Invasive Species Hotline Submission Review Request", render_to_string("reports/_invite_expert.txt", { "inviter": inviter, "message": message, "url": user.get_authentication_url(request, next=reverse("reports-detail", args=[report.pk])) }), "*****@*****.**", [email] ) invite.save() return True
def create(cls, *, email, report, inviter, message, request): """ Create and send an invitation to the person with the given email address Returns True if the invite was sent, otherwise False (meaning the user has already been invited before) """ try: user = User.objects.get(email__iexact=email) except User.DoesNotExist: user = User(email=email, is_active=False) user.save() if Invite.objects.filter(user=user, report=report).exists(): return False invite = Invite(user=user, created_by=inviter, report=report) send_mail( "Invasive Species Hotline Submission Review Request", render_to_string( "reports/_invite_expert.txt", { "inviter": inviter, "message": message, "url": user.get_authentication_url(request, next=reverse("reports-detail", args=[report.pk])) }), "*****@*****.**", [email]) invite.save() return True
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
class SpeciesFormsTest(TestCase, elasticmodels.ESTestCase): """ Some unit tests to ensure forms in the species app work as they should. """ def setUp(self): super(SpeciesFormsTest, self).setUp() make(Species, name="stuff") self.user = User(first_name="foo", last_name="bar", email="*****@*****.**", is_staff=True) self.user.set_password("foobar") self.user.save() self.client.login(username="******", password="******") def test_get_initial_queryset(self): form = SpeciesSearchForm(user=self.user, data={}) queryset = form.get_queryset() self.assertEqual(len(queryset), Species.objects.count()) def test_valid_form(self): form = SpeciesSearchForm({'querystring': 'other'}, user=self.user) self.assertTrue(form.is_valid()) def test_form_with_empty_querystring_returns_everything(self): form = SpeciesSearchForm({'querystring': ''}, user=self.user) self.assertTrue(form.is_valid()) results = list(form.search().execute()) self.assertEqual(len(results), Species.objects.count()) def test_search_returns_correct_object(self): # test object name = "other" make(Species, name=name) # set it all up form = SpeciesSearchForm({'querystring': 'other'}, user=self.user) # make sure the form is valid self.assertTrue(form.is_valid()) results = form.search().execute()[0] # Check to see that the id of the test object "other" # is in the list of ids returned by the search function self.assertEqual(results['name'], name)
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
FROM vcards LEFT JOIN users ON vcards.cardable_id = users.id AND cardable_type = 'User' ORDER BY cardable_type """) for row in dictfetchall(old): user = User.objects.filter(email=row['email']).first() if not user: user = User(email=row['email'], is_active=False) user.email = row['email'] user.first_name = row['n_given'] or "" user.last_name = row['n_family'] or "" user.prefix = row['n_prefix'] or "" user.suffix = row['n_suffix'] or "" user.is_active = user.is_active or bool(row['enabled']) user.affiliations = user.affiliations or (row['affiliations'] or "") user.save() user_id_to_user_id[row['user_id']] = user.pk if row['cardable_type'] == "Submitter": report_submitter_user_id[row['cardable_id']] = user.pk key_to_user_id[(row['cardable_type'], row['cardable_id'])] = user.pk # create reports old.execute(""" SELECT reports.id, category_id, issue_id, reported_category, reported_issue, has_sample, issue_desc, private_note, location_desc, reports.created_at, reports.updated_at, closed, user_id, edrr_status, lat, lng FROM reports LEFT JOIN locations ON locations.locateable_id = reports.id AND locateable_type = 'Report' """)