• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Django além do admin
 

Django além do admin

on

  • 3,086 views

Apresentação "Django além do admin", realizado no ciclo de apresentações internas da Giran (Giran Siege)....

Apresentação "Django além do admin", realizado no ciclo de apresentações internas da Giran (Giran Siege).

Mais detalhes sobre o Giran Siege: http://blog.giran.com.br/2010/09/giran-siege-palestras-internas-da-giran/

Statistics

Views

Total Views
3,086
Views on SlideShare
3,083
Embed Views
3

Actions

Likes
1
Downloads
29
Comments
0

3 Embeds 3

http://twitter.com 1
http://us-w1.rockmelt.com 1
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Django além do admin Django além do admin Presentation Transcript

    • O Django é o “framework web paraperfeccionistas com prazos”... Esse cara ta me zoando... ... e o seu principal recurso é o Django Admin.
    • Além do que seus olhos podem ver!http://2.bp.blogspot.com/_WHZ6KCOzbjE/S-qISN_FKuI/AAAAAAAABq4/Np0J_Vsf_vk/s1600/RafikisWords.jpg
    • Django além do admin Francisco Souza francisco@franciscosouza.net www.franciscosouza.com
    • http://www.flickr.com/photos/41460120@N04/4217783923/ Quer dizer que o admin não é o principal recurso do Django?! Não é bem assim, mano...
    • http://www.flickr.com/photos/villes/1348742988/
    • então qual éhttp://www.flickr.com/photos/desiitaly/2201907500/
    • O principal recurso doDjango é o mais fundamental para a sua aplicação
    • Conheça os recursos!
    • class Product(models.Model): name = models.CharField(max_length=200) description = models.TextField() price = models.FloatField() creation_date = models.DateField(auto_now_add=True) last_modification_date = models.DateField(auto_now=True) hidden = models.BooleanField(default=False) image = models.ImageField(upload_to=images/products, max_length=200)
    • Salvando objetosdef new_product(request): """Renders a product form on GET requests and saves a product on POST requests""" form = ProductForm() if request.method == POST: form = ProductForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponse(Product saved.) return render_to_response(product_form.html, { form : form }, context_instance=RequestContext(request) )
    • urls.pyurlpatterns = patterns(, (r^new_product, views.new_product),)
    • E se for outro model?def new_product(request): """Renders a product form on GET requests and saves a product on POST requests""" form = ProductForm() if request.method == POST: form = ProductForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponse(Product saved.) return render_to_response(product_form.html, { form : form }, context_instance=RequestContext(request) )
    • E se for outro model?def new_category(request): """Renders a category form on GET requests and saves a category on POST requests""" form = CategoryForm() if request.method == POST: form = CategoryForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponse(Category saved.) return render_to_response(category_form.html, { form : form }, context_instance=RequestContext(request) )
    • Que tal outro?def new_customer(request): """Renders a customer form on GET requests and saves a customer on POST requests""" form = CustomerForm() if request.method == POST: form = CustomerForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponse(Customer saved.) return render_to_response(customer_form.html, { form : form }, context_instance=RequestContext(request) )
    • http://abhinavpmp.com/wp-content/uploads/repetition.jpgDont repeat yourself!
    • http://abhinavpmp.com/wp-content/uploads/repetition.jpg I dont yourself?!Dont repeat yourself!
    • Generic viewsurlpatterns = patterns(, (r^new_product,django.views.generic.create_update.create_object, { model: Product, post_save_redirect : /products/,template_name : product_form.html }),)
    • http://bit.ly/generic-views
    • AutenticaçãoLOGIN_URL = /login/LOGIN_REDIRECT_URL = /
    • Autenticaçãodef say_hello(request): """Says Hello world on GET requests""" return HttpResponse(Hello world!)
    • Autenticação@login_requireddef say_hello(request): """Says Hello world on GET requests""" return HttpResponse(Hello world!)
    • Django Formsclass ProductForm(forms.Form): name = forms.CharField(max_length=200) description = forms.TextField() price = forms.FloatField() hidden = forms.BooleanField(default=False) image = forms.ImageField(upload_to=images/products, max_length=200)
    • Django Model Formsclass ProductForm(forms.ModelForm): class Meta: model = Product
    • Validação sem dorclass ContactForm(forms.Form): name = forms.CharField(max_length=150) email = forms.EmailField(max_length=75) message = forms.TextField()
    • http://bit.ly/django-felds
    • Localizaçãoclass ContactForm(forms.Form): name = forms.CharField(max_length=150) email = forms.EmailField(max_length=75) cpf = BRCPFField() message = forms.CharField(widget=forms.Textarea)
    • Localizaçãoclass ContactForm(forms.Form): name = forms.CharField(max_length=150) email = forms.EmailField(max_length=75) cpf = BRCPFField() message = forms.CharField(widget=forms.Textarea) Valida CPF?! :O
    • http://bit.ly/django-l10n
    • Enviando e-mailclass ContactForm(forms.Form): name = forms.CharField(max_length=150) email = forms.EmailField(max_length=75) cpf = BRCPFField() message = forms.CharField(widget=forms.Textarea) def send_email(self): msg = "Hi, Im %(name)s. My message for you: %(message)s. My CPF is %(cpf)s." % self.cleaned_data send_mail(Contact, msg, self.cleaned_data[email],[dest@gmail.com], fail_silently=True)
    • django.core.mail.send_mailEMAIL_HOST = smtp.voce.comEMAIL_HOST_USER = nome@sobrenome.comEMAIL_HOST_PASSWORD = senha123EMAIL_PORT = 25EMAIL_USE_TLS = False
    • Enviando e-maildef contact(request): """Renders a contact form on GET requests and sends an email on POST requests""" form = ContactForm() if request.method == POST: form = ContactForm(request.POST) if form.is_valid(): form.send_email() return HttpResponse("Mail sent.") return render_to_response(contact_form.html, { form : form }, context_instance=RequestContext(request) )
    • django.test.client.Client from django.test.client import Client client = Client() response = client.get(/contact/) assert Name in response.contentTest client
    • http://bit.ly/django-testing
    • Chega!http://www.flickr.com/photos/jkonig/2056057464/
    • Antes de terminarmos...
    • Signals pre_save post_save pre_delete post_delete request_started request_fnished
    • http://bit.ly/django-signals
    • Tem mais?!
    • djangoproject.com
    • Obrigado! www.giran.com.brfrancisco@franciscosouza.net