Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hshassets
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
django
hshassets
Commits
04833031
Commit
04833031
authored
7 years ago
by
Tim Fechner
Browse files
Options
Downloads
Patches
Plain Diff
Add more widgets that needs class="input"
parent
44ffb521
No related branches found
No related tags found
1 merge request
!2
Change class rendering.
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hshassets/forms/utils.py
+14
-1
14 additions, 1 deletion
hshassets/forms/utils.py
hshassets/templatetags/bulma.py
+8
-4
8 additions, 4 deletions
hshassets/templatetags/bulma.py
with
22 additions
and
5 deletions
hshassets/forms/utils.py
+
14
−
1
View file @
04833031
from
django.utils.safestring
import
mark_safe
from
django.utils.safestring
import
mark_safe
from
django.utils.html
import
format_html
,
format_html_join
from
django.utils.html
import
format_html
,
format_html_join
from
django.template
import
defaulttags
from
django.template
import
defaulttags
from
django.forms
import
widgets
def
render_form_field
(
field
,
label
=
None
):
def
render_form_field
(
field
,
label
=
None
):
...
@@ -88,7 +89,12 @@ class BulmaFieldMarkup(object):
...
@@ -88,7 +89,12 @@ class BulmaFieldMarkup(object):
@classmethod
@classmethod
def
select
(
cls
,
field
,
content
):
def
select
(
cls
,
field
,
content
):
"""
Dropdowns have an extra wrapping <div class=
"
select
"
>
"""
"""
Dropdowns have an extra wrapping <div class=
"
select
"
>
"""
return
cls
.
label
(
field
.
label
,
cls
.
div_control
(
format_html
(
'
<div class=
"
select
"
>{}</div>
'
,
content
)))
if
isinstance
(
field
.
field
.
widget
,
widgets
.
SelectMultiple
):
css_classes
=
'
select is-multiple
'
else
:
css_classes
=
'
select
'
return
cls
.
label
(
field
.
label
,
cls
.
div_control
(
format_html
(
'
<div class=
"
{}
"
>{}</div>
'
,
css_classes
,
content
)))
@classmethod
@classmethod
def
checkbox
(
cls
,
field
,
content
):
def
checkbox
(
cls
,
field
,
content
):
...
@@ -142,3 +148,10 @@ def render_form_errors(errors):
...
@@ -142,3 +148,10 @@ def render_form_errors(errors):
"""
,
"""
,
error_tags
=
error_tags
,
error_tags
=
error_tags
,
)
)
def
instance_of
(
field_widget
,
widget_list
):
for
widget
in
widget_list
:
if
isinstance
(
field_widget
,
widget
):
return
True
return
False
This diff is collapsed.
Click to expand it.
hshassets/templatetags/bulma.py
+
8
−
4
View file @
04833031
from
django
import
template
from
django
import
template
from
django.utils.safestring
import
mark_safe
from
django.utils.safestring
import
mark_safe
from
django.forms.widgets
import
TextInput
,
Textarea
from
django.forms
import
widgets
from
hshassets.forms.utils
import
render_form_field
,
render_form_generics
,
render_form_errors
from
hshassets.forms.utils
import
render_form_field
,
render_form_generics
,
render_form_errors
,
instance_of
from
hshassets.forms.elements
import
Field
from
hshassets.forms.elements
import
Field
register
=
template
.
Library
()
register
=
template
.
Library
()
...
@@ -17,9 +18,12 @@ def bulma_form_fields(form):
...
@@ -17,9 +18,12 @@ def bulma_form_fields(form):
widget_classes
=
list
()
widget_classes
=
list
()
# not every form element in bulma has the 'input' css class, so we need to differ here
# not every form element in bulma has the 'input' css class, so we need to differ here
if
isinstance
(
field
.
field
.
widget
,
TextInput
):
field_widget
=
field
.
field
.
widget
if
instance_of
(
field_widget
,
[
widgets
.
TextInput
,
widgets
.
NumberInput
,
widgets
.
EmailInput
,
widgets
.
URLInput
,
widgets
.
PasswordInput
]):
widget_classes
.
append
(
"
input
"
)
widget_classes
.
append
(
"
input
"
)
elif
isinstance
(
field
.
field
.
widget
,
Textarea
):
elif
isinstance
(
field
.
field
.
widget
,
widgets
.
Textarea
):
widget_classes
.
append
(
"
textarea
"
)
widget_classes
.
append
(
"
textarea
"
)
# highlight fields with errors
# highlight fields with errors
...
...
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