Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a0632681
authored
Dec 08, 2024
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
penambahan list filter
1 parent
ae0b0fdb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
221 additions
and
48 deletions
opensipkd/base/views/base_views.py
opensipkd/base/views/widget_os.py
opensipkd/base/views/widgets/filters.pt
opensipkd/base/views/widgets/sequence.pt
opensipkd/detable/detable.py
opensipkd/detable/templates/detable.pt
opensipkd/base/views/base_views.py
View file @
a063268
...
...
@@ -139,13 +139,13 @@ class BaseView(object):
self
.
list_url
=
''
self
.
list_route
=
''
self
.
list_schema
=
colander
.
Schema
self
.
allow_view
=
True
self
.
allow_edit
=
True
self
.
allow_delete
=
True
self
.
allow_post
=
False
self
.
allow_unpost
=
False
self
.
state_save
=
False
self
.
allow_view
=
True
self
.
allow_edit
=
True
self
.
allow_delete
=
True
self
.
allow_post
=
False
self
.
allow_unpost
=
False
self
.
state_save
=
False
self
.
list_form
=
None
self
.
form_scripts
=
"""
$('#parent_nm').bind('typeahead:selected', function(obj, datum) {
...
...
@@ -262,7 +262,8 @@ class BaseView(object):
allow_post
=
allow_post
,
allow_unpost
=
allow_unpost
,
state_save
=
state_save
,
new_buttons
=
new_buttons
new_buttons
=
new_buttons
,
form
=
self
.
list_form
,
)
resources
=
table
.
get_widget_resources
()
# resources=dict(css="", js="")
...
...
opensipkd/base/views/widget_os.py
View file @
a063268
...
...
@@ -4,10 +4,11 @@ import logging
from
colander
import
SchemaNode
,
null
,
Mapping
,
Invalid
# , string_types
# from colander import compat # tidak ada di colander 2.0
from
deform
import
widget
from
deform.compat
import
sequence_types
,
text_type
from
deform.form
import
Button
from
deform.i18n
import
_
from
deform.widget
import
Widget
,
_StrippedString
,
Select2Widget
,
\
DateInputWidget
as
WidgetDateInputWidget
DateInputWidget
as
WidgetDateInputWidget
,
_normalize_choices
,
OptGroup
from
deform.widget
import
string_types
from
iso8601.iso8601
import
ISO8601_REGEX
...
...
@@ -392,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
)
...
...
@@ -729,31 +730,123 @@ class MoneyInputWidget(widget.MoneyInputWidget):
readonly_template
=
"readonly/money_input"
class
FilterWidget
(
Widget
):
template
=
"opensipkd.base:/views/widgets/filters.pt"
readonly_template
=
"opensipkd.base:/views/widgets/readonly/filters.pt"
null_value
=
""
values
=
()
size
=
None
multiple
=
False
optgroup_class
=
OptGroup
long_label_generator
=
None
selectize_options
=
None
default_selectize_options
=
((
"allowEmptyOption"
,
True
),)
_pstruct_schema
=
SchemaNode
(
Mapping
(),
SchemaNode
(
_StrippedString
(),
name
=
"fields"
),
SchemaNode
(
_StrippedString
(),
name
=
"equality"
),
SchemaNode
(
_StrippedString
(),
name
=
"nilai"
),
SchemaNode
(
_StrippedString
(),
name
=
"condition"
),
)
def
get_select_value
(
self
,
cstruct
,
value
):
"""Choose whether <opt> is selected or not.
Incoming value is always string, as it has been passed through HTML.
However, our values might be given as integer, UUID.
"""
if
self
.
multiple
:
if
value
in
map
(
text_type
,
cstruct
):
return
"selected"
else
:
if
value
==
text_type
(
cstruct
):
return
"selected"
return
None
def
serialize
(
self
,
field
,
cstruct
,
**
kw
):
if
cstruct
in
(
null
,
None
):
condition
=
""
fields
=
""
equality
=
""
nilai
=
""
else
:
fields
,
equality
,
nilai
,
condition
=
cstruct
.
split
(
"."
,
4
)
# if cstruct in (null, None):
# cstruct = self.null_value
kw
.
setdefault
(
"condition"
,
condition
)
kw
.
setdefault
(
"fields"
,
fields
)
kw
.
setdefault
(
"equality"
,
equality
)
kw
.
setdefault
(
"nilai"
,
nilai
)
readonly
=
kw
.
get
(
"readonly"
,
self
.
readonly
)
values
=
kw
.
get
(
"values"
,
self
.
values
)
if
not
isinstance
(
values
,
sequence_types
):
e
=
"Values must be a sequence type (list, tuple, or range)."
raise
TypeError
(
e
)
template
=
readonly
and
self
.
readonly_template
or
self
.
template
kw
[
"values"
]
=
_normalize_choices
(
values
)
selectize_options
=
dict
(
kw
.
get
(
"selectize_options"
)
or
self
.
selectize_options
or
self
.
default_selectize_options
)
kw
[
"selectize_options_json"
]
=
json
.
dumps
(
selectize_options
)
tmpl_values
=
self
.
get_template_values
(
field
,
cstruct
,
kw
)
return
field
.
renderer
(
template
,
**
tmpl_values
)
def
deserialize
(
self
,
field
,
pstruct
):
if
pstruct
is
null
:
return
null
else
:
try
:
validated
=
self
.
_pstruct_schema
.
deserialize
(
pstruct
)
except
Invalid
as
exc
:
raise
Invalid
(
field
.
schema
,
f
"Invalid pstruct: {exc}"
)
condition
=
validated
[
"condition"
]
fields
=
validated
[
"fields"
]
equality
=
validated
[
"equality"
]
nilai
=
validated
[
"nilai"
]
# if not year and not bundle and not seq:
# return null
#
# if self.assume_y2k and len(year) == 2:
# year = "20" + year
result
=
"."
.
join
([
fields
,
equality
,
nilai
,
condition
])
#
# if not year or not bundle or not seq:
# raise Invalid(field.schema, "No Dokumen tidak lengkap", result)
return
result
# class AutocompleteInputWidget(widget.AutocompleteInputWidget):
# targets = None
# def serialize(self, field, cstruct, **kw):
# item_id = kw.get("item_id", None)
# super().serialize(field, cstruct, **kw)
# if "delay" in kw or getattr(self, "delay", None):
# raise ValueError(
# "AutocompleteWidget does not support *delay* parameter "
# "any longer."
# )
# if cstruct in (null, None):
# cstruct = ""
# self.values = self.values or []
# readonly = kw.get("readonly", self.readonly)
#
# options = {}
# if isinstance(self.values, string_types):
# options["remote"] = "%s?term=%%QUERY" % self.values
# else:
# options["local"] = self.values
#
# options["minLength"] = kw.pop("min_length", self.min_length)
# options["limit"] = kw.pop("items", self.items)
# kw["options"] = json.dumps(options)
# 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
# def serialize(self, field, cstruct, **kw):
# item_id = kw.get("item_id", None)
# super().serialize(field, cstruct, **kw)
# if "delay" in kw or getattr(self, "delay", None):
# raise ValueError(
# "AutocompleteWidget does not support *delay* parameter "
# "any longer."
# )
# if cstruct in (null, None):
# cstruct = ""
# self.values = self.values or []
# readonly = kw.get("readonly", self.readonly)
#
# options = {}
# if isinstance(self.values, string_types):
# options["remote"] = "%s?term=%%QUERY" % self.values
# else:
# options["local"] = self.values
#
# options["minLength"] = kw.pop("min_length", self.min_length)
# options["limit"] = kw.pop("items", self.items)
# kw["options"] = json.dumps(options)
# 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/filters.pt
0 → 100644
View file @
a063268
<div i18n:domain="deform"
tal:omit-tag=""
tal:define="oid oid|field.oid;
name name|field.name;
oid oid|field.oid;
style style|field.widget.style;
size size|field.widget.size;
css_class css_class|field.widget.css_class;
unicode unicode|str;
optgroup_class optgroup_class|field.widget.optgroup_class;
multiple multiple|field.widget.multiple;"
tal:omit-tag="">
${field.start_mapping()}
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<span class="input-group-addon" i18n:translate="">Filter</span>
<select
id="${oid}-fields" name='fields'
tal:attributes="
class string: ${css_class or ''};
multiple multiple;
size size;
style style;
attributes|field.widget.attributes|{};">
<tal:loop tal:repeat="item values">
<optgroup tal:condition="isinstance(item, optgroup_class)"
tal:attributes="label item.label">
<option tal:repeat="(value, description) item.options"
tal:attributes="
selected python:field.widget.get_select_value(fields, value);
class css_class;
label field.widget.long_label_generator and description;
value value"
tal:content="field.widget.long_label_generator and field.widget.long_label_generator(item.label, description) or description"/>
</optgroup>
<option tal:condition="not isinstance(item, optgroup_class)"
tal:attributes="
selected python:field.widget.get_select_value(fields, item[0]);
class css_class;
value item[0]">${item[1]}</option>
</tal:loop>
</select>
<select name="equality" id="${oid}-equality">
<option value="eq">=</option>
<option value="gt" tal:attributes="
selected equality=='gt'">>
</option>
<option value="lt" tal:attributes="
selected equality=='lt'"><
</option>
<option value="gteq" tal:attributes="
selected equality=='gteq'">>=
</option>
<option value="lteq" tal:attributes="
selected equality=='lteq'"><=
</option>
</select>
<input type="text" name="nilai" value="${nilai}"
id="${oid}-value"/>
<select name="condition" id="${oid}-condition">
<option value="AND" tal:attributes="
selected condition=='AND'">AND
</option>
<option value="OR" tal:attributes="
selected condition=='OR'">OR
</option>
</select>
</div>
</div>
</div>
${field.end_mapping()}
</div>
\ No newline at end of file
opensipkd/base/views/widgets/sequence.pt
View file @
a063268
...
...
@@ -33,7 +33,7 @@
attributes|field.widget.attributes|{};"/>
<div class="panel panel-default">
<div class="panel-heading">${title}</div
>
<!--? <div class="panel-heading">${title}</div>--
>
<div class="panel-body">
<div class="deform-seq-container"
...
...
@@ -102,4 +102,4 @@
</div>
</div>
</div>
</div>
\ No newline at end of file
opensipkd/detable/detable.py
View file @
a063268
...
...
@@ -6,7 +6,7 @@ import re
import
colander
import
deform
from
deform
import
compat
from
deform
import
compat
,
Form
from
deform
import
field
from
.
import
widget
...
...
@@ -116,6 +116,8 @@ class DeTable(field.Field):
allow_view
=
True
,
allow_post
=
False
,
allow_unpost
=
False
,
form
=
None
,
form_object
=
False
,
**
kw
):
# field.Field.__init__(self, schema, **kw)
...
...
@@ -144,7 +146,8 @@ class DeTable(field.Field):
}
for
k
in
new_buttons
:
buttons
+=
(
new_buttons
[
k
][
"obj"
],)
dict_buttons
[
k
]
=
'{'
+
new_buttons
[
k
][
"js"
]
.
format
(
tableid
=
tableid
,
params
=
params
)
+
'}'
dict_buttons
[
k
]
=
'{'
+
new_buttons
[
k
][
"js"
]
.
format
(
tableid
=
tableid
,
params
=
params
)
+
'}'
action_suffix
=
f
"{action_suffix}{params}"
_buttons
=
[]
...
...
@@ -243,11 +246,10 @@ class DeTable(field.Field):
headers
.
append
(
f
.
title
)
cols2
.
append
(
data
)
# for t in d:
# if "title" in t:
# headers.append(t["title"])
# else:
# headers.append(t)
if
form
:
form
=
Form
(
form
())
if
not
form_object
:
form
=
form
.
render
()
self
.
headers
=
headers
self
.
head
=
headers
...
...
@@ -260,6 +262,7 @@ class DeTable(field.Field):
self
.
paginates
=
paginates
self
.
filters
=
filters
self
.
state_save
=
json
.
dumps
(
state_save
)
self
.
form
=
form
class
Button
(
object
):
...
...
@@ -343,4 +346,4 @@ class Button(object):
self
.
disabled
=
disabled
self
.
css_class
=
css_class
self
.
icon
=
icon
self
.
attributes
=
attributes
self
.
attributes
=
attributes
\ No newline at end of file
opensipkd/detable/templates/detable.pt
View file @
a063268
...
...
@@ -22,6 +22,7 @@
allow_post allow_post|field.allow_post;
allow_unpost allow_unpost|field.allow_unpost;
state_save state_save|field.state_save;
form form|field.form;
"
tal:attributes="style style; class css_class; attributes|field.widget.attributes|{};"
i18n:domain="detable"
...
...
@@ -38,10 +39,12 @@
<div class="widget-body">
<table
id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer"
>
class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead>
<tr>
<th colspan="${next(field.counter)-1}" tal:condition="form">${structure: form}</th>
</tr>
<tr>
<th tal:repeat="child field">${child.title}</th>
</tr>
</thead>
...
...
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