Skip to content

Commit 1fe0818

Browse files
committed
Fix some files. Add Docker things
1 parent 9b7b82d commit 1fe0818

File tree

16 files changed

+200
-90
lines changed

16 files changed

+200
-90
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.cache
2+
.tox
3+
.tx
4+
__pycache__
5+
*.pyc
6+
node_modules/
7+
env
8+
db.sqlite3

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM alpine:latest
2+
3+
MAINTAINER Håvard Lian
4+
5+
ENV NAME=gradestats
6+
7+
ENV DIR=/srv/app
8+
9+
RUN apk add --update --no-cache \
10+
uwsgi-python3 \
11+
uwsgi-http \
12+
uwsgi-corerouter
13+
14+
RUN mkdir -p $DIR
15+
WORKDIR $DIR
16+
17+
# Install requirements
18+
COPY ./requirements.txt $DIR/requirements.txt
19+
RUN pip3 --no-cache-dir install --upgrade pip
20+
RUN pip3 --no-cache-dir install --upgrade -r requirements.txt
21+
22+
# Copy project files
23+
COPY . $DIR
24+
25+
RUN mkdir -p static media
26+
ENV DJANGO_SETTINGS_MODULE=$NAME.settings.prod
27+
RUN python3 manage.py collectstatic --noinput --clear
28+
29+
EXPOSE 8080
30+
EXPOSE 8081
31+
32+
CMD ["sh", "docker-entrypoint.sh"]

docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
python3 manage.py migrate
3+
4+
5+
echo Starting uwsgi.
6+
exec uwsgi --chdir=/srv/app \
7+
--plugins=python3,http \
8+
--module=gradestats.wsgi:application \
9+
--env DJANGO_SETTINGS_MODULE=gradestats.settings.prod \
10+
--master --pidfile=/tmp/gradestats.pid \
11+
--socket=0.0.0.0:8080 \
12+
--http=0.0.0.0:8081 \
13+
--processes=5 \
14+
--harakiri=20 \
15+
--max-requests=5000 \
16+
--offload-threads=4 \
17+
--static-map=/static=/srv/app/collected_static \
18+
--static-map=/media=/srv/app/media \
19+
--vacuum

grades.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# -*- coding: utf-8 -*-
22
import os
3-
import sys
43
import json
54
import getpass
65
import django
76
from bs4 import BeautifulSoup
87
import requests
9-
import logging
10-
import http.client as http_client
8+
from grades.models import Grade, Course
119

1210
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gradestats.settings")
1311
django.setup()
14-
from grades.models import Grade, Course
1512

1613
session = requests.session()
1714

15+
1816
def login(username, password):
1917
login_data = dict(feidename=username, password=password, org="ntnu.no", asLen="255")
2018
page = session.get("https://innsida.ntnu.no/sso/?target=KarstatProd")
@@ -37,23 +35,22 @@ def login(username, password):
3735

3836
sso_wrapper_url = reply_soup.findAll("form")[0]["action"]
3937

40-
karstat = session.post(sso_wrapper_url, data=sso_wrapper_data)
41-
42-
karstat_soup = BeautifulSoup(karstat.text, "html5lib")
38+
session.post(sso_wrapper_url, data=sso_wrapper_data)
4339

4440
karstat_url = "https://sats.itea.ntnu.no/karstat/menuAction.do"
4541
session.post(karstat_url, data={"reportType": "3"})
4642

43+
4744
def create_course(code, faculty):
4845
base_url = "http://www.ime.ntnu.no/api/course/"
4946
resp = requests.get(url=base_url + code)
5047
if not resp:
5148
return None
5249
data = json.loads(resp.text)
5350

54-
if not "course" in data:
51+
if not data["course"]:
5552
return None
56-
if not "englishName" in data["course"]:
53+
if "englishName" not in data["course"]:
5754
data["course"]["englishName"] = ""
5855

5956
course = Course()

grades/migrations/0001_initial.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10 on 2017-03-28 17:10
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='Course',
19+
fields=[
20+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('norwegian_name', models.CharField(max_length=255, verbose_name='Norwegian Name')),
22+
('short_name', models.CharField(max_length=50, verbose_name='Short name')),
23+
('code', models.CharField(max_length=15, verbose_name='Code')),
24+
('faculty_code', models.IntegerField(default=0, verbose_name='Faculty Code')),
25+
('english_name', models.CharField(max_length=255, verbose_name='English name')),
26+
('credit', models.FloatField(default=7.5, verbose_name='Credit')),
27+
('study_level', models.SmallIntegerField()),
28+
('taught_in_spring', models.BooleanField(default=False)),
29+
('taught_in_autumn', models.BooleanField(default=False)),
30+
('taught_from', models.IntegerField()),
31+
('taught_in_english', models.BooleanField(default=False)),
32+
('last_year_taught', models.IntegerField(default=0)),
33+
('content', models.TextField()),
34+
('learning_form', models.TextField()),
35+
('learning_goal', models.TextField()),
36+
],
37+
),
38+
migrations.CreateModel(
39+
name='Grade',
40+
fields=[
41+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
42+
('semester_code', models.CharField(max_length=10, verbose_name='Semester')),
43+
('average_grade', models.FloatField()),
44+
('passed', models.IntegerField(default=0)),
45+
('a', models.SmallIntegerField(default=0)),
46+
('b', models.SmallIntegerField(default=0)),
47+
('c', models.SmallIntegerField(default=0)),
48+
('d', models.SmallIntegerField(default=0)),
49+
('e', models.SmallIntegerField(default=0)),
50+
('f', models.SmallIntegerField(default=0)),
51+
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='grades.Course')),
52+
],
53+
),
54+
migrations.CreateModel(
55+
name='Tag',
56+
fields=[
57+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
58+
('tag', models.CharField(max_length=32, verbose_name='Tag text')),
59+
('courses', models.ManyToManyField(to='grades.Course')),
60+
],
61+
),
62+
]
File renamed without changes.

grades/static/js/gradestats.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,13 @@ $(function() {
226226
type: 'GET',
227227
url: "grades/",
228228
async: false,
229-
jsonpCallback: 'parse',
230229
contentType: "application/json",
231-
dataType: 'jsonp',
230+
dataType: 'json',
232231
success: function(json) {
233232
$.jqplot.config.enablePlugins = true;
234233
setupGraphSelector(json);
235234
createButtons(json);
236-
createGraph(json[json.length - 1])
235+
createGraph(json[json.length - 1]);
237236
globalJson = json;
238237
},
239238
error: function(e) {

grades/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def add_tag(request, course_code):
5858

5959

6060
def get_grades(request, course_code):
61-
url = "/api/courses/%s/grades.jsonp?callback=parse" % course_code
61+
url = "/api/courses/%s/grades.json" % course_code
6262

6363
return redirect(url)
6464

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
1-
"""
2-
Django settings for gradestats project.
3-
4-
For more information on this file, see
5-
https://docs.djangoproject.com/en/1.7/topics/settings/
6-
7-
For the full list of settings and their values, see
8-
https://docs.djangoproject.com/en/1.7/ref/settings/
9-
"""
10-
111
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
122
import os
133
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
144

15-
16-
# Quick-start development settings - unsuitable for production
17-
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
18-
19-
# SECURITY WARNING: keep the secret key used in production secret!
20-
SECRET_KEY = '!lb^1kz*y+!7%p^x8@ow+cm+m+u%5r*ra^#ozmq%_9vde9cel7'
21-
22-
# SECURITY WARNING: don't run with debug turned on in production!
23-
DEBUG = True
24-
25-
TEMPLATE_DEBUG = True
26-
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates/'),)
27-
28-
ALLOWED_HOSTS = ['127.0.0.1']
29-
5+
DEBUG = False
6+
7+
TEMPLATES = [
8+
{
9+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
10+
'DIRS': [os.path.join(BASE_DIR, '..', 'templates')],
11+
'APP_DIRS': True,
12+
'OPTIONS': {
13+
'context_processors': [
14+
'django.contrib.auth.context_processors.auth',
15+
'django.template.context_processors.debug',
16+
'django.template.context_processors.i18n',
17+
'django.template.context_processors.media',
18+
'django.template.context_processors.static',
19+
'django.template.context_processors.tz',
20+
'django.contrib.messages.context_processors.messages',
21+
],
22+
},
23+
},
24+
]
3025

3126
# Application definition
32-
3327
INSTALLED_APPS = (
3428
'django.contrib.admin',
3529
'django.contrib.auth',
@@ -59,36 +53,20 @@
5953
REST_FRAMEWORK = {
6054
'DEFAULT_RENDERER_CLASSES': (
6155
'rest_framework.renderers.JSONRenderer',
62-
'rest_framework.renderers.JSONPRenderer',
6356
)
6457
}
6558

66-
# Database
67-
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
68-
6959
DATABASES = {
7060
'default': {
7161
'ENGINE': 'django.db.backends.sqlite3',
7262
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
7363
}
7464
}
7565

76-
# Internationalization
77-
# https://docs.djangoproject.com/en/1.7/topics/i18n/
7866

7967
LANGUAGE_CODE = 'en-us'
80-
8168
TIME_ZONE = 'UTC'
82-
8369
USE_I18N = True
84-
8570
USE_L10N = True
86-
8771
USE_TZ = True
8872

89-
90-
# Static files (CSS, JavaScript, Images)
91-
# https://docs.djangoproject.com/en/1.7/howto/static-files/
92-
93-
STATIC_URL = '/static/'
94-
STATIC_ROOT = 'static/'

gradestats/settings/dev.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from gradestats.settings.base import *
2+
3+
DEBUG = True
4+
5+
ALLOWED_HOSTS = []
6+
7+
# SECURITY WARNING: keep the secret key used in production secret!
8+
SECRET_KEY = '!lb^1kz*y+!7%p^x8@ow+cm+m+u%5r*ra^#ozmq%_9vde9cel7'
9+
10+
STATIC_ROOT = os.path.join(BASE_DIR, '..', 'static/')
11+
STATIC_URL = '/static/'

0 commit comments

Comments
 (0)