Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
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):
...
@@ -41,9 +41,15 @@ class Course(models.Model):
related_name
=
'default_group_of'
)
related_name
=
'default_group_of'
)
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
)
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
)
def
get_or_create_default_group
(
self
):
def
get_or_create_default_group
(
self
):
self
.
default_group
=
Group
(
name
=
self
.
name
,
if
self
.
default_group
:
semester
=
Semester
.
get_current
())
return
self
.
default_group
self
.
default_group
.
save
()
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
):
def
save
(
self
,
*
args
,
**
kwargs
):
if
self
.
default_group
:
if
self
.
default_group
:
self
.
default_group
.
course
=
self
self
.
default_group
.
course
=
self
...
...
school/views.py
View file @
df7ff74d
...
@@ -44,6 +44,7 @@ def login(request):
...
@@ -44,6 +44,7 @@ def login(request):
user
.
email
=
request
.
META
[
'email'
]
user
.
email
=
request
.
META
[
'email'
]
user
.
save
()
user
.
save
()
p
,
created
=
Person
.
objects
.
get_or_create
(
user
=
user
)
p
,
created
=
Person
.
objects
.
get_or_create
(
user
=
user
)
p
.
save
()
try
:
try
:
sem
=
Semester
.
get_current
()
sem
=
Semester
.
get_current
()
...
@@ -55,15 +56,18 @@ def login(request):
...
@@ -55,15 +56,18 @@ def login(request):
attended
=
attended
.
split
(
';'
)
attended
=
attended
.
split
(
';'
)
for
c
in
attended
:
for
c
in
attended
:
co
,
created
=
Course
.
objects
.
get_or_create
(
code
=
c
)
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
()
g
=
co
.
get_or_create_default_group
()
if
p
.
course_groups
.
filter
(
semester
=
sem
,
course
=
co
)
.
count
()
==
0
:
if
p
.
course_groups
.
filter
(
semester
=
sem
,
course
=
co
)
.
count
()
==
0
:
try
:
try
:
p
.
course_groups
.
add
(
g
)
g
.
members
.
add
(
p
)
g
.
save
()
messages
.
info
(
request
,
_
(
'Course "
%
s" added.'
)
%
g
.
course
)
messages
.
info
(
request
,
_
(
'Course "
%
s" added.'
)
%
g
.
course
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning
(
"Django ex
%
s"
%
e
)
logger
.
warning
(
"Django ex
%
s"
%
e
)
except
ValidationError
:
except
ValidationError
as
e
:
pass
logger
.
warning
(
"Django ex4
%
s"
%
e
)
held
=
request
.
META
[
'HTTP_NIIFEDUPERSONHELDCOURSE'
]
held
=
request
.
META
[
'HTTP_NIIFEDUPERSONHELDCOURSE'
]
if
held
==
''
:
if
held
==
''
:
...
@@ -72,6 +76,8 @@ def login(request):
...
@@ -72,6 +76,8 @@ def login(request):
held
=
held
.
split
(
';'
)
held
=
held
.
split
(
';'
)
for
c
in
held
:
for
c
in
held
:
co
,
created
=
Course
.
objects
.
get_or_create
(
code
=
c
)
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
()
g
=
co
.
get_or_create_default_group
()
try
:
try
:
co
.
owners
.
add
(
p
)
co
.
owners
.
add
(
p
)
...
@@ -79,6 +85,9 @@ def login(request):
...
@@ -79,6 +85,9 @@ def login(request):
messages
.
info
(
request
,
_
(
'Course "
%
s" ownership added.'
)
%
g
.
course
)
messages
.
info
(
request
,
_
(
'Course "
%
s" ownership added.'
)
%
g
.
course
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning
(
"Django ex
%
s"
%
e
)
logger
.
warning
(
"Django ex
%
s"
%
e
)
co
.
save
()
g
.
save
()
p
.
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