示例#1
0
    def setUp(self):
        super(SendEmailsViewTestCase, self).setUp()
        email_class = get_email_class()

        # Create some emails.
        self.email1 = email_class.objects.create(
            name=u'Test email 1',
            html_en=u'<h1>Test en</h1>',
            html_es=u'<h1>Test es</h1>',
        )
        self.email2 = email_class.objects.create(
            name=u'Test email 2',
            html_en=u'<h1>Test en</h1>',
            html_es=u'<h1>Test es</h1>',
        )

        # Create a few invitees
        self.invitee1 = Invitee.objects.create(
            first_name='Jon',
            last_name='Snow',
            email='*****@*****.**',
            language='en',
        )
        self.invitee2 = Invitee.objects.create(
            first_name='Daenerys',
            last_name='Targaryen',
            email='*****@*****.**',
            language='en',
        )
示例#2
0
文件: views.py 项目: jgasteiz/wedding
    def post(self, *args, **kwargs):

        invitee_ids = self.request.POST.getlist('invitees[]')
        email_id = self.request.POST.get('email')

        Email = get_email_class()

        for invitee_id in invitee_ids:
            invitee = Invitee.objects.get(pk=invitee_id)

            # Check if the email has already been sent to the invitee.
            emails_sent_to_invitee_ids = invitee.get_email_ids()
            if email_id in emails_sent_to_invitee_ids:
                continue

            email = Email.objects.get(pk=email_id)

            message = mail.EmailMessage(
                sender="Javi Manzano <{}>".format(settings.EMAIL_FROM),
                subject="You're invited to our wedding"
            )

            message.to = u'{} <{}>'.format(
                unicode(invitee.fullname),
                invitee.email
            )

            message_html = get_email_content(email=email, language=invitee.language)

            # Replace tokens in the email for their values
            message_html = message_html.replace(INVITEE_NAME_TOKEN, invitee.fullname)
            rsvp_url = '{}{}?invitee={}'.format(settings.SERVER_DOMAIN, reverse('public:rsvp'), invitee.token)
            # Replace the language in the `rsvp_url` for nothing - this should be done in a nicer way.
            rsvp_url = rsvp_url.replace('/en/', '/')
            rsvp_url = rsvp_url.replace('/es/', '/')
            message_html = message_html.replace(RSVP_URL_TOKEN, rsvp_url)

            logging.info(message_html)

            message.html = message_html
            message.send()

            # Add email id to invitee emails list.
            if email_id not in emails_sent_to_invitee_ids:
                emails_sent_to_invitee_ids.append(email_id)
                invitee.emails = ','.join(emails_sent_to_invitee_ids)
                invitee.save()

        return HttpResponse('OK')
示例#3
0
 def setUp(self):
     super(EmailViewsTestCase, self).setUp()
     self.email_class = get_email_class()
示例#4
0
文件: views.py 项目: jgasteiz/wedding
 def get(self, *args, **kwargs):
     language = self.request.GET.get('language')
     Email = get_email_class()
     email_pk = kwargs.get('pk')
     email = Email.objects.get(pk=email_pk)
     return HttpResponse(get_email_content(email=email, language=language))
示例#5
0
文件: views.py 项目: jgasteiz/wedding
 def get_object(self, queryset=None):
     Email = get_email_class()
     email_pk = self.kwargs.get('pk')
     return Email.objects.get(pk=email_pk)
示例#6
0
文件: views.py 项目: jgasteiz/wedding
 def post(self, request, *args, **kwargs):
     Email = get_email_class()
     email_pk = self.kwargs.get('pk')
     self.object = Email.objects.get(pk=email_pk)
     return super(EmailUpdateView, self).post(request, *args, **kwargs)
示例#7
0
文件: views.py 项目: jgasteiz/wedding
 def get_queryset(self):
     Email = get_email_class()
     return Email.objects.all()
示例#8
0
文件: views.py 项目: jgasteiz/wedding
 def get_context_data(self, **kwargs):
     ctx = super(InviteesView, self).get_context_data(**kwargs)
     Email = get_email_class()
     ctx['emails'] = Email.objects.all()
     return ctx