forked from alexdzul/demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
710 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django import forms | ||
|
||
class ContactForm(forms.Form): | ||
Email = forms.EmailField(widget=forms.TextInput()) | ||
Titulo = forms.CharField(widget=forms.TextInput()) | ||
Texto = forms.CharField(widget=forms.Textarea()) | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django import forms | ||
|
||
class ContactForm(forms.Form): | ||
Email = forms.EmailField(widget=forms.TextInput()) | ||
Titulo = forms.CharField(widget=forms.TextInput()) | ||
Texto = forms.CharField(widget=forms.Textarea()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
""" | ||
|
||
from django.test import TestCase | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.conf.urls.defaults import patterns,url | ||
|
||
|
||
urlpatterns = patterns('demo.apps.home.views', | ||
url(r'^$','index_view',name='vista_principal'), | ||
url(r'^about/$','about_view',name='vista_about'), | ||
url(r'^productos/$','productos_view',name='vista_productos'), | ||
url(r'^contacto/$','contacto_view',name='vista_contacto'), | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.shortcuts import render_to_response | ||
from django.template import RequestContext | ||
from demo.apps.ventas.models import producto | ||
from demo.apps.home.forms import ContactForm | ||
from django.core.mail import EmailMultiAlternatives # Enviamos HTML | ||
|
||
|
||
def index_view(request): | ||
return render_to_response('home/index.html',context_instance=RequestContext(request)) | ||
|
||
def about_view(request): | ||
mensaje = "Esto es un mensaje desde mi vista" | ||
ctx = {'msg':mensaje} | ||
return render_to_response('home/about.html',ctx,context_instance=RequestContext(request)) | ||
|
||
def productos_view(request): | ||
prod = producto.objects.filter(status=True) # Select * from ventas_productos where status = True | ||
ctx = {'productos':prod} | ||
return render_to_response('home/productos.html',ctx,context_instance=RequestContext(request)) | ||
|
||
|
||
|
||
def contacto_view(request): | ||
info_enviado = False # Definir si se envio la informacion o no se envio | ||
email = "" | ||
titulo = "" | ||
texto = "" | ||
if request.method == "POST": | ||
formulario = ContactForm(request.POST) | ||
if formulario.is_valid(): | ||
info_enviado = True | ||
email = formulario.cleaned_data['Email'] | ||
titulo = formulario.cleaned_data['Titulo'] | ||
texto = formulario.cleaned_data['Texto'] | ||
|
||
# Configuracion enviando mensaje via GMAIL | ||
to_admin = '[email protected]' | ||
html_content = "Informacion recibida de [%s] <br><br><br>***Mensaje****<br><br>%s"%(email,texto) | ||
msg = EmailMultiAlternatives('Correo de Contacto',html_content,'[email protected]',[to_admin]) | ||
msg.attach_alternative(html_content,'text/html') # Definimos el contenido como HTML | ||
msg.send() # Enviamos en correo | ||
else: | ||
formulario = ContactForm() | ||
ctx = {'form':formulario,'email':email,'titulo':titulo,'texto':texto,'info_enviado':info_enviado} | ||
return render_to_response('home/contacto.html',ctx,context_instance=RequestContext(request)) | ||
|
||
|
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
from demo.apps.ventas.models import cliente,producto | ||
|
||
admin.site.register(cliente) | ||
admin.site.register(producto) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django import forms | ||
|
||
class addProductForm(forms.Form): | ||
nombre = forms.CharField(widget=forms.TextInput()) | ||
descripcion = forms.CharField(widget=forms.TextInput()) | ||
|
||
def clean(self): | ||
return self.cleaned_data |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django import forms | ||
|
||
class addProductForm(forms.Form): | ||
nombre = forms.EmailField(widget=forms.TextInput()) | ||
descripcion = forms.CharField(widget=forms.TextInput()) | ||
|
||
def clean(self): | ||
return self.cleaned_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import models | ||
|
||
|
||
class cliente(models.Model): | ||
nombre = models.CharField(max_length=200) | ||
apellidos = models.CharField(max_length=200) | ||
status = models.BooleanField(default=True) | ||
|
||
def __unicode__(self): | ||
nombreCompleto = "%s %s"%(self.nombre,self.apellidos) | ||
return nombreCompleto | ||
|
||
|
||
class producto(models.Model): | ||
nombre = models.CharField(max_length=100) | ||
descripcion = models.TextField(max_length=300) | ||
status = models.BooleanField(default=True) | ||
|
||
def __unicode__(self): | ||
return self.nombre |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
""" | ||
|
||
from django.test import TestCase | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.conf.urls.defaults import patterns,url | ||
|
||
|
||
urlpatterns = patterns('demo.apps.ventas.views', | ||
url(r'^add/producto/$','add_product_view',name='vista_agregar_producto'), | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.conf.urls.defaults import patterns,url | ||
|
||
|
||
urlpatterns = patterns('demo.apps.ventas.views', | ||
url(r'^add/producto/$','add_product_view',name='vista_agregar_producto'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.shortcuts import render_to_response | ||
from django.template import RequestContext | ||
from demo.apps.ventas.forms import addProductForm | ||
from demo.apps.ventas.models import producto | ||
|
||
|
||
def add_product_view(request): | ||
if request.method == 'POST': | ||
form = addProductForm(request.POST) | ||
guardado = False | ||
info = "Inicia todo" | ||
if form.is_valid(): | ||
|
||
nombre = form.cleaned_data['nombre'] | ||
descripcion = form.cleaned_data['descripcion'] | ||
p = producto() | ||
p.nombre = nombre | ||
p.descripcion = descripcion | ||
p.status = True | ||
p.save() # Guardamos el producto | ||
info = " Se guardo satisfactoriamente!!!!" | ||
guardado = True | ||
else: | ||
info = " No se pudo Guardar" | ||
form = addProductForm() | ||
ctx = {'form':form,'guardado':guardado,'informacion':info} | ||
return render_to_response('ventas/addProducto.html',ctx,context_instance=RequestContext(request)) | ||
else: | ||
form = addProductForm() | ||
ctx = {'form':form} | ||
return render_to_response('ventas/addProducto.html',ctx,context_instance=RequestContext(request)) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.shortcuts import render_to_response | ||
from django.template import RequestContext | ||
from demo.apps.ventas.forms import addProductForm | ||
from demo.apps.ventas.models import producto | ||
|
||
|
||
def add_product_view(request): | ||
if request.method == 'POST': | ||
form = addProductForm(request.POST) | ||
guardado = False | ||
info = "Inicia todo" | ||
if form.is_valid(): | ||
|
||
nombre = form.cleaned_data['nombre'] | ||
descripcion = form.cleaned_data['descripcion'] | ||
p = producto() | ||
p.nombre = nombre | ||
p.descripcion = descripcion | ||
p.status = True | ||
p.save() # Guardamos el producto | ||
info = " Se guardo" | ||
guardado = True | ||
else: | ||
info = " No se pudo Guardar" | ||
form = addProductForm() | ||
ctx = {'form':form,'guardado':guardado,'informacion':info} | ||
return render_to_response('ventas/addProducto.html',ctx,context_instance=RequestContext(request)) | ||
else: | ||
form = addProductForm() | ||
ctx = {'form':form} | ||
return render_to_response('ventas/addProducto.html',ctx,context_instance=RequestContext(request)) |
Oops, something went wrong.