Skip to content

Commit

Permalink
Inicializacion de proyecto
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdzul committed Jun 29, 2012
1 parent ff3f39d commit 51b849f
Show file tree
Hide file tree
Showing 46 changed files with 710 additions and 0 deletions.
Empty file added demo/__init__.py
Empty file.
Binary file added demo/__init__.pyc
Binary file not shown.
Empty file added demo/apps/__init__.py
Empty file.
Binary file added demo/apps/__init__.pyc
Binary file not shown.
Empty file added demo/apps/home/__init__.py
Empty file.
Binary file added demo/apps/home/__init__.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions demo/apps/home/forms.py
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 added demo/apps/home/forms.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions demo/apps/home/forms.py~
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())

3 changes: 3 additions & 0 deletions demo/apps/home/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
16 changes: 16 additions & 0 deletions demo/apps/home/tests.py
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)
9 changes: 9 additions & 0 deletions demo/apps/home/urls.py
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 added demo/apps/home/urls.pyc
Binary file not shown.
47 changes: 47 additions & 0 deletions demo/apps/home/views.py
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 added demo/apps/home/views.pyc
Binary file not shown.
Empty file added demo/apps/ventas/__init__.py
Empty file.
Binary file added demo/apps/ventas/__init__.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions demo/apps/ventas/admin.py
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 added demo/apps/ventas/admin.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions demo/apps/ventas/forms.py
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 added demo/apps/ventas/forms.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions demo/apps/ventas/forms.py~
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
20 changes: 20 additions & 0 deletions demo/apps/ventas/models.py
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 added demo/apps/ventas/models.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions demo/apps/ventas/tests.py
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)
6 changes: 6 additions & 0 deletions demo/apps/ventas/urls.py
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 added demo/apps/ventas/urls.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions demo/apps/ventas/urls.py~
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'),
)
31 changes: 31 additions & 0 deletions demo/apps/ventas/views.py
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 added demo/apps/ventas/views.pyc
Binary file not shown.
31 changes: 31 additions & 0 deletions demo/apps/ventas/views.py~
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))
Loading

0 comments on commit 51b849f

Please sign in to comment.