Skip to content

Commit

Permalink
Tutorial No. 16 Youtube
Browse files Browse the repository at this point in the history
Aquí aprendimos a manejar el Paginator del Core de Django.
  • Loading branch information
alexdzul committed Dec 15, 2012
1 parent 984e1af commit 3f76f35
Show file tree
Hide file tree
Showing 35 changed files with 35 additions and 8 deletions.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified demo/__init__.py
100644 → 100755
Empty file.
Empty file modified demo/apps/__init__.py
100644 → 100755
Empty file.
Empty file modified demo/apps/home/__init__.py
100644 → 100755
Empty file.
Empty file modified demo/apps/home/admin.py
100644 → 100755
Empty file.
Empty file modified demo/apps/home/forms.py
100644 → 100755
Empty file.
Empty file modified demo/apps/home/models.py
100644 → 100755
Empty file.
Empty file modified demo/apps/home/tests.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion demo/apps/home/urls.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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'^productos/page/(?P<pagina>.*)/$','productos_view',name='vista_productos'),
url(r'^producto/(?P<id_prod>.*)/$','singleProduct_view',name='vista_single_producto'),
url(r'^contacto/$','contacto_view',name='vista_contacto'),
url(r'^login/$','login_view',name='vista_login'),
Expand Down
18 changes: 14 additions & 4 deletions demo/apps/home/views.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from django.contrib.auth import login,logout,authenticate
from django.http import HttpResponseRedirect

# Paginacion en Django
from django.core.paginator import Paginator,EmptyPage,InvalidPage

def index_view(request):
return render_to_response('home/index.html',context_instance=RequestContext(request))
Expand All @@ -16,9 +17,18 @@ def about_view(request):
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}
def productos_view(request,pagina):
lista_prod = producto.objects.filter(status=True) # Select * from ventas_productos where status = True
paginator = Paginator(lista_prod,3) # Cuantos productos quieres por pagina? = 3
try:
page = int(pagina)
except:
page = 1
try:
productos = paginator.page(page)
except (EmptyPage,InvalidPage):
productos = paginator.page(paginator.num_pages)
ctx = {'productos':productos}
return render_to_response('home/productos.html',ctx,context_instance=RequestContext(request))

def singleProduct_view(request,id_prod):
Expand Down
Empty file modified demo/apps/ventas/__init__.py
100644 → 100755
Empty file.
Empty file modified demo/apps/ventas/admin.py
100644 → 100755
Empty file.
Empty file modified demo/apps/ventas/forms.py
100644 → 100755
Empty file.
Empty file modified demo/apps/ventas/models.py
100644 → 100755
Empty file.
Empty file modified demo/apps/ventas/tests.py
100644 → 100755
Empty file.
Empty file modified demo/apps/ventas/urls.py
100644 → 100755
Empty file.
Empty file modified demo/apps/ventas/views.py
100644 → 100755
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified demo/media/css/estilo.css
100644 → 100755
Empty file.
Empty file modified demo/media/images/django.gif
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified demo/settings.py
100644 → 100755
Empty file.
Empty file modified demo/settings_original.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion demo/templates/base.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<h1>Proyecto Demo (Venta de Productos ) </h1>
<nav>
<a href="{% url vista_principal %}">Inicio</a>
<a href="{% url vista_productos %}">Productos</a>
<a href="/productos/page/1/">Productos</a>
<a href="{% url vista_contacto %}">Contacto</a>
<a href="{% url vista_about %}">Acerca de ...</a>
{% if user.is_authenticated %}
Expand Down
Empty file modified demo/templates/base.html~
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion demo/templates/home/SingleProducto.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ <h1> {{ producto.nombre }}</h1><br>
<a href="#"> Comprar Producto </a>
{% endif %}
<br><br>
<a href="/productos/"> Regresar a la Lista </a>
<a href="javascript:window.history.go(-1);"> Regresar a la Lista </a>
{% endblock %}
Empty file modified demo/templates/home/about.html
100644 → 100755
Empty file.
Empty file modified demo/templates/home/contacto.html
100644 → 100755
Empty file.
Empty file modified demo/templates/home/index.html
100644 → 100755
Empty file.
Empty file modified demo/templates/home/login.html
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions demo/templates/home/productos.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@ <h1>Catalogo de Productos:</h1>
{% else %}
<h2>No existen productos activos a la venta :( </h2>
{% endif %}
<br><br><br>
{% if productos %}
<a href="/productos/page/1"> << </a>
{% if productos.has_previous %}
<a href="/productos/page/{{productos.previous_page_number }}/"> Prev </a>
{% else %}
<a href="#"> Prev </a>
{% endif %}
{% if productos.has_next %}
<a href="/productos/page/{{productos.next_page_number }}/"> Next </a>
{% else %}
<a href="#"> Next </a>
{% endif %}
<a href="/productos/page/{{productos.paginator.num_pages }} "> >> </a>
<br><br><br>
<h4> Página {{ productos.number }} de {{ productos.paginator.num_pages }}</h4>
{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion demo/templates/ventas/addProducto.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<br>
{{ informacion }}
<br>
<a href="{% url vista_productos %}">Regresar a la lista de Productos </a>
<a href="/productos/page/1/">Regresar a la lista de Productos </a>
{% endblock %}
Empty file modified demo/urls.py
100644 → 100755
Empty file.
Empty file modified demo/wsgi.py
100644 → 100755
Empty file.
Empty file modified manage.py
100644 → 100755
Empty file.

0 comments on commit 3f76f35

Please sign in to comment.