diff --git a/formularios/exemplos/checkbox/__init__.py b/formularios/exemplos/checkbox/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/checkbox/admin.py b/formularios/exemplos/checkbox/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/formularios/exemplos/checkbox/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/formularios/exemplos/checkbox/migrations/0001_initial.py b/formularios/exemplos/checkbox/migrations/0001_initial.py new file mode 100644 index 0000000..a856b05 --- /dev/null +++ b/formularios/exemplos/checkbox/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Transportes', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('carro', models.CharField(blank=True, null=True, max_length=50)), + ('moto', models.CharField(blank=True, null=True, max_length=50)), + ('onibus', models.CharField(blank=True, null=True, max_length=50)), + ('bicicleta', models.CharField(blank=True, null=True, max_length=50)), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/formularios/exemplos/checkbox/migrations/__init__.py b/formularios/exemplos/checkbox/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/checkbox/models.py b/formularios/exemplos/checkbox/models.py new file mode 100644 index 0000000..282d671 --- /dev/null +++ b/formularios/exemplos/checkbox/models.py @@ -0,0 +1,10 @@ +from django.db import models + +class Transportes(models.Model): + carro = models.CharField(max_length=50, blank=True, null=True) + moto = models.CharField(max_length=50, blank=True, null=True) + onibus = models.CharField(max_length=50, blank=True, null=True) + bicicleta = models.CharField(max_length=50, blank=True, null=True) + + def __str__(self): + return str(self.id) \ No newline at end of file diff --git a/formularios/exemplos/checkbox/templates/checkbox/index.html b/formularios/exemplos/checkbox/templates/checkbox/index.html new file mode 100644 index 0000000..4038fce --- /dev/null +++ b/formularios/exemplos/checkbox/templates/checkbox/index.html @@ -0,0 +1,25 @@ + + +
+ID: {{transporte.id}} / + Carro: {{transporte.carro}} / + Moto: {{transporte.moto}} / + Ônibus: {{transporte.onibus}} / + Bicicleta: {{transporte.bicicleta}}| + Remover +
+ {% empty %} +Nenhuma resposta foi encontrada
+ {% endfor %} + + diff --git a/formularios/exemplos/checkbox/templates/checkbox/ver-alternativas.html b/formularios/exemplos/checkbox/templates/checkbox/ver-alternativas.html new file mode 100644 index 0000000..c395c73 --- /dev/null +++ b/formularios/exemplos/checkbox/templates/checkbox/ver-alternativas.html @@ -0,0 +1,32 @@ + + + +ID: {{transporte.id}} / + Carro: {{transporte.carro}} / + Moto: {{transporte.moto}} / + Ônibus: {{transporte.onibus}} / + Bicicleta: {{transporte.bicicleta}}
+ {% endif %} + + diff --git a/formularios/exemplos/checkbox/tests.py b/formularios/exemplos/checkbox/tests.py new file mode 100644 index 0000000..67e8691 --- /dev/null +++ b/formularios/exemplos/checkbox/tests.py @@ -0,0 +1,46 @@ +from django.test import TestCase +from checkbox.models import Transportes + +from django.test import Client + +class TransportesTest(TestCase): + def setUp(self): + self.transporte1 = { + 'id': 1, + 'carro': 'Sim', + 'moto': 'Não', + 'onibus': 'Não', + 'bicicleta': 'Sim', + } + + def test_inserir_transporte(self): + transporte = Transportes.objects.create(**self.transporte1) + self.assertEqual(transporte.id, 1) + + + def test_carregar_alternativas(self): + transporte = Transportes.objects.create(**self.transporte1) + + get_transporte = Transportes.objects.get(id=1) + + + + + def test_enviar_checkbox_selecionados(self): + client = Client() + check1 = client.post('/checkbox/enviar/', {'carro':'Sim','moto':'Não','onibus':'Sim','bicicleta':'Sim'}) + check2 = client.post('/checkbox/enviar/', {'carro':'Sim','onibus':'Sim','bicicleta':'Sim'}) + check3 = client.post('/checkbox/enviar/', {'moto':'Não','onibus':'Sim'}) + check4 = client.post('/checkbox/enviar/', {'onibus':'Sim'}) + check5 = client.post('/checkbox/enviar/', {}) + check6 = client.post('/checkbox/enviar', {}) + check7 = client.get('/checkbox/enviar/') + + self.assertEqual(check1.status_code, 200) + self.assertEqual(check2.status_code, 200) + self.assertEqual(check3.status_code, 200) + self.assertEqual(check4.status_code, 200) + self.assertEqual(check5.status_code, 200) + self.assertEqual(check6.status_code, 301) + self.assertEqual(check7.status_code, 200) + diff --git a/formularios/exemplos/checkbox/urls.py b/formularios/exemplos/checkbox/urls.py new file mode 100644 index 0000000..164d683 --- /dev/null +++ b/formularios/exemplos/checkbox/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls import patterns, url +from checkbox import views + +urlpatterns = patterns('', + + url(r'^$', views.index, name='index'), + url(r'^enviar/$', views.enviar, name='enviar'), + url(r'^listar/$', views.listar, name='listar'), + url(r'^ver-alternativas/(?PID: {{transporte.id}} / + Carro: {% if 'Carro' in transporte.opcoes_transp %}Sim {% else %}Não {% endif %} / + Moto: {% if 'Moto' in transporte.opcoes_transp %}Sim {% else %}Não {% endif %} / + Ônibus: {% if 'Ônibus' in transporte.opcoes_transp %}Sim {% else %}Não {% endif %}/ + Bicicleta: {% if 'Bicicleta' in transporte.opcoes_transp %}Sim {% else %}Não {% endif %}| + Remover +
+ {% empty %} +Nenhuma resposta foi encontrada
+ {% endfor %} + + diff --git a/formularios/exemplos/checkbox_multi/templates/checkbox_multi/ver-alternativas.html b/formularios/exemplos/checkbox_multi/templates/checkbox_multi/ver-alternativas.html new file mode 100644 index 0000000..4732cfa --- /dev/null +++ b/formularios/exemplos/checkbox_multi/templates/checkbox_multi/ver-alternativas.html @@ -0,0 +1,32 @@ + + + +ID: {{transporte.id}} / + Carro: {{transporte.carro}} / + Moto: {{transporte.moto}} / + Ônibus: {{transporte.onibus}} / + Bicicleta: {{transporte.bicicleta}}
+ {% endif %} + + diff --git a/formularios/exemplos/checkbox_multi/tests.py b/formularios/exemplos/checkbox_multi/tests.py new file mode 100644 index 0000000..f884e54 --- /dev/null +++ b/formularios/exemplos/checkbox_multi/tests.py @@ -0,0 +1,46 @@ +from django.test import TestCase +from checkbox_multi.models import Transportes + +from django.test import Client + +class TransportesTest(TestCase): + def setUp(self): + self.transporte1 = { + 'id': 1, + 'carro': 'Sim', + 'moto': 'Não', + 'onibus': 'Não', + 'bicicleta': 'Sim', + } + + def test_inserir_transporte(self): + transporte = Transportes.objects.create(**self.transporte1) + self.assertEqual(transporte.id, 1) + + + def test_carregar_alternativas(self): + transporte = Transportes.objects.create(**self.transporte1) + + get_transporte = Transportes.objects.get(id=1) + + + + + def test_enviar_checkbox_multi_selecionados(self): + client = Client() + check1 = client.post('/checkbox_multi/enviar/', {'carro':'Sim','moto':'Não','onibus':'Sim','bicicleta':'Sim'}) + check2 = client.post('/checkbox_multi/enviar/', {'carro':'Sim','onibus':'Sim','bicicleta':'Sim'}) + check3 = client.post('/checkbox_multi/enviar/', {'moto':'Não','onibus':'Sim'}) + check4 = client.post('/checkbox_multi/enviar/', {'onibus':'Sim'}) + check5 = client.post('/checkbox_multi/enviar/', {}) + check6 = client.post('/checkbox_multi/enviar', {}) + check7 = client.get('/checkbox_multi/enviar/') + + self.assertEqual(check1.status_code, 200) + self.assertEqual(check2.status_code, 200) + self.assertEqual(check3.status_code, 200) + self.assertEqual(check4.status_code, 200) + self.assertEqual(check5.status_code, 200) + self.assertEqual(check6.status_code, 301) + self.assertEqual(check7.status_code, 200) + diff --git a/formularios/exemplos/checkbox_multi/urls.py b/formularios/exemplos/checkbox_multi/urls.py new file mode 100644 index 0000000..da2feb9 --- /dev/null +++ b/formularios/exemplos/checkbox_multi/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls import patterns, url +from checkbox_multi import views + +urlpatterns = patterns('', + + url(r'^$', views.index, name='index'), + url(r'^enviar/$', views.enviar, name='enviar'), + url(r'^listar/$', views.listar, name='listar'), + url(r'^ver-alternativas/(?PNenhum post foi encontrado
+ {% endfor %} + {% endif %} + + Voltar + + diff --git a/formularios/exemplos/textbox/tests.py b/formularios/exemplos/textbox/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/formularios/exemplos/textbox/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/formularios/exemplos/textbox/urls.py b/formularios/exemplos/textbox/urls.py new file mode 100644 index 0000000..f491393 --- /dev/null +++ b/formularios/exemplos/textbox/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import patterns, url +from textbox import views + +urlpatterns = patterns('', + url(r'^$', views.index, name='index'), + url(r'^listar/$', views.listar, name='listar'), + url(r'^enviar/$', views.enviar, name='enviar'), +) diff --git a/formularios/exemplos/textbox/views.py b/formularios/exemplos/textbox/views.py new file mode 100644 index 0000000..8bb5b9a --- /dev/null +++ b/formularios/exemplos/textbox/views.py @@ -0,0 +1,25 @@ +from django.shortcuts import render, redirect +from textbox.models import Postagens + +def index(request): + return render(request, 'textbox/index.html', {}) + +def listar(request): + listar_posts = Postagens.objects.order_by('-data') + + return render(request, 'textbox/listar.html', {'listar_posts':listar_posts}) + +def enviar(request): + if request.method == 'POST': + postagem = Postagens.objects.create( + titulo = request.POST['titulo'], + email = request.POST['email'], + url = request.POST['url'], + rating = request.POST['rating'], + like = request.POST['like'], + conteudo = request.POST['conteudo'], + ) + + return redirect('textbox:textbox.views.listar') + + return render(request, 'app/index.html', {}) \ No newline at end of file diff --git a/formularios/exemplos/textbox_forms/__init__.py b/formularios/exemplos/textbox_forms/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/textbox_forms/admin.py b/formularios/exemplos/textbox_forms/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/formularios/exemplos/textbox_forms/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/formularios/exemplos/textbox_forms/forms.py b/formularios/exemplos/textbox_forms/forms.py new file mode 100644 index 0000000..1ef090d --- /dev/null +++ b/formularios/exemplos/textbox_forms/forms.py @@ -0,0 +1,8 @@ +from django import forms +from textbox_forms.models import Postagem + +class PostagensForm(forms.ModelForm): + + class Meta: + model = Postagem + fields = ('titulo', 'email','url','rating','like','conteudo') \ No newline at end of file diff --git a/formularios/exemplos/textbox_forms/migrations/0001_initial.py b/formularios/exemplos/textbox_forms/migrations/0001_initial.py new file mode 100644 index 0000000..bc85543 --- /dev/null +++ b/formularios/exemplos/textbox_forms/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Postagens', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('titulo', models.CharField(max_length=200)), + ('data', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Publicado')), + ('email', models.EmailField(verbose_name='E-mail', max_length=250)), + ('url', models.URLField(verbose_name='Site')), + ('rating', models.DecimalField(max_digits=9, decimal_places=1)), + ('like', models.IntegerField()), + ('conteudo', models.TextField(verbose_name='Conteúdo')), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/formularios/exemplos/textbox_forms/migrations/0002_auto_20150722_1139.py b/formularios/exemplos/textbox_forms/migrations/0002_auto_20150722_1139.py new file mode 100644 index 0000000..085e826 --- /dev/null +++ b/formularios/exemplos/textbox_forms/migrations/0002_auto_20150722_1139.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('textbox_forms', '0001_initial'), + ] + + operations = [ + migrations.RenameModel( + old_name='Postagens', + new_name='Postagem', + ), + ] diff --git a/formularios/exemplos/textbox_forms/migrations/__init__.py b/formularios/exemplos/textbox_forms/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/textbox_forms/models.py b/formularios/exemplos/textbox_forms/models.py new file mode 100644 index 0000000..6e9885b --- /dev/null +++ b/formularios/exemplos/textbox_forms/models.py @@ -0,0 +1,14 @@ +from django.db import models +from django.utils import timezone + +class Postagem(models.Model): + titulo = models.CharField(max_length=200) + data = models.DateTimeField('Publicado', default=timezone.now) + email = models.EmailField('E-mail', max_length=250) + url = models.URLField('Site') + rating = models.DecimalField(max_digits=9, decimal_places=1) + like = models.IntegerField() + conteudo = models.TextField('Conteúdo') + + def __str__(self): + return self.titulo \ No newline at end of file diff --git a/formularios/exemplos/textbox_forms/templates/textbox_forms/index.html b/formularios/exemplos/textbox_forms/templates/textbox_forms/index.html new file mode 100644 index 0000000..719d252 --- /dev/null +++ b/formularios/exemplos/textbox_forms/templates/textbox_forms/index.html @@ -0,0 +1,36 @@ + + + +Nenhum post foi encontrado
+ {% endfor %} + {% endif %} + + Voltar + + diff --git a/formularios/exemplos/textbox_forms/tests.py b/formularios/exemplos/textbox_forms/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/formularios/exemplos/textbox_forms/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/formularios/exemplos/textbox_forms/urls.py b/formularios/exemplos/textbox_forms/urls.py new file mode 100644 index 0000000..4c9acf7 --- /dev/null +++ b/formularios/exemplos/textbox_forms/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import patterns, url +from textbox_forms import views + +urlpatterns = patterns('', + url(r'^$', views.index, name='index'), + url(r'^listar/$', views.listar, name='listar'), + url(r'^enviar/$', views.enviar, name='enviar'), +) diff --git a/formularios/exemplos/textbox_forms/views.py b/formularios/exemplos/textbox_forms/views.py new file mode 100644 index 0000000..fbc1db8 --- /dev/null +++ b/formularios/exemplos/textbox_forms/views.py @@ -0,0 +1,22 @@ +from django.shortcuts import render, redirect +from textbox_forms.models import Postagem +from textbox_forms.forms import PostagensForm + +def index(request): + return render(request, 'textbox_forms/index.html', {}) + +def listar(request): + listar_posts = Postagem.objects.order_by('-data') + + return render(request, 'textbox_forms/listar.html', {'listar_posts':listar_posts}) + +def enviar(request): + if request.method == 'POST': + form = PostagensForm(request.POST) + if form.is_valid(): + form_valid = form.save(commit=False) + form_valid.save() + + return redirect('textbox_forms:textbox_forms.views.listar') + + return render(request, 'textbox_forms/index.html', {}) \ No newline at end of file