Skip to content
Permalink
Browse files

Merge branch 'day48'

  • Loading branch information
tbrlpld committed Dec 4, 2019
2 parents cafea25 + 5a0beea commit 7d717acbcf3faad4dbe7d5cdd1b24ae8c367dca3
@@ -20,7 +20,7 @@
<div class="mui-container">
<table>
<tr class="mui--appbar-height">
<td class="mui--text-title"><a id="pageTitle" href="{% url "quotes:quote_list" %}">PyBites Quotes</a></td>
<td class="mui--text-title"><a id="pageTitle" href="{% url "quotes:quotes_list" %}">PyBites Quotes</a></td>
<td class="mui--text-right">
<ul class="mui-list--inline mui--text-body2">
<li><a href="#">About</a></li>
@@ -12,9 +12,9 @@ <h3>Are you sure you want to delete the quote?</h3>
<div class="mui-container">
<form action="" method="post" style="display: inline;">
{% csrf_token %}
<input type="submit" class="mui-btn mui-btn--raised mui-btn--danger" href="{% url 'quotes:quote_list' %}" value="Delete">
<input type="submit" class="mui-btn mui-btn--raised mui-btn--danger" value="Delete">
</form>
<a class="mui-btn mui-btn--raised" href="{% url 'quotes:quote_list' %}">Back</a>
<a class="mui-btn mui-btn--raised" href="{% url 'quotes:quotes_list' %}">Back</a>
</div>

{% endblock %}
@@ -12,7 +12,7 @@ <h1>Quote</h1>
</div>
<div class="mui-container">
<a class="mui-btn mui-btn--raised mui-btn--primary" href="{% url 'quotes:quote_update' quote.id %}">Edit</a>
<a class="mui-btn mui-btn--raised" href="{% url 'quotes:quote_list' %}">Back</a>
<a class="mui-btn mui-btn--raised" href="{% url 'quotes:quotes_list' %}">Back</a>
</div>

{% endblock %}
@@ -20,7 +20,7 @@ <h1>{% if quote %}Update{% else %}Create{% endif %} Quote</h1>

<div class="mui-container">
<input type="submit" class="mui-btn mui-btn--raised mui-btn--primary" value="{% if quote %}Update{% else %}Create{% endif %} Quote">
<a class="mui-btn mui-btn--raised" href="{% url 'quotes:quote_list' %}">Back</a>
<a class="mui-btn mui-btn--raised" href="{% url 'quotes:quotes_list' %}">Back</a>
</div>

</form>
@@ -4,15 +4,25 @@

from django.urls import path

from quotes import views
from quotes import views_cb


app_name = "quotes"

# Function based
# urlpatterns = [
# path("", views.quotes_list, name="quotes_list"),
# path("<int:pk>", views.quote_detail, name="quote_detail"),
# path("create", views.quote_create, name="quote_create"),
# path("update/<int:pk>", views.quote_update, name="quote_update"),
# path("delete/<int:pk>", views.quote_delete, name="quote_delete"),
# ]

# Class based
urlpatterns = [
path("", views.quote_list, name="quote_list"),
path("<int:pk>", views.quote_detail, name="quote_detail"),
path("create", views.quote_create, name="quote_create"),
path("update/<int:pk>", views.quote_update, name="quote_update"),
path("delete/<int:pk>", views.quote_delete, name="quote_delete"),
path("", views_cb.QuotesList.as_view(), name="quotes_list"),
path("<int:pk>", views_cb.QuoteDetail.as_view(), name="quote_detail"),
path("create", views_cb.QuoteCreate.as_view(), name="quote_create"),
path("update/<int:pk>", views_cb.QuoteUpdate.as_view(), name="quote_update"),
path("delete/<int:pk>", views_cb.QuoteDelete.as_view(), name="quote_delete"),
]
@@ -10,10 +10,6 @@
from quotes.models import Quote
from quotes.forms import QuoteForm

# def index(request: HttpRequest) -> HttpResponse:
# """Return the rendered index page."""
# return HttpResponse("Welcome to my first custom view.")


def quote_create(request: HttpRequest) -> HttpResponse:
"""Create a new quote.""" # noqa: 201
@@ -31,7 +27,7 @@ def quote_create(request: HttpRequest) -> HttpResponse:
)


def quote_list(request: HttpRequest) -> HttpResponse:
def quotes_list(request: HttpRequest) -> HttpResponse:
"""Render a list of quotes.""" # noqa: 201
quotes = Quote.objects.all()
return render(
@@ -58,7 +54,7 @@ def quote_update(request: HttpRequest, pk: int) -> HttpResponse:
if form.is_valid():
form.save()
messages.success(request, "Quote updated.")
return redirect("quotes:quote_list")
return redirect("quotes:quotes_list")

return render(
request,
@@ -77,7 +73,7 @@ def quote_delete(request: HttpRequest, pk: int) -> HttpResponse:
if request.POST:
quote.delete()
messages.success(request, "Quote delete.")
return redirect("quotes:quote_list")
return redirect("quotes:quotes_list")

return render(
request,
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-

"""Define the views that respond to the urls being requested."""

from django.urls import reverse_lazy
from django.views.generic import ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView

from quotes.models import Quote
from quotes.forms import QuoteForm


class QuoteCreate(CreateView):
"""Create view for a Quote."""

model = Quote
form_class = QuoteForm
success_url = reverse_lazy("quotes:quotes_list")


class QuotesList(ListView):
"""List all quotes."""

model = Quote
template_name = "quotes/quotes_list.html"
context_object_name = "quotes"


class QuoteDetail(DetailView):
"""Show one quote in detail."""

model = Quote


class QuoteUpdate(UpdateView):
"""Show update form for a quote."""

model = Quote
form_class = QuoteForm
success_url = reverse_lazy("quotes:quotes_list")


class QuoteDelete(DeleteView):
"""Delete a quote after getting confirmation."""

model = Quote
success_url = reverse_lazy("quotes:quotes_list")
template_name = "quotes/quote_delete.html"

0 comments on commit 7d717ac

Please sign in to comment.
You can’t perform that action at this time.