Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
irul
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fbef0a9c
authored
Jan 01, 2025
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan widget file
1 parent
4cacc37b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
67 deletions
opensipkd/base/views/base_views.py
opensipkd/base/views/widget_os.py
opensipkd/base/views/widgets/file_upload.pt
opensipkd/base/views/widgets/moneyinput.pt
opensipkd/base/views/widgets/readonly/money_input.pt
opensipkd/base/views/base_views.py
View file @
fbef0a9
...
...
@@ -53,15 +53,19 @@ class BaseView(object):
# self.akhir = dmy(self.dt_akhir)
# self.ses["dt_awal"] = self.dt_awal
# self.ses["dt_akhir"] = self.dt_akhir
self
.
tahun
=
'tahun'
in
self
.
ses
and
self
.
ses
[
'tahun'
]
or
now
.
strftime
(
'
%
Y'
)
self
.
tahun
=
'tahun'
in
self
.
ses
and
self
.
ses
[
'tahun'
]
or
now
.
strftime
(
'
%
Y'
)
self
.
tahun
=
'tahun'
in
self
.
params
and
self
.
params
[
'tahun'
]
or
self
.
tahun
self
.
ses
[
'tahun'
]
=
self
.
tahun
self
.
bulan
=
'bulan'
in
self
.
ses
and
self
.
ses
[
'bulan'
]
or
now
.
strftime
(
'
%
m'
)
self
.
bulan
=
'bulan'
in
self
.
ses
and
self
.
ses
[
'bulan'
]
or
now
.
strftime
(
'
%
m'
)
if
'bulan'
in
self
.
params
and
self
.
params
[
'bulan'
]:
self
.
bulan
=
self
.
params
[
'bulan'
]
.
strip
()
.
zfill
(
2
)
dt_awal
=
date_from_str
(
'{d}-{m}-{y}'
.
format
(
y
=
self
.
tahun
,
m
=
self
.
bulan
,
d
=
'01'
))
dt_akhir
=
dt_awal
+
relativedelta
(
months
=
1
)
-
relativedelta
(
days
=
1
)
dt_awal
=
date_from_str
(
'{d}-{m}-{y}'
.
format
(
y
=
self
.
tahun
,
m
=
self
.
bulan
,
d
=
'01'
))
dt_akhir
=
dt_awal
+
\
relativedelta
(
months
=
1
)
-
relativedelta
(
days
=
1
)
self
.
ses
[
'awal'
]
=
dmy
(
dt_awal
)
self
.
ses
[
'akhir'
]
=
dmy
(
dt_akhir
)
...
...
@@ -71,7 +75,7 @@ class BaseView(object):
if
'posted'
in
self
.
params
and
self
.
params
[
'posted'
]:
posted
=
self
.
params
[
'posted'
]
self
.
posted
=
((
posted
==
'true'
or
posted
==
'1'
)
and
1
)
or
(
(
posted
==
'false'
or
posted
==
'0'
)
and
0
)
or
0
(
posted
==
'false'
or
posted
==
'0'
)
and
0
)
or
0
self
.
ses
[
'posted'
]
=
self
.
posted
self
.
awal
=
'awal'
in
self
.
ses
and
self
.
ses
[
'awal'
]
or
dmy
(
now
)
...
...
@@ -292,7 +296,8 @@ class BaseView(object):
if
not
list_url
and
self
.
list_route
:
list_url
=
self
.
req
.
route_url
(
self
.
list_route
)
else
:
list_url
=
list_url
and
list_url
[
0
:
1
]
!=
"/"
and
"/"
+
list_url
or
list_url
list_url
=
list_url
and
list_url
[
0
:
1
]
!=
"/"
and
"/"
+
\
list_url
or
list_url
list_url
=
self
.
home
+
list_url
table
=
DeTable
(
schema
,
...
...
@@ -361,7 +366,7 @@ class BaseView(object):
for
d
in
list_schema
():
global_search
=
True
search_method
=
hasattr
(
d
,
"search_method"
)
\
and
getattr
(
d
,
"search_method"
)
or
"string_contains"
and
getattr
(
d
,
"search_method"
)
or
"string_contains"
if
hasattr
(
d
,
"global_search"
):
if
d
.
global_search
==
False
:
global_search
=
False
...
...
@@ -504,7 +509,7 @@ class BaseView(object):
def
view_view
(
self
,
**
kwargs
):
# row = query_id(request).first()
request
=
self
.
req
row
=
self
.
query_id
()
.
first
()
self
.
ses
[
"readonly"
]
=
True
self
.
ses
[
"readonly"
]
=
True
if
not
row
:
return
self
.
id_not_found
()
is_object
=
kwargs
.
get
(
"is_object"
,
self
.
is_object
)
...
...
@@ -638,13 +643,14 @@ class BaseView(object):
is_object
=
kwargs
.
get
(
"is_object"
,
self
.
is_object
)
kwargs
[
"is_object"
]
=
is_object
table
=
self
.
get_item_table
(
**
kwargs
)
self
.
ses
[
"readonly"
]
=
False
self
.
ses
[
"readonly"
]
=
False
if
self
.
req
.
POST
:
if
'save'
in
self
.
req
.
POST
:
controls
=
self
.
req
.
POST
.
items
()
try
:
c
=
form
.
validate
(
controls
)
except
ValidationFailure
as
e
:
value
=
self
.
before_add
()
# value = self.validation_failure(e.cstruct)
# value.update(self.before_add())
# form.render(appstruct=value)
...
...
@@ -657,6 +663,7 @@ class BaseView(object):
e
.
cstruct
[
f
.
name
])
if
f
.
name
==
"captcha"
:
e
.
cstruct
[
f
.
name
]
=
self
.
get_captcha_url
()
value
.
update
(
e
.
cstruct
)
form
.
set_appstruct
(
e
.
cstruct
)
return
self
.
returned_form
(
form
,
table
,
**
kwargs
)
...
...
@@ -746,7 +753,7 @@ class BaseView(object):
def
view_edit
(
self
,
**
kwargs
):
request
=
self
.
req
self
.
ses
[
"readonly"
]
=
False
self
.
ses
[
"readonly"
]
=
False
row
=
self
.
query_id
()
.
first
()
is_object
=
kwargs
.
get
(
"is_object"
,
self
.
is_object
)
kwargs
[
"is_object"
]
=
is_object
...
...
@@ -774,7 +781,7 @@ class BaseView(object):
try
:
controls
=
form
.
validate
(
controls
)
except
ValidationFailure
as
e
:
log
.
error
(
f
"Edit Error: {str(e.error)}"
)
log
.
error
(
f
"Edit Error: {str(e.error
.msg
)}"
)
# log.debug(f"Edit Data: {e.cstruct}")
form
.
set_appstruct
(
e
.
cstruct
)
return
self
.
returned_form
(
form
,
table
,
**
kwargs
)
...
...
@@ -800,7 +807,7 @@ class BaseView(object):
def
view_delete
(
self
,
**
kwargs
):
request
=
self
.
req
q
=
self
.
query_id
()
self
.
ses
[
"readonly"
]
=
True
self
.
ses
[
"readonly"
]
=
True
row
=
q
.
first
()
is_object
=
kwargs
.
get
(
"is_object"
,
self
.
is_object
)
kwargs
[
"is_object"
]
=
is_object
...
...
@@ -886,11 +893,14 @@ class BaseView(object):
filename
=
file_dict
[
"filename"
]
.
lower
()
ext
=
get_ext
(
filename
)
if
ext
not
in
self
.
upload_exts
:
error
.
append
((
field
,
InvalidExtension
(
self
.
upload_exts
)
.
error
))
error
.
append
(
(
field
,
InvalidExtension
(
self
.
upload_exts
)
.
error
))
else
:
full_file_name
=
upload
.
save_to_file
(
input_file
,
ext
,
filename
)
full_file_name
=
upload
.
save_to_file
(
input_file
,
ext
,
filename
)
if
ext
==
".avi"
:
full_file_name
=
self
.
convert_avi_to_mp4
(
full_file_name
)
full_file_name
=
self
.
convert_avi_to_mp4
(
full_file_name
)
file_name
=
os
.
path
.
split
(
full_file_name
)[
1
]
return
file_name
...
...
@@ -938,4 +948,4 @@ def need_verify():
def
get_url_captcha
(
request
):
captcha
=
get_captcha
(
request
)
return
os
.
path
.
join
(
get_urls
(
request
.
route_url
(
'home'
)),
'captcha'
,
captcha
)
\ No newline at end of file
return
os
.
path
.
join
(
get_urls
(
request
.
route_url
(
'home'
)),
'captcha'
,
captcha
)
opensipkd/base/views/widget_os.py
View file @
fbef0a9
...
...
@@ -393,7 +393,7 @@ class MapWidget(Widget):
{
"js"
:
"opensipkd.base:static/js/gmap.js"
,
"css"
:
"deform:static/select2/select2.css"
,
},)
},)
def
__init__
(
self
,
**
kw
):
super
()
.
__init__
(
**
kw
)
...
...
@@ -727,7 +727,24 @@ class DateInputWidget(WidgetDateInputWidget):
class
MoneyInputWidget
(
widget
.
MoneyInputWidget
):
readonly_template
=
"readonly/money_input"
readonly_template
=
"readonly/textinput"
def
get_template_values
(
self
,
field
,
cstruct
,
kw
):
options
=
json
.
loads
(
kw
.
get
(
"mask_options"
,
"{}"
))
if
options
:
decimal
=
options
.
get
(
"decimal"
,
'.'
)
precision
=
options
.
get
(
"precision"
,
2
)
thousands
=
options
.
get
(
"thousands"
,
','
)
cstr
=
cstruct
and
float
(
cstruct
)
or
0
cstruct
=
f
"{cstr:,.{precision}f}"
\
.
replace
(
"."
,
"
%
"
)
\
.
replace
(
","
,
thousands
)
\
.
replace
(
"
%
"
,
decimal
)
values
=
{
"cstruct"
:
cstruct
,
"field"
:
field
}
values
.
update
(
kw
)
values
.
pop
(
"template"
,
None
)
return
values
class
FilterWidget
(
Widget
):
...
...
@@ -849,4 +866,4 @@ class FilterWidget(Widget):
# tmpl_values = self.get_template_values(field, cstruct, kw)
# template = readonly and self.readonly_template or self.template
# return field.renderer(template, **tmpl_values)
#
\ No newline at end of file
#
opensipkd/base/views/widgets/file_upload.pt
View file @
fbef0a9
...
...
@@ -9,47 +9,37 @@
img ['jpg', 'jpeg', 'gif', 'png', 'svg', 'eps', 'psd'];
video ['avi', 'mov', 'mpv']
">
${field.start_mapping()}
<img tal:condition="ext in img" id="preview-${oid}" alt="" src="${preview_url}"
style="${style}"
onload="window.URL.revokeObjectURL(this.src);"></img>
<video tal:condition="ext in video" style="${style}" controls
src="${preview_url}" type="video/${ext}"
id="preview-${oid}">
Your browser does not support the video tag.
</video>
${field.start_mapping()}
<div class="thumbnail">
<img tal:condition="ext in img" id="preview-${oid}" alt="" src="${preview_url}" style="${style}"
onload="window.URL.revokeObjectURL(this.src);"></img>
<video tal:condition="ext in video" style="${style}" controls src="${preview_url}" type="video/${ext}"
id="preview-${oid}">
Your browser does not support the video tag.
</video>
<video tal:condition="ext=='mp4'" controls style="${style}" src="${preview_url}" type="video/mp4"
id="preview-${oid}">
Your browser does not support the video tag.
</video>
<video tal:condition="ext=='mp4'"
controls
style="${style}"
src="${preview_url}"
type="video/mp4"
id="preview-${oid}">
Your browser does not support the video tag.
</video>
<embed tal:condition="ext=='pdf'" src="${preview_url}" style="${style}" id="preview-${oid}">
</div>
<a class="label label-default" href="${preview_url}" target="_blank" id="a-preview-${oid}"><i
class="fa fa-search"></i> View</a>
<embed tal:condition="ext=='pdf'" src="${preview_url}" style="${style}"
id="preview-${oid}">
<a class="label label-default" href="${preview_url}"
target="_blank" id="a-preview-${oid}"><i class="fa fa-search"></i> View</a>
<input type="file" name="upload" id="${oid}"
tal:attributes="style style;
<input type="file" name="upload" id="${oid}" tal:attributes="style style;
accept accept|field.widget.accept;
data-filename fname;
attributes|field.widget.attributes|{};"/>
<input tal:define="uid cstruct.get('uid')"
tal:condition="uid"
type="hidden" name="uid" value="${uid}"/>
${field.end_mapping()}
attributes|field.widget.attributes|{};" />
<input tal:define="uid cstruct.get('uid')" tal:condition="uid" type="hidden" name="uid" value="${uid}" />
${field.end_mapping()}
<script type="text/javascript">
deform.addCallback('${oid}', function (oid) {
$('#' + oid).upload();
});
document.getElementById("${oid}").onchange = function () {
if (this.files[0].size > ${
maxsize
}) {
if (this.files[0].size > ${
maxsize
}) {
alert("File is too big!");
this.value = "";
document.getElementById('preview-' + this.id).src = '';
...
...
opensipkd/base/views/widgets/moneyinput.pt
View file @
fbef0a9
...
...
@@ -3,18 +3,16 @@
mask_options mask_options|'{}';
style style|field.widget.style;
css_class css_class|field.widget.css_class;
style style|field.widget.style|False"
tal:omit-tag="">
<input type="text" name="${name}" value="${cstruct}"
tal:attributes="style style;
style style|field.widget.style|False" tal:omit-tag="">
<input type="text" name="${name}" value="${cstruct}" tal:attributes="style style;
class string: form-control ${css_class or ''};
attributes|field.widget.attributes|{};"
id="${oid}"/>
<script type="text/javascript">
attributes|field.widget.attributes|{};" id="${oid}" />
<script type="text/javascript">
deform.addCallback(
'${oid}',
function (oid) {
$("#" + oid).maskMoney(${mask_options});
//$("#" + oid).maskMoney(${mask_options});
$("#" + oid).maskMoney(${ mask_options }, $("#" + oid).val());
});
</script>
</span>
</script>
</span>
\ No newline at end of file
opensipkd/base/views/widgets/readonly/money_input.pt
View file @
fbef0a9
<p class="form-control-static" id="${oid|field.oid}">
</p>
<p class="form-control-static" id="${oid|field.oid}" tal:define="mask_options mask_options|'{}';"></p>
<script type="text/javascript">
deform.addCallback(
'${oid|field.oid}',
function (oid) {
let val = parseInt('${cstruct}');
$("#" + oid).html(val.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}));
let val = parseFloat('${cstruct}');
$("#" + oid).html(val.toLocaleString());
});
</script>
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment