Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
TO
Helios Server
Commits
350fd20e
Unverified
Commit
350fd20e
authored
6 years ago
by
Marco Ciotola
Browse files
Options
Downloads
Patches
Plain Diff
[DJ1.11] Fix widgets
parent
18e24106
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
helios/datetimewidget.py
+2
-0
2 additions, 0 deletions
helios/datetimewidget.py
helios/widgets.py
+12
-16
12 additions, 16 deletions
helios/widgets.py
with
14 additions
and
16 deletions
helios/datetimewidget.py
+
2
−
0
View file @
350fd20e
...
@@ -25,6 +25,8 @@ calbtn = u'''<img src="%smedia/admin/img/admin/icon_calendar.gif" alt="calendar"
...
@@ -25,6 +25,8 @@ calbtn = u'''<img src="%smedia/admin/img/admin/icon_calendar.gif" alt="calendar"
</script>
'''
</script>
'''
class
DateTimeWidget
(
forms
.
widgets
.
TextInput
):
class
DateTimeWidget
(
forms
.
widgets
.
TextInput
):
template_name
=
''
class
Media
:
class
Media
:
css
=
{
css
=
{
'
all
'
:
(
'
all
'
:
(
...
...
This diff is collapsed.
Click to expand it.
helios/widgets.py
+
12
−
16
View file @
350fd20e
...
@@ -35,6 +35,7 @@ class SelectTimeWidget(Widget):
...
@@ -35,6 +35,7 @@ class SelectTimeWidget(Widget):
Also allows user-defined increments for minutes/seconds
Also allows user-defined increments for minutes/seconds
"""
"""
template_name
=
''
hour_field
=
'
%s_hour
'
hour_field
=
'
%s_hour
'
minute_field
=
'
%s_minute
'
minute_field
=
'
%s_minute
'
meridiem_field
=
'
%s_meridiem
'
meridiem_field
=
'
%s_meridiem
'
...
@@ -46,7 +47,7 @@ class SelectTimeWidget(Widget):
...
@@ -46,7 +47,7 @@ class SelectTimeWidget(Widget):
for the range of values for the associated select element
for the range of values for the associated select element
twelve_hr: If True, forces the output to be in 12-hr format (rather than 24-hr)
twelve_hr: If True, forces the output to be in 12-hr format (rather than 24-hr)
"""
"""
s
elf
.
attrs
=
attrs
or
{}
s
uper
(
SelectTimeWidget
,
self
).
__init__
(
attrs
)
if
twelve_hr
:
if
twelve_hr
:
self
.
twelve_hr
=
True
# Do 12hr (rather than 24hr)
self
.
twelve_hr
=
True
# Do 12hr (rather than 24hr)
...
@@ -66,7 +67,7 @@ class SelectTimeWidget(Widget):
...
@@ -66,7 +67,7 @@ class SelectTimeWidget(Widget):
else
:
else
:
self
.
minutes
=
range
(
0
,
60
)
self
.
minutes
=
range
(
0
,
60
)
def
render
(
self
,
name
,
value
,
attrs
=
None
):
def
render
(
self
,
name
,
value
,
attrs
=
None
,
renderer
=
None
):
try
:
# try to get time values from a datetime.time object (value)
try
:
# try to get time values from a datetime.time object (value)
hour_val
,
minute_val
=
value
.
hour
,
value
.
minute
hour_val
,
minute_val
=
value
.
hour
,
value
.
minute
if
self
.
twelve_hr
:
if
self
.
twelve_hr
:
...
@@ -79,7 +80,7 @@ class SelectTimeWidget(Widget):
...
@@ -79,7 +80,7 @@ class SelectTimeWidget(Widget):
if
isinstance
(
value
,
basestring
):
if
isinstance
(
value
,
basestring
):
match
=
RE_TIME
.
match
(
value
)
match
=
RE_TIME
.
match
(
value
)
if
match
:
if
match
:
time_groups
=
match
.
groups
()
;
time_groups
=
match
.
groups
()
hour_val
=
int
(
time_groups
[
HOURS
])
%
24
# force to range(0-24)
hour_val
=
int
(
time_groups
[
HOURS
])
%
24
# force to range(0-24)
minute_val
=
int
(
time_groups
[
MINUTES
])
minute_val
=
int
(
time_groups
[
MINUTES
])
...
@@ -116,7 +117,7 @@ class SelectTimeWidget(Widget):
...
@@ -116,7 +117,7 @@ class SelectTimeWidget(Widget):
minute_val
=
u
"
%.2d
"
%
minute_val
minute_val
=
u
"
%.2d
"
%
minute_val
hour_choices
=
[(
"
%.2d
"
%
i
,
"
%.2d
"
%
i
)
for
i
in
self
.
hours
]
hour_choices
=
[(
"
%.2d
"
%
i
,
"
%.2d
"
%
i
)
for
i
in
self
.
hours
]
local_attrs
=
self
.
build_attrs
(
id
=
self
.
hour_field
%
id_
)
local_attrs
=
self
.
build_attrs
(
{
'
id
'
:
self
.
hour_field
%
id_
}
)
select_html
=
Select
(
choices
=
hour_choices
).
render
(
self
.
hour_field
%
name
,
hour_val
,
local_attrs
)
select_html
=
Select
(
choices
=
hour_choices
).
render
(
self
.
hour_field
%
name
,
hour_val
,
local_attrs
)
output
.
append
(
select_html
)
output
.
append
(
select_html
)
...
@@ -168,6 +169,8 @@ class SplitSelectDateTimeWidget(MultiWidget):
...
@@ -168,6 +169,8 @@ class SplitSelectDateTimeWidget(MultiWidget):
This class combines SelectTimeWidget and SelectDateWidget so we have something
This class combines SelectTimeWidget and SelectDateWidget so we have something
like SpliteDateTimeWidget (in django.forms.widgets), but with Select elements.
like SpliteDateTimeWidget (in django.forms.widgets), but with Select elements.
"""
"""
template_name
=
''
def
__init__
(
self
,
attrs
=
None
,
hour_step
=
None
,
minute_step
=
None
,
twelve_hr
=
None
,
years
=
None
):
def
__init__
(
self
,
attrs
=
None
,
hour_step
=
None
,
minute_step
=
None
,
twelve_hr
=
None
,
years
=
None
):
"""
pass all these parameters to their respective widget constructors...
"""
"""
pass all these parameters to their respective widget constructors...
"""
widgets
=
(
SelectDateWidget
(
attrs
=
attrs
,
years
=
years
),
SelectTimeWidget
(
attrs
=
attrs
,
hour_step
=
hour_step
,
minute_step
=
minute_step
,
twelve_hr
=
twelve_hr
))
widgets
=
(
SelectDateWidget
(
attrs
=
attrs
,
years
=
years
),
SelectTimeWidget
(
attrs
=
attrs
,
hour_step
=
hour_step
,
minute_step
=
minute_step
,
twelve_hr
=
twelve_hr
))
...
@@ -184,13 +187,6 @@ class SplitSelectDateTimeWidget(MultiWidget):
...
@@ -184,13 +187,6 @@ class SplitSelectDateTimeWidget(MultiWidget):
return
[
value
.
date
(),
value
.
time
().
replace
(
microsecond
=
0
)]
return
[
value
.
date
(),
value
.
time
().
replace
(
microsecond
=
0
)]
return
[
None
,
None
]
return
[
None
,
None
]
def
format_output
(
self
,
rendered_widgets
):
def
render
(
self
,
name
,
value
,
attrs
=
None
,
renderer
=
None
):
"""
rendered_widgets
=
list
(
widget
.
render
(
name
,
value
,
attrs
=
attrs
,
renderer
=
renderer
)
for
widget
in
self
.
widgets
)
Given a list of rendered widgets (as strings), it inserts an HTML
return
u
'
<br/>
'
.
join
(
rendered_widgets
)
linebreak between them.
Returns a Unicode string representing the HTML for the whole lot.
"""
rendered_widgets
.
insert
(
-
1
,
'
<br/>
'
)
return
u
''
.
join
(
rendered_widgets
)
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