Commit d6dfbc6d authored by adietmue's avatar adietmue
Browse files

Frontend/Backend: Improve dev server reset script, use dev server in frontend

parent 655b4caf
"""Demo Data.
This script can be used to create demo data on the development server.
This script can be used to reset the demo data on the development server.
You need to have 'requests' installed!
TODO: Accept user and password from command line, provide output
CAREFUL: This script will delete everything existing!
import sys
......@@ -10,11 +11,12 @@ from random import randint
from datetime import datetime as dt, timedelta
import requests
DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
ASSISTANTS = ['pablo', 'assi', 'anon', 'mongo']
ASSISTANTS = ['pablo', 'assi', 'anon']
......@@ -81,10 +83,12 @@ def time_gen(starting_day):
month = starting_day.month
day =
# Random start and end time
start = dt(year, month, day, randint(7, 10)).strftime(DATE_FORMAT)
end = dt(year, month, day, randint(11, 14)).strftime(DATE_FORMAT)
yield {'start': start, 'end': end}
# Always create pairs of courses that overlap (for testing)
for _ in range(2):
# Random start and end time
start = dt(year, month, day, randint(7, 10)).strftime(DATE_FORMAT)
end = dt(year, month, day, randint(11, 14)).strftime(DATE_FORMAT)
yield {'start': start, 'end': end}
# Only one slot per day to avoid overlap
starting_day += timedelta(days=1)
......@@ -113,7 +117,9 @@ def create_course(lecture, assistant, token, open_signup=True):
'room': next(ROOM),
'spots': randint(MIN_SPOTS, MAX_SPOTS),
return post('courses', data, token)
response = post('courses', data, token)
return response
def create_signups(course, token):
......@@ -121,11 +127,29 @@ def create_signups(course, token):
for ind in range(randint(0, 2*MAX_SPOTS)):
data = {
'nethz': 'student%d' % ind,
'course': course
'course': course['_id'],
post('signups', data, token)
def clear(resource, token):
""" Remove every item."""
while True:
items = requests.get('%s/%s' % (PVK_DEV_URL, resource),
headers={'Authorization': token}).json()['_items']
if not items:
return # Done!
for item in items:
item_url = '%s/%s/%s' % (PVK_DEV_URL, resource, item['_id'])
res = requests.delete(item_url,
headers={'Authorization': token,
'If-Match': item['_etag']})
if res.status_code != 204:
def main():
"""Login and create demo data."""
if len(sys.argv) != 3:
......@@ -135,6 +159,12 @@ def main():
print('Logging in...')
token = login(sys.argv[1], sys.argv[2])
# Order is important! some things can't be deleted before others
print('Clearing existing data...')
for res in ['payments', 'signups', 'courses', 'selections', 'lectures']:
print('Removing %s...' % res)
clear(res, token)
# Create courses
# (Repeat for itet and mavt)
for department in ['itet', 'mavt']:
......@@ -149,11 +179,11 @@ def main():
create_course(lecture, ASSISTANTS[ind],
token, open_signup=False)
print('Creating courses with closed signup...')
print('Creating courses with open signup...')
courses = []
for lecture in lectures:
for ind in range(randint(2, len(ASSISTANTS))):
courses.append(create_course(lecture, token, ASSISTANTS[ind]))
courses.append(create_course(lecture, ASSISTANTS[ind], token))
print('Creating signups...')
for course in courses:
......@@ -7,7 +7,9 @@ function isSelectedOrReserved(course) {
export default class CourseList {
static oninit() { courses.getAll(); }
static oninit() {
static view() {
return m('table', [
......@@ -3,7 +3,8 @@
import m from 'mithril';
import session from './session';
const pvkApiUrl = `//${window.location.hostname}`;
// Development URL
const pvkApiUrl = '';
// Helper to filter temp out of list
function withoutTemp(list, temp) { return list.filter(item => item !== temp); }
......@@ -4,51 +4,32 @@ A new AMIV PVK tool using Eve and authenticating users with AMIVAPI.
## Frontend
1. [Install Docker](
(Make sure to verify your installation!)
The frontend is build using [mithril]( and uses
the [webpack build system](
2. You need MongoDB. Luckily, you can just use Docker for that, too.
(It's one long command, make sure to copy everything to your command line)
docker run --name mongodb -d -p 27017 \
-e MONGODB_USERNAME="pvkuser" \
-e MONGODB_PASSWORD="pvkpass" \
The environment variables specified with `-e` make sure that the db and user
are created
In order to bundle all files and use the development server, you first
need to install [node]( and[npm](
3. Start the dev-container
Afterwards, you can use the following commands:
docker run --name pvk -d -p 80:8080 \
--link mongodb \
-e MONGO_HOST="mongodb" \
# Install dependencies and build system
npm install
The `--link` and `-e` make sure the backend can access the db container.
# Start development server
# (As soon as its running, open `localhost:9000` in your browser)
npm start
And now the backend is available at port 80, ready to use!
# The development server reloads if you change anything, if it does not, use:
sudo npm start
4. Create some demo data
# Check coding style
npm run lint
python Backend/ alex_itet_admin pvk
# Bundle files for production
npm run build
5. Now to the frontend: Install `node` and `npm`
Inside the `Frontend` directory, fist install the build and dependencies
with `npm install` and then start the dev server with `npm start`
(the dev server will reload whenever you change anything. If it does not
try `sudo npm start`)
Now, in your browser, open `localhost:9000`
## Backend
The backend is implemented using [Eve](, a python
......@@ -116,3 +97,9 @@ But don't worry, it's very easy to set them up -- take a look at the
curl -X POST -Fusername <user> -Fpassword <pass>
### Development server reset
We have a development server running. The script ``
completely resets its data. (Everything gets deleted and re-created)
Install `requests` (e.g. using `pip install requests`) to use it.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment