Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2531f8c6
authored
Jul 02, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
school: improve conformance of source
parent
6f6b9ee2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
148 additions
and
178 deletions
+148
-178
school/admin.py
+5
-5
school/models.py
+28
-21
school/tests/test_models.py
+28
-20
school/tests/test_views.py
+67
-107
school/views.py
+20
-25
No files found.
school/admin.py
View file @
2531f8c6
from
django.contrib
import
messages
from
django.core.exceptions
import
ValidationError
from
django
import
contrib
from
django
import
contrib
from
django.utils.translation
import
ugettext_lazy
as
_
from
school
import
models
from
school
import
models
import
string
class
GroupInline
(
contrib
.
admin
.
TabularInline
):
class
GroupInline
(
contrib
.
admin
.
TabularInline
):
model
=
models
.
Group
model
=
models
.
Group
extra
=
3
extra
=
3
class
CourseAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
CourseAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Course
model
=
models
.
Course
inlines
=
(
GroupInline
,
)
inlines
=
(
GroupInline
,
)
...
@@ -16,18 +14,20 @@ class CourseAdmin(contrib.admin.ModelAdmin):
...
@@ -16,18 +14,20 @@ class CourseAdmin(contrib.admin.ModelAdmin):
list_display
=
(
'code'
,
'name'
,
'short_name'
,
'owner_list'
)
list_display
=
(
'code'
,
'name'
,
'short_name'
,
'owner_list'
)
list_editable
=
(
'name'
,
'short_name'
)
list_editable
=
(
'name'
,
'short_name'
)
class
GroupAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
GroupAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Group
model
=
models
.
Group
filter_horizontal
=
(
'owners'
,
'members'
,
)
filter_horizontal
=
(
'owners'
,
'members'
,
)
list_display
=
(
'name'
,
'course'
,
'semester'
,
'owner_list'
,
'member_count'
)
list_display
=
(
'name'
,
'course'
,
'semester'
,
'owner_list'
,
'member_count'
)
list_filter
=
(
'semester'
,
'course'
)
list_filter
=
(
'semester'
,
'course'
)
class
SemesterAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
SemesterAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Semester
model
=
models
.
Semester
list_display
=
(
'id'
,
'name'
,
'start'
,
'end'
)
list_display
=
(
'id'
,
'name'
,
'start'
,
'end'
)
list_editable
=
(
'name'
,
'start'
,
'end'
)
list_editable
=
(
'name'
,
'start'
,
'end'
)
contrib
.
admin
.
site
.
register
(
models
.
Course
,
CourseAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Course
,
CourseAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Semester
,
SemesterAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Semester
,
SemesterAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Group
,
GroupAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Group
,
GroupAdmin
)
school/models.py
View file @
2531f8c6
...
@@ -14,6 +14,7 @@ LANGUAGE_CHOICES = (('hu', _('Hungarian')), ('en', _('English')))
...
@@ -14,6 +14,7 @@ LANGUAGE_CHOICES = (('hu', _('Hungarian')), ('en', _('English')))
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
create_user_profile
(
sender
,
instance
,
created
,
**
kwargs
):
def
create_user_profile
(
sender
,
instance
,
created
,
**
kwargs
):
"""
"""
User creation hook.
User creation hook.
...
@@ -33,32 +34,33 @@ def create_user_profile(sender, instance, created, **kwargs):
...
@@ -33,32 +34,33 @@ def create_user_profile(sender, instance, created, **kwargs):
p
=
Person
.
objects
.
create
(
code
=
instance
.
username
)
p
=
Person
.
objects
.
create
(
code
=
instance
.
username
)
except
Exception
as
e
:
# pragma: no cover
except
Exception
as
e
:
# pragma: no cover
logger
.
warning
(
"Couldn't create profile for user:
%(username)
s"
logger
.
warning
(
"Couldn't create profile for user:
%(username)
s"
"
\n
Reason:
%(exception)
s"
,
"
\n
Reason:
%(exception)
s"
,
{
"username"
:
instance
.
username
,
{
"username"
:
instance
.
username
,
"exception"
:
e
})
"exception"
:
e
})
return
return
p
.
clean
()
p
.
clean
()
p
.
save
()
p
.
save
()
post_save
.
connect
(
create_user_profile
,
sender
=
User
)
post_save
.
connect
(
create_user_profile
,
sender
=
User
)
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
"""
"""
Personal settings and attributes of a user.
Personal settings and attributes of a user.
"""
"""
user
=
models
.
ForeignKey
(
User
,
null
=
True
,
blank
=
True
,
unique
=
True
)
user
=
models
.
ForeignKey
(
User
,
null
=
True
,
blank
=
True
,
unique
=
True
)
language
=
models
.
CharField
(
verbose_name
=
_
(
'language'
),
blank
=
False
,
language
=
models
.
CharField
(
verbose_name
=
_
(
'language'
),
blank
=
False
,
max_length
=
10
,
choices
=
LANGUAGE_CHOICES
,
default
=
LANGUAGE_CODE
)
max_length
=
10
,
choices
=
LANGUAGE_CHOICES
,
default
=
LANGUAGE_CODE
)
code
=
models
.
CharField
(
_
(
'code'
),
max_length
=
30
,
unique
=
True
)
code
=
models
.
CharField
(
_
(
'code'
),
max_length
=
30
,
unique
=
True
)
def
get_owned_shares
(
self
):
def
get_owned_shares
(
self
):
"""Get the shares of the groups which the person owns."""
"""Get the shares of the groups which the person owns."""
return
one
.
models
.
Share
.
objects
.
filter
(
return
one
.
models
.
Share
.
objects
.
filter
(
group__in
=
self
.
owned_groups
.
all
())
group__in
=
self
.
owned_groups
.
all
())
def
get_shares
(
self
):
def
get_shares
(
self
):
"""Get the shares of the groups which the person is a member of."""
"""Get the shares of the groups which the person is a member of."""
return
one
.
models
.
Share
.
objects
.
filter
(
return
one
.
models
.
Share
.
objects
.
filter
(
group__in
=
self
.
course_groups
.
all
())
group__in
=
self
.
course_groups
.
all
())
def
short_name
(
self
):
def
short_name
(
self
):
if
self
.
user
:
if
self
.
user
:
...
@@ -74,8 +76,8 @@ class Person(models.Model):
...
@@ -74,8 +76,8 @@ class Person(models.Model):
if
self
.
user
.
last_name
and
self
.
user
.
first_name
:
if
self
.
user
.
last_name
and
self
.
user
.
first_name
:
# TRANSLATORS: full name format used in enumerations
# TRANSLATORS: full name format used in enumerations
return
_
(
"
%(first)
s
%(last)
s"
)
%
{
return
_
(
"
%(first)
s
%(last)
s"
)
%
{
'first'
:
self
.
user
.
first_name
,
'first'
:
self
.
user
.
first_name
,
'last'
:
self
.
user
.
last_name
}
'last'
:
self
.
user
.
last_name
}
else
:
else
:
return
self
.
user
.
username
return
self
.
user
.
username
else
:
else
:
...
@@ -85,18 +87,20 @@ class Person(models.Model):
...
@@ -85,18 +87,20 @@ class Person(models.Model):
verbose_name
=
_
(
'person'
)
verbose_name
=
_
(
'person'
)
verbose_name_plural
=
_
(
'persons'
)
verbose_name_plural
=
_
(
'persons'
)
class
Course
(
models
.
Model
):
class
Course
(
models
.
Model
):
code
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
code
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
verbose_name
=
_
(
'course code'
))
verbose_name
=
_
(
'course code'
))
name
=
models
.
CharField
(
max_length
=
80
,
null
=
True
,
blank
=
True
,
name
=
models
.
CharField
(
max_length
=
80
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'name'
))
verbose_name
=
_
(
'name'
))
short_name
=
models
.
CharField
(
max_length
=
10
,
null
=
True
,
blank
=
True
,
short_name
=
models
.
CharField
(
max_length
=
10
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'name'
))
verbose_name
=
_
(
'name'
))
default_group
=
models
.
ForeignKey
(
'Group'
,
null
=
True
,
blank
=
True
,
default_group
=
models
.
ForeignKey
(
related_name
=
'default_group_of'
,
verbose_name
=
_
(
'default group'
),
'Group'
,
null
=
True
,
blank
=
True
,
related_name
=
'default_group_of'
,
help_text
=
_
(
'New users will be automatically assigned to this group.'
))
verbose_name
=
_
(
'default group'
),
help_text
=
_
(
'New users will be '
'automatically assigned to this group.'
))
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'owners'
))
verbose_name
=
_
(
'owners'
))
class
Meta
:
class
Meta
:
verbose_name
=
_
(
'course'
)
verbose_name
=
_
(
'course'
)
...
@@ -107,7 +111,8 @@ class Course(models.Model):
...
@@ -107,7 +111,8 @@ class Course(models.Model):
return
self
.
default_group
return
self
.
default_group
else
:
else
:
default_group
=
Group
(
name
=
_
(
"
%
s (auto)"
)
%
self
.
short
(),
default_group
=
Group
(
name
=
_
(
"
%
s (auto)"
)
%
self
.
short
(),
semester
=
Semester
.
get_current
(),
course
=
self
)
semester
=
Semester
.
get_current
(),
course
=
self
)
default_group
.
save
()
default_group
.
save
()
self
.
default_group_id
=
default_group
.
id
self
.
default_group_id
=
default_group
.
id
self
.
save
()
self
.
save
()
...
@@ -143,7 +148,7 @@ class Course(models.Model):
...
@@ -143,7 +148,7 @@ class Course(models.Model):
class
Semester
(
models
.
Model
):
class
Semester
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
null
=
False
,
name
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
null
=
False
,
verbose_name
=
_
(
'name'
))
verbose_name
=
_
(
'name'
))
start
=
models
.
DateField
(
verbose_name
=
_
(
'start'
))
start
=
models
.
DateField
(
verbose_name
=
_
(
'start'
))
end
=
models
.
DateField
(
verbose_name
=
_
(
'end'
))
end
=
models
.
DateField
(
verbose_name
=
_
(
'end'
))
...
@@ -171,13 +176,15 @@ class Semester(models.Model):
...
@@ -171,13 +176,15 @@ class Semester(models.Model):
class
Group
(
models
.
Model
):
class
Group
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
80
,
verbose_name
=
_
(
'name'
))
name
=
models
.
CharField
(
max_length
=
80
,
verbose_name
=
_
(
'name'
))
course
=
models
.
ForeignKey
(
'Course'
,
null
=
True
,
blank
=
True
,
course
=
models
.
ForeignKey
(
'Course'
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'course'
))
verbose_name
=
_
(
'course'
))
semester
=
models
.
ForeignKey
(
'Semester'
,
null
=
False
,
blank
=
False
,
semester
=
models
.
ForeignKey
(
'Semester'
,
null
=
False
,
blank
=
False
,
verbose_name
=
_
(
'semester'
))
verbose_name
=
_
(
'semester'
))
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
related_name
=
'owned_groups'
,
verbose_name
=
_
(
'owners'
))
related_name
=
'owned_groups'
,
verbose_name
=
_
(
'owners'
))
members
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
members
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
related_name
=
'course_groups'
,
verbose_name
=
_
(
'members'
))
related_name
=
'course_groups'
,
verbose_name
=
_
(
'members'
))
class
Meta
:
class
Meta
:
unique_together
=
((
'name'
,
'course'
,
'semester'
,
),
)
unique_together
=
((
'name'
,
'course'
,
'semester'
,
),
)
...
...
school/tests/test_models.py
View file @
2531f8c6
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
,
Group
as
AuthGroup
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
..models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
from
..models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
class
CreateUserProfileTestCase
(
TestCase
):
class
CreateUserProfileTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
user
=
User
(
username
=
"testuser"
,
password
=
"testpass"
,
self
.
user
=
User
(
username
=
"testuser"
,
password
=
"testpass"
,
email
=
"test@mail.com"
,
first_name
=
"Test"
,
last_name
=
"User"
)
email
=
"test@mail.com"
,
first_name
=
"Test"
,
last_name
=
"User"
)
Person
.
objects
.
all
()
.
delete
()
Person
.
objects
.
all
()
.
delete
()
with
self
.
assertRaises
(
Person
.
DoesNotExist
):
with
self
.
assertRaises
(
Person
.
DoesNotExist
):
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
...
@@ -23,6 +25,7 @@ class CreateUserProfileTestCase(TestCase):
...
@@ -23,6 +25,7 @@ class CreateUserProfileTestCase(TestCase):
create_user_profile
(
self
.
user
.
__class__
,
self
.
user
,
True
)
create_user_profile
(
self
.
user
.
__class__
,
self
.
user
,
True
)
self
.
assertIsNotNone
(
Person
.
objects
.
get
(
code
=
self
.
user
.
username
))
self
.
assertIsNotNone
(
Person
.
objects
.
get
(
code
=
self
.
user
.
username
))
class
PersonTestCase
(
TestCase
):
class
PersonTestCase
(
TestCase
):
"""Test 'static' Person facts."""
"""Test 'static' Person facts."""
def
test_language_code_in_choices
(
self
):
def
test_language_code_in_choices
(
self
):
...
@@ -32,11 +35,13 @@ class PersonTestCase(TestCase):
...
@@ -32,11 +35,13 @@ class PersonTestCase(TestCase):
choice_codes
=
[
code
for
(
code
,
_
)
in
language_field
.
choices
]
choice_codes
=
[
code
for
(
code
,
_
)
in
language_field
.
choices
]
self
.
assertIn
(
language_field
.
default
,
choice_codes
)
self
.
assertIn
(
language_field
.
default
,
choice_codes
)
class
PersonWithUserTestCase
(
TestCase
):
class
PersonWithUserTestCase
(
TestCase
):
"""Test Person entities which have their user attribute set."""
"""Test Person entities which have their user attribute set."""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
user
=
User
(
username
=
"testuser"
,
password
=
"testpass"
,
self
.
user
=
User
(
username
=
"testuser"
,
password
=
"testpass"
,
email
=
"test@mail.com"
,
first_name
=
"Test"
,
last_name
=
"User"
)
email
=
"test@mail.com"
,
first_name
=
"Test"
,
last_name
=
"User"
)
Person
.
objects
.
all
()
.
delete
()
Person
.
objects
.
all
()
.
delete
()
self
.
person
=
Person
.
objects
.
create
(
code
=
'testcode'
,
user
=
self
.
user
)
self
.
person
=
Person
.
objects
.
create
(
code
=
'testcode'
,
user
=
self
.
user
)
...
@@ -60,6 +65,7 @@ class PersonWithUserTestCase(TestCase):
...
@@ -60,6 +65,7 @@ class PersonWithUserTestCase(TestCase):
self
.
person
.
user
.
last_name
=
None
self
.
person
.
user
.
last_name
=
None
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
class
PersonWithoutUserTestCase
(
TestCase
):
class
PersonWithoutUserTestCase
(
TestCase
):
"""Test Person entities which doesn't have their user attribute set."""
"""Test Person entities which doesn't have their user attribute set."""
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -78,6 +84,7 @@ class PersonWithoutUserTestCase(TestCase):
...
@@ -78,6 +84,7 @@ class PersonWithoutUserTestCase(TestCase):
def
test_unicode
(
self
):
def
test_unicode
(
self
):
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
class
CourseTestCase
(
TestCase
):
class
CourseTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
now
=
datetime
.
now
()
now
=
datetime
.
now
()
...
@@ -85,10 +92,10 @@ class CourseTestCase(TestCase):
...
@@ -85,10 +92,10 @@ class CourseTestCase(TestCase):
delta
=
timedelta
(
weeks
=
7
)
delta
=
timedelta
(
weeks
=
7
)
self
.
testperson1
=
Person
.
objects
.
create
(
code
=
"testperson1"
)
self
.
testperson1
=
Person
.
objects
.
create
(
code
=
"testperson1"
)
self
.
testperson2
=
Person
.
objects
.
create
(
code
=
"testperson2"
)
self
.
testperson2
=
Person
.
objects
.
create
(
code
=
"testperson2"
)
self
.
testsemester
=
Semester
.
objects
.
create
(
name
=
"testsemester"
,
self
.
testsemester
=
Semester
.
objects
.
create
(
start
=
date
-
delta
,
end
=
date
+
delta
)
name
=
"testsemester"
,
start
=
date
-
delta
,
end
=
date
+
delta
)
self
.
testcourse
=
Course
.
objects
.
create
(
code
=
"testcode"
,
self
.
testcourse
=
Course
.
objects
.
create
(
name
=
"testname"
,
short_name
=
"tn"
)
code
=
"testcode"
,
name
=
"testname"
,
short_name
=
"tn"
)
self
.
testcourse
.
owners
.
add
(
self
.
testperson1
,
self
.
testperson2
)
self
.
testcourse
.
owners
.
add
(
self
.
testperson1
,
self
.
testperson2
)
def
test_get_or_create_default_group
(
self
):
def
test_get_or_create_default_group
(
self
):
...
@@ -118,18 +125,19 @@ class CourseTestCase(TestCase):
...
@@ -118,18 +125,19 @@ class CourseTestCase(TestCase):
self
.
testcourse
.
short_name
=
None
self
.
testcourse
.
short_name
=
None
self
.
assertIsNotNone
(
self
.
testcourse
.
short
())
self
.
assertIsNotNone
(
self
.
testcourse
.
short
())
class
SemesterTestCase
(
TestCase
):
class
SemesterTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
now
=
datetime
.
now
()
now
=
datetime
.
now
()
date
=
now
.
date
()
date
=
now
.
date
()
self
.
now
=
now
self
.
now
=
now
delta
=
timedelta
(
weeks
=
7
)
delta
=
timedelta
(
weeks
=
7
)
self
.
last_semester
=
Semester
.
objects
.
create
(
name
=
"testsem1"
,
self
.
last_semester
=
Semester
.
objects
.
create
(
start
=
date
-
3
*
delta
,
end
=
date
-
delta
)
name
=
"testsem1"
,
start
=
date
-
3
*
delta
,
end
=
date
-
delta
)
self
.
current_semester
=
Semester
.
objects
.
create
(
name
=
"testsem2"
,
self
.
current_semester
=
Semester
.
objects
.
create
(
start
=
date
-
delta
,
end
=
date
+
delta
)
name
=
"testsem2"
,
start
=
date
-
delta
,
end
=
date
+
delta
)
self
.
next_semester
=
Semester
.
objects
.
create
(
name
=
"testsem3"
,
self
.
next_semester
=
Semester
.
objects
.
create
(
start
=
date
+
delta
,
end
=
date
+
3
*
delta
)
name
=
"testsem3"
,
start
=
date
+
delta
,
end
=
date
+
3
*
delta
)
def
test_is_on
(
self
):
def
test_is_on
(
self
):
self
.
assertFalse
(
self
.
last_semester
.
is_on
(
self
.
now
))
self
.
assertFalse
(
self
.
last_semester
.
is_on
(
self
.
now
))
...
@@ -146,16 +154,17 @@ class SemesterTestCase(TestCase):
...
@@ -146,16 +154,17 @@ class SemesterTestCase(TestCase):
def
test_unicode
(
self
):
def
test_unicode
(
self
):
self
.
current_semester
.
__unicode__
()
self
.
current_semester
.
__unicode__
()
class
GroupTestCase
(
TestCase
):
class
GroupTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
date
=
datetime
.
now
()
.
date
()
date
=
datetime
.
now
()
.
date
()
delta
=
timedelta
(
weeks
=
7
)
delta
=
timedelta
(
weeks
=
7
)
semester
=
Semester
.
objects
.
create
(
name
=
"testsem"
,
semester
=
Semester
.
objects
.
create
(
start
=
date
-
delta
,
end
=
date
+
delta
)
name
=
"testsem"
,
start
=
date
-
delta
,
end
=
date
+
delta
)
self
.
testcourse
=
Course
.
objects
.
create
(
code
=
"testcode"
,
self
.
testcourse
=
Course
.
objects
.
create
(
name
=
"testname"
,
short_name
=
"tn"
)
code
=
"testcode"
,
name
=
"testname"
,
short_name
=
"tn"
)
self
.
testgroup
=
Group
.
objects
.
create
(
name
=
"testgrp"
,
self
.
testgroup
=
Group
.
objects
.
create
(
semester
=
semester
,
course
=
self
.
testcourse
)
name
=
"testgrp"
,
semester
=
semester
,
course
=
self
.
testcourse
)
def
test_owner_list
(
self
):
def
test_owner_list
(
self
):
self
.
assertIsNotNone
(
self
.
testgroup
.
owner_list
())
self
.
assertIsNotNone
(
self
.
testgroup
.
owner_list
())
...
@@ -184,4 +193,3 @@ class GroupTestCase(TestCase):
...
@@ -184,4 +193,3 @@ class GroupTestCase(TestCase):
def
test_get_absolute_url
(
self
):
def
test_get_absolute_url
(
self
):
self
.
assertIsNotNone
(
self
.
testgroup
.
get_absolute_url
())
self
.
assertIsNotNone
(
self
.
testgroup
.
get_absolute_url
())
school/tests/test_views.py
View file @
2531f8c6
...
@@ -2,30 +2,30 @@ from datetime import datetime, timedelta
...
@@ -2,30 +2,30 @@ from datetime import datetime, timedelta
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Group
as
AuthGroup
from
django.contrib.auth.models
import
User
,
Group
as
AuthGroup
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.utils.datastructures
import
MultiValueDictKeyError
from
django.utils.datastructures
import
MultiValueDictKeyError
from
..models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
from
..models
import
Person
,
Course
,
Semester
,
Group
from
one.models
import
(
UserCloudDetails
,
Disk
,
InstanceType
,
Network
,
from
one.models
import
(
UserCloudDetails
,
Disk
,
InstanceType
,
Network
,
Template
)
Template
)
import
json
import
json
class
ViewTestCase
(
TestCase
):
class
ViewTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
client
=
Client
()
date
=
datetime
.
now
()
.
date
()
date
=
datetime
.
now
()
.
date
()
delta
=
timedelta
(
weeks
=
7
)
delta
=
timedelta
(
weeks
=
7
)
self
.
semester
=
Semester
.
objects
.
create
(
name
=
"testsem"
,
self
.
semester
=
Semester
.
objects
.
create
(
start
=
date
-
delta
,
end
=
date
+
delta
)
name
=
"testsem"
,
start
=
date
-
delta
,
end
=
date
+
delta
)
course1
=
Course
.
objects
.
create
(
code
=
'tccode1'
,
course1
=
Course
.
objects
.
create
(
name
=
'testcourse1'
,
short_name
=
'tc1'
)
code
=
'tccode1'
,
name
=
'testcourse1'
,
short_name
=
'tc1'
)
course2
=
Course
.
objects
.
create
(
code
=
'tccode2'
,
course2
=
Course
.
objects
.
create
(
name
=
'testcourse2'
,
short_name
=
'tc2'
)
code
=
'tccode2'
,
name
=
'testcourse2'
,
short_name
=
'tc2'
)
nonexistent_course_code1
=
'vacationspotscouting'
nonexistent_course_code1
=
'vacationspotscouting'
nonexistent_course_code2
=
'caringforunicorns'
nonexistent_course_code2
=
'caringforunicorns'
affiliation1
=
AuthGroup
.
objects
.
create
(
name
=
'chalktrademanager'
)
affiliation1
=
AuthGroup
.
objects
.
create
(
name
=
'chalktrademanager'
)
self
.
group1
=
Group
.
objects
.
create
(
name
=
affiliation1
.
name
,
self
.
group1
=
Group
.
objects
.
create
(
semester
=
self
.
semester
,
course
=
course1
)
name
=
affiliation1
.
name
,
semester
=
self
.
semester
,
course
=
course1
)
self
.
http_headers
=
{
self
.
http_headers
=
{
'niifPersonOrgID'
:
'ABUZER'
,
'niifPersonOrgID'
:
'ABUZER'
,
'niifEduPersonHeldCourse'
:
';'
.
join
(
'niifEduPersonHeldCourse'
:
';'
.
join
(
...
@@ -37,7 +37,6 @@ class ViewTestCase(TestCase):
...
@@ -37,7 +37,6 @@ class ViewTestCase(TestCase):
'email'
:
'test.user@testsite.hu'
,
'email'
:
'test.user@testsite.hu'
,
'affiliation'
:
';'
.
join
([
affiliation1
.
name
])}
'affiliation'
:
';'
.
join
([
affiliation1
.
name
])}
def
login
(
self
,
follow
=
False
):
def
login
(
self
,
follow
=
False
):
url
=
reverse
(
'login'
)
url
=
reverse
(
'login'
)
resp
=
self
.
client
.
get
(
url
,
follow
=
follow
,
**
self
.
http_headers
)
resp
=
self
.
client
.
get
(
url
,
follow
=
follow
,
**
self
.
http_headers
)
...
@@ -50,7 +49,6 @@ class ViewTestCase(TestCase):
...
@@ -50,7 +49,6 @@ class ViewTestCase(TestCase):
pass
pass
return
resp
return
resp
#
#
# school.views.logout
# school.views.logout
#
#
...
@@ -58,7 +56,6 @@ class ViewTestCase(TestCase):
...
@@ -58,7 +56,6 @@ class ViewTestCase(TestCase):
resp
=
self
.
client
.
get
(
reverse
(
'logout'
),
follow
=
False
)
resp
=
self
.
client
.
get
(
reverse
(
'logout'
),
follow
=
False
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
#
#
# school.views.login
# school.views.login
#
#
...
@@ -66,7 +63,6 @@ class ViewTestCase(TestCase):
...
@@ -66,7 +63,6 @@ class ViewTestCase(TestCase):
resp
=
self
.
login
(
follow
=
True
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_login_without_id
(
self
):
def
test_login_without_id
(
self
):
del
self
.
http_headers
[
'niifPersonOrgID'
]
del
self
.
http_headers
[
'niifPersonOrgID'
]
resp
=
self
.
login
(
follow
=
True
)
resp
=
self
.
login
(
follow
=
True
)
...
@@ -74,25 +70,21 @@ class ViewTestCase(TestCase):
...
@@ -74,25 +70,21 @@ class ViewTestCase(TestCase):
(
url
,
_
)
=
resp
.
redirect_chain
[
0
]
(
url
,
_
)
=
resp
.
redirect_chain
[
0
]
self
.
assertIn
(
'/admin'
,
url
)
self
.
assertIn
(
'/admin'
,
url
)
def
test_login_without_email
(
self
):
def
test_login_without_email
(
self
):
del
self
.
http_headers
[
'email'
]
del
self
.
http_headers
[
'email'
]
resp
=
self
.
login
(
follow
=
True
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
403
,
resp
.
status_code
)
self
.
assertEqual
(
403
,
resp
.
status_code
)
def
test_login_without_affiliation
(
self
):
def
test_login_without_affiliation
(
self
):
del
self
.
http_headers
[
'affiliation'
]
del
self
.
http_headers
[
'affiliation'
]
resp
=
self
.
login
(
follow
=
True
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_login_without_group_for_affiliation
(
self
):
def
test_login_without_group_for_affiliation
(
self
):
self
.
group1
.
delete
()
self
.
group1
.
delete
()
resp
=
self
.
login
(
follow
=
True
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
#
#
# school.views.language
# school.views.language
#
#
...
@@ -107,7 +99,6 @@ class ViewTestCase(TestCase):
...
@@ -107,7 +99,6 @@ class ViewTestCase(TestCase):
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertEqual
(
lang
,
p
.
language
)
self
.
assertEqual
(
lang
,
p
.
language
)
def
test_language_with_invalid_parameter
(
self
):
def
test_language_with_invalid_parameter
(
self
):
self
.
login
()
self
.
login
()
lang_before
=
Person
.
objects
.
get
(
user
=
self
.
user
)
.
language
lang_before
=
Person
.
objects
.
get
(
user
=
self
.
user
)
.
language
...
@@ -117,8 +108,7 @@ class ViewTestCase(TestCase):
...
@@ -117,8 +108,7 @@ class ViewTestCase(TestCase):
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertEqual
(
lang_before
,
p
.
language
)
# language didn't change
self
.
assertEqual
(
lang_before
,
p
.
language
)
# language didn't change
def
test_language_without_person_for_user
(
self
):
def
test_language_without_person_for_user
(
self
):
self
.
login
()
self
.
login
()
...
@@ -129,7 +119,6 @@ class ViewTestCase(TestCase):
...
@@ -129,7 +119,6 @@ class ViewTestCase(TestCase):
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
#
#
# school.views.group_show
# school.views.group_show
#
#
...
@@ -140,18 +129,17 @@ class ViewTestCase(TestCase):
...
@@ -140,18 +129,17 @@ class ViewTestCase(TestCase):
ucd
.
save
()
ucd
.
save
()
disk
=
Disk
.
objects
.
create
(
name
=
"testdsk1"
)
disk
=
Disk
.
objects
.
create
(
name
=
"testdsk1"
)
insttype
=
InstanceType
.
objects
.
create
(
name
=
"testtype"
,
CPU
=
4
,
insttype
=
InstanceType
.
objects
.
create
(
name
=
"testtype"
,
CPU
=
4
,
RAM
=
4096
,
credit
=
4
)
RAM
=
4096
,
credit
=
4
)
ntwrk
=
Network
.
objects
.
create
(
name
=
"testntwrk"
,
nat
=
False
,
ntwrk
=
Network
.
objects
.
create
(
name
=
"testntwrk"
,
nat
=
False
,
public
=
True
)
public
=
True
)
tmplt
=
Template
.
objects
.
create
(
name
=
"testtmplt1"
,
disk
=
disk
,
Template
.
objects
.
create
(
instance_type
=
insttype
,
network
=
ntwrk
,
owner
=
self
.
user
,
name
=
"testtmplt1"
,
disk
=
disk
,
instance_type
=
insttype
,
state
=
'READY'
)
network
=
ntwrk
,
owner
=
self
.
user
,
state
=
'READY'
)
gid
=
self
.
group1
.
id
gid
=
self
.
group1
.
id
url
=
reverse
(
'school.views.group_show'
,
kwargs
=
{
'gid'
:
gid
})
url
=
reverse
(
'school.views.group_show'
,
kwargs
=
{
'gid'
:
gid
})
resp
=
self
.
client
.
get
(
url
)
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_group_show_with_nonexistent_group_id
(
self
):
def
test_group_show_with_nonexistent_group_id
(
self
):
self
.
login
()
self
.
login
()
gid
=
1337
# this should be the ID of a non-existent group,
gid
=
1337
# this should be the ID of a non-existent group,
...
@@ -160,7 +148,6 @@ class ViewTestCase(TestCase):
...
@@ -160,7 +148,6 @@ class ViewTestCase(TestCase):
resp
=
self
.
client
.
get
(
url
)
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
#
#
# school.views.group_new
# school.views.group_new
#
#
...
@@ -169,53 +156,44 @@ class ViewTestCase(TestCase):
...
@@ -169,53 +156,44 @@ class ViewTestCase(TestCase):
url
=
reverse
(
'school.views.group_new'
)
url
=
reverse
(
'school.views.group_new'
)
member1
=
Person
.
objects
.
create
(
code
=
"A1B2C3"
)
member1
=
Person
.
objects
.
create
(
code
=
"A1B2C3"
)
members
=
[
member1
]
members
=
[
member1
]
data
=
{
data
=
{
'name'
:
'myNewGrp'
,
'name'
:
'myNewGrp'
,
'semester'
:
Semester
.
get_current
()
.
id
,
'semester'
:
Semester
.
get_current
()
.
id
,
'members'
:
'
\n
'
.
join
([
m
.
code
for
m
in
members
]),
'members'
:
'
\n
'
.
join
([
m
.
code
for
m
in
members
])}
}
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
group
=
Group
.
objects
.
get
(
name
=
data
[
'name'
])
group
=
Group
.
objects
.
get
(
name
=
data
[
'name'
])
self
.
assertEqual
(
Semester
.
get_current
(),
group
.
semester
)
self
.
assertEqual
(
Semester
.
get_current
(),
group
.
semester
)
for
member
in
members
:
for
member
in
members
:
self
.
assertIn
(
member
,
group
.
members
.
all
())
self
.
assertIn
(
member
,
group
.
members
.
all
())
def
test_group_new_without_members
(
self
):
def
test_group_new_without_members
(
self
):
self
.
login
()
self
.
login
()
url
=
reverse
(
'school.views.group_new'
)
url
=
reverse
(
'school.views.group_new'
)
data
=
{
data
=
{
'name'
:
'myNewGrp'
,
'name'
:
'myNewGrp'
,
'semester'
:
Semester
.
get_current
()
.
id
,
'semester'
:
Semester
.
get_current
()
.
id
,
'members'
:
''
,
'members'
:
''
}
}
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
group
=
Group
.
objects
.
get
(
name
=
data
[
'name'
])
group
=
Group
.
objects
.
get
(
name
=
data
[
'name'
])
self
.
assertEqual
(
Semester
.
get_current
(),
group
.
semester
)
self
.
assertEqual
(
Semester
.
get_current
(),
group
.
semester
)
self
.
assertFalse
(
group
.
members
.
exists
())
self
.
assertFalse
(
group
.
members
.
exists
())
def
test_group_new_with_invalid_neptun
(
self
):
def
test_group_new_with_invalid_neptun
(
self
):
self
.
login
()
self
.
login
()
url
=
reverse
(
'school.views.group_new'
)
url
=
reverse
(
'school.views.group_new'
)
data
=
{
data
=
{
'name'
:
'myNewGrp'
,
'name'
:
'myNewGrp'
,
'semester'
:
Semester
.
get_current
()
.
id
,
'semester'
:
Semester
.
get_current
()
.
id
,
'members'
:
'1ABC123'
,
# invalid neptun
'members'
:
'1ABC123'
}
# invalid neptun
}
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertFalse
(
Group
.
objects
.
filter
(
name
=
data
[
'name'
])
.
exists
())
self
.
assertFalse
(
Group
.
objects
.
filter
(
name
=
data
[
'name'
])
.
exists
())
#
#
# school.views.group_ajax_add_new_member
# school.views.group_ajax_add_new_member
#
#
def
test_group_ajax_add_new_member
(
self
):
def
test_group_ajax_add_new_member
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
data
=
{
'neptun'
:
new_member
.
code
}
data
=
{
'neptun'
:
new_member
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
...
@@ -223,25 +201,23 @@ class ViewTestCase(TestCase):
...
@@ -223,25 +201,23 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertIn
(
new_member
,
group
.
members
.
all
())
self
.
assertIn
(
new_member
,
group
.
members
.
all
())
def
test_group_ajax_add_new_member_with_nonexistent_group_id
(
self
):
def
test_group_ajax_add_new_member_with_nonexistent_group_id
(
self
):
self
.
login
()
self
.
login
()
gid
=
1337
# this should be the ID of a non-existent group,
gid
=
1337
# this should be the ID of a non-existent group,
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
kwargs
=
{
'gid'
:
gid
})
kwargs
=
{
'gid'
:
gid
})
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
data
=
{
'neptun'
:
new_member
.
code
}
data
=
{
'neptun'
:
new_member
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
def
test_group_ajax_add_new_member_without_neptun
(
self
):
def
test_group_ajax_add_new_member_without_neptun
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
data
=
{}
data
=
{}
with
self
.
assertRaises
(
MultiValueDictKeyError
):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
...
@@ -249,13 +225,12 @@ class ViewTestCase(TestCase):
...
@@ -249,13 +225,12 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertNotIn
(
new_member
,
group
.
members
.
all
())
self
.
assertNotIn
(
new_member
,
group
.
members
.
all
())
def
test_group_ajax_add_new_member_with_invalid_neptun
(
self
):
def
test_group_ajax_add_new_member_with_invalid_neptun
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
new_member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertNotIn
(
new_member
,
group
.
members
.
all
())
self
.
assertNotIn
(
new_member
,
group
.
members
.
all
())
data
=
{
'neptun'
:
'1'
+
new_member
.
code
}
data
=
{
'neptun'
:
'1'
+
new_member
.
code
}
...
@@ -266,13 +241,12 @@ class ViewTestCase(TestCase):
...
@@ -266,13 +241,12 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertNotIn
(
new_member
,
group
.
members
.
all
())
self
.
assertNotIn
(
new_member
,
group
.
members
.
all
())
def
test_group_ajax_add_new_member_with_nonexistent_member
(
self
):
def
test_group_ajax_add_new_member_with_nonexistent_member
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
url
=
reverse
(
'school.views.group_ajax_add_new_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
new_member_code
=
'ZXY012'
# this should be the ID of a
new_member_code
=
'ZXY012'
# this should be the ID of a
# non-existent person, so if it exists,
# non-existent person, so if it exists,
Person
.
objects
.
filter
(
code
=
new_member_code
)
.
delete
()
# delete it!
Person
.
objects
.
filter
(
code
=
new_member_code
)
.
delete
()
# delete it!
...
@@ -284,63 +258,59 @@ class ViewTestCase(TestCase):
...
@@ -284,63 +258,59 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertIn
(
new_member
,
group
.
members
.
all
())
self
.
assertIn
(
new_member
,
group
.
members
.
all
())
#
#
# school.views.group_ajax_remove_member
# school.views.group_ajax_remove_member
#
#
def
test_group_ajax_remove_member
(
self
):
def
test_group_ajax_remove_member
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
group
.
members
.
add
(
member
)
group
.
members
.
add
(
member
)
group
.
save
()
group
.
save
()
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{
'neptun'
:
member
.
code
}
data
=
{
'neptun'
:
member
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertNotIn
(
member
,
group
.
members
.
all
())
self
.
assertNotIn
(
member
,
group
.
members
.
all
())
def
test_group_ajax_remove_member_with_nonexistent_group_id
(
self
):
def
test_group_ajax_remove_member_with_nonexistent_group_id
(
self
):
self
.
login
()
self
.
login
()
gid
=
1337
# this should be the ID of a non-existent group,
gid
=
1337
# this should be the ID of a non-existent group,
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
kwargs
=
{
'gid'
:
gid
})
kwargs
=
{
'gid'
:
gid
})
data
=
{
'neptun'
:
member
.
code
}
data
=
{
'neptun'
:
member
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
def
test_group_ajax_remove_member_without_neptun
(
self
):
def
test_group_ajax_remove_member_without_neptun
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
group
.
members
.
add
(
member
)
group
.
members
.
add
(
member
)
group
.
save
()
group
.
save
()
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{}
data
=
{}
with
self
.
assertRaises
(
MultiValueDictKeyError
):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
self
.
client
.
post
(
url
,
data
)
self
.
client
.
post
(
url
,
data
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertIn
(
member
,
group
.
members
.
all
())
self
.
assertIn
(
member
,
group
.
members
.
all
())
def
test_group_ajax_remove_member_with_invalid_neptun
(
self
):
def
test_group_ajax_remove_member_with_invalid_neptun
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
member
=
Person
.
objects
.
get
(
user
=
self
.
user
)
group
.
members
.
add
(
member
)
group
.
members
.
add
(
member
)
group
.
save
()
group
.
save
()
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{
'neptun'
:
'1'
+
member
.
code
}
# invalid Neptun code
data
=
{
'neptun'
:
'1'
+
member
.
code
}
# invalid Neptun code
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
...
@@ -349,36 +319,33 @@ class ViewTestCase(TestCase):
...
@@ -349,36 +319,33 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertIn
(
member
,
group
.
members
.
all
())
self
.
assertIn
(
member
,
group
.
members
.
all
())
def
test_group_ajax_remove_member_with_nonexistent_member
(
self
):
def
test_group_ajax_remove_member_with_nonexistent_member
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
member_code
=
'ZXY012'
# this should be the ID of a non-existent
member_code
=
'ZXY012'
# this should be the ID of a non-existent
# person, so if it exists,
# person, so if it exists,
Person
.
objects
.
filter
(
code
=
member_code
)
.
delete
()
# delete it!
Person
.
objects
.
filter
(
code
=
member_code
)
.
delete
()
# delete it!
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
url
=
reverse
(
'school.views.group_ajax_remove_member'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{
'neptun'
:
member_code
}
data
=
{
'neptun'
:
member_code
}
with
self
.
assertRaises
(
Person
.
DoesNotExist
):
with
self
.
assertRaises
(
Person
.
DoesNotExist
):
self
.
client
.
post
(
url
,
data
)
self
.
client
.
post
(
url
,
data
)
self
.
assertFalse
(
Person
.
objects
.
filter
(
code
=
member_code
)
.
exists
())
self
.
assertFalse
(
Person
.
objects
.
filter
(
code
=
member_code
)
.
exists
())
#
#
# school.views.group_ajax_delete
# school.views.group_ajax_delete
#
#
def
test_group_ajax_delete
(
self
):
def
test_group_ajax_delete
(
self
):
self
.
login
()
self
.
login
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
url
=
reverse
(
'school.views.group_ajax_delete'
)
url
=
reverse
(
'school.views.group_ajax_delete'
)
data
=
{
'gid'
:
group
.
id
}
data
=
{
'gid'
:
group
.
id
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertFalse
(
Group
.
objects
.
filter
(
id
=
group
.
id
)
.
exists
())
self
.
assertFalse
(
Group
.
objects
.
filter
(
id
=
group
.
id
)
.
exists
())
def
test_group_ajax_delete_without_gid
(
self
):
def
test_group_ajax_delete_without_gid
(
self
):
self
.
login
()
self
.
login
()
url
=
reverse
(
'school.views.group_ajax_delete'
)
url
=
reverse
(
'school.views.group_ajax_delete'
)
...
@@ -386,7 +353,6 @@ class ViewTestCase(TestCase):
...
@@ -386,7 +353,6 @@ class ViewTestCase(TestCase):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
self
.
client
.
post
(
url
,
data
)
self
.
client
.
post
(
url
,
data
)
def
test_group_ajax_delete_with_nonexistent_group_id
(
self
):
def
test_group_ajax_delete_with_nonexistent_group_id
(
self
):
self
.
login
()
self
.
login
()
gid
=
1337
# this should be the ID of a non-existent group,
gid
=
1337
# this should be the ID of a non-existent group,
...
@@ -396,7 +362,6 @@ class ViewTestCase(TestCase):
...
@@ -396,7 +362,6 @@ class ViewTestCase(TestCase):
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
#
#
# school.views.group_ajax_owner_autocomplete
# school.views.group_ajax_owner_autocomplete
#
#
...
@@ -412,7 +377,6 @@ class ViewTestCase(TestCase):
...
@@ -412,7 +377,6 @@ class ViewTestCase(TestCase):
'neptun'
:
self
.
user
.
username
}
'neptun'
:
self
.
user
.
username
}
self
.
assertIn
(
user_data
,
content
)
self
.
assertIn
(
user_data
,
content
)
def
test_group_ajax_owner_autocomplete_without_query
(
self
):
def
test_group_ajax_owner_autocomplete_without_query
(
self
):
self
.
login
()
self
.
login
()
url
=
reverse
(
'school.views.group_ajax_owner_autocomplete'
)
url
=
reverse
(
'school.views.group_ajax_owner_autocomplete'
)
...
@@ -420,7 +384,6 @@ class ViewTestCase(TestCase):
...
@@ -420,7 +384,6 @@ class ViewTestCase(TestCase):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
self
.
client
.
post
(
url
,
data
)
self
.
client
.
post
(
url
,
data
)
#
#
# school.views.group_ajax_add_new_owner
# school.views.group_ajax_add_new_owner
#
#
...
@@ -429,12 +392,12 @@ class ViewTestCase(TestCase):
...
@@ -429,12 +392,12 @@ class ViewTestCase(TestCase):
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
.
share_quota
=
10
user_details
.
share_quota
=
10
user_details
.
save
()
user_details
.
save
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{
'neptun'
:
new_owner
.
code
}
data
=
{
'neptun'
:
new_owner
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
...
@@ -443,18 +406,17 @@ class ViewTestCase(TestCase):
...
@@ -443,18 +406,17 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertIn
(
new_owner
,
group
.
owners
.
all
())
def
test_group_ajax_add_new_owner_without_enough_share_quota
(
self
):
def
test_group_ajax_add_new_owner_without_enough_share_quota
(
self
):
self
.
login
()
self
.
login
()
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
.
share_quota
=
0
user_details
.
share_quota
=
0
user_details
.
save
()
user_details
.
save
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{
'neptun'
:
new_owner
.
code
}
data
=
{
'neptun'
:
new_owner
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
...
@@ -463,7 +425,6 @@ class ViewTestCase(TestCase):
...
@@ -463,7 +425,6 @@ class ViewTestCase(TestCase):
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
def
test_group_ajax_add_new_owner_with_nonexistent_group_id
(
self
):
def
test_group_ajax_add_new_owner_with_nonexistent_group_id
(
self
):
self
.
login
()
self
.
login
()
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
...
@@ -473,7 +434,7 @@ class ViewTestCase(TestCase):
...
@@ -473,7 +434,7 @@ class ViewTestCase(TestCase):
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
kwargs
=
{
'gid'
:
gid
})
kwargs
=
{
'gid'
:
gid
})
data
=
{
'neptun'
:
new_owner
.
code
}
data
=
{
'neptun'
:
new_owner
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
...
@@ -483,30 +444,29 @@ class ViewTestCase(TestCase):
...
@@ -483,30 +444,29 @@ class ViewTestCase(TestCase):
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
.
share_quota
=
10
user_details
.
share_quota
=
10
user_details
.
save
()
user_details
.
save
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{}
data
=
{}
with
self
.
assertRaises
(
MultiValueDictKeyError
):
with
self
.
assertRaises
(
MultiValueDictKeyError
):
self
.
client
.
post
(
url
,
data
)
self
.
client
.
post
(
url
,
data
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
group
=
Group
.
objects
.
get
(
id
=
group
.
id
)
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
def
test_group_ajax_add_new_owner_with_invalid_neptun
(
self
):
def
test_group_ajax_add_new_owner_with_invalid_neptun
(
self
):
self
.
login
()
self
.
login
()
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
user_details
.
share_quota
=
10
user_details
.
share_quota
=
10
user_details
.
save
()
user_details
.
save
()
group
=
Group
.
objects
.
create
(
name
=
"mytestgroup"
,
group
=
Group
.
objects
.
create
(
semester
=
Semester
.
get_current
())
name
=
"mytestgroup"
,
semester
=
Semester
.
get_current
())
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
new_owner
=
Person
.
objects
.
get
(
code
=
self
.
user
.
username
)
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
self
.
assertNotIn
(
new_owner
,
group
.
owners
.
all
())
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
url
=
reverse
(
'school.views.group_ajax_add_new_owner'
,
kwargs
=
{
'gid'
:
group
.
id
})
kwargs
=
{
'gid'
:
group
.
id
})
data
=
{
'neptun'
:
'1'
+
new_owner
.
code
}
data
=
{
'neptun'
:
'1'
+
new_owner
.
code
}
resp
=
self
.
client
.
post
(
url
,
data
)
resp
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
...
...
school/views.py
View file @
2531f8c6
from
datetime
import
datetime
from
itertools
import
chain
from
itertools
import
chain
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.models
import
User
,
Group
as
AGroup
from
django.contrib.auth.models
import
User
,
Group
as
AGroup
from
django.contrib
import
messages
from
django.contrib
import
messages
from
django.core
import
signing
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.core.mail
import
mail_managers
,
send_mail
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.db
import
transaction
from
django.http
import
HttpResponse
from
django.forms
import
ModelForm
,
Textarea
from
django.shortcuts
import
(
render_to_response
,
get_object_or_404
,
from
django.http
import
Http404
redirect
)
from
django.shortcuts
import
(
render
,
render_to_response
,
get_object_or_404
,
redirect
)
from
django.template
import
RequestContext
from
django.template
import
RequestContext
from
django.template.loader
import
render_to_string
from
django.utils.decorators
import
method_decorator
from
django.utils.http
import
is_safe_url
from
django.utils.http
import
is_safe_url
from
django.utils.translation
import
get_language
as
lang
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.decorators.csrf
import
ensure_csrf_cookie
from
django.views.decorators.csrf
import
ensure_csrf_cookie
from
django.views.decorators.http
import
*
from
one.models
import
Template
,
UserCloudDetails
from
django.views.generic
import
*
from
school.models
import
Person
,
Semester
,
Course
,
Group
from
one.models
import
*
from
school.models
import
*
import
django.contrib.auth
as
auth
import
django.contrib.auth
as
auth
import
logging
import
logging
import
json
import
json
import
re
import
re
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
neptun_re
=
re
.
compile
(
'^[a-zA-Z][a-zA-Z0-9]{5}$'
)
neptun_re
=
re
.
compile
(
'^[a-zA-Z][a-zA-Z0-9]{5}$'
)
def
logout
(
request
):
def
logout
(
request
):
auth
.
logout
(
request
)
auth
.
logout
(
request
)
return
redirect
(
'/Shibboleth.sso/Logout?return=https
%3
a
%2
f
%2
fcloud.ik.bme.hu
%2
f'
)
url
=
'/Shibboleth.sso/Logout?return=https
%3
a
%2
f
%2
fcloud.ik.bme.hu
%2
f'
return
redirect
(
url
)
@ensure_csrf_cookie
@ensure_csrf_cookie
...
@@ -54,7 +47,9 @@ def login(request):
...
@@ -54,7 +47,9 @@ def login(request):
try
:
try
:
user
.
email
=
request
.
META
[
'email'
]
user
.
email
=
request
.
META
[
'email'
]
except
KeyError
:
except
KeyError
:
messages
.
error
(
request
,
_
(
"The identity provider did not pass the mandatory e-mail data."
))
messages
.
error
(
request
,
_
(
"The identity provider did not pass the mandatory "
"e-mail data."
))
raise
PermissionDenied
()
raise
PermissionDenied
()
user
.
save
()
user
.
save
()
p
,
created
=
Person
.
objects
.
get_or_create
(
code
=
user
.
username
)
p
,
created
=
Person
.
objects
.
get_or_create
(
code
=
user
.
username
)
...
@@ -76,12 +71,11 @@ def login(request):
...
@@ -76,12 +71,11 @@ def login(request):
try
:
try
:
g
.
members
.
add
(
p
)
g
.
members
.
add
(
p
)
g
.
save
()
g
.
save
()
messages
.
info
(
request
,
messages
.
info
(
request
,
_
(
'Course "
%
s" added.'
)
%
g
.
course
)
_
(
'Course "
%
s" added.'
)
%
g
.
course
)
logger
.
info
(
'Django Course "
%
s" added.'
%
g
.
course
)
logger
.
info
(
'Django Course "
%
s" added.'
%
g
.
course
)
except
Exception
as
e
:
except
Exception
as
e
:
messages
.
error
(
request
,
messages
.
error
(
request
,
_
(
'Failed to add course "
%
s".'
)
%
g
.
course
)
_
(
'Failed to add course "
%
s".'
)
%
g
.
course
)
logger
.
warning
(
"Django ex
%
s"
%
e
)
logger
.
warning
(
"Django ex
%
s"
%
e
)
held
=
request
.
META
[
'niifEduPersonHeldCourse'
]
held
=
request
.
META
[
'niifEduPersonHeldCourse'
]
...
@@ -95,10 +89,11 @@ def login(request):
...
@@ -95,10 +89,11 @@ def login(request):
co
.
owners
.
add
(
p
)
co
.
owners
.
add
(
p
)
g
.
owners
.
add
(
p
)
g
.
owners
.
add
(
p
)
messages
.
info
(
request
,
messages
.
info
(
request
,
_
(
'Course "
%
s" ownership added.'
)
%
g
.
course
)
_
(
'Course "
%
s" ownership added.'
)
%
g
.
course
)
except
Exception
as
e
:
except
Exception
as
e
:
messages
.
error
(
request
,
messages
.
error
(
request
,
_
(
'Failed to add course "
%
s" ownership.'
)
%
g
.
course
)
_
(
'Failed to add course "
%
s" ownership.'
)
%
g
.
course
)
logger
.
warning
(
"Django ex
%
s"
%
e
)
logger
.
warning
(
"Django ex
%
s"
%
e
)
co
.
save
()
co
.
save
()
g
.
save
()
g
.
save
()
...
@@ -119,7 +114,7 @@ def login(request):
...
@@ -119,7 +114,7 @@ def login(request):
logger
.
info
(
"Django affiliation group
%
s added to
%
s"
%
(
a
,
p
))
logger
.
info
(
"Django affiliation group
%
s added to
%
s"
%
(
a
,
p
))
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning
(
"Django FAILed to add affiliation group
%
s to
%
s."
logger
.
warning
(
"Django FAILed to add affiliation group
%
s to
%
s."
" Reason:
%
s"
%
(
a
,
p
,
e
))
" Reason:
%
s"
%
(
a
,
p
,
e
))
user
.
save
()
user
.
save
()
p
.
save
()
p
.
save
()
...
@@ -158,7 +153,7 @@ def group_show(request, gid):
...
@@ -158,7 +153,7 @@ def group_show(request, gid):
user
=
request
.
user
user
=
request
.
user
group
=
get_object_or_404
(
Group
,
id
=
gid
)
group
=
get_object_or_404
(
Group
,
id
=
gid
)
mytemplates
=
Template
.
objects
.
filter
(
owner
=
request
.
user
,
state
=
'READY'
)
mytemplates
=
Template
.
objects
.
filter
(
owner
=
user
,
state
=
'READY'
)
for
t
in
mytemplates
:
for
t
in
mytemplates
:
t
.
myshares
=
t
.
share_set
.
filter
(
group
=
group
)
t
.
myshares
=
t
.
share_set
.
filter
(
group
=
group
)
...
@@ -175,7 +170,7 @@ def group_show(request, gid):
...
@@ -175,7 +170,7 @@ def group_show(request, gid):
'mytemplates'
:
mytemplates
,
'mytemplates'
:
mytemplates
,
'publictemplates'
:
publictemplates
,
'publictemplates'
:
publictemplates
,
'noshare'
:
not
has_share
,
'noshare'
:
not
has_share
,
'userdetails'
:
UserCloudDetails
.
objects
.
get
(
user
=
request
.
user
),
'userdetails'
:
UserCloudDetails
.
objects
.
get
(
user
=
user
),
'owners'
:
group
.
owners
.
all
(),
'owners'
:
group
.
owners
.
all
(),
}))
}))
...
...
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