Commit fbef0a9c by aa.gusti

perbaikan widget file

1 parent 4cacc37b
......@@ -53,15 +53,19 @@ class BaseView(object):
# self.akhir = dmy(self.dt_akhir)
# self.ses["dt_awal"] = self.dt_awal
# self.ses["dt_akhir"] = self.dt_akhir
self.tahun = 'tahun' in self.ses and self.ses['tahun'] or now.strftime('%Y')
self.tahun = 'tahun' in self.ses and self.ses['tahun'] or now.strftime(
'%Y')
self.tahun = 'tahun' in self.params and self.params['tahun'] or self.tahun
self.ses['tahun'] = self.tahun
self.bulan = 'bulan' in self.ses and self.ses['bulan'] or now.strftime('%m')
self.bulan = 'bulan' in self.ses and self.ses['bulan'] or now.strftime(
'%m')
if 'bulan' in self.params and self.params['bulan']:
self.bulan = self.params['bulan'].strip().zfill(2)
dt_awal = date_from_str('{d}-{m}-{y}'.format(y=self.tahun, m=self.bulan, d='01'))
dt_akhir = dt_awal + relativedelta(months=1) - relativedelta(days=1)
dt_awal = date_from_str(
'{d}-{m}-{y}'.format(y=self.tahun, m=self.bulan, d='01'))
dt_akhir = dt_awal + \
relativedelta(months=1) - relativedelta(days=1)
self.ses['awal'] = dmy(dt_awal)
self.ses['akhir'] = dmy(dt_akhir)
......@@ -292,7 +296,8 @@ class BaseView(object):
if not list_url and self.list_route:
list_url = self.req.route_url(self.list_route)
else:
list_url = list_url and list_url[0:1] != "/" and "/" + list_url or list_url
list_url = list_url and list_url[0:1] != "/" and "/" + \
list_url or list_url
list_url = self.home + list_url
table = DeTable(schema,
......@@ -504,7 +509,7 @@ class BaseView(object):
def view_view(self, **kwargs): # row = query_id(request).first()
request = self.req
row = self.query_id().first()
self.ses["readonly"]=True
self.ses["readonly"] = True
if not row:
return self.id_not_found()
is_object = kwargs.get("is_object", self.is_object)
......@@ -638,13 +643,14 @@ class BaseView(object):
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
table = self.get_item_table(**kwargs)
self.ses["readonly"]=False
self.ses["readonly"] = False
if self.req.POST:
if 'save' in self.req.POST:
controls = self.req.POST.items()
try:
c = form.validate(controls)
except ValidationFailure as e:
value = self.before_add()
# value = self.validation_failure(e.cstruct)
# value.update(self.before_add())
# form.render(appstruct=value)
......@@ -657,6 +663,7 @@ class BaseView(object):
e.cstruct[f.name])
if f.name == "captcha":
e.cstruct[f.name] = self.get_captcha_url()
value.update(e.cstruct)
form.set_appstruct(e.cstruct)
return self.returned_form(form, table, **kwargs)
......@@ -746,7 +753,7 @@ class BaseView(object):
def view_edit(self, **kwargs):
request = self.req
self.ses["readonly"]=False
self.ses["readonly"] = False
row = self.query_id().first()
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
......@@ -774,7 +781,7 @@ class BaseView(object):
try:
controls = form.validate(controls)
except ValidationFailure as e:
log.error(f"Edit Error: {str(e.error)}")
log.error(f"Edit Error: {str(e.error.msg)}")
# log.debug(f"Edit Data: {e.cstruct}")
form.set_appstruct(e.cstruct)
return self.returned_form(form, table, **kwargs)
......@@ -800,7 +807,7 @@ class BaseView(object):
def view_delete(self, **kwargs):
request = self.req
q = self.query_id()
self.ses["readonly"]=True
self.ses["readonly"] = True
row = q.first()
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
......@@ -886,11 +893,14 @@ class BaseView(object):
filename = file_dict["filename"].lower()
ext = get_ext(filename)
if ext not in self.upload_exts:
error.append((field, InvalidExtension(self.upload_exts).error))
error.append(
(field, InvalidExtension(self.upload_exts).error))
else:
full_file_name = upload.save_to_file(input_file, ext, filename)
full_file_name = upload.save_to_file(
input_file, ext, filename)
if ext == ".avi":
full_file_name = self.convert_avi_to_mp4(full_file_name)
full_file_name = self.convert_avi_to_mp4(
full_file_name)
file_name = os.path.split(full_file_name)[1]
return file_name
......
......@@ -727,7 +727,24 @@ class DateInputWidget(WidgetDateInputWidget):
class MoneyInputWidget(widget.MoneyInputWidget):
readonly_template = "readonly/money_input"
readonly_template = "readonly/textinput"
def get_template_values(self, field, cstruct, kw):
options = json.loads(kw.get("mask_options", "{}"))
if options:
decimal = options.get("decimal", '.')
precision = options.get("precision", 2)
thousands = options.get("thousands", ',')
cstr = cstruct and float(cstruct) or 0
cstruct = f"{cstr:,.{precision}f}"\
.replace(".", "%")\
.replace(",", thousands)\
.replace("%", decimal)
values = {"cstruct": cstruct, "field": field}
values.update(kw)
values.pop("template", None)
return values
class FilterWidget(Widget):
......
......@@ -9,47 +9,37 @@
img ['jpg', 'jpeg', 'gif', 'png', 'svg', 'eps', 'psd'];
video ['avi', 'mov', 'mpv']
">
${field.start_mapping()}
<img tal:condition="ext in img" id="preview-${oid}" alt="" src="${preview_url}"
style="${style}"
${field.start_mapping()}
<div class="thumbnail">
<img tal:condition="ext in img" 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}"
<video tal:condition="ext in video" style="${style}" controls src="${preview_url}" type="video/${ext}"
id="preview-${oid}">
Your browser does not support the video tag.
</video>
<video tal:condition="ext=='mp4'"
controls
style="${style}"
src="${preview_url}"
type="video/mp4"
<video tal:condition="ext=='mp4'" controls style="${style}" src="${preview_url}" type="video/mp4"
id="preview-${oid}">
Your browser does not support the video tag.
</video>
<embed tal:condition="ext=='pdf'" src="${preview_url}" style="${style}"
id="preview-${oid}">
<a class="label label-default" href="${preview_url}"
target="_blank" id="a-preview-${oid}"><i class="fa fa-search"></i> View</a>
<embed tal:condition="ext=='pdf'" src="${preview_url}" style="${style}" id="preview-${oid}">
</div>
<a class="label label-default" href="${preview_url}" target="_blank" id="a-preview-${oid}"><i
class="fa fa-search"></i> View</a>
<input type="file" name="upload" id="${oid}"
tal:attributes="style style;
<input type="file" name="upload" id="${oid}" tal:attributes="style style;
accept accept|field.widget.accept;
data-filename fname;
attributes|field.widget.attributes|{};"/>
<input tal:define="uid cstruct.get('uid')"
tal:condition="uid"
type="hidden" name="uid" value="${uid}"/>
attributes|field.widget.attributes|{};" />
<input tal:define="uid cstruct.get('uid')" tal:condition="uid" type="hidden" name="uid" value="${uid}" />
${field.end_mapping()}
<script type="text/javascript">
deform.addCallback('${oid}', function (oid) {
$('#' + oid).upload();
});
document.getElementById("${oid}").onchange = function () {
if (this.files[0].size > ${maxsize}) {
if (this.files[0].size > ${ maxsize }) {
alert("File is too big!");
this.value = "";
document.getElementById('preview-' + this.id).src = '';
......
......@@ -3,18 +3,16 @@
mask_options mask_options|'{}';
style style|field.widget.style;
css_class css_class|field.widget.css_class;
style style|field.widget.style|False"
tal:omit-tag="">
<input type="text" name="${name}" value="${cstruct}"
tal:attributes="style style;
style style|field.widget.style|False" tal:omit-tag="">
<input type="text" name="${name}" value="${cstruct}" tal:attributes="style style;
class string: form-control ${css_class or ''};
attributes|field.widget.attributes|{};"
id="${oid}"/>
attributes|field.widget.attributes|{};" id="${oid}" />
<script type="text/javascript">
deform.addCallback(
'${oid}',
function (oid) {
$("#" + oid).maskMoney(${mask_options});
//$("#" + oid).maskMoney(${mask_options});
$("#" + oid).maskMoney(${ mask_options }, $("#" + oid).val());
});
</script>
</span>
\ No newline at end of file
<p class="form-control-static" id="${oid|field.oid}">
</p>
<p class="form-control-static" id="${oid|field.oid}" tal:define="mask_options mask_options|'{}';"></p>
<script type="text/javascript">
deform.addCallback(
'${oid|field.oid}',
function (oid) {
let val = parseInt('${cstruct}');
$("#" + oid).html(val.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}));
let val = parseFloat('${cstruct}');
$("#" + oid).html(val.toLocaleString());
});
</script>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!