Merge branch 'master' into production
This commit is contained in:
commit
097e46988a
|
@ -0,0 +1,8 @@
|
||||||
|
from django import forms
|
||||||
|
from currencies.models import ExchangeRate_name
|
||||||
|
|
||||||
|
|
||||||
|
class CurrenciesForm(forms.Form):
|
||||||
|
currencies = forms.ModelChoiceField(
|
||||||
|
queryset=ExchangeRate_name.objects.all(),
|
||||||
|
required=False)
|
|
@ -23,5 +23,9 @@ class ExchangeRate(models.Model):
|
||||||
exchange_rate_to_chf = models.DecimalField(max_digits=12,
|
exchange_rate_to_chf = models.DecimalField(max_digits=12,
|
||||||
decimal_places=5)
|
decimal_places=5)
|
||||||
|
|
||||||
|
def exchange(_currency_id, _base_currency):
|
||||||
|
rate = ExchangeRate.objects.filter(name=_currency_id).latest('date')
|
||||||
|
return round(rate.exchange_rate_to_chf * _base_currency,2)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
{% block section_title %}Login{% endblock %}
|
{% block section_title %}Login{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="post">
|
<form id="login" name="login" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button type="submit">Login</button>
|
<button name="button_login" type="submit">Login</button>
|
||||||
<p><a href="{% url 'registration' %}">Go to registration.</a></p>
|
<p><a href="{% url 'registration' %}">Go to registration.</a></p>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
Please correct the error{{ form.errors|pluralize }} below.
|
Please correct the error{{ form.errors|pluralize }} below.
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form action="" method="post" novalidate>
|
<form id="register" name="register" action="" method="post" novalidate>
|
||||||
<table>
|
<table>
|
||||||
{{ user_form.as_table }}
|
{{ user_form.as_table }}
|
||||||
{{ profile_form.as_table }}
|
{{ profile_form.as_table }}
|
||||||
</table>
|
</table>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button type="submit">Register</button>
|
<button name="button_register" type="submit">Register</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
<h3>Description</h3>
|
<h3>Description</h3>
|
||||||
<p>{{ article.description }}</p>
|
<p>{{ article.description }}</p>
|
||||||
<p><b>Stock:</b> {{ article.stock }}</p>
|
<p><b>Stock:</b> {{ article.stock }}</p>
|
||||||
<p><b>Status:</b> {{ article.status}}</p>
|
<p><b>Status:</b> {{ article.status }}</p>
|
||||||
<p><b>Price:</b> {{ article.price_in_chf }}</p>
|
<p><b>Price:</b> {{ article.price_in_chf }} {{ currency_name }}</p>
|
||||||
{% for picture in picture_list %}
|
{% for picture in picture_list %}
|
||||||
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
|
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<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">
|
<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>
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||||
|
|
||||||
<!-- Add additional CSS in static file -->
|
<!-- Add additional CSS in static file -->
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% 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 articles_list %}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr class="table_header">
|
<tr class="table_header">
|
||||||
<th scope="col">ID</th>
|
<th scope="col">ID</th>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
<th scope="col">STOCK</th>
|
<th scope="col">STOCK</th>
|
||||||
<th scope="col">PRICE</th>
|
<th scope="col">PRICE</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for article in article_list %}
|
{% for article in articles_list %}
|
||||||
<tr class="table_content">
|
<tr class="table_content">
|
||||||
<td scope="col">{{ article.id }}</td>
|
<td scope="col">{{ article.id }}</td>
|
||||||
<td scope="col">
|
<td scope="col">
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
</a></td>
|
</a></td>
|
||||||
<td scope="col">{{ article.category }}</td>
|
<td scope="col">{{ article.category }}</td>
|
||||||
<td scope="col">{{ article.stock }}</td>
|
<td scope="col">{{ article.stock }}</td>
|
||||||
<td scope="col">{{ article.price_in_chf }}</td>
|
<td scope="col">{{ article.price_in_chf }} {{ currency_name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td scope="col">{{ article.category }}</td>
|
<td scope="col">{{ article.category }}</td>
|
||||||
<td scope="col">{{ article.stock }}</td>
|
<td scope="col">{{ article.stock }}</td>
|
||||||
<td scope="col">{{ article.price_in_chf }}</td>
|
<td scope="col">{{ article.price_in_chf }} {{ currency_name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -19,24 +19,19 @@
|
||||||
<a href="{% url 'login' %}">LOGIN</a>
|
<a href="{% url 'login' %}">LOGIN</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- https://pypi.python.org/pypi/django-select-multiple-field -->
|
<li>
|
||||||
<form method="POST" novalidate>
|
{% if article_view %}
|
||||||
<select name="currency_update" id="id_currency_update">
|
<form id="currency" name="currency" action="" method="POST" novalidate>
|
||||||
<option value="CHF">CHF</option>
|
{{ currencies_form.as_ul }}
|
||||||
<option value="USD">USD</option>
|
<li>
|
||||||
<option value="GBP">GBP</option>
|
<input type="submit" value="Select">
|
||||||
<option value="JPY">JPY</option>
|
</li>
|
||||||
</select>
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<!--
|
|
||||||
Es wird auf id im app.js file gemached.
|
|
||||||
die URL wird im app.js gesetzt
|
|
||||||
und mit urls.py weitergereicht.
|
|
||||||
dann auf name im views.py gemached und ausgeführt.
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,77 +3,159 @@ from django.shortcuts import get_object_or_404, render
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from webshop.models import (Article,
|
from webshop.models import (Article, Category, ArticleStatus, Person,
|
||||||
Category,
|
City, Picture)
|
||||||
ArticleStatus,
|
|
||||||
Person,
|
|
||||||
City,
|
|
||||||
Picture)
|
|
||||||
from webshop.forms import RegistrationForm
|
from webshop.forms import RegistrationForm
|
||||||
|
|
||||||
|
from currencies.models import ExchangeRate, ExchangeRate_name
|
||||||
|
from currencies.forms import CurrenciesForm
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
def get_categories():
|
||||||
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(
|
||||||
{i: Category.objects.filter(parent_category=i.id)})
|
{i: Category.objects.filter(parent_category=i.id)})
|
||||||
|
return category_list
|
||||||
|
|
||||||
|
|
||||||
|
def get_hidden_status_id():
|
||||||
|
hidden_status = ArticleStatus.objects.get(name="hidden")
|
||||||
|
return hidden_status.id
|
||||||
|
|
||||||
|
|
||||||
|
def index(request):
|
||||||
|
category_list = get_categories()
|
||||||
|
articles = Article.objects.all().exclude(status=get_hidden_status_id())
|
||||||
|
articles_list = list(articles)
|
||||||
|
currencies_form = CurrenciesForm
|
||||||
|
rate=ExchangeRate
|
||||||
|
article_view = True
|
||||||
|
currency_name = "CHF"
|
||||||
|
|
||||||
|
if not 'currency' in request.session:
|
||||||
|
request.session['currency'] = None
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
currencies_form = CurrenciesForm(request.POST)
|
||||||
|
if currencies_form.is_valid():
|
||||||
|
cf = currencies_form.cleaned_data
|
||||||
|
if cf['currencies']:
|
||||||
|
selection = cf['currencies']
|
||||||
|
request.session['currency'] = selection.id
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=selection.id)
|
||||||
|
else:
|
||||||
|
request.session['currency'] = None
|
||||||
|
|
||||||
|
if request.session['currency']:
|
||||||
|
currency = request.session['currency']
|
||||||
|
for idx, article in enumerate(articles_list):
|
||||||
|
article.price_in_chf = rate.exchange(currency, article.price_in_chf)
|
||||||
|
articles_list[idx] = article
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=currency)
|
||||||
|
|
||||||
return render(request,
|
return render(request,
|
||||||
'webshop/index.html',
|
'webshop/index.html',
|
||||||
{'category_list': category_list,
|
{'category_list': category_list,
|
||||||
'articles_list': articles_list})
|
'articles_list': articles_list,
|
||||||
|
'currencies_form': currencies_form,
|
||||||
|
'article_view': article_view,
|
||||||
|
'currency_name': currency_name})
|
||||||
|
|
||||||
|
|
||||||
def articles_in_category(request, category_id):
|
def articles_in_category(request, category_id):
|
||||||
|
category_list = get_categories()
|
||||||
selected_category = Category.objects.get(id=category_id)
|
selected_category = Category.objects.get(id=category_id)
|
||||||
hidden = ArticleStatus.objects.get(name="hidden")
|
articles = Article.objects.filter(
|
||||||
|
category=selected_category.id).exclude(status=get_hidden_status_id())
|
||||||
|
articles_list = list(articles)
|
||||||
|
currencies_form = CurrenciesForm
|
||||||
|
rate=ExchangeRate
|
||||||
|
article_view = True
|
||||||
|
currency_name = "CHF"
|
||||||
|
|
||||||
article_list = Article.objects.filter(
|
if not 'currency' in request.session:
|
||||||
category=selected_category.id).exclude(status=hidden.id)
|
request.session['currency'] = None
|
||||||
|
|
||||||
parent_category_list = Category.objects.filter(parent_category=None)
|
if request.method == 'POST':
|
||||||
category_list = {}
|
currencies_form = CurrenciesForm(request.POST)
|
||||||
|
if currencies_form.is_valid():
|
||||||
|
cf = currencies_form.cleaned_data
|
||||||
|
if cf['currencies']:
|
||||||
|
selection = cf['currencies']
|
||||||
|
request.session['currency'] = selection.id
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=selection.id)
|
||||||
|
else:
|
||||||
|
request.session['currency'] = None
|
||||||
|
|
||||||
for i in parent_category_list:
|
if request.session['currency']:
|
||||||
category_list.update(
|
currency = request.session['currency']
|
||||||
{i: Category.objects.filter(parent_category=i.id)})
|
for idx, article in enumerate(articles_list):
|
||||||
|
article.price_in_chf = rate.exchange(currency, article.price_in_chf)
|
||||||
|
articles_list[idx] = article
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=currency)
|
||||||
|
|
||||||
return render(request, 'webshop/category.html',
|
return render(request, 'webshop/category.html',
|
||||||
{'article_list': article_list,
|
{'articles_list': articles_list,
|
||||||
'category_list': category_list,
|
'category_list': category_list,
|
||||||
|
'currencies_form': currencies_form,
|
||||||
|
'article_view': article_view,
|
||||||
|
'currency_name': currency_name,
|
||||||
'category': selected_category})
|
'category': selected_category})
|
||||||
|
|
||||||
|
|
||||||
def article_details(request, article_id):
|
def article_details(request, article_id):
|
||||||
parent_category_list = Category.objects.filter(parent_category=None)
|
category_list = get_categories()
|
||||||
category_list = {}
|
currencies_form = CurrenciesForm
|
||||||
|
rate=ExchangeRate
|
||||||
|
article_view = True
|
||||||
|
currency_name = "CHF"
|
||||||
|
|
||||||
for i in parent_category_list:
|
if not 'currency' in request.session:
|
||||||
category_list.update(
|
request.session['currency'] = None
|
||||||
{i: Category.objects.filter(parent_category=i.id)})
|
|
||||||
|
|
||||||
article = get_object_or_404(Article, pk=article_id)
|
article = get_object_or_404(Article, pk=article_id)
|
||||||
picture_list = Picture.objects.filter(article=article_id)
|
picture_list = Picture.objects.filter(article=article_id)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
currencies_form = CurrenciesForm(request.POST)
|
||||||
|
if currencies_form.is_valid():
|
||||||
|
cf = currencies_form.cleaned_data
|
||||||
|
if cf['currencies']:
|
||||||
|
selection = cf['currencies']
|
||||||
|
request.session['currency'] = selection.id
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=selection.id)
|
||||||
|
else:
|
||||||
|
request.session['currency'] = None
|
||||||
|
|
||||||
|
if request.session['currency']:
|
||||||
|
currency = request.session['currency']
|
||||||
|
article.price_in_chf = rate.exchange(currency, article.price_in_chf)
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=currency)
|
||||||
|
|
||||||
return render(request, 'webshop/article_details.html',
|
return render(request, 'webshop/article_details.html',
|
||||||
{'article': article,
|
{'article': article,
|
||||||
'category_list': category_list,
|
'category_list': category_list,
|
||||||
|
'currencies_form': currencies_form,
|
||||||
|
'article_view': article_view,
|
||||||
|
'currency_name': currency_name,
|
||||||
'picture_list': picture_list})
|
'picture_list': picture_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profile(request):
|
def profile(request):
|
||||||
|
category_list = get_categories()
|
||||||
person = Person.objects.get(user=request.user)
|
person = Person.objects.get(user=request.user)
|
||||||
return render(request, 'registration/profile.html',
|
return render(request, 'registration/profile.html',
|
||||||
{'person': person})
|
{'person': person,
|
||||||
|
'category_list': category_list})
|
||||||
|
|
||||||
|
|
||||||
def registration(request):
|
def registration(request):
|
||||||
|
category_list = get_categories()
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
profile_form = RegistrationForm(request.POST)
|
profile_form = RegistrationForm(request.POST)
|
||||||
user_form = UserCreationForm(request.POST)
|
user_form = UserCreationForm(request.POST)
|
||||||
|
@ -99,4 +181,5 @@ def registration(request):
|
||||||
user_form = UserCreationForm
|
user_form = UserCreationForm
|
||||||
return render(request, 'registration/register.html',
|
return render(request, 'registration/register.html',
|
||||||
{'profile_form': profile_form,
|
{'profile_form': profile_form,
|
||||||
|
'category_list': category_list,
|
||||||
'user_form': user_form})
|
'user_form': user_form})
|
||||||
|
|
Loading…
Reference in New Issue