コード例 #1
0
# --// sortChildNodes //--

from Products.zms import standard

request = container.REQUEST
records = options.get('records')
prepare = options.get('prepare', True)

qorder = request.get('qorder', '')
qorderdir = request.get('qorderdir', '')
if not qorder:
    qorderdefault = zmscontext.attr('record_order_default')
    if qorderdefault.find(':') >= 0:
        qorder = qorderdefault[:qorderdefault.find(':')]
        qorderdir = qorderdefault[qorderdefault.find(':') + 1:]
    qorder = standard.get_session_value(zmscontext, 'qorder%s' % zmscontext.id,
                                        qorder)
    qorderdir = standard.get_session_value(zmscontext,
                                           'qorderdir%s' % zmscontext.id,
                                           qorderdir)
if records and qorder and qorderdir:
    if prepare:
        records = [{qorder: x.attr(qorder), 'ob': x} for x in records]
    [
        standard.operator_setitem(x, qorder, 'None') for x in records
        if x.get(qorder) is None
    ]
    records = standard.sort_list(records, qorder, qorderdir)
    if prepare:
        records = [x['ob'] for x in records]
    request.set('qorder', qorder)
    request.set('qorderdir', qorderdir)
コード例 #2
0
                                        None)
    records.append(record)
res = records
request.set('res', res)

# init filter from request.
self = zmscontext
REQUEST = request
index = 0
for filterIndex in range(100):
    for filterStereotype in ['attr', 'op', 'value']:
        requestkey = 'filter%s%i' % (filterStereotype, filterIndex)
        sessionkey = '%s_%s' % (requestkey, self.id)
        if REQUEST.get('btn') is None:
            # get value from session
            requestvalue = standard.get_session_value(self, sessionkey, '')
            # set request-value
            REQUEST.set(requestkey, requestvalue)
        else:
            # reset session-value
            standard.set_session_value(self, sessionkey, '')
            # get value from request
            requestvalue = REQUEST.form.get(requestkey, '')
            # reset value
            if REQUEST.get('btn') == 'BTN_RESET':
                requestvalue = ''
            # set request-/session-values for new index
            requestkey = 'filter%s%i' % (filterStereotype, index)
            sessionkey = '%s_%s' % (requestkey, self.id)
            REQUEST.set(requestkey, requestvalue)
            standard.set_session_value(self, sessionkey, requestvalue)
コード例 #3
0
 def recordSet_Filter(self, REQUEST):
     metaObj = self.getMetaobj(self.meta_id)
     res = REQUEST['res']
     # foreign key
     filterattr = 'fk_key'
     filtervalue = 'fk_val'
     sessionattr = '%s_%s' % (filterattr, self.id)
     sessionvalue = '%s_%s' % (filtervalue, self.id)
     standard.set_session_value(
         self, sessionattr,
         REQUEST.form.get(filterattr,
                          standard.get_session_value(self, sessionattr,
                                                     '')))
     standard.set_session_value(
         self, sessionvalue,
         REQUEST.form.get(
             filtervalue,
             standard.get_session_value(self, sessionvalue, '')))
     if REQUEST.get('btn') == 'BTN_RESET':
         standard.set_session_value(self, sessionattr, '')
         standard.set_session_value(self, sessionvalue, '')
     if standard.get_session_value(self,sessionattr, '') != '' and \
        standard.get_session_value(self,sessionvalue, ''):
         res = standard.filter_list(
             res, standard.get_session_value(self, sessionattr),
             standard.get_session_value(self, sessionvalue), '==')
         masterType = [
             x for x in metaObj['attrs'][1:]
             if x['id'] == standard.get_session_value(self, sessionattr)
         ][0]['type']
         master = [
             x for x in self.getParentNode().objectValues(['ZMSCustom'])
             if x.meta_id == masterType
         ][0]
         masterMetaObj = self.getMetaobj(masterType)
         masterAttrs = masterMetaObj['attrs']
         masterRows = master.getObjProperty(masterAttrs[0]['id'], REQUEST)
         masterRows = standard.filter_list(
             masterRows, masterAttrs[1]['id'],
             standard.get_session_value(self, sessionvalue), '==')
         REQUEST.set('masterMetaObj', masterMetaObj)
         REQUEST.set('masterRow', masterRows[0])
     # init filter from request.
     for filterIndex in range(100):
         for filterStereotype in ['attr', 'op', 'value']:
             requestkey = 'filter%s%i' % (filterStereotype, filterIndex)
             sessionkey = '%s_%s' % (requestkey, self.id)
             requestvalue = REQUEST.form.get(
                 requestkey,
                 standard.get_session_value(self, sessionkey, ''))
             if REQUEST.get('btn') == 'BTN_RESET':
                 requestvalue = ''
             REQUEST.set(requestkey, requestvalue)
             standard.set_session_value(self, sessionkey, requestvalue)
     standard.set_session_value(
         self, 'qfilters_%s' % self.id,
         REQUEST.form.get(
             'qfilters',
             standard.get_session_value(self, 'qfilters_%s' % self.id, 1)))
     # apply filter
     for filterIndex in range(100):
         suffix = '%i_%s' % (filterIndex, self.id)
         sessionattr = standard.get_session_value(self,
                                                  'filterattr%s' % suffix,
                                                  '')
         sessionop = standard.get_session_value(self, 'filterop%s' % suffix,
                                                '%')
         sessionvalue = standard.get_session_value(self,
                                                   'filtervalue%s' % suffix,
                                                   '')
         if sessionattr and sessionvalue:
             metaObjAttr = self.getMetaobjAttr(self.meta_id, sessionattr)
             sessionvalue = self.formatObjAttrValue(metaObjAttr,
                                                    sessionvalue,
                                                    REQUEST['lang'])
             res = standard.filter_list(res, sessionattr, sessionvalue,
                                        sessionop)
     REQUEST.set('res', res)
     return res