本文整理汇总了Python中s3crud.S3CRUD.crud_string方法的典型用法代码示例。如果您正苦于以下问题:Python S3CRUD.crud_string方法的具体用法?Python S3CRUD.crud_string怎么用?Python S3CRUD.crud_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类s3crud.S3CRUD
的用法示例。
在下文中一共展示了S3CRUD.crud_string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _datalist
# 需要导入模块: from s3crud import S3CRUD [as 别名]
# 或者: from s3crud.S3CRUD import crud_string [as 别名]
def _datalist(self, r, widget, **attr):
"""
Generate a dataList
@param r: the S3Request instance
@param widget: the widget as a tuple: (label, tablename, icon, filter)
@param attr: controller attributes for the request
"""
T = current.T
s3db = current.s3db
id = r.id
context = widget.get("context", None)
if context:
context = self._resolve_context(context, id)
s3db.context = context
tablename = widget.get("tablename", None)
resource = s3db.resource(tablename, context=True)
table = resource.table
# Config Options:
# 1st choice: Widget
# 2nd choice: get_config
# 3rd choice: Default
config = resource.get_config
list_fields = widget.get("list_fields", config("list_fields", None))
list_layout = widget.get("list_layout", config("list_layout", None))
orderby = widget.get("orderby", config("list_orderby", ~resource.table.created_on))
filter = widget.get("filter", None)
if filter:
resource.add_filter(filter)
# Use the widget-index to create a unique ID
listid = "profile-list-%s-%s" % (tablename, widget["index"])
# Page size
pagesize = widget.get("pagesize", 4)
representation = r.representation
if representation == "dl":
# Ajax-update
get_vars = r.get_vars
record_id = get_vars.get("record", None)
if record_id is not None:
# Ajax-update of a single record
resource.add_filter(S3FieldSelector("id") == record_id)
start, limit = 0, 1
else:
# Ajax-update of full page
start = get_vars.get("start", None)
limit = get_vars.get("limit", None)
if limit is not None:
try:
start = int(start)
limit = int(limit)
except ValueError:
start, limit = 0, pagesize
else:
start = None
else:
# Page-load
start, limit = 0, pagesize
# Ajax-delete items?
if representation == "dl" and r.http in ("DELETE", "POST"):
if "delete" in r.get_vars:
return self._dl_ajax_delete(r, resource)
else:
r.error(405, r.ERROR.BAD_METHOD)
# dataList
datalist, numrows, ids = resource.datalist(
fields=list_fields, start=start, limit=limit, listid=listid, orderby=orderby, layout=list_layout
)
# Render the list
ajaxurl = r.url(vars={"update": widget["index"]}, representation="dl")
data = datalist.html(
ajaxurl=ajaxurl,
pagesize=pagesize,
empty=P(
I(_class="icon-folder-open-alt"),
BR(),
S3CRUD.crud_string(tablename, "msg_no_match"),
_class="empty_card-holder",
),
)
if representation == "dl":
# This is an Ajax-request, so we don't need the wrapper
current.response.view = "plain.html"
return data
# Interactive only below here
label = widget.get("label", "")
if label:
label = T(label)
icon = widget.get("icon", "")
if icon:
icon = TAG[""](I(_class=icon), " ")
#.........这里部分代码省略.........
示例2: _create_popup
# 需要导入模块: from s3crud import S3CRUD [as 别名]
# 或者: from s3crud.S3CRUD import crud_string [as 别名]
def _create_popup(self, r, widget, list_id, resource, context, numrows):
"""
Render an action link for a create-popup (used in data lists
and data tables).
@param r: the S3Request instance
@param widget: the widget definition as dict
@param list_id: the list ID
@param resource: the target resource
@param context: the context filter
@param numrows: the total number of rows in the list/table
"""
create = ""
insert = widget.get("insert", True)
table = resource.table
if insert and current.auth.s3_has_permission("create", table):
s3 = current.response.s3
tablename = resource.tablename
#if tablename = "org_organisation":
# @ToDo: Special check for creating resources on Organisation profile
# URL-serialize the widget filter
widget_filter = widget.get("filter")
if widget_filter:
vars = widget_filter.serialize_url(resource)
else:
vars = Storage()
# URL-serialize the context filter
if context:
filters = context.serialize_url(resource)
for f in filters:
vars[f] = filters[f]
# URL-serialize the widget default
default = widget.get("default")
if default:
k, v = default.split("=", 1)
vars[k] = v
# URL-serialize the list ID (refresh-target of the popup)
vars.refresh = list_id
# CRUD string
title_create = widget.get("title_create", None)
if title_create:
title_create = current.T(title_create)
else:
title_create = S3CRUD.crud_string(tablename, "title_create")
# Popup URL
# Default to primary REST controller for the resource being added
c, f = tablename.split("_", 1)
c = widget.get("create_controller", c)
f = widget.get("create_function", f)
component = widget.get("create_component", None)
if component:
args = [r.id, component, "create.popup"]
else:
args = ["create.popup"]
add_url = URL(c=c, f=f, args=args, vars=vars)
if callable(insert):
# Custom widget
create = insert(r, list_id, title_create, add_url)
elif s3.crud.formstyle == "bootstrap":
# Bootstrap-style action icon
create = A(I(_class="icon icon-plus-sign small-add"),
_href=add_url,
_class="s3_modal",
_title=title_create,
)
else:
# Standard action button
create = A(title_create,
_href=add_url,
_class="action-btn profile-add-btn s3_modal",
)
if widget.get("type") == "datalist":
# If this is a multiple=False widget and we already
# have a record, we hide the create-button
multiple = widget.get("multiple", True)
if not multiple and hasattr(create, "update"):
if numrows:
create.update(_style="display:none;")
else:
create.update(_style="display:block;")
# Script to hide/unhide the create-button on Ajax
# list updates
createid = create["_id"]
if not createid:
createid = "%s-add-button" % list_id
create.update(_id=createid)
#.........这里部分代码省略.........
示例3: _datalist
# 需要导入模块: from s3crud import S3CRUD [as 别名]
# 或者: from s3crud.S3CRUD import crud_string [as 别名]
def _datalist(self, r, widget, **attr):
"""
Generate a data list
@param r: the S3Request instance
@param widget: the widget definition as dict
@param attr: controller attributes for the request
"""
T = current.T
s3db = current.s3db
context = widget.get("context", None)
tablename = widget.get("tablename", None)
resource, context = self._resolve_context(r, tablename, context)
# Config Options:
# 1st choice: Widget
# 2nd choice: get_config
# 3rd choice: Default
config = resource.get_config
list_fields = widget.get("list_fields",
config("list_fields", None))
list_layout = widget.get("list_layout",
config("list_layout", None))
orderby = widget.get("orderby",
config("list_orderby",
~resource.table.created_on))
filter = widget.get("filter", None)
if filter:
resource.add_filter(filter)
# Use the widget-index to create a unique ID
list_id = "profile-list-%s-%s" % (tablename, widget["index"])
# Page size
pagesize = widget.get("pagesize", 4)
representation = r.representation
if representation == "dl":
# Ajax-update
get_vars = r.get_vars
record_id = get_vars.get("record", None)
if record_id is not None:
# Ajax-update of a single record
resource.add_filter(S3FieldSelector("id") == record_id)
start, limit = 0, 1
else:
# Ajax-update of full page
start = get_vars.get("start", None)
limit = get_vars.get("limit", None)
if limit is not None:
try:
start = int(start)
limit = int(limit)
except ValueError:
start, limit = 0, pagesize
else:
start = None
else:
# Page-load
start, limit = 0, pagesize
# Ajax-delete items?
if representation == "dl" and r.http in ("DELETE", "POST"):
if "delete" in r.get_vars:
return self._dl_ajax_delete(r, resource)
else:
r.error(405, current.ERROR.BAD_METHOD)
# dataList
datalist, numrows, ids = resource.datalist(fields=list_fields,
start=start,
limit=limit,
list_id=list_id,
orderby=orderby,
layout=list_layout)
# Render the list
ajaxurl = r.url(vars={"update": widget["index"]},
representation="dl")
data = datalist.html(ajaxurl=ajaxurl,
pagesize=pagesize,
empty = P(I(_class="icon-folder-open-alt"),
BR(),
S3CRUD.crud_string(tablename,
"msg_no_match"),
_class="empty_card-holder"
),
)
if representation == "dl":
# This is an Ajax-request, so we don't need the wrapper
current.response.view = "plain.html"
return data
# Interactive only below here
label = widget.get("label", "")
if label:
label = T(label)
icon = widget.get("icon", "")
#.........这里部分代码省略.........
示例4: _datatable
# 需要导入模块: from s3crud import S3CRUD [as 别名]
# 或者: from s3crud.S3CRUD import crud_string [as 别名]
#.........这里部分代码省略.........
if s3.dataTable_pageLength:
display_length = s3.dataTable_pageLength
else:
display_length = widget.get("pagesize", 10)
dtargs["dt_lengthMenu"] = [[10, 25, 50, -1],
[10, 25, 50, str(current.T("All"))]
]
# ORDERBY fallbacks: widget->resource->default
orderby = widget.get("orderby")
if not orderby:
orderby = resource.get_config("orderby")
if not orderby:
orderby = default_orderby()
# Server-side pagination?
if not s3.no_sspag:
dt_pagination = "true"
if not limit and display_length is not None:
limit = 2 * display_length
else:
limit = None
else:
dt_pagination = "false"
# Get the data table
dt, totalrows, ids = resource.datatable(fields=list_fields,
start=start,
limit=limit,
orderby=orderby)
displayrows = totalrows
if dt.empty:
empty_str = self.crud_string(tablename,
"msg_list_empty")
else:
empty_str = self.crud_string(tablename,
"msg_no_match")
empty = DIV(empty_str, _class="empty")
dtargs["dt_pagination"] = dt_pagination
dtargs["dt_pageLength"] = display_length
# @todo: fix base URL (make configurable?) to fix export options
s3.no_formats = True
dtargs["dt_base_url"] = r.url(method="", vars={})
dtargs["dt_ajax_url"] = r.url(vars={"update": widget["index"]},
representation="aadata")
actions = widget.get("actions")
if callable(actions):
actions = actions(r, list_id)
if actions:
dtargs["dt_row_actions"] = actions
datatable = dt.html(totalrows,
displayrows,
id=list_id,
**dtargs)
if dt.data:
empty.update(_style="display:none")
else:
datatable.update(_style="display:none")
contents = DIV(datatable, empty, _class="dt-contents")
# Link for create-popup
create_popup = self._create_popup(r,
示例5: _create_popup
# 需要导入模块: from s3crud import S3CRUD [as 别名]
# 或者: from s3crud.S3CRUD import crud_string [as 别名]
def _create_popup(r, widget, list_id, resource, context, numrows):
"""
Render an action link for a create-popup (used in data lists
and data tables).
@param r: the S3Request instance
@param widget: the widget definition as dict
@param list_id: the list ID
@param resource: the target resource
@param context: the context filter
@param numrows: the total number of rows in the list/table
"""
create = ""
insert = widget.get("insert", True)
if not insert:
return create
table = resource.table
tablename = resource.tablename
# Default to primary REST controller for the resource being added
c, f = tablename.split("_", 1)
create_controller = widget.get("create_controller")
if create_controller:
c = create_controller
create_function = widget.get("create_function")
if create_function:
f = create_function
permit = current.auth.s3_has_permission
create_ok = permit("create", table, c=c, f=f)
if create_ok:
if not create_controller or not create_function:
# Assume not component context
create_ok = permit("update", r.table, record_id=r.id, c=c, f=f)
if create_ok:
#if tablename = "org_organisation":
# @ToDo: Special check for creating resources on Organisation profile
# URL-serialize the widget filter
widget_filter = widget.get("filter")
if widget_filter:
url_vars = widget_filter.serialize_url(resource)
else:
url_vars = Storage()
# URL-serialize the context filter
if context:
filters = context.serialize_url(resource)
for selector in filters:
url_vars[selector] = filters[selector]
# URL-serialize the widget default
default = widget.get("default")
if default:
k, v = default.split("=", 1)
url_vars[k] = v
# URL-serialize the list ID (refresh-target of the popup)
url_vars.refresh = list_id
# Indicate that popup comes from profile (and which)
url_vars.profile = r.tablename
# CRUD string
label_create = widget.get("label_create", None)
# Activate if-required
#if label_create and isinstance(label_create, basestring):
if label_create:
label_create = current.T(label_create)
else:
label_create = S3CRUD.crud_string(tablename, "label_create")
# Popup URL
component = widget.get("create_component", None)
if component:
args = [r.id, component, "create.popup"]
else:
args = ["create.popup"]
add_url = URL(c=c, f=f, args=args, vars=url_vars)
if callable(insert):
# Custom widget
create = insert(r, list_id, label_create, add_url)
elif current.deployment_settings.ui.formstyle == "bootstrap":
# Bootstrap-style action icon
create = A(ICON("plus-sign", _class="small-add"),
_href=add_url,
_class="s3_modal",
_title=label_create,
)
else:
# Standard action button
create = A(label_create,
_href=add_url,
_class="action-btn profile-add-btn s3_modal",
)
#.........这里部分代码省略.........
示例6: _datalist
# 需要导入模块: from s3crud import S3CRUD [as 别名]
# 或者: from s3crud.S3CRUD import crud_string [as 别名]
#.........这里部分代码省略.........
if filter:
resource.add_filter(filter)
# Use the widget-index to create a unique ID
listid = "profile-list-%s-%s" % (tablename, widget["index"])
c, f = tablename.split("_", 1)
# Permission to create new items?
# @ToDo: Special check for creating resources on Organisation profile
if current.auth.s3_has_permission("create", table):
if filter:
vars = filter.serialize_url(filter)
else:
vars = Storage()
vars.refresh = listid
if context:
vars[context] = r.id
create = A(I(_class="icon icon-plus-sign small-add"),
_href=URL(c=c, f=f, args=["create.popup"], vars=vars),
_class="s3_modal",
)
else:
create = ""
# Page size
pagesize = 4
representation = r.representation
if representation == "dl":
# Ajax-update
get_vars = r.get_vars
record_id = get_vars.get("record", None)
if record_id is not None:
# Ajax-update of a single record
resource.add_filter(S3FieldSelector("id") == record_id)
start, limit = 0, 1
else:
# Ajax-update of full page
start = get_vars.get("start", None)
limit = get_vars.get("limit", None)
if limit is not None:
try:
start = int(start)
limit = int(limit)
except ValueError:
start, limit = 0, 4
else:
start = None
else:
# Page-load
start, limit = 0, 4
# Ajax-delete items?
if representation == "dl" and r.http in ("DELETE", "POST"):
if "delete" in r.get_vars:
return self._dl_ajax_delete(r, resource)
else:
r.error(405, r.ERROR.BAD_METHOD)
# dataList
datalist, numrows, ids = resource.datalist(fields=list_fields,
start=start,
limit=limit,
listid=listid,
orderby=orderby,
layout=list_layout)
# Render the list
ajaxurl = r.url(vars={"update": widget["index"]},
representation="dl")
data = datalist.html(ajaxurl=ajaxurl, pagesize=pagesize)
if numrows == 0:
msg = P(I(_class="icon-folder-open-alt"),
BR(),
S3CRUD.crud_string(resource.tablename,
"msg_no_match"),
_class="empty_card-holder")
data.insert(1, msg)
if representation == "dl":
# This is an Ajax-request, so we don't need the wrapper
current.response.view = "plain.html"
return data
label = widget.get("label", "")
if label:
label = current.T(label)
icon = widget.get("icon", "")
if icon:
icon = TAG[""](I(_class=icon), " ")
# Render the widget
output = DIV(create,
H4(icon,
label,
_class="profile-sub-header"),
DIV(data,
_class="card-holder"),
_class="span6")
return output