Commit 712624f7 by aa.gustiana@gmail.com

Enhance logging and template definitions for improved error handling and response clarity

2 parents 36e817a9 b417aa72
......@@ -223,6 +223,7 @@ class ApiViews(APIView):
"""
Mengubah data menjadi list dan convert objek menjadi string
"""
_log.debug("Response to Client: %s", data)
if not isinstance(data, list):
data = [data]
for i, item in enumerate(data):
......
......@@ -57,9 +57,11 @@ log = logging.getLogger(__name__)
# }
class AddSchema(colander.Schema):
kode = colander.SchemaNode(colander.String(), title="Kode", validator=colander.Length(max=50),
kode = colander.SchemaNode(colander.String(), title="Kode",
validator=colander.Length(max=50),
search_method = "string_contains",
searchable = True,
aligned = "text-left"
)
class UploadSchema(colander.Schema):
upload = colander.SchemaNode(
......@@ -143,7 +145,7 @@ class BaseView(object):
self.list_form = None # List dam Form
self.form_list = None # Form kemudian detail list
self.global_search = False
self.form_scripts = """
$('#parent_nm').bind('typeahead:selected', function(obj, datum) {
$('#parent_id').val(datum.id);
......@@ -590,9 +592,10 @@ class BaseView(object):
if not self.columns:
columns = []
for d in list_schema():
global_search = getattr(d, "global_search", False)
global_search = hasattr(d, "global_search") \
and getattr(d, "global_search", self.global_search) or self.global_search
search_method = hasattr(d, "search_method") \
and getattr(d, "search_method") or "string_contains"
and getattr(d, "search_method", "string_contains") or "string_contains"
if hasattr(d, "field"):
if isinstance(d.field, str):
columns.append(
......@@ -825,8 +828,10 @@ class BaseView(object):
def view_view(self, **kwargs):
request = self.req
row = self.query_id().first()
qry = self.query_id()
row = qry.first()
if not row:
log.debug(str(qry.statement.compile(compile_kwargs={'literal_binds': True})))
return self.id_not_found()
self.ses["readonly"] = True
......@@ -1196,6 +1201,7 @@ class BaseView(object):
msg = f"Data yang dicari Tidak Ditemukan ID:" \
f" {self.req.matchdict['id']}."
self.req.session.flash(msg, 'error')
log.error(msg)
return self.route_list(**kwargs)
def get_values(self, row, istime=False, null=False):
......@@ -1250,6 +1256,8 @@ class BaseView(object):
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
if not row:
log.debug(self.query_id().statement.compile(
compile_kwargs={'literal_binds': True}))
return self.id_not_found(**kwargs)
if self.edit_restrict(row):
......@@ -1350,6 +1358,9 @@ class BaseView(object):
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
if not row:
log.debug(str(q.statement.compile(
compile_kwargs={'literal_binds': True})))
return self.id_not_found()
if not self.bindings:
self.bindings = self.get_bindings(row)
......
<html tal:define="home '';">
<html tal:define="home request.home.strip('/');">
<body>
<div class="well">
<h2>${request.app_name}</h2>
......
<html>
<html tal:define="home request.home.strip('/');">
<body>
<div class="well">
......
<!DOCTYPE html>
<html lang="en-us" tal:define="
home request.home;
home request.home.strip('/');
user_path ['user', 'user-add', 'user-edit', 'user-view', 'user-delete'];
user_area_path ['user-area', 'user-area-add', 'user-area-edit', 'user-area-view', 'user-area-delete'];
user_dep_path ['user-departemen', 'user-departemen-add', 'user-departemen-edit', 'user-departemen-view', 'user-departemen-delete'];
......
......@@ -5,13 +5,9 @@
css css|[];
js js|[];
">
<head>
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->
<title>${request.app_name} | ${request.company}</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
......@@ -207,8 +203,6 @@
</span>
</aside>
<!-- END NAVIGATION -->
<!-- JS -->
<script src="${home}/static/v3/js/jquery-2.1.1.min.js"></script>
<script>
......
<!DOCTYPE html>
<html lang="en" tal:define="home request.home;">
<html lang="en" tal:define="home request.home.strip('/');">
<head>
<meta charset="utf-8">
......
<!DOCTYPE html>
<html lang="en" tal:define="home request.home;">
<html lang="en" tal:define="home request.home.strip('/');">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
......
......@@ -2,7 +2,7 @@
css_class css_class|field.widget.css_class;
style style|field.widget.style;
preview_url cstruct.get('preview_url')|'';
ext str(cstruct.get('filename').split('.')[-1:][0]).lower()|[];
ext str(cstruct.get('filename').split('.')[-1:][0]).lower()|'';
fname str(cstruct.get('filename'))|'';
delete cstruct.get('delete')|'';
maxsize field.widget.size|5242880;
......@@ -10,8 +10,12 @@
video ['avi', 'mov', 'mp4']
">
${field.start_mapping()}
<div class="thumbnail" tal:condition="not ext or ext ==''">
<img id="preview-${oid}" alt="" src="${preview_url}" style="${style}"
onload="window.URL.revokeObjectURL(this.src);"></img>
</div>
<div class="thumbnail" tal:condition="ext in img or ext in video or ext=='pdf'">
<img tal:condition="ext in img" id="preview-${oid}" alt="" src="${preview_url}" style="${style}"
<img tal:condition="ext in img or ext" 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}">
......
from pyramid.csrf import new_csrf_token, get_csrf_token
from iso8601.iso8601 import ISO8601_REGEX
# from deform.widget import str
import json
import logging
from pyramid.csrf import new_csrf_token, get_csrf_token
from iso8601.iso8601 import ISO8601_REGEX
from colander import SchemaNode, null, Mapping, Invalid # , string_types
from colander import SchemaNode, null, Mapping, Invalid # , str
# from colander import compat # tidak ada di colander 2.0
from deform import widget
# from deform.compat import sequence_types, text_type, text_
......@@ -16,7 +19,7 @@ from deform.widget import (
from opensipkd.tools.captcha import img_captcha
_logging = logging.getLogger(__name__)
sequence_types = (list, range, tuple)
class DokumenWidget(Widget):
template = "opensipkd.base:/widgets/templates/dokumen.pt"
readonly_template = "opensipkd.base:/widgets/templates/readonly/dokumen.pt"
......@@ -257,12 +260,12 @@ class AutocompleteMsInputWidget(AutocompleteInputWidget):
readonly = kw.get("readonly", self.readonly)
options = {}
if isinstance(self.values, str): #string_types
if isinstance(self.values, str):
options["remote"] = "%s?term=%%QUERY" % self.values
else:
# vals = []
# for v in self.values:
# if not isinstance(v, str): #string_types
# if not isinstance(v, str):
# vals.append(v[1])
# if not vals:
# vals = self.values
......@@ -285,7 +288,7 @@ class AutocompleteMsInputWidget(AutocompleteInputWidget):
try:
validated = self._pstruct_schema.deserialize(pstruct)
except Invalid as exc:
raise Invalid(field.schema, text_("Invalid pstruct: %s" % exc))
raise Invalid(field.schema, "Invalid pstruct: %s" % exc)
auto_id = validated["auto_id"]
auto_value = validated["auto_value"]
......@@ -394,7 +397,7 @@ class CaptchaWidget(Widget):
def deserialize(self, field, pstruct):
if pstruct is null:
return null
elif not isinstance(pstruct, str): #string_types
elif not isinstance(pstruct, str):
raise Invalid(field.schema, "Pstruct is not a string")
if self.strip:
pstruct = pstruct.strip()
......@@ -460,7 +463,7 @@ class ImageWidget(Widget):
def deserialize(self, field, pstruct):
if pstruct is null:
return null
elif not isinstance(pstruct, str): # string_types
elif not isinstance(pstruct, str):
raise Invalid(field.schema, "Pstruct is not a string")
if self.strip:
pstruct = pstruct.strip()
......@@ -540,7 +543,7 @@ class MapWidget(Widget):
def deserialize(self, field, pstruct):
if pstruct is null:
return null
elif not isinstance(pstruct, str): #string_types
elif not isinstance(pstruct, str):
raise Invalid(field.schema, "Pstruct is not a string")
if self.strip:
pstruct = pstruct.strip()
......@@ -622,7 +625,7 @@ class MapWidget(Widget):
# def deserialize(self, field, pstruct):
# if pstruct is null:
# return null
# elif not isinstance(pstruct, str): #string_types
# elif not isinstance(pstruct, str):
# raise Invalid(field.schema, "Pstruct is not a string")
# if self.strip:
# pstruct = pstruct.strip()
......@@ -834,7 +837,7 @@ class TextInputWidget(widget.TextInputWidget):
def __init__(self, **kw):
super(TextInputWidget, self).__init__(**kw)
# if isinstance(self.button, compat.string_types):
# if isinstance(self.button, compat.str):
if self.button:
if isinstance(self.button, str):
self.button = Button(self.button, type="button")
......@@ -893,10 +896,10 @@ class FilterWidget(Widget):
"""
if self.multiple:
if value in map(text_type, cstruct):
if value in map(str, cstruct): # text_type
return "selected"
else:
if value == text_type(cstruct):
if value == str(cstruct): #text_type
return "selected"
return None
......@@ -973,7 +976,7 @@ class FilterWidget(Widget):
# readonly = kw.get("readonly", self.readonly)
#
# options = {}
# if isinstance(self.values, string_types):
# if isinstance(self.values, str):
# options["remote"] = "%s?term=%%QUERY" % self.values
# else:
# options["local"] = self.values
......@@ -1003,7 +1006,7 @@ class CSRFWidget(widget.HiddenWidget):
cstruct = get_csrf_token(request)
if pstruct is null:
return null
elif not isinstance(pstruct, str): #string_types
elif not isinstance(pstruct, str):
raise Invalid(field.schema, "Pstruct is not a string")
if not pstruct:
return null
......
......@@ -6,13 +6,17 @@ import re
import colander
# import deform
# from deform import compat, widget as deform_widget, field
from deform import field, widget as deform_widget
from deform import widget as deform_widget, field # compat,
from . import widget
log = logging.getLogger(__name__)
sequence_types = (
list,
tuple,
range,
)
class DeTable(field.Field):
"""
Field representing an entire form.
......
......@@ -19,7 +19,7 @@ from deform.widget import MappingWidget
# from deform.compat import text_
from .i18n import _
# _BLANK = text_("")
_BLANK = ""
class TableWidget(MappingWidget):
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!