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:
parent
dc083d9c5e
commit
d500712dc2
|
@ -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&%'
|
SECRET_KEY = '(#4#-$$&mx7(%q+6&&@-c&g%i0dc4)zfks1%sy8b%lsxspou&%'
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
'localhost',
|
'localhost',
|
||||||
|
|
|
@ -16,34 +16,55 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<h1>
|
<h1>
|
||||||
{% block shop_name %}Music Instruments Inc.{% endblock %}
|
{% block shop_name %}Music Instruments Inc.{% endblock %}
|
||||||
</h1>
|
</h1>
|
||||||
|
<div>
|
||||||
|
{% block search %}{% endblock %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</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="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
{% block nav %}
|
{% block sidebar %}
|
||||||
<ul class="sidebar-nav">
|
{% if category_list %}
|
||||||
<li><a href="{% url 'index' %}">Home</a></li>
|
<ul>
|
||||||
<li><a href="/category/1/">Category 1</a></li> <!--change href!!!-->
|
{% for category, sub_category in category_list.items %}
|
||||||
<li><a href="/category/2/">Category 2</a></li> <!--change href!!!-->
|
<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>
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No categories are available.</p>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-10 ">
|
<div class="col-sm-10 ">
|
||||||
|
|
|
@ -1,13 +1,31 @@
|
||||||
{% extends "webshop/base.html" %}
|
{% extends "webshop/base.html" %}
|
||||||
{% block section_title %}Category Overview{% endblock %}
|
{% block section_title %}Category Overview{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if article_list %}
|
{% if article_list %}
|
||||||
<ul>
|
<table class="table">
|
||||||
{% for article in article_list %}
|
<tr class="table_header">
|
||||||
<li><a href="{% url 'details' article.id %}">{{ article.name }}</a></li>
|
<th scope="col">ID</th>
|
||||||
{% endfor %}
|
<th scope="col">NAME</th>
|
||||||
</ul>
|
<th scope="col">CATHEGORY</th>
|
||||||
{% else %}
|
<th scope="col">STOCK</th>
|
||||||
<p>There are no articles in this category.</p>
|
<th scope="col">PRICE</th>
|
||||||
{% endif %}
|
</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 %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,18 +1,32 @@
|
||||||
{% extends "webshop/base.html" %}
|
{% extends "webshop/base.html" %}
|
||||||
{% block section_title %}Home{% endblock %}
|
{% block section_title %}Articles{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if category_list %}
|
{% if articles_list %}
|
||||||
<ul>
|
<table class="table">
|
||||||
{% for category, sub_category in category_list.items %}
|
<tr class="table_header">
|
||||||
<li><a href="{% url 'category' category.id %}">{{ category.name }}</a></li>
|
<th scope="col">ID</th>
|
||||||
{% for i in sub_category %}
|
<th scope="col">NAME</th>
|
||||||
<ul>
|
<th scope="col">CATHEGORY</th>
|
||||||
<li><a href="{% url 'category' i.id %}">{{ i.name }}</a></li>
|
<th scope="col">STOCK</th>
|
||||||
</ul>
|
<th scope="col">PRICE</th>
|
||||||
{% endfor %}
|
</tr>
|
||||||
{% endfor %}
|
{% for article in articles_list %}
|
||||||
</ul>
|
<tr class="table_content">
|
||||||
{% else %}
|
<td scope="col">{{ article.id }}</td>
|
||||||
<p>No categories are available.</p>
|
<td scope="col">
|
||||||
{% endif %}
|
<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 %}
|
{% endblock %}
|
||||||
|
|
|
@ -12,6 +12,8 @@ from webshop.forms import RegistrationForm
|
||||||
def index(request):
|
def index(request):
|
||||||
parent_category_list = Category.objects.filter(parent_category=None)
|
parent_category_list = Category.objects.filter(parent_category=None)
|
||||||
category_list = {}
|
category_list = {}
|
||||||
|
hidden = ArticleStatus.objects.get(name="hidden")
|
||||||
|
articles_list = Article.objects.all().exclude(status=hidden.id)
|
||||||
|
|
||||||
for i in parent_category_list:
|
for i in parent_category_list:
|
||||||
category_list.update(
|
category_list.update(
|
||||||
|
@ -19,7 +21,8 @@ def index(request):
|
||||||
|
|
||||||
return render(request,
|
return render(request,
|
||||||
'webshop/index.html',
|
'webshop/index.html',
|
||||||
{'category_list': category_list})
|
{'category_list': category_list,
|
||||||
|
'articles_list': articles_list})
|
||||||
|
|
||||||
|
|
||||||
def articles_in_category(request, category_id):
|
def articles_in_category(request, category_id):
|
||||||
|
@ -29,16 +32,33 @@ def articles_in_category(request, category_id):
|
||||||
article_list = Article.objects.filter(
|
article_list = Article.objects.filter(
|
||||||
category=selected_category.id).exclude(status=hidden.id)
|
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',
|
return render(request, 'webshop/category.html',
|
||||||
{'article_list': article_list,
|
{'article_list': article_list,
|
||||||
|
'category_list': category_list,
|
||||||
'category': selected_category})
|
'category': selected_category})
|
||||||
|
|
||||||
|
|
||||||
def article_details(request, article_id):
|
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
|
@login_required
|
||||||
def profile(request):
|
def profile(request):
|
||||||
|
|
Loading…
Reference in New Issue