Merge commit 'bc3b14b5dd697f1784acbcbfa0ef0948de4ef560' into currency

* commit 'bc3b14b5dd697f1784acbcbfa0ef0948de4ef560':
  add a base.html file and refactor the other html files
  refactor the views
This commit is contained in:
Ivan Hörler 2017-12-19 22:38:21 +01:00
commit 4da981e5d6
5 changed files with 50 additions and 63 deletions

View File

@ -1,15 +1,9 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
</head>
<body>
<div id="content" class="flex">
<h1>{{ article.name }}</h1>
<h3>Description</h3>
<p>{{ article.description }}</p>
<p><b>Stock:</b> {{ article.stock }}</p>
<p><b>Status:</b> {{ article.status}}</p>
<p><b>Price:</b> {{ article.price_in_chf }}</p>
</div>
</body>
</html>
{% extends "webshop/base.html" %}
{% block section_title %}{{ article.name }}{% endblock %}
{% block content %}
<h3>Description</h3>
<p>{{ article.description }}</p>
<p><b>Stock:</b> {{ article.stock }}</p>
<p><b>Status:</b> {{ article.status}}</p>
<p><b>Price:</b> {{ article.price_in_chf }}</p>
{% endblock %}

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
</head>
<body>
<div id="content" class="flex">
<h1>{% block section_title %}Music Instrument Shop{% endblock %}</h1>
{% block content %}{% endblock %}
</div>
</body>
<footer>
{% block footer %}
<p><font size="1">This is a case study project of Ivan Hörler and Andreas Zweili.
It is a school project/excercise and has no commercial intent.</font></p>
{% endblock %}
</footer>
</html>

View File

@ -1,21 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
</head>
<body>
<div id="content" class="flex">
<h1>{{ category.name }}</h1>
{% if article_list %}
<ul>
{% for article in article_list %}
<li><a href="{% url 'details' article.id %}">{{ article.name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>There are no articles in this category.</p>
{% endif %}
</div>
</body>
</html>
{% extends "webshop/base.html" %}
{% block section_title %}Category Overview{% endblock %}
{% block content %}
{% if article_list %}
<ul>
{% for article in article_list %}
<li><a href="{% url 'details' article.id %}">{{ article.name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>There are no articles in this category.</p>
{% endif %}
{% endblock %}

View File

@ -1,10 +1,5 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
</head>
<body>
<div id="content" class="flex">
<h1>Music Shop</h1>
{% extends "webshop/base.html" %}
{% block content %}
{% if category_list %}
<ul>
{% for category, sub_category in category_list.items %}
@ -18,7 +13,5 @@
</ul>
{% else %}
<p>No categories are available.</p>
{% endif %}
</div>
</body>
</html>
{% endif %}
{% endblock %}

View File

@ -1,7 +1,4 @@
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from django.template import loader
from .models import Article, Category, ArticleStatus
# Create your views here.
@ -15,11 +12,9 @@ def index(request):
category_list.update(
{i: Category.objects.filter(parent_category=i.id)})
template = loader.get_template('webshop/index.html')
context = {
'category_list': category_list,
}
return HttpResponse(template.render(context, request))
return render(request,
'webshop/index.html',
{'category_list': category_list})
def articles_in_category(request, category_id):
@ -29,16 +24,12 @@ def articles_in_category(request, category_id):
article_list = Article.objects.filter(
category=selected_category.id).exclude(status=hidden.id)
template = loader.get_template('webshop/category.html')
context = {
'article_list': article_list,
'category': selected_category,
}
return HttpResponse(template.render(context, request))
return render(request, 'webshop/category.html',
{'article_list': article_list,
'category': selected_category})
def article_details(request, article_id):
article = get_object_or_404(Article, pk=article_id)
return render(request,
'webshop/article_details.html',
return render(request, 'webshop/article_details.html',
{'article': article})