本文整理汇总了Python中core.Core.get_document方法的典型用法代码示例。如果您正苦于以下问题:Python Core.get_document方法的具体用法?Python Core.get_document怎么用?Python Core.get_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.Core
的用法示例。
在下文中一共展示了Core.get_document方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DocSet
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import get_document [as 别名]
class DocSet(FORM):
T = current.T
request = current.request
response = current.response
session = current.session
TOTAL_DOCUMENT_COUNT = 'TOTAL_DOCUMENTS'
INITIAL_DOCUMENT_COUNT = 'INITIAL_DOCUMENTS'
TEMPLATE = 'TEMPLATE'
DELETION_FIELD_NAME = 'DELETE'
def __init__(self, document, docset, extra=4, *args, **kwargs):
if not 'hidden' in kwargs:
kwargs['hidden'] = self._get_hidden_fields()
FORM.__init__(self, *args, **kwargs)
self.document = document
self.docset = docset
self.db = Core().db()
self.extra = extra
self._template_fields = filter(lambda df: df.type not in ('sectionbreak', 'columnbreak') or \
df.property('visibility', 'is_writable')!='NEVER', self.document.META.DOCFIELDS)
self._cols = self.document.property('type', 'listable_columns') or \
[df.df_name for df in filter(lambda x: x.property('policy','is_readable')=='ALWAYS', self.DOCUMENT.META.DOCFIELDS)]
self._cols = [filter(lambda x: x.df_name == column, self.document.META.DOC_FIELDS)[0] for column in self._cols]
self._head = TR([TH()]+[TH(df.df_title, **{'_data-metatype': df.df_type}) for df in self._cols])
components = [self._head, self._construct_documents()]
for i in xrange(self.extra):
components.append(self._get_empty_document((self.get_total_document_count()-self.extra)+i))
self.components = [components]
def _get_hidden_fields(self):
from gluon.dal import Field
hidden = [
Field(self.TOTAL_DOCUMENT_COUNT, 'integer', default=self.get_total_document_count(), required=True),
Field(self.INITIAL_DOCUMENT_COUNT, 'integer', default=self.get_initial_document_count(), required=True),
Field(self.TEMPLATE, 'text', required=True, default=self._template_document())
]
return hidden
def __iter__(self):
return iter(self.documents)
def __getitem__(self, index):
return self.documents[index]
def __len__(self):
return len(self.documents)
def __nonzero__(self):
return True
def _template_document(self):
template = TR(*[TD(widgets[df.df_type].widget(df,
'' ,
row=self.document)) for df in self._template_fields])
for element in template.elements('_name*=[_]'):
element['_name']+='_{id}'
return template.xml()
def get_total_document_count(self):
return int(self.vars[self.TOTAL_DOCUMENT_COUNT] or 0) + self.extra
def get_initial_document_count(self):
return self.vars[self.INITIAL_DOCUMENT_COUNT] or len(self.docset)
def _construct_documents(self):
self.forms = []
for i in xrange(self.get_total_document_count()):
self.forms.append(self._contruct_form(i))
def _construct_document(self, i, **kwargs):
from gluon.dal import Field
document = TR(*[TD(widgets[df.df_type].widget(df,
self.docset[i][df.df_name] if hasattr(self.docset[i], df.df_name) else '' ,
row=self.document)) for df in self._template_fields] + \
[TD(Field(self.DELETION_FIELD_NAME + '_%d'%i, 'boolean', default=False))])
for element in document.elements('_name*=[_]'):
element['_name']+='_%d'%i
return document
def _get_empty_document(self, i, **kwargs):
emptydoc = self.db.get_document(self.document.doc_name)
document = TR(*[TD(widgets[df.df_type].widget(df,
emptydoc[df.df_name] if hasattr(emptydoc, df.df_name) else '' ,
row=self.document)) for df in self._template_fields])
for element in document.elements('_name*=[_]'):
element['_name']+='_%d'%i
return document
def process(self, **kwargs):
for i in xrange(self.get_total_document_count()):
#.........这里部分代码省略.........