Exemple #1
0
 def setUp(self):
     user = UserFactory.build()
     confirm = EmailTemplate(
         name='registration confirmation',
         subject='Account activation',
     )
     confirm.save()
     self.before = User.objects.count()
     self.user = create_new_user(first_name=user.first_name,
                                 last_name=user.last_name,
                                 email=user.email,
                                 password='******')
Exemple #2
0
 def setUp(self):
     user = UserFactory.build()
     confirm = EmailTemplate(
         name='registration confirmation',
         subject='Account activation',
     )
     confirm.save()
     self.before = User.objects.count()
     self.user = create_new_user(
         first_name=user.first_name,
         last_name=user.last_name,
         email=user.email,
         password='******'
     )
    def handle_noargs(self, **options):
        # Get the list of files in the email templates folder.
        email_root_path = settings.EMAIL_ROOT
        email_templates = [t for t in os.listdir(email_root_path) if t.endswith('.html')]

        # Get current templates from the database
        post_office_templates = EmailTemplate.objects.all()

        already_in_database = set()
        for template in post_office_templates:
            # Get the template name.
            this_email_template_name = template.name.replace('.email','.html')
            already_in_database.add(this_email_template_name)

            #Read the corresponding template from file. If it doesn't exist, move on.
            if not this_email_template_name in email_templates:
                self.stdout.write('Skipping %s - cannot find the template!' % template.name)
                continue
            self.stdout.write('Updating %s' % template.name)
            this_email_template = open(os.path.join(email_root_path, this_email_template_name), 'r').read()

            #Update content
            template.html_content = this_email_template
            soup = BeautifulSoup.BeautifulSoup(this_email_template)
            for l in soup.findAll('a'):
                l.setString(l.getString() + u'( ' + l['href'] + ' )')
            template.content = strip_tags(str(soup)) #<---- Note: We can do soup.prettify() here instead of str(soup)
            #Update subject
            template.subject = open(os.path.join(email_root_path, this_email_template_name).replace('.html','.subject'), 'r').read()

            template.save()

        new_templates = set(email_templates) - already_in_database

        for template in new_templates:
            #Read the template:
            content = open(os.path.join(email_root_path, template),'r').read()

            new_template = EmailTemplate()

            new_template.name = template.replace('.html','.email')
            new_template.description = new_template.name.replace('.', ' ')
            new_template.subject = open(os.path.join(email_root_path, template).replace('.html','.subject'),'r').read()
            new_template.html_content = content
            soup = BeautifulSoup.BeautifulSoup(content)
            for l in soup.findAll('a'):
                l.setString(l.getString() + u'( ' + l['href'] + ' )')
            for l in soup.findAll('li'):
                l.setString(u'- ' + l.getString())
            new_template.content = strip_tags(str(soup)) #<---- Note: We can do soup.prettify() here instead of str(soup)
            new_template.save()
            self.stdout.write('Adding %s' % template)

        self.stdout.write('All done. Check if everything is fine from the admin console. Wouldn\'t hurt!' )
Exemple #4
0
 def get_email_template_or_default(cls, name, instance):
     try:
         template = EmailTemplate.objects.get(name=name)
     except EmailTemplate.DoesNotExist:
         template = EmailTemplate(subject='Trip {}: {}'.format(
             instance.status, instance.reference))
     return template
Exemple #5
0
 def setUp(self):
     encoder = UserAuthCode(settings.SECRET_KEY)
     self.user = UserFactory(is_active=False)
     self.code = encoder.auth_code(self.user)
     confirm = EmailTemplate(
         name='registration confirmation',
         subject='Account activation',
     )
     confirm.save()
     complete = EmailTemplate(name='registration complete', )
     complete.save()
Exemple #6
0
 def setUp(self):
     self.site = Site.objects.get()
     self.site.domain = "example.com"
     self.site.name = "Example site"
     self.site.save()
     confirm = EmailTemplate(
         name='registration confirmation',
         subject='Account activation',
         content='http://{{site.domain}}/user/activate/{{user.id}}/{{activation_code}}',
         html_content='http://{{site.domain}}/user/activate/{{user.id}}/{{activation_code}}',
     )
     confirm.save()
     complete = EmailTemplate(
         name='registration complete',
         subject='Welcome to team !',
     )
     complete.save()
Exemple #7
0
 def setUp(self):
     encoder = UserAuthCode(settings.SECRET_KEY)
     self.user = UserFactory(is_active=False)
     self.code = encoder.auth_code(self.user)
     confirm = EmailTemplate(
         name='registration confirmation',
         subject='Account activation',
     )
     confirm.save()
     complete = EmailTemplate(
         name='registration complete',
     )
     complete.save()
    def handle_noargs(self, **options):
        # Get the list of files in the email templates folder.
        email_root_path = settings.EMAIL_ROOT
        email_templates = [t for t in os.listdir(email_root_path) if t.endswith('.html')]

        # Get current templates from the database
        post_office_templates = EmailTemplate.objects.all()

        already_in_database = set()
        for template in post_office_templates:
            # Get the template name.
            this_email_template_name = template.name.replace('.email','.html')
            already_in_database.add(this_email_template_name)

            #Read the corresponding template from file. If it doesn't exist, move on.
            if not this_email_template_name in email_templates:
                self.stdout.write('Skipping %s - cannot find the template!' % template.name)
                continue
            self.stdout.write('Updating %s' % template.name)
            this_email_template = open(os.path.join(email_root_path, this_email_template_name), 'r').read()

            #Update content
            template.html_content = this_email_template
            soup = BeautifulSoup.BeautifulSoup(this_email_template)
            for l in soup.findAll('a'):
                if l.getString():
                    string = l.getString()
                else:
                    string = ""
                l.setString(string + u'( ' + l['href'] + ' )')
            template.content = strip_tags(str(soup)) #<---- Note: We can do soup.prettify() here instead of str(soup)
            #Update subject
            template.subject = open(os.path.join(email_root_path, this_email_template_name).replace('.html','.subject'), 'r').read()

            template.save()

        new_templates = set(email_templates) - already_in_database

        for template in new_templates:
            #Read the template:
            content = open(os.path.join(email_root_path, template),'r').read()

            new_template = EmailTemplate()

            new_template.name = template.replace('.html','.email')
            new_template.description = new_template.name.replace('.', ' ')
            new_template.subject = open(os.path.join(email_root_path, template).replace('.html','.subject'),'r').read()
            new_template.html_content = content
            soup = BeautifulSoup.BeautifulSoup(content)
            for l in soup.findAll('a'):
                if l.getString():
                    l.setString(l.getString() + u'( ' + l['href'] + ' )')
                else:
                    l.setString(u'( ' + l['href'] + ' )')
            for l in soup.findAll('li'):
                l.setString(u'- ' + l.getString())
            new_template.content = strip_tags(str(soup)) #<---- Note: We can do soup.prettify() here instead of str(soup)
            new_template.save()
            self.stdout.write('Adding %s' % template)

        self.stdout.write('All done. Check if everything is fine from the admin console. Wouldn\'t hurt!' )