Commit 085d2cd9 by Owo Sugiana

Tambah tabel khas OpenSIPKD

1 parent 95af3531
0.2.2 2022-04-18
----------------
- Tambah route /theme2/user untuk table khas OpenSIPKD
0.2.1 2022-04-14 0.2.1 2022-04-14
---------------- ----------------
- Tambah route /theme1/user/add untuk form yang lebih ringkas. - Tambah route /theme1/user/add untuk form yang lebih ringkas.
......
...@@ -32,7 +32,8 @@ requires = [ ...@@ -32,7 +32,8 @@ requires = [
'pyramid_mailer', 'pyramid_mailer',
'sqlalchemy-datatables', 'sqlalchemy-datatables',
'ColanderAlchemy', 'ColanderAlchemy',
'yaform @ git+https://git.opensipkd.com/sugiana/web-starter.git'] 'yaform @ git+https://git.opensipkd.com/sugiana/yaform.git',
]
tests_require = [ tests_require = [
'WebTest >= 1.3.1', # py3 compat 'WebTest >= 1.3.1', # py3 compat
......
...@@ -72,6 +72,7 @@ def main(global_config, **settings): ...@@ -72,6 +72,7 @@ def main(global_config, **settings):
config.add_notfound_view(RemoveSlashNotFoundViewFactory()) config.add_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_static_view('static', 'static', cache_max_age=3600) config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static') config.add_static_view('deform_static', 'deform:static')
config.add_static_view('detable_static', 'detable:static')
config.add_translation_dirs('locale') config.add_translation_dirs('locale')
config.registry['mailer'] = mailer_factory_from_settings(settings) config.registry['mailer'] = mailer_factory_from_settings(settings)
......
...@@ -20,3 +20,5 @@ user-act,/user/{act}/act ...@@ -20,3 +20,5 @@ user-act,/user/{act}/act
theme1-user,/theme1/user theme1-user,/theme1/user
theme1-user-add,/theme1/user/add theme1-user-add,/theme1/user/add
theme1-user-edit,/theme1/user/{id} theme1-user-edit,/theme1/user/{id}
theme2-user-act,/theme2/user/{act}/act
theme2-user,/theme2/user
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
<!-- Custom styles for this template --> <!-- Custom styles for this template -->
<link href="/static/signin.css" rel="stylesheet"> <link href="/static/signin.css" rel="stylesheet">
<script type="text/javascript" src="/deform_static/scripts/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="/deform_static/scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="/deform_static/scripts/deform.js"></script>
<div metal:define-slot="head"/> <div metal:define-slot="head"/>
</head> </head>
...@@ -92,10 +96,6 @@ ...@@ -92,10 +96,6 @@
<!-- Bootstrap core JavaScript <!-- Bootstrap core JavaScript
================================================== --> ================================================== -->
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="/deform_static/scripts/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="/deform_static/scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="/deform_static/scripts/deform.js"></script>
<div metal:define-slot="content-script"/> <div metal:define-slot="content-script"/>
</body> </body>
......
import os
import yaml
import colander
from deform import field
from deform.widget import MappingWidget
schema = colander.Schema()
class PanelWidget(MappingWidget):
# templates/user/panel.pt
template = 'panel'
class Panel(field.Field):
widget = PanelWidget()
def get_widgets(form, fields, level=0):
r = []
for field_id in fields:
if isinstance(field_id, str):
form[field_id].my_level = level
# templates/user/mapping_item.pt
field = form[field_id].render_template('mapping_item')
else:
for group_id in field_id:
field_ids = field_id[group_id]
field = get_widgets(form, field_ids, level+1)
r.append(field)
return '\n'.join(r)
def render(form, yml_template):
yml_file = yml_template + '.yml'
full_path = None
for path in Panel.default_renderer.loader.search_path:
full_path = os.path.join(path, yml_file)
if os.path.exists(full_path):
break
if not full_path:
raise Exception(f'File {yml_file} tidak ditemukan')
with open(full_path) as f:
y = yaml.safe_load(f)
panels = []
for title in y['Panels']:
panel = Panel(schema)
panel.title = title
fields = y['Panels'][title]
panel.my_widgets = get_widgets(form, fields)
panels.append(panel.render())
return '\n'.join(panels)
...@@ -3,6 +3,7 @@ from sqlalchemy import ( ...@@ -3,6 +3,7 @@ from sqlalchemy import (
cast, cast,
Text, Text,
) )
from pyramid.i18n import TranslationStringFactory
from pyramid.view import view_config from pyramid.view import view_config
from datatables import ( from datatables import (
ColumnDT, ColumnDT,
...@@ -14,6 +15,8 @@ from ...models.ziggurat import User ...@@ -14,6 +15,8 @@ from ...models.ziggurat import User
from ..user import BaseView from ..user import BaseView
_ = TranslationStringFactory('user')
columns = [ columns = [
ColumnDT(User.id), ColumnDT(User.id),
ColumnDT(User.user_name), ColumnDT(User.user_name),
......
<div metal:use-macro="load: ../../../templates/layout-menu.pt">
<div metal:fill-slot="head">
<link rel="stylesheet" type="text/css" href="/static/datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="/detable_static/css/demo_table.css"/>
<link rel="stylesheet" type="text/css" href="/detable_static/css/osipkd.css"/>
<script type="text/javascript" src="/static/datatables.min.js"></script>
</div>
<div metal:fill-slot="content" i18n:domain="user">
<h1 i18n:translate="">Users</h1>
<div class="jarviswidget jarviswidget-color-blueLight">
<div tal:content="structure table"/>
</div>
</div>
</div>
import colander
from sqlalchemy import (
cast,
Text,
)
from pyramid.i18n import TranslationStringFactory
from pyramid.view import view_config
from datatables import (
ColumnDT,
DataTables,
)
from detable import DeTable
from opensipkd.tools.buttons import (
btn_view,
btn_add,
btn_edit,
btn_delete,
btn_close,
)
from ...models import DBSession
from ...models.ziggurat import User
_ = TranslationStringFactory('user')
columns = [
ColumnDT(User.id, mData='id'),
ColumnDT(User.user_name, mData='user_name'),
ColumnDT(User.email, mData='email'),
ColumnDT(User.status, mData='status'),
ColumnDT(cast(User.last_login_date, Text), mData='last_login_date')]
@view_config(
route_name='theme2-user-act', renderer='json', permission='user-edit')
def view_act(request):
if request.matchdict['act'] == 'grid':
q = DBSession.query().select_from(User)
dt = DataTables(request.GET, q, columns)
return dt.output_result()
class ListSchema(colander.Schema):
id = colander.SchemaNode(colander.Integer())
user_name = colander.SchemaNode(colander.String(), width='100pt')
email = colander.SchemaNode(colander.String())
status = colander.SchemaNode(colander.String())
last_login_date = colander.SchemaNode(colander.String())
@view_config(
route_name='theme2-user', renderer='templates/user/list.pt',
permission='user-edit')
def view_list(request):
table = DeTable(
ListSchema(), action=f'/theme2/user',
buttons=(btn_view, btn_add, btn_edit, btn_delete, btn_close))
return dict(table=table.render(), title=_('Users'))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!