Commit e043490b by aagusti

get_params

1 parent 6927a3eb
...@@ -115,6 +115,19 @@ def round_up(n): ...@@ -115,6 +115,19 @@ def round_up(n):
def get_settings(): def get_settings():
return get_current_registry().settings return get_current_registry().settings
def get_params(params, alternate=None):
"""
Digunakan untuk mengambil nilai dari konfigurasi sesuai params yang disebut
:param params: variable
:param alternate: default apabila tidak ditemukan data/params
:return: value
contoh penggunaan:
get_params('devel', False)
"""
settings = get_settings()
result = settings and params in settings and settings[params].strip() or None
return result and result or alternate
def devel(): def devel():
settings = get_settings() settings = get_settings()
...@@ -424,15 +437,26 @@ class Upload(SaveFile): ...@@ -424,15 +437,26 @@ class Upload(SaveFile):
ext = get_ext(request.POST[name].filename) ext = get_ext(request.POST[name].filename)
return self.save_to_file(input_file, ext) return self.save_to_file(input_file, ext)
def save_fp(self, upload):
if 'fp' not in upload or upload['fp'] == b'':
if "filename" in upload:
return upload['filename']
return
filename = upload['filename']
input_file = upload['fp']
ext = get_ext(filename)
return self.save_to_file(input_file, ext)
def saves(self, uploads): def saves(self, uploads):
d = {} d = {}
for upload in uploads: for upload in uploads:
if 'fp' not in upload or upload['fp'] == b'': if 'fp' not in upload or upload['fp'] == b'':
continue continue
filename = upload['filename'] filename = upload['filename']
input_file = upload['fp'] # input_file = upload['fp']
ext = get_ext(filename) # ext = get_ext(filename)
d[filename] = self.save_to_file(input_file, ext) # d[filename] = self.save_to_file(input_file, ext)
d[filename] = self.save_fp(upload)
return d return d
......
...@@ -4,10 +4,10 @@ import ntpath ...@@ -4,10 +4,10 @@ import ntpath
import csv import csv
import io import io
from datetime import datetime from datetime import datetime
# from z3c.rml import rml2pdf from z3c.rml import rml2pdf
import subprocess import subprocess
import logging import logging
from ..tools import get_settings from ..tools import get_settings, get_params
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
rpt_path = "" rpt_path = ""
...@@ -19,7 +19,7 @@ def get_root_path(): ...@@ -19,7 +19,7 @@ def get_root_path():
def get_logo(): def get_logo():
path = os.path.join(os.path.dirname(get_root_path()), 'static/img') path = get_params('report_img', os.path.join(os.path.dirname(get_root_path()), 'static/img'))
# FIXME opensipkd/static to be changed by active app folder # FIXME opensipkd/static to be changed by active app folder
return path + "/logo.png", path + "/line.png" return path + "/logo.png", path + "/line.png"
......
...@@ -22,8 +22,8 @@ requires = [ ...@@ -22,8 +22,8 @@ requires = [
"hupper", "hupper",
"urllib3", "urllib3",
"idna", "idna",
"z3c.rml",
# "pikepdf", # "pikepdf",
# "z3c.rml",
] ]
dev_requires = [ dev_requires = [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!