Add and improve routes

This commit is contained in:
Sascha Ißbrücker 2019-06-28 07:33:08 +02:00
parent d9e1c64340
commit e2a834a56c
7 changed files with 33 additions and 11 deletions

View File

@ -1 +0,0 @@
<h2>Edit bookmark {{ bookmark.id }}</h2>

View File

@ -0,0 +1,5 @@
{% extends "bookmarks/layout.html" %}
{% block content %}
<h2>Edit bookmark</h2>
{% endblock %}

View File

@ -1,7 +1,10 @@
{% extends "bookmarks/layout.html" %}
{% block content %}
<h2>Bookmarks</h2>
<div>
<h2>Bookmarks</h2>
<a href="{% url 'bookmarks:new' %}">Add</a>
</div>
<ul class="bookmark-list">
{% for bookmark in bookmarks %}
<li>
@ -12,7 +15,7 @@
<p>{{ bookmark.description }}</p>
{% endif %}
<p>
<a href="{% url 'bookmarks:detail' bookmark.id %}">Edit</a>
<a href="{% url 'bookmarks:edit' bookmark.id %}">Edit</a>
<a href="{% url 'bookmarks:remove' bookmark.id %}"
onclick="return confirm('Do you really want to delete this bookmark?')">Remove</a>
</p>

View File

@ -0,0 +1,5 @@
{% extends "bookmarks/layout.html" %}
{% block content %}
<h2>New bookmark</h2>
{% endblock %}

View File

@ -1,10 +1,17 @@
from django.conf.urls import url
from django.urls import path
from django.views.generic import RedirectView
from . import views
app_name = 'bookmarks'
urlpatterns = [
path('', views.index, name='index'),
path('bookmark/<int:bookmark_id>', views.detail, name='detail'),
path('bookmark/<int:bookmark_id>/remove', views.remove, name='remove'),
# Redirect root to bookmarks index
url(r'^$', RedirectView.as_view(pattern_name='bookmarks:index', permanent=False)),
path('bookmarks', views.index, name='index'),
path('bookmarks/new', views.new, name='new'),
# path('bookmarks/create', views.create, name='create'),
path('bookmarks/<int:bookmark_id>/edit', views.edit, name='edit'),
# path('bookmarks/<int:bookmark_id>/update', views.update, name='edit'),
path('bookmarks/<int:bookmark_id>/remove', views.remove, name='remove'),
]

View File

@ -1,6 +1,5 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
# Create your views here.
from django.urls import reverse
@ -18,11 +17,15 @@ def create(request):
return HttpResponse('OK')
def detail(request, bookmark_id):
def new(request):
return render(request, 'bookmarks/new.html')
def edit(request, bookmark_id):
context = {
'bookmark': Bookmark.objects.get(bookmark_id)
'bookmark': Bookmark.objects.get(pk=bookmark_id)
}
return render(request, 'bookmarks/detail.html', context)
return render(request, 'bookmarks/edit.html', context)
def remove(request, bookmark_id: int):

View File

@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('bookmarks/', include('bookmarks.urls')),
path('admin/', admin.site.urls),
path('', include('bookmarks.urls')),
]