VI encontro PythonOnRioÉlysson Mendes RezendeDesenvolvedor pleno na BrBid.com
# coding: utf-8 import os from setuptools import setup current_dir = os.path.abspath(os.path.dirname(__file__)) readme = open(os.path.join(current_dir, 'README.md')).read() setup( name='pythononrio-templatetags', version='1.0', packages=['notificacoes'], description='Templates Tags desenvolvidos no Python On Rio', long_description=readme, author='Élysson MR', author_email='elyssonmr@gmail.com', url='https://github.com/elyssonmr/django_pkg/', license='MIT', install_requires=[ 'Django>=1.8', ] )
include *.md recursive-include notificacoes *.py *.html
$ python setup.py develop ... Installed /path/to/project/django_pkg Processing dependencies for django-templatetags==1.0 Searching for Django==1.8.5 Best match: Django 1.8.5 Adding Django 1.8.5 to easy-install.pth file Installing django-admin script to /home/user/.virtualenvs/venv/bin Using /home/user/.virtualenvs/venv/lib/python2.7/site-packages Finished processing dependencies for django-templatetags==1.0
# coding: utf-8 from django import template register = template.Library() @register.inclusion_tag('notificacoes/notification.html') def render_notification(): return {} @register.filter def format_hello(value, nome): return value % (nome)
<p>Oi eu sou uma notificação!</p>
INSTALLED_APPS = ( 'notificacoes', ) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:', } } SECRET_KEY = "ultra_secret_key_for_testing"
# coding: utf-8 from django.test import TestCase from django.template import Context from django.template import Template class TemplateTagTest(TestCase): def setUp(self): self.template = Template('{% load notify %} {% render_notification %}') def test_templatetag_inclusion(self): rendered = self.template.render(Context()) self.assertIn(u'sou uma notificação', rendered) class FilterTest(TestCase): def setUp(self): self.template = Template(u'{% load notify %}' + u' {{ "Oi %s, Como você esta?"|format_hello:"Élysson MR" }}') def test_filter(self): rendered = self.template.render(Context()) self.assertIn(u'Élysson MR', rendered)