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 @@ + + + + checkbox + + + + +

Inserir item

+

Adicionar | Listar |

+ +
+ {% csrf_token %} + +
+ +
+ +
+ +
+
+
+ + diff --git a/formularios/exemplos/checkbox/templates/checkbox/listar.html b/formularios/exemplos/checkbox/templates/checkbox/listar.html new file mode 100644 index 0000000..3a0251f --- /dev/null +++ b/formularios/exemplos/checkbox/templates/checkbox/listar.html @@ -0,0 +1,23 @@ + + + + checkbox + + + + +

Adicionar | Listar |

+

Listando as alternativas

+ {% for transporte in transportes %} +

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 @@ + + + + TODO supply a title + + + + +

Adicionar | Listar |

+ {% if transporte %} +
+ {% csrf_token %} + + +
+ +
+ +
+ +
+
+
+ +

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/(?P[0-9]+)/$', views.carregar, name='ver-alternativas'), + url(r'^atualizar/(?P[0-9]+)/$', views.atualizar, name='atualizar'), + url(r'^deletar/(?P[0-9]+)/$', views.deletar, name='deletar'), +) diff --git a/formularios/exemplos/checkbox/views.py b/formularios/exemplos/checkbox/views.py new file mode 100644 index 0000000..e9f2887 --- /dev/null +++ b/formularios/exemplos/checkbox/views.py @@ -0,0 +1,57 @@ +from django.shortcuts import render, get_object_or_404, redirect +from checkbox.models import Transportes + +def index(request): + return render(request, 'checkbox/index.html', {}) + +def enviar(request): + if request.method == 'POST': + + p_carro = request.POST.get('carro','Não') + p_moto = request.POST.get('moto','Não') + p_onibus = request.POST.get('onibus','Não') + p_bicicleta = request.POST.get('bicicleta','Não') + + transportes = Transportes.objects.create( + carro = p_carro, + moto = p_moto, + onibus = p_onibus, + bicicleta = p_bicicleta, + ) + + return redirect('checkbox:checkbox.views.listar') + + +def listar(request): + transportes = Transportes.objects.order_by('-id') + return render(request, 'checkbox/listar.html', {'transportes':transportes}) + + +def carregar(request, pk): + transporte = get_object_or_404(Transportes, pk=pk) + return render(request, 'checkbox/ver-alternativas.html', {'transporte': transporte}) + + +def atualizar(request, pk): + transporte = get_object_or_404(Transportes, pk=pk) + + if request.method == 'POST': + p_carro = request.POST.get('carro','Não') + p_moto = request.POST.get('moto','Não') + p_onibus = request.POST.get('onibus','Não') + p_bicicleta = request.POST.get('bicicleta','Não') + + transporte.carro = p_carro + transporte.moto = p_moto + transporte.onibus = p_onibus + transporte.bicicleta = p_bicicleta + transporte.save() + + return render(request, 'checkbox/ver-alternativas.html', {'transporte': transporte}) + +def deletar(request, pk): + transporte = get_object_or_404(Transportes, pk=pk) + + transporte.delete() + + return redirect('checkbox:checkbox.views.listar') \ No newline at end of file diff --git a/formularios/exemplos/checkbox_multi/__init__.py b/formularios/exemplos/checkbox_multi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/checkbox_multi/admin.py b/formularios/exemplos/checkbox_multi/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/formularios/exemplos/checkbox_multi/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/formularios/exemplos/checkbox_multi/migrations/0001_initial.py b/formularios/exemplos/checkbox_multi/migrations/0001_initial.py new file mode 100644 index 0000000..8fdd794 --- /dev/null +++ b/formularios/exemplos/checkbox_multi/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# -*- 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(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), + ('opcoes_transp', models.CharField(blank=True, null=True, max_length=50)), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/formularios/exemplos/checkbox_multi/migrations/__init__.py b/formularios/exemplos/checkbox_multi/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/checkbox_multi/models.py b/formularios/exemplos/checkbox_multi/models.py new file mode 100644 index 0000000..0d4e368 --- /dev/null +++ b/formularios/exemplos/checkbox_multi/models.py @@ -0,0 +1,7 @@ +from django.db import models + +class Transportes(models.Model): + opcoes_transp = 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_multi/templates/checkbox_multi/index.html b/formularios/exemplos/checkbox_multi/templates/checkbox_multi/index.html new file mode 100644 index 0000000..8d662d6 --- /dev/null +++ b/formularios/exemplos/checkbox_multi/templates/checkbox_multi/index.html @@ -0,0 +1,25 @@ + + + + checkbox_multi + + + + +

Inserir item

+

Adicionar | Listar |

+ +
+ {% csrf_token %} + +
+ +
+ +
+ +
+
+
+ + diff --git a/formularios/exemplos/checkbox_multi/templates/checkbox_multi/listar.html b/formularios/exemplos/checkbox_multi/templates/checkbox_multi/listar.html new file mode 100644 index 0000000..4ab2dc3 --- /dev/null +++ b/formularios/exemplos/checkbox_multi/templates/checkbox_multi/listar.html @@ -0,0 +1,23 @@ + + + + checkbox_multi + + + + +

Adicionar | Listar |

+

Listando as alternativas

+ {% for transporte in transportes %} +

ID: {{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 @@ + + + + TODO supply a title + + + + +

Adicionar | Listar |

+ {% if transporte %} +
+ {% csrf_token %} + + +
+ +
+ +
+ +
+
+
+ +

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/(?P[0-9]+)/$', views.carregar, name='ver-alternativas'), + url(r'^atualizar/(?P[0-9]+)/$', views.atualizar, name='atualizar'), + url(r'^deletar/(?P[0-9]+)/$', views.deletar, name='deletar'), +) diff --git a/formularios/exemplos/checkbox_multi/views.py b/formularios/exemplos/checkbox_multi/views.py new file mode 100644 index 0000000..45e44cd --- /dev/null +++ b/formularios/exemplos/checkbox_multi/views.py @@ -0,0 +1,42 @@ +from django.shortcuts import render, get_object_or_404, redirect +from checkbox_multi.models import Transportes + +def index(request): + return render(request, 'checkbox_multi/index.html', {}) + +def enviar(request): + if request.method == 'POST': + transportes = Transportes.objects.create( + opcoes_transp = request.POST.getlist('opcoes_transp','Nenhuma opção foi escolhida') + ) + + return redirect('checkbox_multi:checkbox_multi.views.listar') + + +def listar(request): + transportes = Transportes.objects.order_by('-id') + return render(request, 'checkbox_multi/listar.html', {'transportes':transportes}) + + +def carregar(request, pk): + transporte = get_object_or_404(Transportes, pk=pk) + return render(request, 'checkbox_multi/ver-alternativas.html', {'transporte': transporte}) + + +def atualizar(request, pk): + transporte = get_object_or_404(Transportes, pk=pk) + + if request.method == 'POST': + opcoes_transp = request.POST.getlist('opcoes_transp','Nenhuma opção foi escolhida') + + transporte.opcoes_transp = opcoes_transp + transporte.save() + + return render(request, 'checkbox_multi/ver-alternativas.html', {'transporte': transporte}) + +def deletar(request, pk): + transporte = get_object_or_404(Transportes, pk=pk) + + transporte.delete() + + return redirect('checkbox_multi:checkbox_multi.views.listar') \ No newline at end of file diff --git a/formularios/exemplos/db.sqlite3 b/formularios/exemplos/db.sqlite3 new file mode 100644 index 0000000..6c885de Binary files /dev/null and b/formularios/exemplos/db.sqlite3 differ diff --git a/formularios/exemplos/exemplos/__init__.py b/formularios/exemplos/exemplos/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/exemplos/settings.py b/formularios/exemplos/exemplos/settings.py new file mode 100644 index 0000000..74df3fc --- /dev/null +++ b/formularios/exemplos/exemplos/settings.py @@ -0,0 +1,94 @@ +""" +Django settings for exemplos project. + +For more information on this file, see +https://docs.djangoproject.com/en/1.7/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.7/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '^zlw0ajk$*gv55h(!zj0zcyvdpmc0x36uu_o**dy3%jx0m(^0h' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +TEMPLATE_DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'checkbox', + 'checkbox_multi', + 'textbox', + 'textbox_forms', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) + +ROOT_URLCONF = 'exemplos.urls' + +WSGI_APPLICATION = 'exemplos.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.7/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +# Internationalization +# https://docs.djangoproject.com/en/1.7/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.7/howto/static-files/ + +STATIC_URL = '/static/' + + +TEMPLATE_DIRS = [ + os.path.join(BASE_DIR, 'checkbox/templates'), + os.path.join(BASE_DIR, 'checkbox_multi/templates'), + os.path.join(BASE_DIR, 'textbox/templates'), +] \ No newline at end of file diff --git a/formularios/exemplos/exemplos/urls.py b/formularios/exemplos/exemplos/urls.py new file mode 100644 index 0000000..01ad2dc --- /dev/null +++ b/formularios/exemplos/exemplos/urls.py @@ -0,0 +1,14 @@ +from django.conf.urls import patterns, include, url +from django.contrib import admin + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'exemplos.views.home', name='home'), + # url(r'^blog/', include('blog.urls')), + + url(r'^admin/', include(admin.site.urls)), + url(r'^checkbox/', include('checkbox.urls', namespace='checkbox')), + url(r'^checkbox_multi/', include('checkbox_multi.urls', namespace='checkbox_multi')), + url(r'^textbox/', include('textbox.urls', namespace='textbox')), + url(r'^textbox_forms/', include('textbox_forms.urls', namespace='textbox_forms')), +) diff --git a/formularios/exemplos/exemplos/wsgi.py b/formularios/exemplos/exemplos/wsgi.py new file mode 100644 index 0000000..3d04e43 --- /dev/null +++ b/formularios/exemplos/exemplos/wsgi.py @@ -0,0 +1,14 @@ +""" +WSGI config for exemplos project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ +""" + +import os +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "exemplos.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() diff --git a/formularios/exemplos/manage.py b/formularios/exemplos/manage.py new file mode 100755 index 0000000..db93371 --- /dev/null +++ b/formularios/exemplos/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "exemplos.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/formularios/exemplos/textbox/__init__.py b/formularios/exemplos/textbox/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/textbox/admin.py b/formularios/exemplos/textbox/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/formularios/exemplos/textbox/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/formularios/exemplos/textbox/migrations/0001_initial.py b/formularios/exemplos/textbox/migrations/0001_initial.py new file mode 100644 index 0000000..3ef1de6 --- /dev/null +++ b/formularios/exemplos/textbox/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, verbose_name='ID', serialize=False)), + ('titulo', models.CharField(max_length=200)), + ('data', models.DateTimeField(verbose_name='Publicado', default=django.utils.timezone.now)), + ('email', models.EmailField(max_length=250, verbose_name='E-mail')), + ('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/migrations/__init__.py b/formularios/exemplos/textbox/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/formularios/exemplos/textbox/models.py b/formularios/exemplos/textbox/models.py new file mode 100644 index 0000000..8bfc48f --- /dev/null +++ b/formularios/exemplos/textbox/models.py @@ -0,0 +1,14 @@ +from django.db import models +from django.utils import timezone + +class Postagens(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/templates/textbox/index.html b/formularios/exemplos/textbox/templates/textbox/index.html new file mode 100644 index 0000000..5bb9c3c --- /dev/null +++ b/formularios/exemplos/textbox/templates/textbox/index.html @@ -0,0 +1,30 @@ + + + + Textbox + + + + +

Textbox

+
+ Formulário Simples +
+ {% csrf_token %} +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/formularios/exemplos/textbox/templates/textbox/listar.html b/formularios/exemplos/textbox/templates/textbox/listar.html new file mode 100644 index 0000000..5dd1536 --- /dev/null +++ b/formularios/exemplos/textbox/templates/textbox/listar.html @@ -0,0 +1,25 @@ + + + + Textbox + + + + + {% if listar_posts %} + {% for post in listar_posts %} + Título: {{ post.titulo }}
+ Data: {{post.data}}
+ E-mail {{ post.email }}
+ Site: {{post.url}}
+ Pontuação: {{ post.rating }}
+ Like: {{post.like}}
+ Conteúdo: {{post.conteudo}}

+ {% empty %} +

Nenhum 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 @@ + + + + Forms + + + + +

Textbox

+
+ Formulário Forms +
+ {% csrf_token %} +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ + diff --git a/formularios/exemplos/textbox_forms/templates/textbox_forms/listar.html b/formularios/exemplos/textbox_forms/templates/textbox_forms/listar.html new file mode 100644 index 0000000..e2ec6da --- /dev/null +++ b/formularios/exemplos/textbox_forms/templates/textbox_forms/listar.html @@ -0,0 +1,25 @@ + + + + Forms + + + + + {% if listar_posts %} + {% for post in listar_posts %} + Título: {{ post.titulo }}
+ Data: {{post.data}}
+ E-mail {{ post.email }}
+ Site: {{post.url}}
+ Pontuação: {{ post.rating }}
+ Like: {{post.like}}
+ Conteúdo: {{post.conteudo}}

+ {% empty %} +

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