diff --git a/app/apps/imports/tasks.py b/app/apps/imports/tasks.py index 6ecfc50fce11394d340ed178d5341ec86e1b9a0e..cb810a720d9ca9547bbec3be6b8ea82f4a17d13e 100644 --- a/app/apps/imports/tasks.py +++ b/app/apps/imports/tasks.py @@ -151,6 +151,6 @@ def document_export(task, file_format, user_pk, document_pk, part_pks, send_email('export/email/ready_subject.txt', 'export/email/ready_message.txt', 'export/email/ready_html.html', - user.email, + (user.email,), context={'domain': Site.objects.get_current().domain, 'export_uri': rel_path}) diff --git a/app/apps/users/admin.py b/app/apps/users/admin.py index 423dac64946e2f06d9d7eb8ca6d6851f0ac954da..d44bb4caff795746b50e2ce697a1c71584637f90 100644 --- a/app/apps/users/admin.py +++ b/app/apps/users/admin.py @@ -60,8 +60,12 @@ class InvitationAdmin(admin.ModelAdmin): ) % count, messages.SUCCESS) +class ContactUsAdmin(admin.ModelAdmin): + readonly_fields = ('created_at',) + + admin.site.register(User, MyUserAdmin) admin.site.register(ResearchField) admin.site.register(Invitation, InvitationAdmin) -admin.site.register(ContactUs) +admin.site.register(ContactUs, ContactUsAdmin) admin.site.register(GroupOwner) diff --git a/app/apps/users/migrations/0013_auto_20210106_1305.py b/app/apps/users/migrations/0013_auto_20210106_1305.py new file mode 100644 index 0000000000000000000000000000000000000000..474cb1f0bad536b5424100c9ca688fb66c2e8b50 --- /dev/null +++ b/app/apps/users/migrations/0013_auto_20210106_1305.py @@ -0,0 +1,25 @@ +# Generated by Django 2.1.4 on 2021-01-06 13:05 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0012_create_group_owners'), + ] + + operations = [ + migrations.AddField( + model_name='contactus', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AlterField( + model_name='user', + name='onboarding', + field=models.BooleanField(default=True, verbose_name='Show onboarding'), + ), + ] diff --git a/app/apps/users/models.py b/app/apps/users/models.py index 91264d718bb07f9c6959c948490a6ef0d460a61b..3ef8cc9f2de8800cf7d0c36ac6029f3fb2594b0a 100644 --- a/app/apps/users/models.py +++ b/app/apps/users/models.py @@ -114,7 +114,7 @@ class Invitation(models.Model): "team": self.group.name, "accept_link": accept_url, } - self.send_email(self.recipient.email, context) + self.send_email((self.recipient.email,), context) def send_invitation_to_service(self, request): accept_url = request.build_absolute_uri( @@ -127,7 +127,7 @@ class Invitation(models.Model): "team": self.group and self.group.name, "accept_link": accept_url, } - self.send_email(self.recipient_email, context) + self.send_email((self.recipient_email,), context) def send_email(self, to, context): send_email( @@ -163,7 +163,6 @@ class Invitation(models.Model): return True - class ContactUs(models.Model): """ Represents Contact Us form @@ -174,10 +173,11 @@ class ContactUs(models.Model): max_length=255, ) message = models.TextField() + created_at = models.DateTimeField(auto_now_add=True, editable=False) class Meta: - verbose_name = "message" - verbose_name_plural = "messages" + verbose_name = "Contact message" + verbose_name_plural = "Contact messages" def __str__(self): return "from {}({})".format(self.name, self.email) @@ -197,7 +197,6 @@ class ContactUs(models.Model): context=context, result_interface=None ) - super().save(*args, **kwargs) diff --git a/app/escriptorium/utils.py b/app/escriptorium/utils.py index b50a8f97d0bca2d68ec95481e78eecacf7123bee..0da34866ead8c4d66a0761fd9602483c1ec702c7 100644 --- a/app/escriptorium/utils.py +++ b/app/escriptorium/utils.py @@ -5,23 +5,24 @@ from users.tasks import async_email def send_email(subject_template, txt_template, html_template, - recipient, context=None, + recipients, + context=None, result_interface=None): """ Higher level interface to send a multipart/aternative email with text/plain + text/html - + Send an email to the given recipient using given templates and context Queue with celery if settings.USE_CELERY == True - + result_interface is used by the task to update an instance if the mail was sent or got an error it's a tuple (app_name, model_name, instance_id) which needs to present .email_sent() and .email_error(msg) methods """ subject_tmplt = get_template(subject_template) txt_tmplt = get_template(txt_template) html_tmplt = get_template(html_template) - + subject = subject_tmplt.render(context=context).strip('\n') msg = txt_tmplt.render(context=context) html = html_tmplt.render(context=context) - - async_email.delay(subject, msg, (recipient,), html=html, result_interface=result_interface) + + async_email.delay(subject, msg, recipients, html=html, result_interface=result_interface)