Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-tools
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 a78377b3
authored
Jan 31, 2025
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
penampaabahan lain2
1 parent
6036cd6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
1 deletions
opensipkd/tools/__init__.py
opensipkd/tools/report.py
opensipkd/tools/__init__.py
View file @
a78377b
...
...
@@ -9,11 +9,13 @@ import logging
import
mimetypes
import
os
import
re
from
deform
import
widget
from
json
import
JSONEncoder
from
random
import
choice
from
string
import
(
ascii_uppercase
,
ascii_lowercase
,
digits
,
)
import
colander
from
pyramid.csrf
import
new_csrf_token
import
pytz
from
pyramid.httpexceptions
import
HTTPNotFound
from
pyramid.threadlocal
import
get_current_registry
...
...
@@ -1005,7 +1007,6 @@ def terbilang_(n):
hasil
=
terbilang_
(
n
%
10
)
+
[
'belas'
]
else
:
hasil
=
[
satuan
[
n
]]
print
(
'hasil'
)
return
hasil
...
...
opensipkd/tools/report.py
View file @
a78377b
...
...
@@ -343,3 +343,138 @@ def tmp_reports(settings = None, tmp_path = None, module_dirname = None):
class
Item
(
object
):
pass
#Jasper Processor
class
BaseView
(
object
):
def
__init__
(
self
,
request
):
# super().__init__(request)
# self.user_id = self.req.user.id
# self.user_admin = self.req.has_permission('pjdl-admin') \
# or self.req.has_permission('admin') or False
# self.report_folder = "master"
# self._file = None
# self.report_path = MODULE_CLASS.report_path
@property
def
report_file
(
self
):
return
os
.
path
.
join
(
self
.
report_path
,
self
.
report_folder
,
self
.
_file
)
@report_file.setter
def
report_file
(
self
,
value
):
self
.
_file
=
value
# def get_report_filter(self, values, pars, opts=True):
# # pars = p.split(":")
# if opts:
# if pars[1] not in values:
# par = len(pars) > 3 and pars[3] or pars[1]
# raise HTTPNotFound(f"Parameter {par} belum diisi")
# # if pars[1].find("customer")>-1:
# # raise Exception("X")
# if pars[1] in values:
# vals = values[pars[1]]
# if pars[2] == "str":
# self.params[pars[1]] = str(vals)
# if not opts:
# self.kondisi = f"{self.kondisi} AND {pars[0]}='{vals}'"
# vals = f"'{vals}'"
# self.qry = self.qry.filter(
# func.CAST(PjdlReportItems.params[pars[1]], String) == f'"{vals}"')
# elif pars[2] == "int":
# self.params[pars[1]] = int(vals)
# if not opts:
# self.kondisi = f"{self.kondisi} AND {pars[0]}={vals}"
# vals = f"{vals}"
# self.qry = self.qry.filter(
# func.CAST(PjdlReportItems.params[pars[1]], String) == f'{vals}')
# elif pars[2] in ["dMy", "ymd", "dmy"]:
# vals = date_from_str(vals)
# fc = getattr(opensipkd.tools, pars[2])
# vals = f"{fc(vals)}"
# self.params[pars[1]] = vals
# self.qry = self.qry.filter(
# func.CAST(PjdlReportItems.params[pars[1]], String) == f'"{vals}"')
# if not opts:
# self.kondisi = f"{self.kondisi} AND {pars[0]}='{vals}'"
# else:
# raise Exception(f"Belum ada fungsi {pars[2]}")
# # if pars[1]!="tgl_cetak":
def
jasper_response
(
self
,
**
kwargs
):
from
opensipkd.base.tools.report
import
jasper_export
output_formats
=
kwargs
.
get
(
"output_formats"
,
[
"pdf"
])
force
=
kwargs
.
get
(
"force"
,
False
)
# Menghindari temporary file dalam module aplikasi
out_path
=
get_params
(
"pjdl_report_files"
,
'/tmp/pjdl/reports'
)
out_path
=
os
.
path
.
join
(
out_path
,
"out"
)
if
not
os
.
path
.
exists
(
out_path
):
os
.
makedirs
(
out_path
)
# Ambil-nama-report dari tabel report
rpt_kode
=
os
.
path
.
basename
(
self
.
report_file
)
row
=
PjdlReports
.
query_kode
(
rpt_kode
)
.
first
()
if
not
row
:
return
HTTPNotFound
(
f
"File report {rpt_kode} belum terdaftar"
)
# Check data pada report yang sudah dibuat
self
.
qry
=
PjdlReportItems
.
query
()
.
filter
(
PjdlReportItems
.
report_id
==
row
.
id
)
self
.
params
=
{}
self
.
kondisi
=
""
if
row
and
row
.
params
:
par
=
row
.
params
.
replace
(
'
\r
'
,
''
)
.
replace
(
'
\n
'
,
''
)
par
=
par
.
split
(
","
)
if
par
:
values
=
kwargs
.
get
(
"values"
,
{})
for
p
in
par
:
if
p
.
startswith
(
'['
):
# optional parameter
p
=
p
.
strip
(
'['
)
.
strip
(
']'
)
pars
=
p
.
split
(
":"
)
_logging
.
debug
(
f
"pars: {pars}"
)
self
.
get_report_filter
(
values
,
pars
,
False
)
else
:
pars
=
p
.
split
(
":"
)
_logging
.
debug
(
f
"pars: {pars}"
)
if
pars
[
1
]
not
in
values
:
par
=
len
(
pars
)
>
3
and
pars
[
3
]
or
pars
[
1
]
return
HTTPNotFound
(
f
"Parameter {par} Belum Diisi"
)
self
.
get_report_filter
(
values
,
pars
)
_logging
.
debug
(
f
"kondisinya: {self.kondisi}"
)
self
.
params
[
"kondisi"
]
=
self
.
kondisi
self
.
qry
=
self
.
qry
.
filter
(
func
.
CAST
(
PjdlReportItems
.
params
[
"output_formats"
],
String
)
==
f
'"{output_formats}"'
)
items
=
self
.
qry
.
first
()
if
items
and
not
force
:
file_name
=
os
.
path
.
join
(
out_path
,
items
.
file_name
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
out_path
,
file_name
)):
force
=
True
else
:
force
=
True
if
force
:
self
.
params
.
update
(
MODULE_CLASS
.
report_params
)
_logging
.
debug
(
f
"parameter: {self.params}"
)
file_name
=
jasper_export
(
self
.
report_file
,
out_path
,
parameters
=
self
.
params
,
output_formats
=
output_formats
)[
0
]
if
not
items
:
items
=
PjdlReportItems
()
items
.
report_id
=
row
.
id
self
.
params
[
"output_formats"
]
=
output_formats
items
.
params
=
self
.
params
_logging
.
debug
(
f
"parameter: {self.params}"
)
items
.
file_name
=
os
.
path
.
basename
(
file_name
)
flush
(
items
)
return
file_response
(
self
.
req
,
filename
=
file_name
)
\ 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