Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route to delete agenda #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions agenda/routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@

def includeme(config):
"""
Quando entender como funciona, voce pode terminar a app.
O que falta?
Deletar uma agenda


add_route(nome_da_rota, url)
config.scan(view_file)
Depois de definidas as rotas, o scan verifica se os route_name das Views
Expand All @@ -15,6 +10,7 @@ def includeme(config):
config.add_route('items', '/items/{agenda_id}')
config.add_route('new_agenda', '/new_agenda')
config.add_route('edit_agenda', '/edit_agenda/{agenda_id}')
config.add_route('delete_agenda', '/delete_agenda/{agenda_id}')
config.add_route('new_item', '/items/{agenda_id}/new_item')
config.add_route('edit_item', '/items/{agenda_id}/edit_item/{item_id}')
config.add_route('delete_item', '/items/{agenda_id}/delete_item/{item_id}')
Expand Down
3 changes: 3 additions & 0 deletions agenda/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<a href="{{ request.route_url('edit_agenda', agenda_id=agenda.id) }}" class="btn btn-info">
Editar
</a>
<a href="{{ request.route_url('delete_agenda', agenda_id=agenda.id) }}" class="btn btn-info">
Apagar
</a>
</td>
</tr>
{% endfor %}
Expand Down
13 changes: 13 additions & 0 deletions agenda/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from pyramid.httpexceptions import HTTPFound
from pyramid.response import Response
from pyramid.view import view_config
Expand Down Expand Up @@ -48,6 +50,17 @@ def new_item(request):

return {'form': form}

"""
Está aceitando apagar agenda via get apenas por simplicidade
isso não é uma boa pratica
"""
@view_config(route_name='delete_agenda')
def delete_agenda(request):
agenda = Agenda.by_id(request.matchdict.get('agenda_id'))
request.db.delete(agenda)
home_url = request.route_url('home')
return HTTPFound(location=home_url)

@view_config(route_name='delete_item', renderer='json')
def delete_item(request):
item = ItemAgenda.by_id(request.matchdict['item_id'])
Expand Down