
diff --git a/Dockerfile b/Dockerfile index 554f7fe..d711537 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3 +FROM python:3.7 ENV PYTHONUNBUFFERED 1 ENV SHELL /bin/bash @@ -6,9 +6,13 @@ ENV SHELL /bin/bash # ------------------------------------------ # install necessary packages via apt-get: # ------------------------------------------ -# RUN apt-get update && \ -# apt-get install -y --no-install-recommends \ -# libsaxonhe-java +# RUN apt-get update && apt-get install -y --no-install-recommends \ +# pkg1 \ +# pkg2 +# ... + +# this is supposed to save memory: +# RUN rm -rf /var/lib/apt/lists/* # ------------------------------------------ # install python dependencies: diff --git a/README.md b/README.md index d7a9d27..494be63 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,28 @@ Experimental implementation. Aims to replace relational database/django by xml t $ ./scripts/run.py +- Create superuser for django CMS: + + $ ./scripts/exec_in_container.py 'python manage.py createsuperuser' + + (enter username, etc) + +- enter basic CMS pages + + in your browser, go to 'http://localhost:8002/admin/cms/page/'. Add 3 pages: + + - Introduction (Id: 'introduction') + - Contact (Id: 'contact') + - Imprint (Id: 'imprint') + + These are required by the system! + - Import example publication (similar for other publications): $ ./scripts/exec_in_container.py 'python manage.py publication_import $INPUT_DIR/example' + (you'll need to stop and start the webserver afterwards) + - Stop the Webserver $ ./scripts/stop.py @@ -34,4 +52,4 @@ Experimental implementation. Aims to replace relational database/django by xml t ## Other Scripts -- see './scripts'. All scripts accept `--help`. +- see './scripts/'. All scripts accept `--help`. diff --git a/requirements.txt b/requirements.txt index 40b0525..9caa359 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,10 @@ Django==2.1.5 pytz==2018.9 -psycopg2-binary +psycopg2-binary==2.7.7 lxml == 4.4.2 +django-cms == 3.7.1 +django-treebeard == 4.3 +django-sekizai == 1.1.0 # the xml database pyexistdb diff --git a/scripts/install.py b/scripts/install.py index 696d837..0a01717 100755 --- a/scripts/install.py +++ b/scripts/install.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 from utils.settings import BASE_DIR, load_config, create_docker_env_file -from utils.functions import exec_in_xmldb, exec_in_container +from utils.functions import exec_in_xmldb, exec_in_container, run +from stop import stop from pathlib import Path import shlex @@ -130,7 +131,12 @@ def init_sqldb( config ): parser = ArgumentParser( description="initialize the repository: create directories, initialize xml database, initialize sql database" ) - parser.parse_args() + parser.add_argument( + "--build", + action = "store_true", + help = "rebuild docker image from Dockerfile", + ) + args = parser.parse_args() # orig_config_file -> env_file: create_docker_env_file() @@ -141,4 +147,15 @@ def init_sqldb( config ): create_dirs( config ) install_xml_db( config ) + + # rebuild docker image: + if args.build: + run( + env = config, + build = True, + ) + stop( + env = config, + ) + init_sqldb( config ) diff --git a/scripts/run.py b/scripts/run.py index 0dc1a68..d81baf8 100755 --- a/scripts/run.py +++ b/scripts/run.py @@ -4,8 +4,7 @@ from stop import stop from utils.settings import BASE_DIR, load_config -from utils.functions import exec_in_xmldb - +from utils.functions import exec_in_xmldb, run from pathlib import Path import subprocess import shlex @@ -37,24 +36,6 @@ def init_xml_db( config ): shlex.split( "docker-compose down" ), ) -def run( - env, - build=False, - cmd=[] -): - if len(cmd) > 0: - # run application - subprocess.call( - shlex.split("docker-compose run webserver") + cmd, - env=env - ) - else: - # run application - subprocess.call( - shlex.split("docker-compose up -d") + (["--build"] if build else []), - env=env - ) - def copy_dir(src, dst): print( "'{}' -> '{}'".format( src, dst ) ) if Path(dst).exists(): diff --git a/scripts/utils/functions.py b/scripts/utils/functions.py index b1d0afb..80a779d 100644 --- a/scripts/utils/functions.py +++ b/scripts/utils/functions.py @@ -3,6 +3,24 @@ import subprocess import shlex +def run( + env, + build=False, + cmd=[] +): + if len(cmd) > 0: + # run application + subprocess.call( + shlex.split("docker-compose run webserver") + cmd, + env=env + ) + else: + # run application + subprocess.call( + shlex.split("docker-compose up -d") + (["--build"] if build else []), + env=env + ) + def exec_in_xmldb( *args, env=None @@ -26,7 +44,7 @@ def exec_in_container( cmd = \ [ "docker-compose", "exec", "webserver", "bash" ] - if len(args) is not 0: + if len(args) != 0: cmd.append( "-c" ) cmd.append( reduce(lambda x,y: x + " " + y, args ) diff --git a/src/website/settings.py b/src/website/settings.py index 6b2ec3a..22eeecf 100644 --- a/src/website/settings.py +++ b/src/website/settings.py @@ -37,6 +37,7 @@ # Application definition INSTALLED_APPS = [ + 'djangocms_admin_style', # needed by django cms 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -44,9 +45,31 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'pyexistdb', + + # django cms config: + 'django.contrib.sites', + 'cms', + 'menus', + 'treebeard', + 'sekizai', # cms static files + + # main app: 'website' ] +SITE_ID = 1 + +LANGUAGES = [ + ('en', 'English'), + ('de', 'Deutsch'), + ('it', 'Italiano'), + ('fr', 'Français'), +] + +CMS_TEMPLATES = [ + ('base.html', 'Home page template'), +] + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -55,6 +78,14 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + + # needed by django-cms: + 'django.middleware.locale.LocaleMiddleware', + 'cms.middleware.user.CurrentUserMiddleware', + 'cms.middleware.page.CurrentPageMiddleware', + 'cms.middleware.toolbar.ToolbarMiddleware', + 'cms.middleware.language.LanguageCookieMiddleware', + 'cms.middleware.utils.ApphookReloadMiddleware', ] ROOT_URLCONF = 'website.urls' @@ -62,7 +93,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [Path(BASE_DIR, 'website', 'templates'),], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -70,6 +101,10 @@ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + # needed by django-cms: + 'sekizai.context_processors.sekizai', + 'cms.context_processors.cms_settings', + 'django.template.context_processors.i18n', ], }, }, @@ -121,7 +156,7 @@ # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'en' TIME_ZONE = 'UTC' diff --git a/src/website/templates/base.html b/src/website/templates/base.html new file mode 100644 index 0000000..a71f7dc --- /dev/null +++ b/src/website/templates/base.html @@ -0,0 +1,79 @@ +{% load cms_tags menu_tags sekizai_tags staticfiles %} + + +
+ +