Merge branch 'develop' into 'master'

Merge CI tests and fixes



See merge request !11
This commit is contained in:
Jan Tuomi
2017-03-06 14:57:19 +02:00
25 changed files with 399 additions and 41 deletions
+1
View File
@@ -14,3 +14,4 @@ logs/
/static/
/media/
node_modules/
/.coverage
+13
View File
@@ -0,0 +1,13 @@
image: python:3.5
all_tests:
script:
- sh ./scripts/autoinstall.sh
- docker-compose run web python manage.py test
after_script:
- docker-compose exec -T web find . -path '*/migrations*' -delete
- docker-compose exec -T web find . -type f -name '*.pyc' -delete
when: on_success
only:
- develop
- master
+6 -1
View File
@@ -1,11 +1,16 @@
version: '2'
services:
db:
build:
context: .
dockerfile: scripts/db/Dockerfile
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD=toor
web:
build: .
build:
context: .
dockerfile: scripts/web/Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
+2 -1
View File
@@ -51,6 +51,7 @@ class InfoItem(models.Model):
'name': self.name,
'item_type': ContentType.objects.get_for_model(self).id,
'template_url': self.get_template_url(),
'display_name': self.display_name,
'create_template_url': self.get_create_template_url(),
'options': {}
}
@@ -99,7 +100,7 @@ class SossoInfoItem(InfoItem):
class ImageInfoItem(InfoItem):
display_name = _("Image upload")
display_name = _("Image")
img = models.ImageField(upload_to="infoimages/")
def get_template_url(self):
+2 -2
View File
@@ -27,8 +27,8 @@
}
.thumbnail {
height: 20vh;
width: auto;
max-width 355px;
max-height 200px;
}
#sossoimage {
+1 -1
View File
@@ -6,7 +6,7 @@
<div id="container">
<div class="article-row row" ng-repeat="post in data.posts">
<div class="article-thumb-col col-md-6">
<img class="thumbnail" ng-src="{{ post.thumbnail_images.medium.url }}">
<img class="thumbnail" ng-src="{{ post.thumbnail_images['mh-edition-lite-medium'].url }}">
</div>
<div>
<h1 class="col-md-6">
+4 -2
View File
@@ -36,13 +36,15 @@
<table class="table table-striped">
<tr>
<th>{% trans "Item" %}</th>
<th>{% trans "Type" %}</th>
<th>{% trans "Set duration" %}</th>
<th>{% trans "Add to rotation" %}</th>
<th>{% trans "Delete" %}</th>
</tr>
<tr ng-repeat="i in infoitems">
<tr ng-repeat="i in infoitems | orderBy:['display_name','name']">
<td>{$ i.name $}</td>
<td><input type="text" class="form-control" ng-model="i.duration"></input></td>
<td>{$ i.display_name $}</td>
<td><input type="number" min="1" max="60" class="form-control" ng-model="i.duration"></input></td>
<td><input type="button" class="btn btn-success" ng-click="createInstance(selected_rot.id, i.id, i.item_type, i.duration);" value="{% trans "Add" %}"></input></td>
<td><input type="button" class="btn btn-danger" ng-click="deleteItem(i.item_type, i.id);" value="{% trans "Delete" %}"></input></td>
</tr>
+5 -4
View File
@@ -4,7 +4,8 @@ from datetime import datetime
from members.models import Member, MemberRequest
from django.conf import settings
#, default=timezone.now
# , default=datetime.fromtimestamp(0)
class MemberSerializer(serializers.Serializer):
id = serializers.IntegerField(read_only=True)
first_name = serializers.CharField(required=True, max_length=127)
@@ -13,8 +14,8 @@ class MemberSerializer(serializers.Serializer):
POR = serializers.CharField(max_length=255)
AYY = serializers.BooleanField(default=False)
jas = serializers.BooleanField(default=False)
created = serializers.DateTimeField(default=timezone.now)
paid = serializers.DateTimeField(default=datetime.fromtimestamp(0))
created = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
paid = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
def create(self, validated_data):
'''
@@ -32,7 +33,7 @@ class MemberSerializer(serializers.Serializer):
instance.POR = validated_data.get('POR', instance.POR)
instance.AYY = validated_data.get('AYY', instance.AYY)
instance.jas = validated_data.get('jas', instance.jas)
instance.created = validated_data.get('created', instance.created)
# instance.created = validated_data.get('created', instance.created)
instance.paid = validated_data.get('paid', instance.paid)
instance.save()
return instance
+31 -22
View File
@@ -23,12 +23,12 @@ function memberDataEditor(returnPath) {
return function($scope, $http, $window, $location) {
var id = memberId;
console.log("id: " + id);
$http.get("/members/api/member/" + id).then(function(response) {
$http.get("/members/rest/api/members/" + id).then(function(response) {
$scope.member = response.data;
});
$scope.send = function() {
$http.put("/members/api/member/" + id, $scope.member).then(function(response){
$http.put("/members/rest/api/members/" + id + "/", $scope.member).then(function(response){
notySuccess("Jäsentiedot tallennettu");
$window.location = returnPath;
});
@@ -69,26 +69,26 @@ app.controller("getController", function($scope, $document, $http){
/* Fetch all members from the database and show all members in the table */
$scope.updateMembers = function() {
$http.get("/members/api/members").then(function(response){
$http.get("/members/rest/api/members").then(function(response){
$scope.members = response.data;
// map trues and falses to more user-friendly format
_.each($scope.members, function(m){
m.jas = m.jas ? "Kyllä" : "Ei";
m.AYY = m.AYY ? "Kyllä" : "Ei";
});
// _.each($scope.members, function(m){
// m.jas = m.jas ? "Kyllä" : "Ei";
// m.AYY = m.AYY ? "Kyllä" : "Ei";
// });
$scope.shown_members = $scope.members;
});
};
/* Fetch a single member from the database by id and update its row */
$scope.updateMember = function(id) {
$http.get("/members/api/member/" + id).then(function(response) {
$http.get("/members/rest/api/members/" + id).then(function(response) {
for (var i = 0; i < $scope.shown_members.length; i++) {
var member = $scope.shown_members[i];
if (String(member.id) == String(id)) {
member = response.data;
member.jas = member.jas ? "Kyllä" : "Ei";
member.AYY = member.AYY ? "Kyllä" : "Ei";
// member.jas = member.jas ? "Kyllä" : "Ei";
// member.AYY = member.AYY ? "Kyllä" : "Ei";
$scope.shown_members[i] = member;
}
@@ -99,12 +99,21 @@ app.controller("getController", function($scope, $document, $http){
/* Update the payment date of a single member to the current time and send
* the member to the database */
$scope.updatePayment= function(id){
$http.put("/members/api/member/"+id, { paid: moment().format("YYYY-MM-DD kk:mm:ss") }).then(function(response) {
$scope.updateMember(id);
notySuccess("Maksupäivämäärä päivitetty.");
$scope.member = {};
//Find member whose payment needs to be updated
$scope.member = $scope.members.find(function(element){
return element.id == id;
});
//Update the member data if member was found
if($scope.member != undefined){
$scope.member.paid = moment().format("YYYY-MM-DD kk:mm:ss");
$http.put("/members/rest/api/members/"+id +"/", $scope.member).then(function(response) {
$scope.updateMember(id);
notySuccess("Maksupäivämäärä päivitetty.");
});
}
};
/* Redirect the browser to the CSV dump download endpoint */
$scope.loadCSV = function() {
window.location = "/members/api/getCSV";
@@ -112,7 +121,7 @@ app.controller("getController", function($scope, $document, $http){
/* Delete a single member by id */
$scope.deleteMember = function(id) {
$http.delete("/members/api/member/" + id).then(
$http.delete("/members/rest/api/members/" + id).then(
function(response) {
notySuccess("Poistaminen onnistui")
$scope.updateMembers();
@@ -160,7 +169,7 @@ app.controller("getController", function($scope, $document, $http){
if (name.length == 0) continue;
if (member.first_name.toLowerCase().includes(name)
|| member.last_name.toLowerCase().includes(name)
|| member.last_name.toLowerCase().includes(name)
|| member.email.toLowerCase().includes(name)) {
result.push(member);
@@ -213,7 +222,7 @@ app.controller("getController", function($scope, $document, $http){
app.controller("postController", function($scope, $http, $location) {
$scope.member = {};
$scope.send = function() {
$http.post("/members/api/member/", $scope.member).then(function(response){
$http.post("/members/rest/api/members/", $scope.member).then(function(response){
notySuccess("Jäsen lisätty!");
});
}
@@ -222,12 +231,12 @@ app.controller("postController", function($scope, $http, $location) {
/* Controller for application page */
app.controller("applController", function($scope, $http){
$scope.applUpdateAll = function() {
$http.get("/members/api/requests").then(function(response){
$http.get("/members/rest/api/requests").then(function(response){
$scope.applications = response.data;
_.each($scope.applications, function(a){
a.member.jas = a.member.jas ? "Kyllä" : "Ei";
a.member.AYY = a.member.AYY ? "Kyllä" : "Ei";
});
// _.each($scope.applications, function(a){
// a.member.jas = a.member.jas ? "Kyllä" : "Ei";
// a.member.AYY = a.member.AYY ? "Kyllä" : "Ei";
// });
});
};
+2 -2
View File
@@ -33,8 +33,8 @@
<label>Asuinkunta: </label>
<input id="PORField" required type="text" placeholder="Otaniemi" class="form-control" ng-model="member.POR"></input>
</div>
<button class="btn btn-success" ng-click="applicationForm.$valid && sendappl()" type="submit" id="sendmember">Tallenna</button>
<button class="btn btn-warning" ng-click="cancelappl()" type="submit" id="sendmember">Peruuta</button>
<button class="btn btn-success" ng-click="applicationForm.$valid && send()" type="submit" id="sendmember">Tallenna</button>
<button class="btn btn-warning" ng-click="cancel()" type="submit" id="sendmember">Peruuta</button>
</form>
</div>
</div>
+1 -1
View File
@@ -24,7 +24,7 @@ memberlogger = logging.getLogger(__name__)
logging.basicConfig(format='[%(levelname)s]%(asctime)s %(message)s', level=settings.LOGGERLEVEL, filename=settings.LOGPATH)
#API views
# REST API views
########################################
class MembersList(generics.ListCreateAPIView):
queryset = Member.objects.all()
+14 -4
View File
@@ -19,13 +19,23 @@ git checkout develop
## Installation with Docker
### Installing Docker
### One click install
Install docker and docker-compose. On Ubuntu this can be done with
Run the one click installer
```BASH
sudo apt-get install docker docker-compose
sudo scripts/autoinstall.sh
```
If you experience installation problems, go through the install process manually by following the steps below. If the installation is a success, you can skip to _Running_.
### Installing Docker
Install docker and docker-compose. On Ubuntu you can install Docker from the repositories but docker-compose must be installed separately.
```BASH
sudo apt-get install docker
```
Navigate to [docker-compose releases](https://github.com/docker/compose/releases) for install information.
### Configuring db image
@@ -36,7 +46,7 @@ sudo docker-compose up db
Then configure following with another shell window
```BASH
sudo docker exec -ti <image_name> bash # image name can be found with sudo docker ps (probably web20_db_1)
mysql -u root -p # then enter root password which can be found in docker-compose.yml
mysql -u root -p # then enter root password ("toor" by default) which can be found in docker-compose.yml
```
```SQL
+2
View File
@@ -17,3 +17,5 @@ requests==2.11.1
django-nocaptcha-recaptcha==0.0.19
django-cors-headers==2.0.1
djangorestframework==3.5.3
coverage==4.3.4
django-nose==1.4.4
+60
View File
@@ -0,0 +1,60 @@
#!/bin/bash
echo "Checking if docker is installed..."
docker --version
if [ "$?" -ne 0 ]
then
echo "Installing docker..."
curl -fsSL https://get.docker.com/ | sh
fi
echo "Starting docker daemon and sleeping for 10 seconds..."
dockerd &
sleep 10
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 build db
echo "Starting db container..."
docker-compose up -d db
echo "Waiting 10 seconds..."
sleep 10
echo "Importing database settings..."
docker-compose exec -T db sh /db/install.sh
if [ "$?" -eq 0 ]
then
echo "Success!"
else
echo "Failure!"
exit 1
fi
echo "Shutting down db container..."
echo "Copying settings..."
cp sikweb/settings-docker-sample.py sikweb/settings.py
echo "Building web container..."
docker-compose build web
echo "Running manage.py commands..."
docker-compose run web python manage.py migrate
docker-compose run web python manage.py makemigrations infoscreen members webapp
docker-compose run web python manage.py migrate
docker-compose run web python manage.py createdefaultadmin
echo "Starting all containers..."
docker-compose up -d
echo "Done."
+5
View File
@@ -0,0 +1,5 @@
FROM mariadb:latest
RUN mkdir -p /db
WORKDIR /db
ADD scripts/db/init.sql /db/
ADD scripts/db/install.sh /db/
+7
View File
@@ -0,0 +1,7 @@
DROP USER IF EXISTS 'sik';
FLUSH PRIVILEGES;
CREATE USER 'sik'@'%' IDENTIFIED BY 'password123';
CREATE DATABASE IF NOT EXISTS sik DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON `sik\_%` . * TO 'sik'@'%' IDENTIFIED BY 'password123';
GRANT ALL PRIVILEGES ON sik.* TO 'sik'@'%';
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
set -e
mysql -u root -ptoor < /db/init.sql
+2 -1
View File
@@ -1,6 +1,7 @@
FROM python:3.5
ENV PYTHONBUFFERED 1
RUN mkdir /code
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir -p /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
+1
View File
@@ -0,0 +1 @@
../../requirements.txt
+207
View File
@@ -0,0 +1,207 @@
"""
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',
]
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.mysql',
'NAME': 'sik',
'USER': 'sik',
'PASSWORD': 'password123',
'HOST': 'db',
'PORT': '3306',
'TEST': {
'NAME': 'sik_test',
},
},
}
# 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 = '<gmailtunnarisi>@gmail.com'
EMAIL_HOST_PASSWORD = '<gmail_passu>'
DEFAULT_EMAIL_FROM = 'SIK Viestintä <sikviestinta@gmail.com>'
#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.ERROR
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
+8
View File
@@ -45,6 +45,14 @@ INSTALLED_APPS = [
'members',
'infoscreen',
'rest_framework',
'django_nose',
]
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
'--with-coverage',
'--cover-package=webapp,members,infoscreen',
]
MIDDLEWARE_CLASSES = [
+2
View File
@@ -102,6 +102,8 @@ urlpatterns = [
url(r'^members/api/request/(?P<idx>\d+)$', handle_mem_request),
url(r'^members/api/getCSV$', mem_csv_export),
url(r'^members/tommy$', tommy_blooper),
# Members API
url(r'^members/rest/api/members/$', memsListAPI.as_view()),
url(r'^members/rest/api/members/(?P<pk>\d+)/$', memDetailAPI.as_view()),
url(r'^members/rest/api/requests/$', reqListAPI.as_view()),
View File
@@ -0,0 +1,20 @@
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
class Command(BaseCommand):
user_name = "admin"
password = "password123"
def handle(self, *args, **options):
if User.objects.filter(username=self.user_name).exists():
self.stdout.write("Default admin already exists. Skipping.")
return
u = User(username=self.user_name)
u.set_password(self.password)
u.is_superuser = True
u.is_staff = True
u.save()
self.stdout.write("Created default user {} with password {}.")