-
Notifications
You must be signed in to change notification settings - Fork 72
/
home.py
76 lines (68 loc) · 3.16 KB
/
home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
# Code for Life
#
# Copyright (C) 2018, Ocado Innovation Limited
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ADDITIONAL TERMS – Section 7 GNU General Public Licence
#
# This licence does not grant any right, title or interest in any “Ocado” logos,
# trade names or the trademark “Ocado” or any other trademarks or domain names
# owned by Ocado Innovation Limited or the Ocado group of companies or any other
# distinctive brand features of “Ocado” as may be secured from time to time. You
# must not distribute any modification of this program using the trademark
# “Ocado” or claim any affiliation or association with Ocado or its employees.
#
# You are not authorised to use the name Ocado (or any of its trade names) or
# the names of any author or contributor in advertising or for publicity purposes
# pertaining to the distribution of this program, without the prior written
# authorisation of Ocado.
#
# Any propagation, distribution or conveyance of this program must include this
# copyright notice and these terms. You must not misrepresent the origins of this
# program; modified versions of the program must be marked as such and not
# identified as the original program.
from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.decorators import login_required
from portal.permissions import preview_user
from portal.views.teacher.teach import get_session_pdfs, get_resource_sheets_pdfs
from aimmo import forms
from aimmo.app_settings import get_users_for_new_game
@login_required(login_url=reverse_lazy('login_view'))
@preview_user
def aimmo_home_view(request):
ks3_sessions = []
ks3_sheets = []
get_session_pdfs("ks3_session_", ks3_sessions)
get_resource_sheets_pdfs(ks3_sessions, "KS3_S", ks3_sheets)
if request.method == 'POST':
create_game_form = forms.AddGameForm(request.POST)
if create_game_form.is_valid():
game = create_game_form.save(commit=False)
game.generator = 'Main'
game.owner = request.user
game.main_user = request.user
game.save()
users = get_users_for_new_game(request)
if users is not None:
game.can_play.add(*users)
return redirect('aimmo/play', id=game.id)
else:
create_game_form = forms.AddGameForm()
return render(request, 'portal/aimmo_home.html',
{'create_game_form': create_game_form,
'ks3_sessions': ks3_sessions,
'ks3_sheets': ks3_sheets})