Permalink
Browse files

merge django_debug

  • Loading branch information...
2 parents 0e748ba + bf38032 commit f9c8856c99ed46c4b9779fdf23485bc39b642003 Osvaldo Santana committed Oct 29, 2010
Showing with 50 additions and 5 deletions.
  1. +9 −4 agenda/views.py
  2. +6 −0 settings.py
  3. +12 −0 templates/help.html
  4. +19 −1 templates/lista.html
  5. +4 −0 urls.py
View
13 agenda/views.py
@@ -4,14 +4,20 @@
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.http import HttpResponseRedirect
+from django.views.generic import list_detail
from models import ItemAgenda
from forms import FormItemAgenda
@login_required
def lista(request):
- lista_itens = ItemAgenda.objects.filter(usuario=request.user)
- return render_to_response("lista.html", {'lista_itens': lista_itens})
+ return list_detail.object_list(
+ request,
+ queryset = ItemAgenda.objects.filter(usuario=request.user),
+ template_name = "lista.html",
+ template_object_name="itens",
+ paginate_by=2,
+ )
@login_required
def adiciona(request):
@@ -51,7 +57,6 @@ def remove(request, nr_item):
if request.method == "POST":
item.delete()
return HttpResponseRedirect("/")
- else:
- return render_to_response("remove.html", {'item': item},
+ return render_to_response("remove.html", {'item': item},
context_instance=RequestContext(request))
View
6 settings.py
@@ -76,6 +76,7 @@
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
+ 'debug_toolbar.middleware.DebugToolbarMiddleware',
)
ROOT_URLCONF = 'gerenciador.urls'
@@ -96,6 +97,8 @@
'agenda',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
+ # Django Debug Toolbar
+ 'debug_toolbar',
)
LOGIN_URL = "/login/"
@@ -109,3 +112,6 @@
EMAIL_HOST_PASSWORD=r"????"
EMAIL_USE_TLS=True
+# Django Debug Toolbar configuration
+INTERNAL_IPS = ('127.0.0.1',)
+
View
12 templates/help.html
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+
+{% block corpo %}
+
+<h1>Ajuda</h1>
+
+<dl>
+ <dt>Como eu cadastro um novo item?</dt>
+ <dd>Clicando no link "Adicionar novo item"</dd>
+</dl>
+
+{% endblock %}
View
20 templates/lista.html
@@ -3,9 +3,10 @@
{% block corpo %}
<p><a href="/logout/">logout</a></p>
+<p><a href="/help/">Ajuda</a></p>
<p><a href="/adiciona/">Adicionar novo item</a></p>
<ul>
-{% for item in lista_itens %}
+{% for item in itens_list %}
<li>
<a href="/remove/{{ item.id }}"><img src="/media/imagens/lixeira.png" /></a>
<a href="/item/{{ item.id }}">{{ item.data|date:'d/m/Y' }} - {{ item.titulo }}</a>
@@ -15,4 +16,21 @@
{% endfor %}
</ul>
+<ul>
+{% if has_previous %}
+ <li><a href="?page={{ previous }}">anterior</a></li>
+{% endif %}
+{% for page_number in page_range %}
+ {% ifequal page page_number %}
+ <li>{{ page_number }}</li>
+ {% else %}
+ <li><a href="?page={{ page_number }}">{{ page_number }}</a></li>
+ {% endifequal %}
+{% endfor %}
+{% if has_next %}
+ <li><a href="?page={{ next }}">próxima</a></li>
+{% endif %}
+</ul>
+
+
{% endblock %}
View
4 urls.py
@@ -10,6 +10,10 @@
# (r'^gerenciador/', include('gerenciador.foo.urls')),
(r'^$', 'agenda.views.lista'),
+
+ (r'^help/$', 'django.views.generic.simple.direct_to_template',
+ {'template': 'help.html'}),
+
(r'adiciona/$', 'agenda.views.adiciona'),
(r'item/(?P<nr_item>\d+)/$', 'agenda.views.item'),
(r'remove/(?P<nr_item>\d+)/$', 'agenda.views.remove'),

0 comments on commit f9c8856

Please sign in to comment.