diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26149e0..8e0643a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ test: script: - python -V - pip install -r requirements.txt - - cp sikweb/ci-settings.py sikweb/settings.py + - cp sikweb/.ci-settings.py sikweb/settings.py - python manage.py migrate --noinput - python manage.py createdefaultadmin - python manage.py test diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 15e0f2d..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '2' -services: - db: - build: - context: . - dockerfile: scripts/db/Dockerfile - environment: - - POSTGRES_PASSWORD=toor - - POSTGRES_USER=root - web: - build: - context: . - dockerfile: scripts/web/Dockerfile - command: python manage.py runserver 0.0.0.0:8000 - volumes: - - .:/code - ports: - - "8000:8000" - depends_on: - - db diff --git a/examples/members.txt b/examples/members.txt deleted file mode 100644 index 7da3409..0000000 --- a/examples/members.txt +++ /dev/null @@ -1,105 +0,0 @@ -// Get one member - -GET /members/api/member/:id -{ - id: 1, - first_name: "Erkki", - last_name: "Esimerkki", - email: "erkki.esimerkki@aalto.fi", - AYY: 1/0, - jas: 1/0, - POR: 'Espoo', -} - - -// Get all members - -GET /members/api/members - -[{ - id: 1, - first_name: "Erkki", - last_name: "Esimerkki", - email: "erkki.esimerkki@aalto.fi", - AYY: 1, - jas: 0, - POR: 'Espoo', -},{ - id: 2, - first_name: "Matti", - last_name: "Meikäläinen", - email: "superman@hotmail.com", - AYY: 0, - jas: 1, - POR: 'Kerava', -}] - -// Create new member (note:do NOT send id!!) - -POST /members/api/member (gets newly created item (with id) as response) -{ - first_name: "Pena", - last_name: "Perusjäbä", - email: "herpderp@hotmail.com", - AYY: 0, - jas: 0, - POR: 'Korso', -} - -// Delete member. (returns {status:"success"} or {status:'failure', msg: "specific error msg"}) - -DELETE /members/api/member/:id - -// get all pending member requests -GET /members/api/requests - -[ - { - "submitted": "2016-07-25 15:58:22.103187+00:00", - "id": 1, - "member": { - "id": 69, - "AYY": false, - "email": "asd@asd.asd", - "first_name": "reg", - "POR": "", - "jas": false, - "last_name": "uest" - } - }, - { - "submitted": "2016-07-25 15:59:06.069821+00:00", - "id": 2, - "member": { - "id": 70, - "AYY": false, - "email": "asd@asd.asd", - "first_name": "re", - "POR": "", - "jas": false, - "last_name": "guest" - } - } -] -//accept member request (== delete request but leave member) - -POST /members/api/request/:id - -//reject member request (== delete request and delete member) - -DELETE /members/api/request/:id - - -// mass import from csv -POST /members/api/csvimport -//csvformat first_name,last_name,email,POR,AYY,JAS -// example data -Pekka,Pöytä,pekka.p.pouta@mosh.pit,Tuska,1,0 - -// example response on success -{"status": "success", "errors": []} -// example response on failure (code will be 400) -{"status": "failure", "errors": ["failure adding item Pekka, P\u00f6yt\u00e42, pekka.p.pouta@mosh.pit, Tuska, Eip"]} - -//member request from official page -POST /members/api/request \ No newline at end of file diff --git a/members/migrations/0007_auto_20170518_1538.py b/members/migrations/0007_auto_20170518_1538.py new file mode 100644 index 0000000..b087919 --- /dev/null +++ b/members/migrations/0007_auto_20170518_1538.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2017-05-18 12:38 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('members', '0006_auto_20170517_1309'), + ] + + operations = [ + migrations.AlterField( + model_name='payment', + name='date', + field=models.DateTimeField(default=datetime.datetime(2017, 5, 18, 15, 38, 7, 668612)), + ), + ] diff --git a/members/migrations/0008_auto_20170518_1540.py b/members/migrations/0008_auto_20170518_1540.py new file mode 100644 index 0000000..1d31da0 --- /dev/null +++ b/members/migrations/0008_auto_20170518_1540.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2017-05-18 12:40 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('members', '0007_auto_20170518_1538'), + ] + + operations = [ + migrations.AlterField( + model_name='member', + name='created', + field=models.DateTimeField(default=datetime.datetime.now), + ), + migrations.AlterField( + model_name='payment', + name='date', + field=models.DateTimeField(default=datetime.datetime.now), + ), + ] diff --git a/members/models.py b/members/models.py index b15e318..4ffc126 100644 --- a/members/models.py +++ b/members/models.py @@ -78,7 +78,7 @@ class Payment(models.Model): ''' Payment model representing one payment event ''' - date = models.DateTimeField(default=datetime.now()) + date = models.DateTimeField(default=datetime.now) source = models.CharField(choices=[ ('AYY', _('AYY')), ('cash', _('Cash')), @@ -95,7 +95,7 @@ class Member(BaseMember): ''' Member model represets one member on the registry. ''' - created = models.DateTimeField(default=timezone.now) + created = models.DateTimeField(default=datetime.now) @staticmethod def from_array(array): diff --git a/scripts/autoinstall.sh b/scripts/autoinstall.sh deleted file mode 100755 index 901f776..0000000 --- a/scripts/autoinstall.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -export DOCKER_OPTS="" -PROJECT="web20" - -echo "SIKWEB 2.0 Dockerific install script" -echo "====================================" - -echo "Checking if docker is installed..." -docker --version -if [ "$?" -ne 0 ] -then - echo "Installing docker..." - curl -fsSL https://get.docker.com/ | sh -fi - -systemctl status docker.service >/dev/null || { echo "Docker daemon is not running. Please start it!"; exit 1; } - -echo "Checking if docker-compose is installed..." -docker-compose --version -if [ "$?" -ne 0 ] -then - echo "Installing docker-compose 1.11.2..." - curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose -fi - - -echo "Building db container..." -docker-compose -p "$PROJECT" build db || { echo "Failed to build db!"; exit 1; } -docker-compose -p "$PROJECT" up -d db - -echo "Copying settings..." -cp -n sikweb/settings-sample.py sikweb/settings.py || { echo "Failed to copy settings!"; exit 1; } - -echo "Building web container..." -docker-compose -p "$PROJECT" build web - -sleep 10 -echo "Running manage.py commands..." -docker-compose -p "$PROJECT" run web python manage.py migrate --noinput || { echo "Failed to apply migrations!"; exit 1; } -docker-compose -p "$PROJECT" run web python manage.py createdefaultadmin || { echo "Failed to create default admin user."; } -echo "generating dummydata" -docker-compose -p "$PROJECT" run web python /code/misc/create_dummydata.py || { echo "Failed to create default admin user."; } - -echo "Starting web container..." -docker-compose -p "$PROJECT" up -d web || { echo "Failed to start containers!"; exit 1; } - - - -echo "Done." diff --git a/scripts/db/Dockerfile b/scripts/db/Dockerfile deleted file mode 100644 index 4bd2dee..0000000 --- a/scripts/db/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM postgres:9.6 -COPY scripts/db/init.sql /docker-entrypoint-initdb.d/init.sql diff --git a/scripts/db/init.sql b/scripts/db/init.sql index acd8ab4..174e287 100644 --- a/scripts/db/init.sql +++ b/scripts/db/init.sql @@ -6,3 +6,5 @@ ALTER ROLE sik SET timezone TO 'UTC'; CREATE DATABASE sik ENCODING 'UTF8' OWNER sik; +GRANT ALL PRIVILEGES ON DATABASE sik TO sik; +ALTER USER sik CREATEDB; diff --git a/scripts/production/Dockerfile b/scripts/production/Dockerfile deleted file mode 100644 index 31f1682..0000000 --- a/scripts/production/Dockerfile +++ /dev/null @@ -1,68 +0,0 @@ -# TODO https://github.com/Kazanz/docker-nginx-uwsgi-django/blob/master/Dockerfile -#FROM ubuntu:16.04 - - -#RUN apt-get update -#Install python dependencies -#RUN apt-get install -y python3-dev python3 python3-pip python3 -# install nginx -#RUN apt-get install -y nginx -# install install packet dependencies -#RUN apt-get install -y mysql-client libmysqlclient-dev libssl-dev - -#RUN mkdir -p /code -#RUN mkdir -p /run -#WORKDIR /code -#ADD requirements.txt /code/ -#ADD scripts/production/nginx.conf /etc/nginx/sites-enabled/default - -#RUN pip3 install -r requirements.txt -#ADD . /code/ -#RUN python3 manage.py collectstatic --no-input - -#EXPOSE 80 - -#ENTRYPOINT ["/usr/bin/uwsgi", "/code/scripts/production/uwsgi.ini"] -#ENTRYPOINT ["/bin/bash"] - -FROM python:3.5-alpine - -RUN apk add --update \ - nginx \ - supervisor \ - python-dev \ - build-base \ - linux-headers \ - pcre-dev \ - py-pip \ - vim \ - mysql-client \ - mysql-dev \ - openssl-dev \ - libffi-dev \ - jpeg-dev \ - zlib-dev\ -&& rm -rf /var/cache/apk/* \ -&& chown -R nginx:www-data /var/lib/nginx - -RUN mkdir -p /code -RUN mkdir -p /run -RUN mkdir -p /run/nginx -RUN chmod -R 777 /run - -WORKDIR /code -ADD . /code/ -ADD requirements.txt /code/ - -RUN pip install -r requirements.txt -RUN python manage.py collectstatic --no-input - - -RUN rm -f /etc/nginx/nginx.conf -ADD scripts/production/nginx.conf /etc/nginx/nginx.conf -RUN mkdir /etc/nginx/sites-enabled -ADD scripts/production/nginx-app.conf /etc/nginx/sites-enabled/default - -RUN rm /etc/supervisord.conf -ADD scripts/production/supervisord.conf /etc/supervisord.conf -CMD ["supervisord", "-n"] diff --git a/scripts/production/nginx-app.conf b/scripts/production/nginx-app.conf deleted file mode 100644 index bff49f7..0000000 --- a/scripts/production/nginx-app.conf +++ /dev/null @@ -1,14 +0,0 @@ -server{ - listen 80; - server_name _; - location / { - uwsgi_pass unix:///run/django.socket; - include /etc/nginx/uwsgi_params; - } - location /static { - alias /code/static; - } - location /media { - alias /code/media; - } -} diff --git a/scripts/production/nginx.conf b/scripts/production/nginx.conf deleted file mode 100644 index 5ec9942..0000000 --- a/scripts/production/nginx.conf +++ /dev/null @@ -1,20 +0,0 @@ -#user nobody; -worker_processes 4; - -error_log /dev/stdout debug; -#error_log logs/error.log notice; -#error_log logs/error.log info; -#pid run/nginx.pid; - - -events { - worker_connections 1024; -} -http { - include mime.types; - include /etc/nginx/sites-enabled/*; - default_type application/octet-stream; - keepalive_timeout 65; - sendfile on; -} -daemon off; diff --git a/scripts/production/supervisord.conf b/scripts/production/supervisord.conf deleted file mode 100644 index d5166e9..0000000 --- a/scripts/production/supervisord.conf +++ /dev/null @@ -1,17 +0,0 @@ -[supervisord] - -[supervisorctl] - -[program:app-uwsgi] -command = /usr/local/bin/uwsgi --ini /code/scripts/production/uwsgi.ini -stdout_logfile = /dev/stdout -stderr_logfile = /dev/stderr -stdout_logfile_maxbytes=0 -stderr_logfile_maxbytes=0 - -[program:nginx-app] -command = /usr/sbin/nginx -stdout_logfile = /dev/stdout -stderr_logfile = /dev/stderr -stdout_logfile_maxbytes=0 -stderr_logfile_maxbytes=0 diff --git a/scripts/web/Dockerfile b/scripts/web/Dockerfile deleted file mode 100644 index 4211c62..0000000 --- a/scripts/web/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM python:3.5 -ENV PYTHONBUFFERED 1 -ENV PYTHONDONTWRITEBYTECODE 1 -RUN mkdir -p /code -WORKDIR /code -ADD requirements.txt /code/ -RUN pip install -r requirements.txt -ADD . /code/ diff --git a/scripts/web/requirements.txt b/scripts/web/requirements.txt deleted file mode 120000 index fd1efae..0000000 --- a/scripts/web/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -../../requirements.txt \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..d1548cb --- /dev/null +++ b/setup.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +echo "SIK WEB 2.0" +echo "This script will set up the environment for this project." +echo "=========================================================" +echo "Dependencies: postgresql>9.5, python>3.5" + +read -p "Are these programs installed? [y/n]" -n 1 -r +echo "" + +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo "Please install the dependencies. Exiting." + exit 0 +fi + +read -p "Create user 'sik' in postgres (needs sudo) [y/n]?" -n 1 -r +echo "" + +if [[ $REPLY =~ ^[Yy]$ ]] +then + sudo -u postgres psql < "$PWD/scripts/db/init.sql" +fi + +read -p "Is virtualenv activated? [y/n]" -n 1 -r +echo "" + +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo "Please activate virtualenv first. Exiting." + exit 0 +fi + +read -p "Copy settings from template? [y/n]" -n 1 -r +echo "" + +if [[ $REPLY =~ ^[Yy]$ ]] +then + cp "$PWD/sikweb/settings-sample.py" "$PWD/sikweb/settings.py" +fi + + +read -p "Start setup? [y/n]" -n 1 -r +echo "" + +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo "Exiting." + exit 0 +fi + +(set -x; pip install -r requirements.txt) +(set -x; python manage.py migrate) +(set -x; python manage.py createdefaultadmin) + +echo "Done." +echo "Run 'python manage.py runserver 0.0.0.0:8000' to start the development server!" diff --git a/sikweb/.ci-settings.py b/sikweb/.ci-settings.py new file mode 100644 index 0000000..00ce5c6 --- /dev/null +++ b/sikweb/.ci-settings.py @@ -0,0 +1,12 @@ +from sikweb.settings import * + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'ci', + 'USER': 'postgres', + 'PASSWORD': 'postgres', + 'HOST': 'postgres', + 'PORT': '5432', + }, +} diff --git a/sikweb/ci-settings.py b/sikweb/ci-settings.py deleted file mode 100644 index e824f98..0000000 --- a/sikweb/ci-settings.py +++ /dev/null @@ -1,206 +0,0 @@ -""" -Django settings for sikweb project. - -Generated by 'django-admin startproject' using Django 1.9. - -For more information on this file, see -https://docs.djangoproject.com/en/1.9/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.9/ref/settings/ -""" - -import os -import logging -from os.path import expanduser -from django.utils.translation import ugettext_lazy as _ - -# 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.9/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp(' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'corsheaders', - 'webapp', - 'members', - 'infoscreen', - 'rest_framework', - 'django_nose', - 'bootstrap3', - 'django_tables2', -] - -TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' - -NOSE_ARGS = [ - '--with-coverage', - '--cover-package=webapp,members,infoscreen', -] - -MIDDLEWARE_CLASSES = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'corsheaders.middleware.CorsMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] -CORS_ORIGIN_ALLOW_ALL = True - -ROOT_URLCONF = 'sikweb.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': ['templates'], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.template.context_processors.i18n', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - 'django.core.context_processors.static', - ], - }, - }, -] - -WSGI_APPLICATION = 'sikweb.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.9/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'ci', - 'USER': 'postgres', - 'PASSWORD': 'postgres', - 'HOST': 'postgres', - 'PORT': '5432', - }, -} - -# Password validation -# https://docs.djangoproject.com/en/1.9/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', - }, -] - -REST_FRAMEWORK = { - 'DEFAULT_PERMISSION_CLASSES': ( - 'rest_framework.permissions.IsAuthenticated', - 'rest_framework.permissions.DjangoModelPermissions', - ), - 'DEFAULT_THROTTLE_CLASSES': ( - 'members.throttles.BurstRateThrottle', - 'members.throttles.SustainedRateThrottle' - ), - 'DEFAULT_THROTTLE_RATES': { - 'burst': '60/min', - 'sustained': '1000/day' - }, -} - -# Email settings (tested working with gmail) -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -EMAIL_USE_TLS = True -EMAIL_HOST='smtp.gmail.com' -EMAIL_PORT=587 -EMAIL_HOST_USER = '@gmail.com' -EMAIL_HOST_PASSWORD = '' -DEFAULT_EMAIL_FROM = 'SIK Viestintä ' - - -#ReCaptcha -# http://www.yaconiello.com/blog/integrating-google-recaptcha-to-django/ - -GOOGLE_RECAPTCHA_SITE_KEY = "YOUR-PUBLIC-KEY" -GOOGLE_RECAPTCHA_SECRET_KEY = "YOUR-PRIVATE-KEY" - -#Logger level - -LOGGERLEVEL = logging.INFO -LOGPATH = "logs/debug.log" - -# Internationalization -# https://docs.djangoproject.com/en/1.9/topics/i18n/ - -LANGUAGES = ( - ('en', _('English')), - ('fi', _('Finnish')), -) - -LANGUAGE_CODE = 'fi' - -LOCALE_PATHS = ( - os.path.join(BASE_DIR, 'locale'), -) - -print("LOCALE_PATHS: {}".format(LOCALE_PATHS)) - -TIME_ZONE = 'Europe/Helsinki' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.9/howto/static-files/ -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', - 'django.contrib.staticfiles.finders.FileSystemFinder', -) -STATIC_URL = '/static/' -STATIC_ROOT = os.path.join(BASE_DIR, 'static') -STATICFILES_DIRS = ( - os.path.join(BASE_DIR, 'global_static'), -) -MEDIA_ROOT = os.path.join(BASE_DIR, 'media') -MEDIA_URL = '/media/' - -HSL_USERHASH = 'YOUR HSL USERHASH HERE' -HSL_DEPARTURE_THRESHOLD = 8 -HSL_HURRY_THRESHOLD = 13 diff --git a/sikweb/settings-sample.py b/sikweb/settings-sample.py index 20d2925..6aefaea 100644 --- a/sikweb/settings-sample.py +++ b/sikweb/settings-sample.py @@ -103,7 +103,7 @@ DATABASES = { 'NAME': 'sik', 'USER': 'sik', 'PASSWORD': 'password123', - 'HOST': 'db', + 'HOST': 'localhost', 'PORT': '5432', 'TEST': { 'NAME': 'sik_test', diff --git a/test_applet.sh b/test_applet.sh deleted file mode 100755 index ea52e3b..0000000 --- a/test_applet.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - - -activate () { - . ../virtualenv.sikweb/bin/activate -} -clear - -echo "This is a script that does the following things:" -echo "* activate virtualenv" -echo "* run Django migrations" -echo "* run unit tests" -echo "* start Django devserver" -echo "* deactivate virtualenv" - -activate -python manage.py makemigrations --merge -python manage.py makemigrations -python manage.py migrate -python manage.py test -python manage.py runserver -deactivate