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
bab6a711
Commit
bab6a711
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Plain Diff
Merge branch '337-add-option-to-define-rows-for-preferences-forms' into 'master'
Resolve "Add option to define rows for preferences forms" Closes
#337
See merge request
!422
parents
c7621afe
8b8b6ec2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!422
Resolve "Add option to define rows for preferences forms"
Pipeline
#5105
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/core/util/forms.py
+34
-0
34 additions, 0 deletions
aleksis/core/util/forms.py
aleksis/core/views.py
+4
-0
4 additions, 0 deletions
aleksis/core/views.py
with
38 additions
and
0 deletions
aleksis/core/util/forms.py
0 → 100644
+
34
−
0
View file @
bab6a711
from
collections
import
OrderedDict
from
material
import
Layout
,
Row
class
PreferenceLayout
(
Layout
):
"""
django-material Layout object for managing preferences.
"""
def
__init__
(
self
,
form_base_class
,
section
=
None
):
"""
Create Layout object for the given form_base_class.
:param form_base_class: A Form class used as the base. Must have a ``registry` attribute
:param section: A section where the layout builder will load preferences
"""
registry
=
form_base_class
.
registry
if
section
:
# Try to use section param
preferences_obj
=
registry
.
preferences
(
section
=
section
)
else
:
# display all preferences in the form
preferences_obj
=
registry
.
preferences
()
rows
=
OrderedDict
()
for
preference
in
preferences_obj
:
row_name
=
preference
.
get
(
"
row
"
,
preference
.
identifier
())
rows
.
setdefault
(
row_name
,
[])
rows
[
row_name
].
append
(
preference
.
identifier
())
rows_material
=
[]
for
fields
in
rows
.
values
():
rows_material
.
append
(
Row
(
*
fields
))
super
().
__init__
(
*
rows_material
)
This diff is collapsed.
Click to expand it.
aleksis/core/views.py
+
4
−
0
View file @
bab6a711
...
...
@@ -75,6 +75,7 @@ from .tables import (
from
.util
import
messages
from
.util.apps
import
AppConfig
from
.util.core_helpers
import
objectgetter_optional
from
.util.forms
import
PreferenceLayout
@permission_required
(
"
core.view_dashboard
"
)
...
...
@@ -545,6 +546,9 @@ def preferences(
# Build final form from dynamic-preferences
form_class
=
preference_form_builder
(
form_class
,
instance
=
instance
,
section
=
section
)
# Get layout
form_class
.
layout
=
PreferenceLayout
(
form_class
,
section
=
section
)
if
request
.
method
==
"
POST
"
:
form
=
form_class
(
request
.
POST
,
request
.
FILES
or
None
)
if
form
.
is_valid
():
...
...
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