Merge branch 'master' into production

This commit is contained in:
Andreas Zweili 2017-12-29 16:46:48 +01:00
commit ddd4001fb3
13 changed files with 142 additions and 38 deletions

View File

@ -25,7 +25,11 @@ 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
ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
'localhost',
'127.0.0.1',
'didgeridoo.ml'
]
# Application definition
@ -130,9 +134,4 @@ STATIC_URL = '/static/'
STATIC_ROOT = '/vagrant/django/didgeridoo/static/'
MEDIA_ROOT = '/vagrant/django/didgeridoo/media/'
ALLOWED_HOSTS = [
'localhost',
'127.0.0.1',
'didgeridoo.ml'
]
LOGIN_REDIRECT_URL = '/'

View File

@ -3,8 +3,9 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User
# Register your models here.
from .models import (Article, Order, OrderPosition, Person, City, Picture,
OrderOfGoods, Category, Option, Setting)
from webshop.models import (Article, Order, OrderPosition,
Person, City, Picture, OrderOfGoods,
Category, Option, Setting)
class PersonInline(admin.StackedInline):

View File

@ -0,0 +1,24 @@
from django import forms
from webshop.models import Salutation, City
class RegistrationForm(forms.Form):
email = forms.EmailField()
salutation = forms.ModelChoiceField(queryset=Salutation.objects.all())
first_name = forms.CharField()
last_name = forms.CharField()
street_name = forms.CharField()
street_number = forms.CharField()
zip_code = forms.IntegerField(min_value=1000, max_value=9999)
city = forms.CharField()
def clean_city(self):
# Check that the two password entries match
city = self.cleaned_data['city']
zip_code = self.cleaned_data['zip_code']
try:
City.objects.get(name=city, zip_code=zip_code)
except City.DoesNotExist:
raise forms.ValidationError(
"The zip code and the city don't match.")
return city

View File

@ -1,5 +1,3 @@
#!/usr/bin/python3
from decimal import Decimal
from django.core.validators import MinValueValidator
from django.db import models
@ -138,8 +136,6 @@ class Salutation(models.Model):
class Person(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
salutation = models.ForeignKey(Salutation)
city = models.ForeignKey(City)
street_name = models.CharField(max_length=200)
@ -147,4 +143,4 @@ class Person(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
def __str__(self):
return self.last_name
return self.user.username

View File

@ -0,0 +1,6 @@
{% extends 'webshop/base.html' %}
{% block section_title %}You have been successfully logged out.{% endblock %}
{% block content %}
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends 'webshop/base.html' %}
{% block section_title %}Login{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
<p><a href="{% url 'registration' %}">Go to registration.</a></p>
</form>
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends 'webshop/base.html' %}
{% block section_title %}User Profile{% endblock %}
{% block content %}
<p><b>Username: </b>{{ request.user.username }}</p>
<p><b>Salutation: </b>{{ person.salutation }}</p>
<p><b>Firstname: </b>{{ request.user.first_name }}</p>
<p><b>Lastname: </b>{{ request.user.last_name }}</p>
<p><b>City: </b>{{ person.city }}</p>
<p><b>Street: </b>{{ person.street_name }}</p>
<p><b>Streetnumber: </b>{{ person.street_number }}</p>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
</form>
{% endblock %}

View File

@ -0,0 +1,19 @@
{% extends 'webshop/base.html' %}
{% block section_title %}Registration{% endblock %}
{% block content %}
{% if profile_form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form action="" method="post" novalidate>
<table>
{{ user_form.as_table }}
{{ profile_form.as_table }}
</table>
{% csrf_token %}
<button type="submit">Register</button>
</form>
{% endblock %}

View File

@ -4,6 +4,12 @@
</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>

View File

@ -1,6 +1,6 @@
from django.conf.urls import url
from django.conf.urls import url, include
from . import views
from webshop import views
urlpatterns = [
url(r'^$', views.index, name='index'),
@ -10,4 +10,7 @@ urlpatterns = [
url(r'^category/(?P<category_id>[0-9]+)/$',
views.articles_in_category,
name='category'),
url('^', include('django.contrib.auth.urls')),
url(r'^profile/$', views.profile, name='profile'),
url(r'^registration/$', views.registration, name='registration'),
]

View File

@ -1,5 +1,10 @@
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from .models import Article, Category, ArticleStatus
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from webshop.models import Article, Category, ArticleStatus, Person, City
from webshop.forms import RegistrationForm
# Create your views here.
@ -33,3 +38,39 @@ def article_details(request, article_id):
article = get_object_or_404(Article, pk=article_id)
return render(request, 'webshop/article_details.html',
{'article': article})
@login_required
def profile(request):
person = Person.objects.get(user=request.user)
return render(request, 'registration/profile.html',
{'person': person})
def registration(request):
if request.method == 'POST':
profile_form = RegistrationForm(request.POST)
user_form = UserCreationForm(request.POST)
if (profile_form.is_valid() and user_form.is_valid()):
pf = profile_form.cleaned_data
uf = user_form.cleaned_data
user = User.objects.create_user(uf['username'],
pf['email'],
uf['password2'])
user.last_name = pf['last_name']
user.first_name = pf['first_name']
user.save()
person = Person.objects.create(
salutation=pf['salutation'],
city=City.objects.get(zip_code=pf['zip_code'],
name=pf['city']),
street_name=pf['street_name'],
street_number=pf['street_number'],
user=user)
return HttpResponseRedirect('/login/')
else:
profile_form = RegistrationForm
user_form = UserCreationForm
return render(request, 'registration/register.html',
{'profile_form': profile_form,
'user_form': user_form})

View File

@ -1,20 +0,0 @@
<!DOCTYPE HTML>
<meta charset="UTF-8">
<html>
<head></head>
<body>
<header>
<h1>audioguide</h1>
<h3>a mobile offline audioguide</h3>
noop
noop
noop
noop
noop
noop
<p>the audioguide that makes a offline usage possible.</p>
</header>
<nav>
</nav>
</body>
</html>

View File

@ -24,7 +24,7 @@ use webshopdb;
insert into webshop_articlestatus (name)
values ('out of stock'),
('hidden'),
('on sale');
('active');
use webshopdb;
insert into webshop_city (zip_code, name)