Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
web-starter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 95af3531
authored
Apr 14, 2022
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Penggunaan modul yaform
1 parent
9225fc21
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
215 deletions
CHANGES.txt
setup.py
web_starter/views/theme1/templates/user/edit.yml
web_starter/views/theme1/templates/user/form.pt
web_starter/views/theme1/templates/user/mapping_item.pt
web_starter/views/theme1/templates/user/panel.pt
web_starter/views/theme1/user.py
web_starter/views/user.py
CHANGES.txt
View file @
95af353
0.2.1 2022-04-1
1
0.2.1 2022-04-1
4
----------------
----------------
- Tambah route /theme1/user/add untuk form yang lebih ringkas.
- Tambah route /theme1/user/add untuk form yang lebih ringkas.
...
...
setup.py
View file @
95af353
...
@@ -28,13 +28,11 @@ requires = [
...
@@ -28,13 +28,11 @@ requires = [
'pytz'
,
'pytz'
,
'ziggurat-foundations'
,
'ziggurat-foundations'
,
'alembic'
,
'alembic'
,
'colander'
,
'deform'
,
'pyramid_beaker'
,
'pyramid_beaker'
,
'pyramid_mailer'
,
'pyramid_mailer'
,
'sqlalchemy-datatables'
,
'sqlalchemy-datatables'
,
'ColanderAlchemy'
,
'ColanderAlchemy'
,
'
PyYAML
'
]
'
yaform @ git+https://git.opensipkd.com/sugiana/web-starter.git
'
]
tests_require
=
[
tests_require
=
[
'WebTest >= 1.3.1'
,
# py3 compat
'WebTest >= 1.3.1'
,
# py3 compat
...
...
web_starter/views/theme1/templates/user/edit.yml
View file @
95af353
%YAML
1.2
%YAML
1.2
---
---
Panels
:
No Title
:
No Title
:
-
user_name
-
user_name
-
email
-
email
-
groups
-
groups
Bio Data
:
Bio Data
:
-
tempat_lahir
-
tempat_lahir
-
tgl_lahir
-
tgl_lahir
Alamat
:
Alamat
:
-
alamat
-
alamat
-
Group 1
:
-
rt col-md-2
-
rt
-
rw col-md-2
-
rw
-
kelurahan
-
Group 2
:
-
kecamatan
-
kelurahan
-
kabupaten
-
kecamatan
-
provinsi
-
kabupaten
-
provinsi
web_starter/views/theme1/templates/user/form.pt
deleted
100644 → 0
View file @
9225fc2
<form
tal:define="style style|field.widget.style;
css_class css_class|string:${field.widget.css_class or field.css_class or ''};
item_template item_template|field.widget.item_template;
autocomplete autocomplete|field.autocomplete;
title title|field.title;
errormsg errormsg|field.errormsg;
description description|field.description;
buttons buttons|field.buttons;
use_ajax use_ajax|field.use_ajax;
ajax_options ajax_options|field.ajax_options;
formid formid|field.formid;
action action|field.action or None;
method method|field.method;"
tal:attributes="autocomplete autocomplete;
style style;
class css_class;
action action;
attributes|field.widget.attributes|{};"
id="${formid}"
method="${method}"
enctype="multipart/form-data"
accept-charset="utf-8"
i18n:domain="deform">
<!-- fieldset class="deform-form-fieldset" -->
<legend tal:condition="title">${title}</legend>
<input type="hidden" name="_charset_"/>
<input type="hidden" name="__formid__" value="${formid}"/>
<div class="alert alert-danger" tal:condition="field.error">
<div class="error-msg-lbl" i18n:translate="">
There was a problem with your submission
</div>
<div class="error-msg-detail" i18n:translate="">
Errors have been highlighted below
</div>
<p class="error-msg">${field.errormsg}</p>
</div>
<p class="section first" tal:condition="description">
${description}
</p>
<div tal:replace="structure field.my_widgets"/>
<div class="form-group deform-form-buttons">
<tal:loop tal:repeat="button buttons">
<button
tal:define="btn_disposition repeat.button.start and 'btn-primary' or 'btn-default';"
tal:attributes="disabled button.disabled if button.disabled else None;
attributes|button.attributes|{};"
id="${formid+button.name}"
name="${button.name}"
type="${button.type}"
class="btn ${button.css_class or btn_disposition}"
value="${button.value}"
tal:condition="button.type != 'link'">
<span tal:condition="button.icon" class="glyphicon glyphicon-${button.icon}"></span>
${button.title}
</button>
<a
tal:define="btn_disposition repeat.button.start and 'btn-primary' or 'btn-default';
btn_href button.value|''"
class="btn ${button.css_class or btn_disposition}"
id="${field.formid + button.name}"
href="${btn_href}"
tal:condition="button.type == 'link'">
<span tal:condition="button.icon" class="glyphicon glyphicon-${button.icon}"></span>
${button.title}
</a>
</tal:loop>
</div>
<!-- /fieldset -->
<script type="text/javascript" tal:condition="use_ajax">
deform.addCallback(
'${formid}',
function(oid) {
var target = '#' + oid;
var options = {
target: target,
replaceTarget: true,
success: function() {
deform.processCallbacks();
deform.focusFirstInput(target);
},
beforeSerialize: function() {
// See http://bit.ly/1agBs9Z (hack to fix tinymce-related ajax bug)
if ('tinymce' in window) {
$(tinymce.get()).each(
function(i, el) {
var content = el.getContent();
var editor_input = document.getElementById(el.id);
editor_input.value = content;
});
}
}
};
var extra_options = ${ajax_options} || {};
$('#' + oid).ajaxForm($.extend(options, extra_options));
}
);
</script>
</form>
web_starter/views/theme1/templates/user/mapping_item.pt
deleted
100644 → 0
View file @
9225fc2
<div class="${field.my_level < 2 and 'col-md-6' or 'col-md-2'}">
<div tal:define="error_class error_class|field.widget.error_class;
description description|field.description;
title title|field.title;
oid oid|field.oid;
hidden hidden|field.widget.hidden;
category category|field.widget.category;
structural hidden or category == 'structural';
required required|field.required;"
class="form-group ${field.error and 'has-error' or ''} ${field.widget.item_css_class or ''} ${field.default_item_css_class()}"
title="${description}"
id="item-${oid}"
tal:omit-tag="structural"
i18n:domain="user">
<label for="${oid}"
class="col-md-3 control-label ${required and 'required' or ''}"
tal:condition="not structural"
id="req-${oid}">
${title}
</label>
<div tal:define="input_prepend field.widget.input_prepend | None;
input_append field.widget.input_append | None"
tal:omit-tag="not (input_prepend or input_append)">
<span class="input-group-addon" tal:condition="input_prepend">
${input_prepend}
</span>
<div class="col-md-9">
<span tal:replace="structure field.serialize(cstruct).strip()"/>
<span class="input-group-addon" tal:condition="input_append">
${input_append}
</span>
</div>
</div>
<p class="help-block"
tal:define="errstr 'error-%s' % field.oid"
tal:repeat="msg field.error.messages()"
i18n:translate=""
tal:attributes="id repeat.msg.index==0 and errstr or
('%s-%s' % (errstr, repeat.msg.index))"
tal:condition="field.error and not field.widget.hidden and not field.typ.__class__.__name__=='Mapping'">
${msg}
</p>
<p tal:condition="field.description and not field.widget.hidden" class="help-block">
${field.description}
</p>
</div>
</div>
web_starter/views/theme1/templates/user/panel.pt
deleted
100644 → 0
View file @
9225fc2
<div
tal:define="title field.title;
widgets field.my_widgets;"
class="panel">
<div tal:condition="title != 'No Title'" class="panel-heading bg-info">
<h2 class="panel-title text-center">${title}</h2>
</div>
<div class="panel-body">
<div tal:replace="structure widgets"/>
</div>
</div>
web_starter/views/theme1/user.py
View file @
95af353
...
@@ -4,24 +4,14 @@ from sqlalchemy import (
...
@@ -4,24 +4,14 @@ from sqlalchemy import (
Text
,
Text
,
)
)
from
pyramid.view
import
view_config
from
pyramid.view
import
view_config
from
deform
import
(
Form
,
ZPTRendererFactory
,
)
from
datatables
import
(
from
datatables
import
(
ColumnDT
,
ColumnDT
,
DataTables
,
DataTables
,
)
)
from
yaform
import
Form
from
...models
import
DBSession
from
...models
import
DBSession
from
...models.ziggurat
import
User
from
...models.ziggurat
import
User
from
..user
import
(
from
..user
import
BaseView
deform_templates
,
BaseView
,
)
from
.renderer
import
(
Panel
,
render
,
)
columns
=
[
columns
=
[
...
@@ -33,9 +23,9 @@ columns = [
...
@@ -33,9 +23,9 @@ columns = [
here
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
here
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
my_templates
=
os
.
path
.
join
(
here
,
'templates'
,
'user'
)
my_templates
=
os
.
path
.
join
(
here
,
'templates'
,
'user'
)
search_path
=
[
my_templates
,
deform_templates
]
my_renderer
=
ZPTRendererFactory
(
search_path
)
# Ini untuk memberitahu di mana file *.yml berada
Panel
.
set_zpt_renderer
(
search_path
)
Form
.
default_renderer
.
loader
.
search_path
.
insert
(
0
,
my_templates
)
@view_config
(
@view_config
(
...
@@ -54,12 +44,10 @@ def view_act(request):
...
@@ -54,12 +44,10 @@ def view_act(request):
class
View
(
BaseView
):
class
View
(
BaseView
):
def
render
(
self
,
form
):
# Override
form_class
=
Form
form
.
my_widgets
=
render
(
form
,
'edit'
)
return
form
.
render
()
def
get_form
(
self
,
schema
,
user
=
None
):
# Override
def
render
(
self
,
form
):
# Override
return
super
()
.
get_form
(
schema
,
user
,
my_renderer
)
return
form
.
render
(
yml_template
=
'edit'
)
@view_config
(
@view_config
(
route_name
=
'theme1-user-add'
,
renderer
=
'templates/user/add.pt'
,
route_name
=
'theme1-user-add'
,
renderer
=
'templates/user/add.pt'
,
...
...
web_starter/views/user.py
View file @
95af353
...
@@ -248,6 +248,8 @@ def update(request, user, values):
...
@@ -248,6 +248,8 @@ def update(request, user, values):
class
BaseView
:
class
BaseView
:
form_class
=
Form
def
__init__
(
self
,
request
):
def
__init__
(
self
,
request
):
self
.
request
=
request
self
.
request
=
request
...
@@ -259,9 +261,9 @@ class BaseView:
...
@@ -259,9 +261,9 @@ class BaseView:
schema
=
schema
.
bind
(
schema
=
schema
.
bind
(
status_list
=
status_list
,
group_list
=
group_list
,
user
=
user
)
status_list
=
status_list
,
group_list
=
group_list
,
user
=
user
)
if
renderer
:
if
renderer
:
return
Form
(
return
self
.
form_class
(
schema
,
buttons
=
(
btn_save
,
btn_cancel
),
renderer
=
renderer
)
schema
,
buttons
=
(
btn_save
,
btn_cancel
),
renderer
=
renderer
)
return
Form
(
schema
,
buttons
=
(
btn_save
,
btn_cancel
))
return
self
.
form_class
(
schema
,
buttons
=
(
btn_save
,
btn_cancel
))
def
add
(
self
):
def
add
(
self
):
request
=
self
.
request
request
=
self
.
request
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment