Merge commit '0048475a2d63a08805050d767834606e6547eab9' into currency

* commit '0048475a2d63a08805050d767834606e6547eab9':
  remove a migration file
  add a cronjob to trigger the currency updates
  add migrations to the ignore list
  remove a duplicate entry
  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.
  selfmade css file
  unfinshed atempt to make a nav abandoned for later use maybe
  add bootstrap to ansible and vagrant for django-bootstrap3 support
This commit is contained in:
Ivan Hörler 2018-01-13 13:42:06 +01:00
commit d5ad3c77d5
10 changed files with 185 additions and 99 deletions

1
.gitignore vendored
View File

@ -267,3 +267,4 @@ fabric.properties
# End of https://www.gitignore.io/api/pycharm
/django/.idea/workspace.xml
/docs/main.listing
/django/didgeridoo/currencies/migrations/*.py

7
Vagrantfile vendored
View File

@ -30,7 +30,8 @@ Vagrant.configure("2") do |config|
#zu installierende Pakete
apt-get install -y apache2 python3-django mariadb-server avahi-daemon \
libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip
pip3 install django-extensions Pillow pyaml
pip3 install django-extensions Pillow pyaml django-bootstrap3
#Copy the apache configuration for django to the correct place
cp /vagrant/apache/000-default.conf /etc/apache2/sites-available/
@ -42,6 +43,10 @@ Vagrant.configure("2") do |config|
systemctl restart apache2.service
/vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh
#insert the currency update cronjob
echo "wget -O /dev/null http://localhost:8080" > /etc/cron.hourly/currency_update
chmod +x /etc/cron.hourly/currency_update
SHELL
end

View File

@ -29,6 +29,7 @@
- django-extensions
- Pillow
- pyaml
- django-bootstrap3
executable: pip3
- name: Run the setup script to add some final touches

View File

@ -1,48 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-01-09 18:21
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='ExchangeRate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('exchange_rate_to_chf', models.DecimalField(decimal_places=5, max_digits=12)),
],
),
migrations.CreateModel(
name='ExchangeRate_date',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(unique_for_date=True, verbose_name='%Y-%m-%d')),
],
),
migrations.CreateModel(
name='ExchangeRate_name',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
],
),
migrations.AddField(
model_name='exchangerate',
name='date',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='currencies.ExchangeRate_date'),
),
migrations.AddField(
model_name='exchangerate',
name='name',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='currencies.ExchangeRate_name'),
),
]

View File

@ -35,7 +35,6 @@ ALLOWED_HOSTS = [
# Application definition
INSTALLED_APPS = [
'currencies',
'webshop.apps.WebshopConfig',
'django_extensions',
'django.contrib.admin',
@ -44,6 +43,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'currencies',
'bootstrap3',
]
MIDDLEWARE = [

View File

@ -0,0 +1,6 @@
.sidebar-nav {
margin-top: 30px;
padding: 10;
list-style: none;
}

View File

@ -1,23 +1,93 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
</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>
</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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{{ STATIC_URL }}/static/webshop/css/base.css" />
{% block title %}
<title>
Casestudy 'Webshop' IBZ TIAE-5(2017/18)
</title>
{% endblock %}
</footer>
</head>
<body>
<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 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 ">
<h1>
{% block section_title %}{% endblock %}
</h1>
</div>
<div class="col-sm-10 ">
{% block content %}{% endblock %}
</div>
</div>
</div>
<footer>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
{% block footer %}
This is a case study project of Ivan Hörler and Andreas Zweili. </br>
It is a school project/excercise and has no commercial intent.
{% endblock %}
</div>
</div>
</div>
</footer>
</body>
</html>

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,17 +1,32 @@
{% extends "webshop/base.html" %}
{% 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

@ -17,6 +17,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(
@ -24,7 +26,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):
@ -34,18 +37,32 @@ 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)
picture_list = Picture.objects.filter(article=article_id)
return render(request, 'webshop/article_details.html',
{'article': article,
'picture_list': picture_list})
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):