def setUp(self): super(TestAppDirectoriesFinder, self).setUp() self.finder = finders.AppDirectoriesFinder() test_file_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'test', 'file1.txt') self.find_first = (os.path.join('test', 'file1.txt'), test_file_path) self.find_all = (os.path.join('test', 'file1.txt'), [test_file_path])
def render(self, msg, render_format, lang): """ This basic renderer just returns the subject in the Msg payload """ if not self.can_render_format(render_format): NotImplementedError() if not self.underscore_template: template_url_path = self.get_template_path(render_format) template_url_path = template_url_path.replace(static(''), '') underscore_filepath = finders.AppDirectoriesFinder().find( template_url_path) if not underscore_filepath: err_msg = ( 'Could not resolve Underscore static url path {url_path} ' 'to a filesystem path.').format(url_path=template_url_path) raise Exception(err_msg) with open(underscore_filepath, "r") as _file: template_string = _file.read() self.underscore_template = us.template(template_string) _payload = copy.deepcopy(msg.payload) created_str = msg.created.strftime( "%B %d, %Y") + ' at ' + msg.created.strftime("%H:%M%p") + ' GMT' _payload.update({'__display_created': created_str}) return self.underscore_template(_payload)
def setUp(self): super().setUp() self.finder = finders.AppDirectoriesFinder() test_file_path = os.path.join( TEST_ROOT, "apps", "test", "static", "test", "file1.txt" ) self.find_first = (os.path.join("test", "file1.txt"), test_file_path) self.find_all = (os.path.join("test", "file1.txt"), [test_file_path])
def attach_image(img_dict, filename): """ attach images in the email headers """ img_path = img_dict['path'] if not img_path.startswith('/'): img_path = finders.AppDirectoriesFinder().find(img_path) if img_path: with open(img_path, 'rb') as img: msg_image = MIMEImage(img.read(), name=os.path.basename(img_path)) msg_image.add_header('Content-ID', '<{}>'.format(img_dict['cid'])) msg_image.add_header("Content-Disposition", "inline", filename=filename) return msg_image
def with_inline_css(html_without_css): """ returns html with inline css if css file path exists else returns html with out the inline css. """ css_filepath = const.NOTIFICATION_DIGEST_EMAIL_CSS if not css_filepath.startswith('/'): css_filepath = finders.AppDirectoriesFinder().find(const.NOTIFICATION_DIGEST_EMAIL_CSS) if css_filepath: with open(css_filepath, "r") as _file: css_content = _file.read() # insert style tag in the html and run pyliner. html_with_inline_css = pynliner.fromString('<style>' + css_content + '</style>' + html_without_css) return html_with_inline_css return html_without_css
def setUp(self): super(TestAppDirectoriesFinder, self).setUp() self.finder = finders.AppDirectoriesFinder() test_file_path = os.path.join(TEST_ROOT, 'apps/test/static/test/file1.txt') self.find_first = ("test/file1.txt", test_file_path) self.find_all = ("test/file1.txt", [test_file_path])