Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-openid-auth
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-openid-auth
Commits
406b9dde
Commit
406b9dde
authored
Jun 21, 2009
by
Stuart Metcalfe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch Group and extend UserChangeForm to be teams-aware
parent
511a27aa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
django_openid_auth/forms.py
+37
-0
No files found.
django_openid_auth/forms.py
View file @
406b9dde
...
...
@@ -27,13 +27,50 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import
settings
from
django
import
forms
from
django.contrib.auth.admin
import
UserAdmin
from
django.contrib.auth.forms
import
UserChangeForm
from
django.contrib.auth.models
import
Group
from
django.utils.translation
import
ugettext
as
_
from
django.conf
import
settings
from
openid.yadis
import
xri
def
teams_new_unicode
(
self
):
"""
Replacement for Group.__unicode__()
Calls original method to chain results
"""
name
=
self
.
unicode_before_teams
()
teams_mapping
=
getattr
(
settings
,
'OPENID_LAUNCHPAD_TEAMS_MAPPING'
,
{})
group_teams
=
[
t
for
t
in
teams_mapping
if
teams_mapping
[
t
]
==
self
.
name
]
if
len
(
group_teams
)
>
0
:
return
"
%
s ->
%
s"
%
(
name
,
", "
.
join
(
group_teams
))
else
:
return
name
Group
.
unicode_before_teams
=
Group
.
__unicode__
Group
.
__unicode__
=
teams_new_unicode
class
UserChangeFormWithTeamRestriction
(
UserChangeForm
):
"""
Extends UserChangeForm to add teams awareness to the user admin form
"""
def
clean_groups
(
self
):
data
=
self
.
cleaned_data
[
'groups'
]
teams_mapping
=
getattr
(
settings
,
'OPENID_LAUNCHPAD_TEAMS_MAPPING'
,
{})
known_teams
=
teams_mapping
.
values
()
user_groups
=
self
.
instance
.
groups
.
all
()
for
group
in
data
:
if
group
.
name
in
known_teams
and
group
not
in
user_groups
:
raise
forms
.
ValidationError
(
"""The group
%
s is mapped to an
external team. You cannot assign it manually."""
%
group
.
name
)
return
data
UserAdmin
.
form
=
UserChangeFormWithTeamRestriction
class
OpenIDLoginForm
(
forms
.
Form
):
openid_identifier
=
forms
.
CharField
(
max_length
=
255
,
...
...
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