changed some of the views and implemented a more selfish perspective of a shop.

For shure not ideal and in NO way DRY but a solution for now.
This commit is contained in:
Ivan Hörler 2017-12-29 22:32:27 +01:00
parent dc083d9c5e
commit d500712dc2
5 changed files with 117 additions and 44 deletions

View File

@ -23,7 +23,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '(#4#-$$&mx7(%q+6&&@-c&g%i0dc4)zfks1%sy8b%lsxspou&%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True
ALLOWED_HOSTS = [
'localhost',

View File

@ -16,34 +16,55 @@
{% endblock %}
</head>
<body>
<div id="content" class="flex">
<a href="{% url 'index' %}">Home</a> |
{% if user.is_authenticated %}
<a href="{% url 'profile' %}">Profile</a> | <a href="{% url 'logout' %}">Logout</a>
{% else %}
<a href="{% url 'login' %}">Login</a>
{% endif %}
<h1>{% block section_title %}Music Instrument Shop{% endblock %}</h1>
{% block content %}{% endblock %}
</div>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<h1>
{% block shop_name %}Music Instruments Inc.{% endblock %}
</h1>
<div>
{% block search %}{% endblock %}
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'index' %}">
HOME
</a>
</div>
<ul class="nav navbar-nav">
<li><a href="#">CART</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'profile' %}">PROFILE</a></li>
<li><a href="{% url 'logout' %}">LOGOUT</a></li>
{% else %}
<li><a href="{% url 'login' %}">LOGIN</a></li>
{% endif %}
<li><a href="#">CURRENCY</a></li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
{% block nav %}
<ul class="sidebar-nav">
<li><a href="{% url 'index' %}">Home</a></li>
<li><a href="/category/1/">Category 1</a></li> <!--change href!!!-->
<li><a href="/category/2/">Category 2</a></li> <!--change href!!!-->
{% block sidebar %}
{% if category_list %}
<ul>
{% for category, sub_category in category_list.items %}
<li><a href="{% url 'category' category.id %}">{{ category.name }}</a></li>
{% for i in sub_category %}
<ul>
<li><a href="{% url 'category' i.id %}">{{ i.name }}</a></li>
</ul>
{% endfor %}
{% endfor %}
</ul>
{% else %}
<p>No categories are available.</p>
{% endif %}
{% endblock %}
</div>
<div class="col-sm-10 ">

View File

@ -1,13 +1,31 @@
{% 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 %}
{% if article_list %}
<table class="table">
<tr class="table_header">
<th scope="col">ID</th>
<th scope="col">NAME</th>
<th scope="col">CATHEGORY</th>
<th scope="col">STOCK</th>
<th scope="col">PRICE</th>
</tr>
{% for article in article_list %}
<tr class="table_content">
<td scope="col">{{ article.id }}</td>
<td scope="col">
<a href="{% url 'details' article.id %}">
{{ article.name }}
</a></td>
<td scope="col">{{ article.category }}</td>
<td scope="col">{{ article.stock }}</td>
<td scope="col">{{ article.price_in_chf }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p class="alert">
Something whent wrong, no articles are stored.
</p>
{% endif %}
{% endblock %}

View File

@ -1,18 +1,32 @@
{% extends "webshop/base.html" %}
{% block section_title %}Home{% endblock %}
{% block section_title %}Articles{% endblock %}
{% block content %}
{% if category_list %}
<ul>
{% for category, sub_category in category_list.items %}
<li><a href="{% url 'category' category.id %}">{{ category.name }}</a></li>
{% for i in sub_category %}
<ul>
<li><a href="{% url 'category' i.id %}">{{ i.name }}</a></li>
</ul>
{% endfor %}
{% endfor %}
</ul>
{% else %}
<p>No categories are available.</p>
{% endif %}
{% if articles_list %}
<table class="table">
<tr class="table_header">
<th scope="col">ID</th>
<th scope="col">NAME</th>
<th scope="col">CATHEGORY</th>
<th scope="col">STOCK</th>
<th scope="col">PRICE</th>
</tr>
{% for article in articles_list %}
<tr class="table_content">
<td scope="col">{{ article.id }}</td>
<td scope="col">
<a href="{% url 'details' article.id %}">
{{ article.name }}
</a>
</td>
<td scope="col">{{ article.category }}</td>
<td scope="col">{{ article.stock }}</td>
<td scope="col">{{ article.price_in_chf }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p class="alert">
Something whent wrong, no articles are stored.
</p>
{% endif %}
{% endblock %}

View File

@ -12,6 +12,8 @@ from webshop.forms import RegistrationForm
def index(request):
parent_category_list = Category.objects.filter(parent_category=None)
category_list = {}
hidden = ArticleStatus.objects.get(name="hidden")
articles_list = Article.objects.all().exclude(status=hidden.id)
for i in parent_category_list:
category_list.update(
@ -19,7 +21,8 @@ def index(request):
return render(request,
'webshop/index.html',
{'category_list': category_list})
{'category_list': category_list,
'articles_list': articles_list})
def articles_in_category(request, category_id):
@ -29,16 +32,33 @@ def articles_in_category(request, category_id):
article_list = Article.objects.filter(
category=selected_category.id).exclude(status=hidden.id)
parent_category_list = Category.objects.filter(parent_category=None)
category_list = {}
for i in parent_category_list:
category_list.update(
{i: Category.objects.filter(parent_category=i.id)})
return render(request, 'webshop/category.html',
{'article_list': article_list,
'category_list': category_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',
{'article': article})
parent_category_list = Category.objects.filter(parent_category=None)
category_list = {}
for i in parent_category_list:
category_list.update(
{i: Category.objects.filter(parent_category=i.id)})
article = get_object_or_404(Article, pk=article_id)
return render(request, 'webshop/article_details.html',
{'article': article,
'category_list': category_list})
@login_required
def profile(request):