Slide 1

Slide 1 text

Taller de Django Betabeers Antonio Melé y Miguel Araujo 01

Slide 2

Slide 2 text

Tests y Docs 02

Slide 3

Slide 3 text

tests.py class BetabeersViewsTest(TestCase): fixtures = ['initial-data.json'] def setUp(self): self.client = Client() self.client.login(username="rebeca", password="rebeca") def test_login_200(self): context = { 'title': 'Betabeers Test note', 'text': 'I like beers more than beta', } response = self.client.post(reverse('post_note'), context) self.assertTrue(Note.objects.filter(title='Betabeers Test note').exists()) 03

Slide 4

Slide 4 text

Ecosistema 04

Slide 5

Slide 5 text

pip y PyPi PyPi (The Python Package Index): repositorio de software de Python https://github.com/pypa/pip: pip es el instalador pip install django • • • 05

Slide 6

Slide 6 text

Virtual Environments (venvs) http://www.virtualenv.org/en/latest/index.html https://github.com/pypa/virtualenv virtualenvwrapper virtualenv-burrito mkvirtualenv betabeers workon betabeers • • • • • • 06

Slide 7

Slide 7 text

Virtual Environments (venvs) ¿Una forma fácil de instalarlo todo? curl -s https://raw.github.com/brainsik/virtualenv- burrito/master/virtualenv-burrito.sh | bash • • 07

Slide 8

Slide 8 text

Django apps 08

Slide 9

Slide 9 text

django-debug-toolbar (DjDT) https://github.com/django-debug-toolbar/django-debug-toolbar Barra de debugging de aplicaciones Muestra información de una página: contexto disponible, sentencias SQL ejecutadas... Dispone de un sistema de plugins • • • • 09

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

Pinax Plataforma de desarrollo extremo de aplicaciones web. Numerosas Django apps reutilizables integradas y manejables fácilmente. • • 11

Slide 12

Slide 12 text

django-extensions https://github.com/django-extensions/django-extensions Amplia la lista de comandos disponibles Ayuda: python manage.py graph_models --help $ ./manage.py graph_models -a -g -o my_project.png • • • • 12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

django-extensions ./manage.py shell_plus ./manage.py dumpscript • • 14

Slide 15

Slide 15 text

django-social-auth https://github.com/omab/django-social-auth Open Authentication login: Twitter, Facebook, Google... y muchos más La mejor alternativa. NO confundir con django-socialauth Muy configurable y customizable • • • • 15

Slide 16

Slide 16 text

Plantilla 16

Slide 17

Slide 17 text

django_compressor https://github.com/jezdez/django_compressor Django Compressor combina y comprime linked e inline Javascript o CSS en las plantillas de Django en ficheros estáticos cacheables. python manage.py compress • • • 17

Slide 18

Slide 18 text

Plantilla {% load compress %} {% compress js %} obj.value = "value"; {% endcompress %} Renderiza: 18

Slide 19

Slide 19 text

django-celery https://github.com/ask/django-celery Cola de tareas asíncronas Tiempo Real o planificada RabbitMQ / Redis • • • • 19

Slide 20

Slide 20 text

django-sentry https://github.com/dcramer/django-sentry Agregador de logs en tiempo real Raven Servicio tecnológicamente agnóstico • • • 20

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

django-uni-form https://github.com/pydanny/django-uni-form Layouts programáticos reutilizables construidos por componentes. La mejor forma de tener DRY forms en Django. • • • 22

Slide 23

Slide 23 text

class MyForm(forms.Form): form_field_1 = forms.CharField(...) def __init__(self, *arg, **kwargs): self.helper = FormHelper() self.helper.form_action = 'submit-survey' self.helper.layout = Layout( Div( 'form_field_2', 'form_field_3', ) ButtonHolder( Submit('save', 'Save', css_class='button white') ) ) super(MyForm, self).__init__(*args, **kwargs) 23

Slide 24

Slide 24 text

Plantilla {% load uni_form_tags %} {% uni_form my_form my_form.helper %} 24

Slide 25

Slide 25 text

django-floppyforms https://github.com/brutasse/django-floppyforms Remplaza los widgets de Django por HTML5 widgets. Widgets basados en plantillas. Añade widgets y algún campo nuevo. import floppyforms as forms • • • • • 25

Slide 26

Slide 26 text

django-cache-machine https://github.com/jbalogh/django-cache-machine Cacheado/Invalidación autómatico de los modelos a través del ORM. Redefine el Django Memcached backend para cacheado infinito. Cuando un objeto cambia, es invalidado. Nuestros model managers deben heredar de CachingManager. • • • • • 26

Slide 27

Slide 27 text

models.py from django.db import models import caching.base class Zomg(caching.base.CachingMixin, models.Model): val = models.IntegerField() objects = caching.base.CachingManager() 27

Slide 28

Slide 28 text

django-secure https://github.com/carljm/django-secure Cumprueba nuestros settings para evitar que hagamos cosas estupidas. python manage.py checksecure Middleware configurable que nos ayuda a mejorar la seguridad de nuestro site. • • • • 28

Slide 29

Slide 29 text

django-devserver https://github.com/dcramer/django-devserver Reemplazo plug and play del servidor de desarrollo de Django. Incluye módulos para el profiling de consultas SQL, vistas, uso de memoria, etc. python manage.py runserver • • • • 29

Slide 30

Slide 30 text

django-dajax https://github.com/jorgebastida/django-dajax http://dajaxproject.com/ Forma fácil y potente de utilizar AJAX en nuestro proyectos sin escribir casi nada de código JS Soporta jQuery, Dojo, Prototype y motools • • • • 30

Slide 31

Slide 31 text

views.py from dajax.core.Dajax import Dajax def assign_test(request): dajax = Dajax() dajax.assign('#block01 li', 'innerHTML', 'Something else...') return dajax.json() Plantilla
Click Here!
31

Slide 32

Slide 32 text

Haystack https://github.com/toastdriven/django-haystack http://toastdriven.com/ La mejor forma de añadir un motor de búsqueda a Django Arquitectura similar a los modelos ORM, pero orientado a búsqueda. Soporte de varios motores: Solr, Xapian, Whoosh Escribiendo SearchIndex en search_indexes.py • • • • • • 32

Slide 33

Slide 33 text

search_indexes.py class NoteIndex(SearchIndex): text = CharField(document=True, use_template=True) author = CharField(model_attr='user') pub_date = DateTimeField(model_attr='pub_date') def index_queryset(self): """Used when the entire index for model is updated.""" return Note.objects.filter(pub_date__lte=datetime.datetime.now()) site.register(Note, NoteIndex) 33

Slide 34

Slide 34 text

Plantilla {{ object.title }} {{ object.user.get_full_name }} {{ object.body }} 34

Slide 35

Slide 35 text

django-reversion https://github.com/etianen/django-reversion Extensión que añade funcionalidad de control de versiones a los modelos Recuperar modelos borrados Histórico de datos con capacidad de retroceso en el tiempo API a bajo nivel • • • • • 35

Slide 36

Slide 36 text

South https://bitbucket.org/andrewgodwin/south/overview http://south.aeracode.org/ Migraciones de bases de datos relacionales sin volverse loco, de forma semiautomática Interesante opción para trabajo en equipo • • • • 36

Slide 37

Slide 37 text

South ./manage.py schemamigration my_app --initial ./manage.py migrate my_app ./manage.py migrate schemamigration my_app --auto ./manage.py migrate my_app Metadatos en: tabla south_migrationhistory y directorio migrations • • • • • 37

Slide 38

Slide 38 text

django-registration https://github.com/nathanborror/django-registration Fork del proyecto. Django app con probablemente record de forks. Sistema de registro de usuarios customizable en la aplicación Usar versión 0.8.0 alpha • • • • 38

Slide 39

Slide 39 text

django-tastypie https://github.com/toastdriven/django-tastypie Genera deliciosas APIs para proyectos de Django. Mi favorita para hacer interfaces RESTful HTTP Tremendamente potente: autenticación, autorización, serializado, customizado... • • • • 39

Slide 40

Slide 40 text

my_app/api.py from tastypie.resources import ModelResource from myapp.models import Entry class EntryResource(ModelResource): class Meta: queryset = Entry.objects.all() 40

Slide 41

Slide 41 text

urls.py from myapp.api import EntryResource entry_resource = EntryResource() urlpatterns = patterns('', (r'^api/', include(entry_resource.urls)), ) 41

Slide 42

Slide 42 text

django-tastypie httli://127.0.0.1:8000/api/entry/?format=json httli://127.0.0.1:8000/api/entry/1/?format=json httli://127.0.0.1:8000/api/entry/schema/?format=json httli://127.0.0.1:8000/api/entry/set/1;3/?format=json • • • • 42