Merge branch 'develop' into 'master'

Develop

Closes #78

See merge request vtmk/web2.0!82
This commit is contained in:
Jan Tuomi
2017-10-25 22:08:02 +03:00
19 changed files with 283 additions and 169 deletions
+1
View File
@@ -15,3 +15,4 @@ node_modules/
db.sqlite3
requirements_henu.txt
/collected_static/
mydatabase
+27 -4
View File
@@ -53,16 +53,19 @@ publish:
- develop
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY_URL
script:
- docker build . -t "$IMAGE_NAME"
- docker push "$IMAGE_NAME"
deploy:
deploy_dev:
stage: deploy
image: alpine:latest
environment:
name: dev
url: http://web.sik.party
url: http://web.sik.party:8080
only:
- develop
before_script:
- pwd
- apk add --update openssh
@@ -72,5 +75,25 @@ deploy:
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- scp docker-compose.yml $SSH_USER@$SSH_HOST:~/deployment/docker-compose.yml
- ssh $SSH_USER@$SSH_HOST "cd deployment && docker-compose down && docker pull \"$IMAGE_NAME\" && docker-compose up -d && docker image prune -f"
- scp docker-compose.yml $DEV_SSH_USER@$DEV_SSH_HOST:~/deployment/docker-compose.yml
- ssh $DEV_SSH_USER@$DEV_SSH_HOST "cd deployment && docker-compose down && docker pull \"$IMAGE_NAME\" && docker-compose up -d && docker image prune -f"
deploy_production:
stage: deploy
image: alpine:latest
environment:
name: production
url: https://sika.sahkoinsinoorikilta.fi
when: manual
only:
- master
before_script:
- pwd
- apk add --update openssh
- ssh -V
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
script:
- ssh $PROD_SSH_USER@PROD_SSH_HOST "zsh ~/deploy.sh"
+1 -1
View File
@@ -14,7 +14,7 @@ from infoscreen.models import HSLDataModel
class HSLFetcher:
"""Main class of Infoscreen HSL fetcher."""
last_fetched = datetime.fromtimestamp(0) # epoch
last_fetched = datetime.fromtimestamp(86400) # epoch
INTERVAL = 1 # minutes
logging.info(
"Set up scheduled HSL API fetch every {} minutes".format(INTERVAL))
@@ -40,7 +40,6 @@
<li class="divider">
<li class="nav-item"><a data-toggle="tab" href="#deleterot" role="tab">{% trans "Create/Delete" %}</a></li>
</ul>
<li><a data-toggle="tab" href="#settings" role="tab">{% trans "Settings" %}</a></li>
</ul>
<div class="tab-content row">
<div id="slides" class="tab-pane active">
@@ -146,28 +145,6 @@
</table>
</div>
</div>
<div id="settings" class="tab-pane">
<div>
<div class="col-md-12">
<h2>{% trans "Settings" %}</h2>
</div>
<form action="/i18n/setlang/" method="post" class="form-group"> {% csrf_token %}
<div class="col-md-12">
<h4>{% trans "Language" %}</h4>
</div>
<div class="col-md-6">
<select name="language" class="form-control">
<option value="fi" {% if LANGUAGE_CODE == "fi" %} selected {% endif %}>{% trans "Finnish" %}</option>
<option value="en" {% if LANGUAGE_CODE == "en" %} selected {% endif %}>{% trans "English" %}</option>
</select>
</div>
<div class="col-md-3">
<input type="submit" class="btn btn-success" value="{% trans "Submit" %}">
</div>
</form>
</div>
</div>
</div>
<div style="margin-top: 100px;">
{% include "footer.html" %}
+57
View File
@@ -0,0 +1,57 @@
# Linux/Mac installation instructions
## Install dependencies
### Dependency list
* Python >3.5
* PostgreSQL >9.5
* pip3
* virtualenv
* npm
Install with apt:
```
sudo apt install python3
sudo apt install python3-pip
sudo apt install postgresql
sudo pip3 install virtualenv
sudo apt install npm
```
More info about PostgreSQL at:
[https://www.postgresql.org/](https://www.postgresql.org)
These packages might be needed on certain platforms:
* python3-dev
* libffi-dev
* python3-cffi
* libssl-dev
## Create a virtual environment for python
Create a virtualenv in the parent directory.
```
virtualenv -p python3 ../virtualenv.sikweb
```
## Activate virtualenv
Assuming we are at the root of this repository and virtualenv is one level above.
```
. ../virtualenv.sikweb/bin/activate
```
## Run install wizard
Run the install wizard with
```
bash setup.sh
```
and follow the instructions.
## Done!
+22 -54
View File
@@ -14,7 +14,11 @@ Data table app for viewing and modifying the member register, member application
### Web app
Mostly static website with an event calendar.
Mostly static website with an event calendar and news feed.
### Coffee scale
Shows the current coffee scale status.
## Accessing the source
@@ -23,65 +27,29 @@ Mostly static website with an event calendar.
Set up your SSH key authentication in GitLab Profile Settings. Then clone the repository and checkout the development branch:
```
git clone git@sika.sahkoinsinoorikilta.fi:vtmk/web2.0.git
git clone git@git.sahkoinsinoorikilta.fi:vtmk/web2.0.git
cd web2.0
git checkout develop
```
## Install dependencies
## Windows install instructions
### Dependency list
See [Windows install instructions](./windows_install.md)
* Python >3.5
* PostgreSQL >9.5
* pip3
* virtualenv
* npm
## Linux/Mac install instructions
Install with apt:
```
sudo apt install python3
sudo apt install python3-pip
sudo apt install postgresql
sudo pip3 install virtualenv
sudo apt install npm
```
See [Linux/Mac install instructions](./linux_install.md)
More info about PostgreSQL at:
[https://www.postgresql.org/](https://www.postgresql.org)
## Initializing data
These packages might be needed on certain platforms:
* python3-dev
* libffi-dev
* python3-cffi
* libssl-dev
## Create a virtual environment for python
Create a virtualenv in the parent directory.
```
virtualenv -p python3 ../virtualenv.sikweb
```
## Activate virtualenv
Assuming we are at the root of this repository and virtualenv is one level above.
Run the following `manage.py` commands. Do not run these in production without thinking!
```
. ../virtualenv.sikweb/bin/activate
python manage.py createdefaultadmin # creates an admin user
python manage.py initialize # creates user groups
python manage.py createdummydata # creates dummy members to the member register
```
## Run install wizard
Run the install wizard with
```
bash setup.sh
```
and follow the instructions.
## Running
### Use runserver command
@@ -90,7 +58,7 @@ and follow the instructions.
python manage.py runserver 0.0.0.0:8000
```
Using address 0.0.0.0 will bind to all IP addresses.
Using address `0.0.0.0` will bind to all IP addresses. Using `localhost` will only bind to your machine.
### Visit the page
@@ -98,14 +66,14 @@ Visit [https://localhost:8000](https://localhost:8000) in your browser!
## Running in production
A good way to run django in production is by using uWSGI. Install uWSGI with:
Run the project in production with gunicorn. Refer to [this page](https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04) for instructions.
Install production dependencies.
```
pip install -r requirements.production.txt
```
Create an uWSGI ini file and run the daemon according to online instructions.
## Development workflow
When pulling changes from the server, use `rebase` instead of `merge` for a nice and clean linear history.
@@ -136,13 +104,13 @@ Lint python files using `pep8` with
pep8 --config=setup.cfg --count .
```
Lint javascript using `eslint` with
Lint javascript and markdown using `eslint` and `remark` with
```
eslint .
npm test
```
Use an editor with linting capabilities to write pretty code that passes linting. Examples include _Atom_ and _Pycharm_.
Use an editor with linting capabilities to write pretty code that passes linting. Examples include _VSCode_, _Atom_ and _Pycharm_.
### Unit tests
+1 -1
View File
@@ -9,7 +9,7 @@ ptyprocess==0.5.1
pytz==2016.4
simplegeneric==0.8.1
traitlets==4.2.1
Pillow==3.3.1
Pillow==4.3.0
requests==2.11.1
django-nocaptcha-recaptcha==0.0.19
django-cors-headers==2.0.1
+9
View File
@@ -68,3 +68,12 @@ TELEGRAM_BOT_TOKEN = "<BOT_TOKEN>"
# },
# },
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase',
'TEST': {
'NAME': 'sik_test',
},
}
}
+11 -14
View File
@@ -2,20 +2,19 @@
height:10vh;
}
.footer {
text-align: center;
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px; /* Set the fixed height of the footer here */
line-height: 60px; /* Vertically center the text there */
margin-top: 2rem;
margin-bottom: 1rem;
}
#fi-button {
background: url("/static/img/fi.png") no-repeat;
background-size: cover;
}
#en-button {
background: url("/static/img/en.png") no-repeat;
background-size: cover;
footer .container .col .nav .nav-item {
display: inline-block;
margin-right: 3vh;
}
.lang-button {
@@ -30,8 +29,6 @@
display: inline-block;
}
.lang-form {
margin-left: auto;
margin-right: auto;
footer .lang-form {
max-width: 10rem;
}
}
+3 -1
View File
@@ -7,6 +7,8 @@
</head>
<body>
<h1>SIKWEB 2.0</h1>
{{ TAG }}
<p>{{ commit }}</p>
<p>{{ date }}</p>
<p>{{ tag }}</p>
</body>
</html>
+37 -19
View File
@@ -2,23 +2,41 @@
{% load static %}
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/footer.css" %}">
<div class="footer">
<div>
<form class="lang-form form" action="{% url 'set_language' %}" method="post">{% csrf_token %}
<span>
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select onchange="this.form.submit()" class="lang-select form-control" name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</span>
</form>
{% trans "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" %} {% now 'Y' %}
<footer>
<div class="container">
<div class="row align-items-center">
<div class="col">
<form class="lang-form form" action="{% url 'set_language' %}" method="post">{% csrf_token %}
<span>
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select onchange="this.form.submit()" class="lang-select form-control" name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</span>
</form>
<span>{% trans "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" %} {% now 'Y' %}</span>
</div>
<div class="col">
<ul class="nav">
<li class="nav-item">
<a href="/members"><i class="fa fa-group"></i></a>
</li>
<li class="nav-item">
<a href="/infoscreen"><i class="fa fa-info"></i></a>
</li>
<li class="nav-item">
<a href="/admin"><i class="fa fa-gears"></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</footer>
@@ -33,10 +33,6 @@ class Migration(migrations.Migration):
],
bases=('webapp.presetrole',),
),
migrations.RemoveField(
model_name='customrole',
name='baserole_ptr',
),
migrations.CreateModel(
name='KaehmyForm',
fields=[
+3
View File
@@ -0,0 +1,3 @@
.main_navigation .navbar-border .navbar-nav .nav-item {
display: block;
}
+2 -5
View File
@@ -8,7 +8,6 @@
.header-content .logo img {
display: block;
width: 100%;
height: auto;
margin: auto;
}
@@ -20,7 +19,7 @@
}
@media screen and (min-width: 1000px) {
.header-content {
.kaehmy_header-content {
position: absolute;
left: 0;
top: 0;
@@ -28,9 +27,7 @@
width: 100%;
}
.header {
.kaehmy_header {
margin-bottom: 331px;
}
}
+6 -5
View File
@@ -18,7 +18,7 @@
<script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script src="{% static "js/lib/underscore-min.js" %}"></script>
<script>
@@ -43,9 +43,10 @@
{% block content %}
{% endblock %}
</div>
{% block footer %}
{% include "footer.html" %}
{% endblock footer %}
<div class="footer">
{% block footer %}
{% include "footer.html" %}
{% endblock footer %}
</div>
</body>
</html>
+2 -2
View File
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block header %}
<div class="header">
<div class="kaehmy_header">
{% include "kaehmy_header.html" %}
</div>
{% endblock header %}
{% endblock header %}
+35 -35
View File
@@ -1,36 +1,36 @@
{% load i18n %}
<nav class="navbar navbar-default sidebar" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-sidebar-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-sidebar-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="/">SIK<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-home"></span></a></li>
<li><a href="/guild">{% trans "Guild" %}</a></li>
<li><a href="/freshmen">{% trans "Freshmen" %}</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Corporate" %}<span class="caret"></span><span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-user"></span></a>
<ul class="dropdown-menu forAnimate" role="menu">
<li><a href="/jobs">{% trans "Jobs" %}</a></li>
<li><a href="#">Yritysdadaa</a></li>
<li><a href="#">Lisää yritysdadaa</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">Informes</a></li>
</ul>
</li>
<li ><a href="/event_calendar">{% trans "Event calendar" %}<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-th-list"></span></a></li>
<li ><a href="/international">{% trans "International" %}<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-tags"></span></a></li>
<li ><a href="/sosso">{% trans "Sössö" %}</a></li>
<li ><a href="/contact">{% trans "Contact" %}<span class="pull-right hidden-xs showopacity glyphicon glyphicon-book"></span></a></li>
</ul>
</div>
</div>
</nav>
<link rel="stylesheet" href="/static/css/main_nav.css">
<div class="main_navigation">
<nav class="navbar-border navbar navbar-toggleable-md navbar-light bg-faded">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/guild">{% trans "Guild" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/freshmen">{% trans "Freshmen" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/event_calendar">{% trans "Event calendar" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/international">{% trans "International" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/sosso">{% trans "Sössö" %}</a>
</li>
<li class="nav-item">
<a class="nav-item nav-link" href="/contact">{% trans "Contact" %}</a>
</li>
<li class="nav-item btn-group">
<a class="dropdown-toggle nav-link" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{% trans "Corporate" %}
</a>
<div class="dropdown-menu" aria-labelledby="corpDropdown">
<a class="dropdown-item" href="/jobs">{% trans "Jobs" %}</a>
<a class="dropdown-item" href="/">Yritysdadaa</a>
<a class="dropdown-item" href="/">Something else here</a>
</div>
</li>
</ul>
</nav>
</div>
+11 -1
View File
@@ -11,6 +11,7 @@ from django.conf import settings
import logging
import requests
from dealer.git import git
from webapp.models import PresetKaehmyRole, CustomKaehmyRole
from webapp.models import OhlhafvChallenge, KaehmyForm, TelegramChannel
@@ -81,7 +82,16 @@ def logout_view(request, *args, **kwargs):
@require_http_methods(["GET"])
def about_view(request, *args, **kwargs):
"""Render about page."""
return render(request, "about.html", {})
repo = git.init_repo()
latest_commit = repo.git("rev-parse HEAD").decode('utf-8')
latest_date = repo.git("show -s --format=%ci " + latest_commit).decode('utf-8')
latest_tag = repo.git("describe --tags " + repo.git("rev-list --tags --max-count=1").decode('utf-8')).decode('utf-8')
context = {
'commit': latest_commit,
'date': latest_date,
'tag': latest_tag
}
return render(request, "about.html", context)
@require_http_methods(["GET"])
+55
View File
@@ -0,0 +1,55 @@
# Windows installation instructions
## Install dependencies
### Install python3
Visit [The python website](https://www.python.org/downloads/windows/) to install the latest version of python3.
Make sure to add the python binary directory to PATH. For instructions how to do this, refer to [this Stackoverflow answer](https://superuser.com/questions/143119/how-to-add-python-to-the-windows-path).
### Install virtualenv with pip
Run the following command to install `virtualenv`.
```
python -m pip install virtualenv
```
Setup a virtual python environment.
```
python -m virtualenv ../virtualenv.sikweb
```
## Activate virtualenv and install requirements
Activate `virtualenv` (note that this has to be active at all times).
```
source ../virtualenv.sikweb/Scripts/activate
```
Run the following command to install python packages.
```
pip install -r requirements.txt
```
## Run migrations
Run
```
python manage.py migrate
```
## Install npm for linting javascript
Follow the instructions on [the npm website](https://www.npmjs.com/package/npm).
## Set up database
By default Django uses SQLite, which doesn't need any configuration. If you need PostgreSQL instead, refer to [their website](https://www.postgresql.org/download/windows/).
## Done!