Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
df7ff74d
authored
Feb 03, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
school: fix automatic group handling
parent
6cf601b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
school/models.py
+9
-3
school/views.py
+12
-3
No files found.
school/models.py
View file @
df7ff74d
...
...
@@ -41,9 +41,15 @@ class Course(models.Model):
related_name
=
'default_group_of'
)
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
)
def
get_or_create_default_group
(
self
):
self
.
default_group
=
Group
(
name
=
self
.
name
,
semester
=
Semester
.
get_current
())
self
.
default_group
.
save
()
if
self
.
default_group
:
return
self
.
default_group
else
:
default_group
=
Group
(
name
=
_
(
"
%
s -- default"
)
%
self
.
short
(),
semester
=
Semester
.
get_current
(),
course
=
self
)
default_group
.
save
()
self
.
default_group_id
=
default_group
.
id
self
.
save
()
return
default_group
def
save
(
self
,
*
args
,
**
kwargs
):
if
self
.
default_group
:
self
.
default_group
.
course
=
self
...
...
school/views.py
View file @
df7ff74d
...
...
@@ -44,6 +44,7 @@ def login(request):
user
.
email
=
request
.
META
[
'email'
]
user
.
save
()
p
,
created
=
Person
.
objects
.
get_or_create
(
user
=
user
)
p
.
save
()
try
:
sem
=
Semester
.
get_current
()
...
...
@@ -55,15 +56,18 @@ def login(request):
attended
=
attended
.
split
(
';'
)
for
c
in
attended
:
co
,
created
=
Course
.
objects
.
get_or_create
(
code
=
c
)
if
created
:
logger
.
warning
(
"django Course
%
s created"
%
c
)
g
=
co
.
get_or_create_default_group
()
if
p
.
course_groups
.
filter
(
semester
=
sem
,
course
=
co
)
.
count
()
==
0
:
try
:
p
.
course_groups
.
add
(
g
)
g
.
members
.
add
(
p
)
g
.
save
()
messages
.
info
(
request
,
_
(
'Course "
%
s" added.'
)
%
g
.
course
)
except
Exception
as
e
:
logger
.
warning
(
"Django ex
%
s"
%
e
)
except
ValidationError
:
pass
except
ValidationError
as
e
:
logger
.
warning
(
"Django ex4
%
s"
%
e
)
held
=
request
.
META
[
'HTTP_NIIFEDUPERSONHELDCOURSE'
]
if
held
==
''
:
...
...
@@ -72,6 +76,8 @@ def login(request):
held
=
held
.
split
(
';'
)
for
c
in
held
:
co
,
created
=
Course
.
objects
.
get_or_create
(
code
=
c
)
if
created
:
logger
.
warning
(
"django Course
%
s created"
%
c
)
g
=
co
.
get_or_create_default_group
()
try
:
co
.
owners
.
add
(
p
)
...
...
@@ -79,6 +85,9 @@ def login(request):
messages
.
info
(
request
,
_
(
'Course "
%
s" ownership added.'
)
%
g
.
course
)
except
Exception
as
e
:
logger
.
warning
(
"Django ex
%
s"
%
e
)
co
.
save
()
g
.
save
()
p
.
save
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment