Merge branch 'master' into currency

* master:
  fix a typo
  move some parts from the vagrant file into a separate script
  make the setup script executable
  fix a typo
  add a setup script to the ansible role
  add a pip install routine to the ansible role
  add the repository to the ansible role
  fix a typo in the ansbible role
  add missing packages to the ansible role
  add a list of allowed hosts to the django settings
  change ansible includes to import_tasks
  extend the admin interface for the order class
  add an intermediate class between order and article
  add a date field to the orders class
  sort city outputs by zip code
  update readme with more up to date information
This commit is contained in:
Ivan Hörler 2017-12-26 13:03:20 +01:00
commit 1b7252a669
9 changed files with 96 additions and 37 deletions

View File

@ -34,7 +34,12 @@ vagrant up
Vagrant will then provision a virtual machine according to the
specifications in the "Vagrantfile" file. After it's finished you
should be able to access the web page under http://localhost:8000
should be able to access the web page under http://localhost:8080
To access the admin panel visit http://localhost:8080/admin the
default login is admin and the corresponding password is
"password". By default the application contains no data, you can enter
whatever you need.
### Support

24
Vagrantfile vendored
View File

@ -32,29 +32,7 @@ Vagrant.configure("2") do |config|
libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip
pip3 install django-extensions Pillow
#initialize the db
mysql < /vagrant/sql/04_remove_database.sql
mysql < /vagrant/sql/01_create_database.sql
#löschen und verlinken der HTML root damit man diese nicht manuel kopieren muss.
if ! [ -L /var/www/html ]; then
rm -rf /var/www/html
ln -s /vagrant/html /var/www/html
fi
#Copy the apache configuration for django to the correct place
cp /vagrant/apache/000-default.conf /etc/apache2/sites-available/
#restart the webserver
systemctl restart apache2.service
rm /vagrant/django/didgeridoo/webshop/migrations/*.py
python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop
python3 /vagrant/django/didgeridoo/manage.py migrate
mysql < /vagrant/sql/02_insert_data.sql
echo "from django.contrib.auth.models import User; \
User.objects.filter(email='admin@example.com').delete(); \
User.objects.create_superuser('admin', 'admin@example.com', 'password')" |
python3 /vagrant/django/didgeridoo/manage.py shell
/vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh
SHELL
end

View File

@ -1,7 +1,7 @@
# System Upgrade and package installation
- include: tasks/apt_update_cache.yml
- include: tasks/apt_distupgrade.yml
- include: tasks/apt_install.yml
- import_tasks: tasks/apt_update_cache.yml
- import_tasks: tasks/apt_distupgrade.yml
- import_tasks: tasks/apt_install.yml
# User configuration
- name: Lock root user
@ -16,7 +16,7 @@
line='{{ deploy_user_name }} ALL=(ALL) NOPASSWD: ALL'
state=present"
- include: tasks/ufw_tcp.yml
- import_tasks: tasks/ufw_tcp.yml
- name: Copy over the sshd_config file
template: src=sshd_config.j2 dest=/etc/ssh/sshd_config owner=root group=root

View File

@ -1,15 +1,36 @@
---
- include: tasks/apt_install.yml
- include: tasks/ufw_tcp.yml
- import_tasks: tasks/apt_install.yml
- import_tasks: tasks/ufw_tcp.yml
- include: mariadb.yml
- import_tasks: mariadb.yml
- name: Copy apache config
copy: src=000-default.conf
dest=/etc/apache2/site-available/
dest=/etc/apache2/sites-available/
owner=root
group=root
mode=655
- name: Clone repository
git: repo=https://git.2li.ch/ibz/web_AI-5.git
dest="/vagrant"
force=yes
- name: Set Permissions on the repository
file:
dest=/vagrant
owner=ansible group=ansible
recurse=yes
- name: Install pip packages
pip:
name:
- django-extensions
- Pillow
executable: pip3
- name: Run the setup script to add some final touches
shell: "/vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh"
- name: Restart apache service
service: name=apache2 state=restarted

View File

@ -0,0 +1,19 @@
#initialize the db
mysql < /vagrant/sql/04_remove_database.sql
mysql < /vagrant/sql/01_create_database.sql
#remove old migrations
rm /vagrant/django/didgeridoo/webshop/migrations/*.py
#create and insert the new migrations
python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop
python3 /vagrant/django/didgeridoo/manage.py migrate
#insert some default data into the database
mysql < /vagrant/sql/02_insert_data.sql
#create an admin user
echo "from django.contrib.auth.models import User; \
User.objects.filter(email='admin@example.com').delete(); \
User.objects.create_superuser('admin', 'admin@example.com', 'password')" |
python3 /vagrant/django/didgeridoo/manage.py shell

View File

@ -4,6 +4,8 @@ apt_packages:
- python3-django
- libapache2-mod-wsgi-py3
- python3-mysqldb
- python3-pip
- git
open_tcp_ports:
- 80

View File

@ -130,3 +130,10 @@ USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = '/vagrant/django/didgeridoo/static/'
MEDIA_ROOT = '/vagrant/django/didgeridoo/media/'
ALLOWED_HOSTS = [
'localhost',
'127.0.0.1',
'didgeridoo.ml'
]

View File

@ -3,8 +3,8 @@ 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, Person, City, Picture, OrderOfGoods,
Category, Option, Setting)
from .models import (Article, Order, OrderPosition, Person, City, Picture,
OrderOfGoods, Category, Option, Setting)
class PersonInline(admin.StackedInline):
@ -17,11 +17,25 @@ class UserAdmin(BaseUserAdmin):
inlines = (PersonInline,)
class OrderPositionInline(admin.StackedInline):
model = OrderPosition
can_delete = False
verbose_name_plural = 'Order Positions'
class OrderAdmin(admin.ModelAdmin):
list_display = ('id', 'user', 'date')
list_filter = ('date',)
date_hierarchy = 'date'
ordering = ('-date',)
inlines = (OrderPositionInline,)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.register(Article)
admin.site.register(Order)
admin.site.register(Order, OrderAdmin)
admin.site.register(City)
admin.site.register(Picture)
admin.site.register(OrderOfGoods)

View File

@ -4,6 +4,7 @@ from decimal import Decimal
from django.core.validators import MinValueValidator
from django.db import models
from django.contrib.auth.models import User
import datetime
class Option(models.Model):
@ -85,8 +86,19 @@ class Picture(models.Model):
class Order(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
article = models.ManyToManyField(Article)
order_status = models.ForeignKey(OrderStatus)
article = models.ManyToManyField(Article, through='OrderPosition')
status = models.ForeignKey(OrderStatus)
date = models.DateTimeField(default=datetime.datetime.now())
class OrderPosition(models.Model):
article = models.ForeignKey(Article, on_delete=models.CASCADE)
order = models.ForeignKey(Order, on_delete=models.CASCADE)
amount = models.FloatField(max_length=5)
price_in_chf = models.DecimalField(max_digits=19,
decimal_places=2,
validators=[MinValueValidator(
Decimal('0.00'))])
class ShoppingCart(models.Model):
@ -107,6 +119,7 @@ class City(models.Model):
class Meta:
verbose_name_plural = "Cities"
ordering = ['zip_code']
class Salutation(models.Model):