Commit 4c2cb197 by iqbal

pembaruan validator dan input group by iqbal

2 parents 62e296c8 bb463100
...@@ -5,6 +5,7 @@ __pycache__/ ...@@ -5,6 +5,7 @@ __pycache__/
.vs/ .vs/
.vscode/ .vscode/
base.ini base.ini
# C extensions # C extensions
*.so *.so
......
...@@ -698,9 +698,9 @@ def main(global_config, **settings): ...@@ -698,9 +698,9 @@ def main(global_config, **settings):
if 'localization' not in settings: if 'localization' not in settings:
settings['localization'] = 'id_ID.UTF-8' settings['localization'] = 'id_ID.UTF-8'
locale.setlocale(locale.LC_ALL, settings['localization']) # locale.setlocale(locale.LC_ALL, settings['localization'])
if 'timezone' not in settings: # if 'timezone' not in settings:
settings['timezone'] = DefaultTimeZone # settings['timezone'] = DefaultTimeZone
# modules = get_modules(settings) # modules = get_modules(settings)
# from importlib import import_module # from importlib import import_module
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.5.final using JasperReports Library version 6.20.5-3efcf2e67f959db3888d79f73dde2dbd7acb4f8e -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Group" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6630eb66-846c-4826-9d1e-493d584e9622">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="groups_csv"/>
<parameter name="judul1" class="java.lang.String">
<defaultValueExpression><![CDATA["PEMERINTAH KABUPATEN KUNINGAN"]]></defaultValueExpression>
</parameter>
<queryString language="csv">
<![CDATA[]]>
</queryString>
<field name="group_name" class="java.lang.String"/>
<field name="description" class="java.lang.String"/>
<field name="member_count" class="java.lang.Integer"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="123" splitType="Stretch">
<staticText>
<reportElement x="143" y="49" width="269" height="30" uuid="5b7637d7-75f9-4fcb-83f0-3199ee657145"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[BADAN PENDAPATAN DAERAH]]></text>
</staticText>
<staticText>
<reportElement x="186" y="67" width="182" height="30" uuid="a139563f-3249-4b06-9842-377b1c0e9730"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[ALAMAT DEPARTEMEN BARIS 1]]></text>
</staticText>
<line>
<reportElement x="10" y="90" width="551" height="2" uuid="86ddd920-2fb3-4145-9b92-a35c943f22d1"/>
<graphicElement>
<pen lineWidth="4.0"/>
</graphicElement>
</line>
<image>
<reportElement x="40" y="14" width="71" height="71" uuid="d7dac611-e67c-45fd-b795-9d704ae37822"/>
<imageExpression><![CDATA["C:/Users/hamzah/Downloads/pngegg.png"]]></imageExpression>
</image>
<staticText>
<reportElement x="20" y="100" width="191" height="21" uuid="073f879a-0d32-48b7-924f-1c0068f82a49"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[DAFTAR GROUP APLIKASI]]></text>
</staticText>
<textField>
<reportElement x="111" y="30" width="340" height="30" uuid="821c62e9-865c-4586-9e53-ff72d03d4189"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{judul1}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="24" splitType="Stretch">
<staticText>
<reportElement mode="Opaque" x="10" y="2" width="91" height="21" backcolor="#F7E516" uuid="8b09b79a-77ce-4c05-87ed-0a9de42057b7"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Group]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="101" y="2" width="369" height="21" backcolor="#F7E516" uuid="b2839bdc-e0cc-47b2-8a5e-4890a6b3daca"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Deskripsi]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="470" y="2" width="91" height="21" backcolor="#F7E516" uuid="a2a310fd-6670-49bb-8a41-b2adb8eb1048"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Anggota]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="21" splitType="Stretch">
<textField>
<reportElement x="470" y="0" width="91" height="21" uuid="3e05ad54-5bbb-4211-ad68-7bd5c9c652d9"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{member_count}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="101" y="0" width="369" height="21" uuid="0f36284e-eadb-4603-b0f2-e2a68b7e508a"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="10" y="0" width="91" height="21" uuid="7a46ccdd-d3f8-49d9-837c-f40c80ec869c"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{group_name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
...@@ -39,44 +39,82 @@ def departemen_widget_form(): ...@@ -39,44 +39,82 @@ def departemen_widget_form():
{"js": "opensipkd.base:static/js/form/departemen_form.js"}), {"js": "opensipkd.base:static/js/form/departemen_form.js"}),
) )
# Mencoba membuat validator sendiri
class Validator:
def __init__(self, user):
self.user = user
# Validator nama
class NameValidator(Validator):
def __call__(self, node, value):
name = value
if (len(name) > 128):
raise colander.Invalid(node, _('Maksimal 128 karakter'))
@colander.deferred
def name_validator(node, kw):
return NameValidator(kw['user'])
class AddSchema(colander.Schema): class AddSchema(colander.Schema):
parent_id = colander.SchemaNode( parent_id = colander.SchemaNode(
colander.Integer(), colander.Integer(),
widget=widget.HiddenWidget(), oid="parent_id", missing=colander.drop, widget=widget.HiddenWidget(),
) oid="parent_id",
missing=colander.drop,)
parent_nm = colander.SchemaNode( parent_nm = colander.SchemaNode(
colander.String(), missing=colander.drop, colander.String(),
missing=colander.drop,
widget=widget.AutocompleteInputWidget( widget=widget.AutocompleteInputWidget(
size=60, min_length=3, size=60, min_length=3,
requirements=(("typeahead", None), ("deform", None), requirements=(("typeahead", None),
{"js": "opensipkd.base:static/js/form/departemen.js"}), ("deform", None),
{"js": "opensipkd.base:static/js/form/departemen.js"}),
# options={"allowClear": True} # options={"allowClear": True}
), ),
oid="parent_nm", title="Induk") oid="parent_nm",
title="Induk")
parent_kd = colander.SchemaNode(colander.String(),
widget=widget.TextInputWidget(css_class="readonly"), parent_kd = colander.SchemaNode(
missing=colander.drop, oid="parent_kd", title="Kode Induk") colander.String(),
widget=widget.TextInputWidget(css_class="readonly"),
kode = colander.SchemaNode(colander.String(), missing=colander.drop,
validator=colander.Length(max=32), oid="kode") oid="parent_kd",
title="Kode Induk")
nama = colander.SchemaNode(colander.String(), oid="nama")
kode = colander.SchemaNode(
singkat = colander.SchemaNode(colander.String(), missing=colander.drop, colander.String(),
oid="singkat") validator=colander.Length(max=32, max_err='Maksimal 32 karakter'),
oid="kode")
kategori = colander.SchemaNode(colander.String(), missing=colander.drop,
oid="kategori") nama = colander.SchemaNode(
colander.String(),
alamat = colander.SchemaNode(colander.String(), missing=colander.drop, oid="nama",
oid="alamat") validator=colander.Length(min=1, max=128, max_err="Maksimal 128 karakter", min_err='Minimal 1 karakter'))
company_id = colander.SchemaNode(colander.Integer(),
widget=company_widget, singkat = colander.SchemaNode(
missing=colander.drop, colander.String(),
oid="company_id") missing=colander.drop,
oid="singkat",
validator=colander.Length(max=32, max_err='Maksimal 32 karakter'))
kategori = colander.SchemaNode(
colander.String(),
missing=colander.drop,
oid="kategori",
validator=colander.Length(max=32, max_err='Maksimal 32 karakter'))
alamat = colander.SchemaNode(
colander.String(),
missing=colander.drop,
oid="alamat",
validator=colander.Length(max=255, max_err='Maksimal 255 karakter'))
company_id = colander.SchemaNode(
colander.Integer(),
widget=company_widget,
missing=colander.drop,
oid="company_id")
status = colander.SchemaNode( status = colander.SchemaNode(
colander.Integer(), colander.Integer(),
...@@ -407,4 +445,4 @@ class ViewDepartemen(BaseView): ...@@ -407,4 +445,4 @@ class ViewDepartemen(BaseView):
# row.kode = kode # row.kode = kode
# row.nama = csv_row['nama'] # row.nama = csv_row['nama']
# DBSession.add(row) # DBSession.add(row)
# return row # return row
\ No newline at end of file \ No newline at end of file
...@@ -6,6 +6,7 @@ from pyramid.view import (view_config, ) ...@@ -6,6 +6,7 @@ from pyramid.view import (view_config, )
from . import widget_os from . import widget_os
from opensipkd.models import DBSession, ResProvinsi, kategori_provinsi from opensipkd.models import DBSession, ResProvinsi, kategori_provinsi
from ..views import BaseView from ..views import BaseView
_ = TranslationStringFactory("opensipkd") _ = TranslationStringFactory("opensipkd")
SESS_ADD_FAILED = 'Tambah provinsi gagal' SESS_ADD_FAILED = 'Tambah provinsi gagal'
...@@ -19,34 +20,51 @@ def provinsi_widget(node, kw): ...@@ -19,34 +20,51 @@ def provinsi_widget(node, kw):
slave = node and hasattr(node, 'slave') and node.slave or "" slave = node and hasattr(node, 'slave') and node.slave or ""
values.insert(0, ("", "Pilih Propinsi...")) values.insert(0, ("", "Pilih Propinsi..."))
readonly = kw.get("readonly", False) readonly = kw.get("readonly", False)
return widget_os.Select2MsWidget(values=values, return widget_os.Select2MsWidget(
readonly=readonly, values=values,
url=url, readonly=readonly,
slave=slave, url=url,
placeholder="Pilih Provinsi") slave=slave,
placeholder="Pilih Provinsi")
class AddSchema(colander.Schema): class AddSchema(colander.Schema):
kode = colander.SchemaNode(colander.String(), kode = colander.SchemaNode(
oid="kode", colander.String(),
validator=colander.Length(max=32), ) oid="kode",
kategori = colander.SchemaNode(colander.String(), validator=colander.Length(max=32, max_err='Maksimal 32 karakter'))
widget=widget.SelectWidget(values=kategori_provinsi),
validator=colander.Length(max=32), oid="kode") kategori = colander.SchemaNode(
colander.String(),
widget=widget.SelectWidget(values=kategori_provinsi),
validator=colander.Length(max=32, max_err='Maksimal 32 karakter'),
oid="kode")
nama = colander.SchemaNode(
colander.String(),
oid="nama",
validator=colander.Length(max=128, max_err='Maksimal 128 karakter'))
nama = colander.SchemaNode(colander.String(), oid="nama") ibu_kota = colander.SchemaNode(
ibu_kota = colander.SchemaNode(colander.String(), oid="nama", missing=colander.drop) colander.String(),
oid="nama",
missing=colander.drop,
validator=colander.Length(max=64, max_err='Maksimal 64 karakter'))
class EditSchema(AddSchema): class EditSchema(AddSchema):
id = colander.SchemaNode(colander.String(), missing=colander.drop, id = colander.SchemaNode(
widget=widget.HiddenWidget(readonly=True), colander.String(),
visible=False) missing=colander.drop,
widget=widget.HiddenWidget(readonly=True),
visible=False)
class ListSchema(colander.Schema): class ListSchema(colander.Schema):
id = colander.SchemaNode(colander.Integer(), id = colander.SchemaNode(
title=_("action", default="Action")) colander.Integer(),
title=_("action",
default="Action"))
kode = colander.SchemaNode(colander.String(), width=100) kode = colander.SchemaNode(colander.String(), width=100)
nama = colander.SchemaNode(colander.String()) nama = colander.SchemaNode(colander.String())
ibu_kota=colander.SchemaNode(colander.String()) ibu_kota=colander.SchemaNode(colander.String())
...@@ -69,13 +87,14 @@ class ViewProvinsi(BaseView): ...@@ -69,13 +87,14 @@ class ViewProvinsi(BaseView):
def form_validator(self, form, value): def form_validator(self, form, value):
def err_kode(): def err_kode():
raise colander.Invalid(form, 'Kode %s sudah digunakan oleh %s' % ( raise colander.Invalid(
value['kode'], found.nama)) form,
'Kode %s sudah digunakan oleh %s' % (value['kode'], found.nama))
def err_nama(): def err_nama():
raise colander.Invalid(form, raise colander.Invalid(
'Uraian %s sudah digunakan oleh kode %s' % ( form,
value['nama'], found.kode)) 'Uraian %s sudah digunakan oleh kode %s' % (value['nama'], found.kode))
if 'id' in form.request.matchdict: if 'id' in form.request.matchdict:
uid = form.request.matchdict['id'] uid = form.request.matchdict['id']
......
...@@ -273,6 +273,13 @@ class EmailValidator(colander.Email, Validator): ...@@ -273,6 +273,13 @@ class EmailValidator(colander.Email, Validator):
if found and (not self.user or self.user.email != found.email): if found and (not self.user or self.user.email != found.email):
email_found() email_found()
# Cek karakter
def email_max():
raise colander.Invalid(node, _('Maksimal 100 karakter'))
if (len(email) > 100):
email_max()
REGEX_ONLY_CONTAIN = re.compile('([A-Za-z0-9-]*)') REGEX_ONLY_CONTAIN = re.compile('([A-Za-z0-9-]*)')
REGEX_BEGIN_END_ALPHANUMERIC = re.compile('^[A-Za-z0-9]+(?:[-][A-Za-z0-9]+)*$') REGEX_BEGIN_END_ALPHANUMERIC = re.compile('^[A-Za-z0-9]+(?:[-][A-Za-z0-9]+)*$')
...@@ -281,6 +288,15 @@ REGEX_BEGIN_END_ALPHANUMERIC = re.compile('^[A-Za-z0-9]+(?:[-][A-Za-z0-9]+)*$') ...@@ -281,6 +288,15 @@ REGEX_BEGIN_END_ALPHANUMERIC = re.compile('^[A-Za-z0-9]+(?:[-][A-Za-z0-9]+)*$')
class UsernameValidator(Validator): class UsernameValidator(Validator):
def __call__(self, node, value): def __call__(self, node, value):
username = value username = value
# Fungsi menampilkan error pada field form
def username_max():
raise colander.Invalid(node, _('Maksimal 128 karakter'))
# Jika karakter melebihi 128 karakter maka, panggil fungsi
if (len(username) > 128):
username_max()
if self.user and self.user.user_name == username: if self.user and self.user.user_name == username:
return return
match = REGEX_ONLY_CONTAIN.search(username) match = REGEX_ONLY_CONTAIN.search(username)
...@@ -333,20 +349,34 @@ def save_user(values, user, row=None): ...@@ -333,20 +349,34 @@ def save_user(values, user, row=None):
class AddSchema(colander.Schema): class AddSchema(colander.Schema):
email = colander.SchemaNode( email = colander.SchemaNode(
colander.String(), title=_('Email'), colander.String(),
title=_('Email'),
validator=email_validator) validator=email_validator)
user_name = colander.SchemaNode(colander.String(), title=_('Username'),
validator=username_validator) user_name = colander.SchemaNode(
colander.String(),
title=_('Username tetst'),
validator=username_validator)
groups = colander.SchemaNode( groups = colander.SchemaNode(
colander.Set(), widget=group_widget, title=_('Group')) colander.Set(),
widget=group_widget,
title=_('Group'))
is_api_key = colander.SchemaNode( is_api_key = colander.SchemaNode(
colander.String(), widget=api_key_widget, title=_('API Key'), colander.String(),
widget=api_key_widget,
title=_('API Key'),
missing=colander.drop) missing=colander.drop)
password = colander.SchemaNode( password = colander.SchemaNode(
colander.String(), widget=widget.CheckedPasswordWidget(), colander.String(),
widget=widget.CheckedPasswordWidget(),
missing=colander.drop) missing=colander.drop)
company_id = colander.SchemaNode( company_id = colander.SchemaNode(
colander.Integer(), widget=company_widget, colander.Integer(),
widget=company_widget,
title="Company", title="Company",
missing=colander.drop) missing=colander.drop)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!