From 96939992b031634f62c371cd7b928e5c829eae60 Mon Sep 17 00:00:00 2001 From: Malte Vogl Date: Tue, 11 Jul 2017 15:33:49 +0200 Subject: [PATCH] addings models --- .dockerignore | 1 + .gitignore | 1 + eoa/migrations/0003_auto_20170711_1243.py | 216 ++++++++++++++++++++++ eoa/migrations/0004_auto_20170711_1251.py | 30 +++ eoa/migrations/0005_auto_20170711_1306.py | 21 +++ eoa/migrations/0006_paragraph.py | 41 ++++ eoa/models.py | 55 ++++-- eoa/tests.py | 4 +- eoasite/settings_local.py | 126 +++++++++++++ 9 files changed, 478 insertions(+), 17 deletions(-) create mode 100644 eoa/migrations/0003_auto_20170711_1243.py create mode 100644 eoa/migrations/0004_auto_20170711_1251.py create mode 100644 eoa/migrations/0005_auto_20170711_1306.py create mode 100644 eoa/migrations/0006_paragraph.py create mode 100644 eoasite/settings_local.py diff --git a/.dockerignore b/.dockerignore index faea375..4931b75 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,3 +4,4 @@ .gitignore .gitlab-ci.yml myvenv +eoa-venv diff --git a/.gitignore b/.gitignore index 4134212..57caf0e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *~ __pychache__ myvenv +eoa-venv db.sqlite3 /static .DS_Store diff --git a/eoa/migrations/0003_auto_20170711_1243.py b/eoa/migrations/0003_auto_20170711_1243.py new file mode 100644 index 0000000..5083625 --- /dev/null +++ b/eoa/migrations/0003_auto_20170711_1243.py @@ -0,0 +1,216 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-11 10:43 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import eoa.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('eoa', '0002_auto_20170705_1329'), + ] + + operations = [ + migrations.CreateModel( + name='Chapter', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=200)), + ('order', models.PositiveIntegerField()), + ('number', models.CharField(blank=True, max_length=20)), + ('language', models.CharField(choices=[('de', 'German'), ('en', 'English'), ('it', 'Italian')], default='de', max_length=2)), + ('doi', models.CharField(blank=True, max_length=200)), + ('citation', models.CharField(blank=True, max_length=200)), + ('pdf', models.FileField(blank=True, upload_to=eoa.models.filepath)), + ], + options={ + 'ordering': ('order',), + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Part', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=200)), + ('order', models.PositiveIntegerField()), + ('number', models.CharField(blank=True, max_length=20)), + ('language', models.CharField(choices=[('de', 'German'), ('en', 'English'), ('it', 'Italian')], default='de', max_length=2)), + ('doi', models.CharField(blank=True, max_length=200)), + ('citation', models.CharField(blank=True, max_length=200)), + ('pdf', models.FileField(blank=True, upload_to=eoa.models.filepath)), + ], + options={ + 'ordering': ('order',), + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Section', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=200)), + ('order', models.PositiveIntegerField()), + ('number', models.CharField(blank=True, max_length=20)), + ('language', models.CharField(choices=[('de', 'German'), ('en', 'English'), ('it', 'Italian')], default='de', max_length=2)), + ('doi', models.CharField(blank=True, max_length=200)), + ('citation', models.CharField(blank=True, max_length=200)), + ('pdf', models.FileField(blank=True, upload_to=eoa.models.filepath)), + ], + options={ + 'ordering': ('order',), + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Subsection', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=200)), + ('order', models.PositiveIntegerField()), + ('number', models.CharField(blank=True, max_length=20)), + ('language', models.CharField(choices=[('de', 'German'), ('en', 'English'), ('it', 'Italian')], default='de', max_length=2)), + ('doi', models.CharField(blank=True, max_length=200)), + ('citation', models.CharField(blank=True, max_length=200)), + ('pdf', models.FileField(blank=True, upload_to=eoa.models.filepath)), + ], + options={ + 'ordering': ('order',), + 'abstract': False, + }, + ), + migrations.AlterModelOptions( + name='author', + options={'ordering': ('lastname',)}, + ), + migrations.AlterModelOptions( + name='publication', + options={'ordering': ('title',)}, + ), + migrations.RemoveField( + model_name='author', + name='middlenames', + ), + migrations.RemoveField( + model_name='publication', + name='author', + ), + migrations.AddField( + model_name='author', + name='foto', + field=models.ImageField(blank=True, upload_to='authors'), + ), + migrations.AddField( + model_name='author', + name='publications', + field=models.ManyToManyField(to='eoa.Publication'), + ), + migrations.AddField( + model_name='publication', + name='featured', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='publication', + name='language', + field=models.CharField(choices=[('de', 'German'), ('en', 'English'), ('it', 'Italian')], default='de', max_length=2), + ), + migrations.AddField( + model_name='publication', + name='publication_id', + field=models.IntegerField(default=None), + ), + migrations.AddField( + model_name='publication', + name='published', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='publication', + name='series', + field=models.CharField(choices=[('sources', 'Sources'), ('studies', 'Studies'), ('essays', 'Essays'), ('proceedings', 'Proceedings'), ('textbooks', 'Textbooks')], default='sources', max_length=20), + ), + migrations.AddField( + model_name='publication', + name='subtitle', + field=models.CharField(default=None, max_length=200), + ), + migrations.AlterField( + model_name='publication', + name='pages', + field=models.PositiveIntegerField(), + ), + migrations.AddField( + model_name='subsection', + name='authors', + field=models.ManyToManyField(blank=True, default=None, to='eoa.Author'), + ), + migrations.AddField( + model_name='subsection', + name='chapter', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Chapter'), + ), + migrations.AddField( + model_name='subsection', + name='part', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Part'), + ), + migrations.AddField( + model_name='subsection', + name='publication', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Publication'), + ), + migrations.AddField( + model_name='subsection', + name='section', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Section'), + ), + migrations.AddField( + model_name='section', + name='authors', + field=models.ManyToManyField(blank=True, default=None, to='eoa.Author'), + ), + migrations.AddField( + model_name='section', + name='chapter', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Chapter'), + ), + migrations.AddField( + model_name='section', + name='part', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Part'), + ), + migrations.AddField( + model_name='section', + name='publication', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Publication'), + ), + migrations.AddField( + model_name='part', + name='authors', + field=models.ManyToManyField(blank=True, default=None, to='eoa.Author'), + ), + migrations.AddField( + model_name='part', + name='publication', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Publication'), + ), + migrations.AddField( + model_name='chapter', + name='authors', + field=models.ManyToManyField(blank=True, default=None, to='eoa.Author'), + ), + migrations.AddField( + model_name='chapter', + name='part', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Part'), + ), + migrations.AddField( + model_name='chapter', + name='publication', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Publication'), + ), + ] diff --git a/eoa/migrations/0004_auto_20170711_1251.py b/eoa/migrations/0004_auto_20170711_1251.py new file mode 100644 index 0000000..56969fb --- /dev/null +++ b/eoa/migrations/0004_auto_20170711_1251.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-11 10:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('eoa', '0003_auto_20170711_1243'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='description', + field=models.CharField(blank=True, default=None, max_length=200, null=True), + ), + migrations.AddField( + model_name='author', + name='homepage', + field=models.CharField(blank=True, default=None, max_length=200, null=True), + ), + migrations.AddField( + model_name='author', + name='middlenames', + field=models.CharField(blank=True, default=None, max_length=200, null=True), + ), + ] diff --git a/eoa/migrations/0005_auto_20170711_1306.py b/eoa/migrations/0005_auto_20170711_1306.py new file mode 100644 index 0000000..544f0b9 --- /dev/null +++ b/eoa/migrations/0005_auto_20170711_1306.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-11 11:06 +from __future__ import unicode_literals + +from django.db import migrations, models +import eoa.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('eoa', '0004_auto_20170711_1251'), + ] + + operations = [ + migrations.AlterField( + model_name='author', + name='foto', + field=models.ImageField(blank=True, upload_to=eoa.models.filepath), + ), + ] diff --git a/eoa/migrations/0006_paragraph.py b/eoa/migrations/0006_paragraph.py new file mode 100644 index 0000000..d7897ab --- /dev/null +++ b/eoa/migrations/0006_paragraph.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-11 13:03 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import eoa.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('eoa', '0005_auto_20170711_1306'), + ] + + operations = [ + migrations.CreateModel( + name='Paragraph', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=200)), + ('order', models.PositiveIntegerField()), + ('number', models.CharField(blank=True, max_length=20)), + ('language', models.CharField(choices=[('de', 'German'), ('en', 'English'), ('it', 'Italian')], default='de', max_length=2)), + ('doi', models.CharField(blank=True, max_length=200)), + ('citation', models.CharField(blank=True, max_length=200)), + ('pdf', models.FileField(blank=True, upload_to=eoa.models.filepath)), + ('text', models.TextField()), + ('authors', models.ManyToManyField(blank=True, default=None, to='eoa.Author')), + ('chapter', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Chapter')), + ('part', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Part')), + ('publication', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='eoa.Publication')), + ('section', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Section')), + ('subsection', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='eoa.Subsection')), + ], + options={ + 'ordering': ('order',), + 'abstract': False, + }, + ), + ] diff --git a/eoa/models.py b/eoa/models.py index eafd88e..329422b 100644 --- a/eoa/models.py +++ b/eoa/models.py @@ -1,35 +1,51 @@ from django.db import models from django.utils import timezone +################################################# +# +# file path should depend on instance type +# +################################################# + def filepath(instance, filename): strPublicationSerie = instance.Publication.Serie strPublicationNumber = str(instance.Publication.Number) baseString = strPublicationSerie + "/" + strPublicationNumber + "/" - if instance.__class__.__name__ == Chapter: - strChapterOrder = str(instance.Order) - strFilePath = baseString + strChapterOrder + "/" + filename + if instance.__class__.__name__ == Author: + strFilePath = 'authors' elif instance.__class__.__name__ == Publication: strFilePath = baseString + "/" + filename + elif instance.__class__.__name__ == Chapter: + strChapterOrder = str(instance.Order) + strFilePath = baseString + strChapterOrder + "/" + filename return strFilePath +############################################ +# +# default settings which are used in several places +# +############################################ + series_choice = ( ('sources', 'Sources'), ('studies', 'Studies'), ('essays', 'Essays'), ('proceedings', 'Proceedings'), ('textbooks', 'Textbooks'), -) + ) + language_choice = ( ('de', 'German'), ('en', 'English'), ('it', 'Italian'), -) + ) -charStandard = models.CharField( - max_length=200, - default=None, - blank=True, - null=True) +default_char = { + 'max_length':200, + 'default':None, + 'blank':True, + 'null':True + } ########################################## # @@ -72,26 +88,28 @@ class Meta: class Author(models.Model): firstname = models.CharField(max_length=50) lastname = models.CharField(max_length=100) - middlenames = charStandard + middlenames = models.CharField(**default_char) email = models.EmailField( default=None, max_length=70, blank=True, null=True, unique=True) - homepage = charStandard - description = charStandard + homepage = models.CharField(**default_char) + description = models.CharField(**default_char) publications = models.ManyToManyField(Publication) born = models.DateField( blank=True, null=True) - foto = models.ImageField(upload_to='authors', blank=True) + foto = models.ImageField(upload_to=filepath, blank=True) def edit_birthday(self): self.born = timezone.now() self.save() def __str__(self): - return (self.firstname + ' ' + self.middlenames + ' ' + self.lastname) + return (str(self.firstname) + ' '\ + + str(self.middlenames) + ' '\ + + str(self.lastname)) class Meta: ordering = ('lastname',) @@ -145,3 +163,10 @@ class Subsection(CommonTextPart): part = models.ForeignKey(Part, blank=True) chapter = models.ForeignKey(Chapter, blank=False) section = models.ForeignKey(Section, blank=False) + +class Paragraph(CommonTextPart): + part = models.ForeignKey(Part, blank=True) + chapter = models.ForeignKey(Chapter, blank=True) + section = models.ForeignKey(Section, blank=True) + subsection = models.ForeignKey(Subsection, blank=True) + text = models.TextField(blank=False) diff --git a/eoa/tests.py b/eoa/tests.py index ae90654..8ea2110 100644 --- a/eoa/tests.py +++ b/eoa/tests.py @@ -5,13 +5,13 @@ from .models import Author - class AuthorModelTests(TestCase): def setUp(self): Author.objects.create( firstname='Test', lastname='Ußer', - middlenames='D.', + middlenames ='D.', + homepage='www.data.de', email='test@test.ert') Author.objects.create( firstname='Test2', diff --git a/eoasite/settings_local.py b/eoasite/settings_local.py new file mode 100644 index 0000000..5b7dd91 --- /dev/null +++ b/eoasite/settings_local.py @@ -0,0 +1,126 @@ +""" +Django settings for eoasite project. + +Generated by 'django-admin startproject' using Django 1.11.3. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '5+7@!8y6k^)b(3s%8_8y$ryhuyw2$fs2z$d8)%cr8o)5as&k@@' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ['web','localhost','127.0.0.1','141.5.105.187'] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'eoa', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'eoasite.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'eoasite.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'dev', + 'USER': 'dev', + 'PASSWORD': 'dev', + 'HOST': 'localhost', + 'PORT': '5432', + }, +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'Europe/Berlin' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static')