Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
e38fa752
Verified
Commit
e38fa752
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Drop form for assigning accounts to persons
parent
752197d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!750
Resolve "person_accounts view hangs while rendering template"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/forms.py
+20
-50
20 additions, 50 deletions
aleksis/core/forms.py
aleksis/core/rules.py
+1
-5
1 addition, 5 deletions
aleksis/core/rules.py
aleksis/core/views.py
+0
-1
0 additions, 1 deletion
aleksis/core/views.py
with
21 additions
and
56 deletions
aleksis/core/forms.py
+
20
−
50
View file @
e38fa752
...
...
@@ -34,54 +34,6 @@ from .registries import (
from
.util.core_helpers
import
get_site_preferences
class
PersonAccountForm
(
forms
.
ModelForm
):
"""
Form to assign user accounts to persons in the frontend.
"""
class
Meta
:
model
=
Person
fields
=
[
"
last_name
"
,
"
first_name
"
,
"
user
"
]
widgets
=
{
"
user
"
:
Select2Widget
(
attrs
=
{
"
class
"
:
"
browser-default
"
})}
new_user
=
forms
.
CharField
(
required
=
False
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
# Fields displayed only for informational purposes
self
.
fields
[
"
first_name
"
].
disabled
=
True
self
.
fields
[
"
last_name
"
].
disabled
=
True
def
clean
(
self
)
->
None
:
user
=
get_user_model
()
if
self
.
cleaned_data
.
get
(
"
new_user
"
,
None
):
if
self
.
cleaned_data
.
get
(
"
user
"
,
None
):
# The user selected both an existing user and provided a name to create a new one
self
.
add_error
(
"
new_user
"
,
_
(
"
You cannot set a new username when also selecting an existing user.
"
),
)
elif
user
.
objects
.
filter
(
username
=
self
.
cleaned_data
[
"
new_user
"
]).
exists
():
# The user tried to create a new user with the name of an existing user
self
.
add_error
(
"
new_user
"
,
_
(
"
This username is already in use.
"
))
else
:
# Create new User object and assign to form field for existing user
new_user_obj
=
user
.
objects
.
create_user
(
self
.
cleaned_data
[
"
new_user
"
],
self
.
instance
.
email
,
first_name
=
self
.
instance
.
first_name
,
last_name
=
self
.
instance
.
last_name
,
)
self
.
cleaned_data
[
"
user
"
]
=
new_user_obj
# Formset for batch-processing of assignments of users to persons
PersonsAccountsFormSet
=
forms
.
modelformset_factory
(
Person
,
form
=
PersonAccountForm
,
max_num
=
0
,
extra
=
0
)
class
EditPersonForm
(
ExtensibleForm
):
"""
Form to edit an existing person object in the frontend.
"""
...
...
@@ -159,8 +111,26 @@ class EditPersonForm(ExtensibleForm):
self
.
fields
[
field
].
disabled
=
True
def
clean
(
self
)
->
None
:
# Use code implemented in dedicated form to verify user selection
return
PersonAccountForm
.
clean
(
self
)
if
self
.
cleaned_data
.
get
(
"
new_user
"
,
None
):
if
self
.
cleaned_data
.
get
(
"
user
"
,
None
):
# The user selected both an existing user and provided a name to create a new one
self
.
add_error
(
"
new_user
"
,
_
(
"
You cannot set a new username when also selecting an existing user.
"
),
)
elif
user
.
objects
.
filter
(
username
=
self
.
cleaned_data
[
"
new_user
"
]).
exists
():
# The user tried to create a new user with the name of an existing user
self
.
add_error
(
"
new_user
"
,
_
(
"
This username is already in use.
"
))
else
:
# Create new User object and assign to form field for existing user
new_user_obj
=
user
.
objects
.
create_user
(
self
.
cleaned_data
[
"
new_user
"
],
self
.
instance
.
email
,
first_name
=
self
.
instance
.
first_name
,
last_name
=
self
.
instance
.
last_name
,
)
self
.
cleaned_data
[
"
user
"
]
=
new_user_obj
class
EditGroupForm
(
SchoolTermRelatedExtensibleForm
):
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/rules.py
+
1
−
5
View file @
e38fa752
...
...
@@ -154,11 +154,7 @@ rules.add_perm("core.view_system_status_rule", view_system_status_predicate)
rules
.
add_perm
(
"
core.view_people_menu_rule
"
,
has_person
&
(
view_persons_predicate
|
view_groups_predicate
|
assign_child_groups_to_groups_predicate
),
&
(
view_persons_predicate
|
view_groups_predicate
|
assign_child_groups_to_groups_predicate
),
)
# View person personal details
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/views.py
+
0
−
1
View file @
e38fa752
...
...
@@ -63,7 +63,6 @@ from .forms import (
EditPersonForm
,
GroupPreferenceForm
,
PersonPreferenceForm
,
PersonsAccountsFormSet
,
SchoolTermForm
,
SitePreferenceForm
,
)
...
...
This diff is collapsed.
Click to expand it.
Jonathan Weth
@hansegucker
mentioned in commit
59fc5f50
·
3 years ago
mentioned in commit
59fc5f50
mentioned in commit 59fc5f50393bfb3cca67c6593fd36044d73dfce6
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment