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
c2635d2e
Verified
Commit
c2635d2e
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add form for actions on multiple objects
parent
df3e032a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!502
Add support to build tables and forms for executing actions for multiple objects
Pipeline
#6199
passed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/forms.py
+41
-0
41 additions, 0 deletions
aleksis/core/forms.py
with
41 additions
and
0 deletions
aleksis/core/forms.py
+
41
−
0
View file @
c2635d2e
from
datetime
import
datetime
,
time
from
typing
import
Callable
,
Dict
,
List
,
Sequence
,
Tuple
from
django
import
forms
from
django.contrib.auth
import
get_user_model
from
django.core.exceptions
import
ValidationError
from
django.db.models
import
QuerySet
from
django.http
import
HttpRequest
from
django.utils.translation
import
gettext_lazy
as
_
from
django_select2.forms
import
ModelSelect2MultipleWidget
,
ModelSelect2Widget
,
Select2Widget
...
...
@@ -370,3 +373,41 @@ class DashboardWidgetOrderForm(ExtensibleForm):
DashboardWidgetOrderFormSet
=
forms
.
formset_factory
(
form
=
DashboardWidgetOrderForm
,
max_num
=
0
,
extra
=
0
)
class
ActionForm
(
forms
.
Form
):
layout
=
Layout
(
"
action
"
)
actions
=
[]
def
get_actions
(
self
)
->
Sequence
[
Callable
]:
return
self
.
actions
def
_get_actions_dict
(
self
)
->
Dict
[
str
,
Callable
]:
return
{
value
.
__name__
:
value
for
value
in
self
.
get_actions
()}
def
_get_action_choices
(
self
)
->
List
[
Tuple
[
str
,
str
]]:
return
[
(
value
.
__name__
,
getattr
(
value
,
"
short_description
"
,
value
.
__name__
))
for
value
in
self
.
get_actions
()
]
def
get_queryset
(
self
)
->
QuerySet
:
raise
NotImplementedError
(
"
Queryset necessary.
"
)
action
=
forms
.
ChoiceField
(
choices
=
[])
selected_objects
=
forms
.
ModelMultipleChoiceField
(
queryset
=
None
)
def
__init__
(
self
,
request
:
HttpRequest
,
*
args
,
queryset
:
QuerySet
=
None
,
**
kwargs
):
self
.
request
=
request
self
.
queryset
=
queryset
if
isinstance
(
queryset
,
QuerySet
)
else
self
.
get_queryset
()
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
"
selected_objects
"
].
queryset
=
self
.
queryset
self
.
fields
[
"
action
"
].
choices
=
self
.
_get_action_choices
()
def
execute
(
self
)
->
bool
:
if
self
.
is_valid
():
qs
=
self
.
cleaned_data
[
"
selected_objects
"
]
action
=
self
.
_get_actions_dict
()[
self
.
cleaned_data
[
"
action
"
]]
action
(
None
,
self
.
request
,
qs
)
return
True
return
False
This diff is collapsed.
Click to expand it.
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