Commit e043490b by aagusti

get_params

1 parent 6927a3eb
......@@ -115,6 +115,19 @@ def round_up(n):
def get_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():
settings = get_settings()
......@@ -424,15 +437,26 @@ class Upload(SaveFile):
ext = get_ext(request.POST[name].filename)
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):
d = {}
for upload in uploads:
if 'fp' not in upload or upload['fp'] == b'':
continue
filename = upload['filename']
input_file = upload['fp']
ext = get_ext(filename)
d[filename] = self.save_to_file(input_file, ext)
# input_file = upload['fp']
# ext = get_ext(filename)
# d[filename] = self.save_to_file(input_file, ext)
d[filename] = self.save_fp(upload)
return d
......
......@@ -4,10 +4,10 @@ import ntpath
import csv
import io
from datetime import datetime
# from z3c.rml import rml2pdf
from z3c.rml import rml2pdf
import subprocess
import logging
from ..tools import get_settings
from ..tools import get_settings, get_params
log = logging.getLogger(__name__)
rpt_path = ""
......@@ -19,7 +19,7 @@ def get_root_path():
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
return path + "/logo.png", path + "/line.png"
......
......@@ -22,8 +22,8 @@ requires = [
"hupper",
"urllib3",
"idna",
"z3c.rml",
# "pikepdf",
# "z3c.rml",
]
dev_requires = [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!