def properties(self): "Displays a generic edit form based on the object's schema" sLang = context.request.get_lang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = (iUserRole == permsresolver.READER) admin = (iUserRole == permsresolver.COORDINATOR) modified = date.Date(self.modified) params = { 'URI': self.id, 'ICON': self.__image__, 'TITLE': xml.xml_encode(self.displayName.value), 'MODIFIED': modified.format(DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.contentclass, 'PROPERTIES': [], 'EXTRA_TABS': [], 'ADMIN': admin, 'ROLES_INHERITED': str(self.inheritRoles).lower(), 'ACTION_DISABLED': str(readonly).lower(), 'METHOD': 'update' } # inspect item properties for attr_name in self.__props__: attr = getattr(self, attr_name) if isinstance(attr, datatypes.DataType): control, tab = \ _getControlFromAttribute(self, attr_name, attr, readonly) params['PROPERTIES'].append(control) params['EXTRA_TABS'].append(tab) return params
def __serializeParam(self, param): if type(param)==str: return('<value>%s</value>' % xml.xml_encode(param)) elif type(param)==unicode: return('<value>%s</value>' % xml.xml_encode(param.encode(self.encoding))) elif type(param)==int or type(param)==long: return('<value><i4>%i</i4></value>' % param) elif type(param)==bool: return('<value><boolean>%i</boolean></value>' % param) elif type(param)==float: return('<value><double>%f</double></value>' % param) elif type(param)==list or type(param)==tuple: sArray = '<value><array><data>' for elem in param: serialized = self.__serializeParam(elem) if serialized: sArray += serialized sArray += '</data></array></value>' return(sArray) elif type(param)==dict: sStruct = '<value><struct>' for member, value in param.items(): serialized = self.__serializeParam(value) if serialized: sStruct += '<member><name>%s</name>%s</member>' % \ (member.encode(self.encoding), serialized) sStruct += '</struct></value>' return(sStruct) elif isinstance(param, objectSet.ObjectSet): sArray = '<value><array><data>' for rec in param: sArray += self.__serializeParam(rec) sArray += '</data></array></value>' return sArray elif isinstance(param, systemObjects.GenericItem) or \ isinstance(param, systemObjects.Composite): xmlrpc_object = {} for attr in param.__props__ + DEFAULT_PROPS: try: oAttr = getattr(param, attr) except AttributeError: continue if isinstance(oAttr, datatypes.ExternalAttribute): xmlrpc_object[attr] = '[EXTERNAL STREAM]' else: oAttr = core.getAttribute(param, [attr]) if isinstance(oAttr, objectSet.ObjectSet): # we have an object set with objects xmlrpc_object[attr] = [ {'id': x._id, 'displayName': x.displayName.value} for x in oAttr ] else: xmlrpc_object[attr] = oAttr return self.__serializeParam( xmlrpc_object ) elif isinstance(param, date.Date): return '<value><dateTime.iso8601>%s</dateTime.iso8601></value>' % \ param.toIso8601() else: return None#self.__serializeParam(str(param))
def rename(self): "Displays the rename dialog" return { "TITLE": xml.xml_encode(self.displayName.value), "ID": self.id, "DN": xml.xml_encode(self.displayName.value), }
def rename(self): "Displays the rename dialog" return { 'TITLE': xml.xml_encode(self.displayName.value), 'ID': self.id, 'DN': xml.xml_encode(self.displayName.value) }
def properties(self): "Displays a generic edit form based on the object's schema" sLang = context.request.get_lang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = iUserRole == permsresolver.READER admin = iUserRole == permsresolver.COORDINATOR modified = date.Date(self.modified) params = { "URI": self.id, "ICON": self.__image__, "TITLE": xml.xml_encode(self.displayName.value), "MODIFIED": modified.format(DATES_FORMAT, sLang), "MODIFIED_BY": xml.xml_encode(self.modifiedBy), "CONTENTCLASS": self.contentclass, "PROPERTIES": [], "EXTRA_TABS": [], "ADMIN": admin, "ROLES_INHERITED": str(self.inheritRoles).lower(), "ACTION_DISABLED": str(readonly).lower(), "METHOD": "update", } # inspect item properties for attr_name in self.__props__: attr = getattr(self, attr_name) if isinstance(attr, datatypes.DataType): control, tab = _getControlFromAttribute(self, attr_name, attr, readonly) params["PROPERTIES"].append(control) params["EXTRA_TABS"].append(tab) return params
def _getControlFromAttribute(item, attrname, attr, readonly, isNew=False): attrlabel = '@@%s@@' % attrname sControl = '' sTab = '' if isinstance(attr, datatypes.String): sControl = AUTO_CONTROLS[datatypes.String] % \ (attrlabel, attrname, xml.xml_encode(attr.value), str(readonly).lower()) elif isinstance(attr, datatypes.Boolean): sControl = AUTO_CONTROLS[datatypes.Boolean] % \ (attrlabel, attrname, str(attr.value).lower(), str(readonly).lower()) elif isinstance(attr, datatypes.Date): sControl = AUTO_CONTROLS[datatypes.Date] % \ (attrlabel, attrname, attr.to_iso_8601(), str(readonly).lower()) elif isinstance(attr, datatypes.File): if isNew: href = '' else: href = item.id + '?cmd=getfile' sControl = AUTO_CONTROLS[datatypes.File] % ( attrlabel, attrname, attr.filename, len(attr), href, str(readonly).lower()) elif isinstance(attr, datatypes.Text): sTab = AUTO_CONTROLS[datatypes.Text] % (attrlabel, attrname, str(readonly).lower(), xml.xml_encode(attr.value)) elif isinstance(attr, datatypes.Reference1): oRefItem = attr.get_item() if oRefItem: refid = oRefItem.id refname = oRefItem.displayName.value else: refid = refname = '' sReadonly = str(readonly).lower() sControl = AUTO_CONTROLS[datatypes.Reference1] % ('|'.join( attr.relCc), attrlabel, attrname, refid, refname, sReadonly) elif isinstance(attr, datatypes.ReferenceN): options = [] rel_items = attr.get_items() for item in rel_items: options += [ xml.xml_encode(item.__image__), item.id, xml.xml_encode(item.displayName.value) ] sTab = AUTO_CONTROLS[datatypes.ReferenceN] % (attrlabel, '|'.join( attr.relCc), attrname, str(readonly).lower(), ';'.join(options)) return (sControl, sTab)
def properties(self): "Displays the deleted item's properties form" sLang = context.request.get_lang() modified = date.Date(self.modified) return { 'ICON': self.__image__, 'NAME': xml.xml_encode(self.originalName), 'LOC': xml.xml_encode(self.originalLocation), 'MODIFIED': modified.format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.get_deleted_item().contentclass}
def properties(self): "Displays the deleted item's properties form" context = HttpContext.current() sLang = context.request.getLang() modified = date.Date(self.modified) return { "ICON": self.__image__, "NAME": xml.xml_encode(self.originalName), "LOC": xml.xml_encode(self.originalLocation), "MODIFIED": modified.format(baseitem.DATES_FORMAT, sLang), "MODIFIED_BY": xml.xml_encode(self.modifiedBy), "CONTENTCLASS": self.get_deleted_item().contentclass, }
def properties(self): "Displays the user's properties form" context = HttpContext.current() context.response.setHeader('cache-control', 'no-cache') sLang = context.request.getLang() user = context.session.user iUserRole = objectAccess.getAccess(self, user) readonly = (iUserRole==1) params = { 'ID' : self.id, 'ICON' : self.__image__, 'NAME' : self.displayName.value, 'FULL_NAME' : self.fullName.value, 'EMAIL' : self.email.value, 'DESCRIPTION' : self.description.value, 'MODIFIED' : date.Date(self.modified).format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY' : self.modifiedBy, 'CONTENTCLASS' : self.contentclass, 'SELECT_FROM' : self.parentid, 'REL_CC' : '|'.join(self.memberof.relCc), 'SELECT_FROM_POLICIES' : 'policies', 'POLICIES_REL_CC' : '|'.join(self.policies.relCc), 'READONLY' : str(readonly).lower() } memberof_options = [] memberof = self.memberof.getItems() for group in memberof: memberof_options += [xml.xml_encode(group.__image__), group.id, xml.xml_encode(group.displayName.value)] params['MEMBEROF'] = ';'.join(memberof_options) policies_options = [] policies = self.policies.getItems() for policy in policies: policies_options += [xml.xml_encode(policy.__image__), policy.id, xml.xml_encode(policy.displayName.value)] params['POLICIES'] = ';'.join(policies_options) params['SECURITY_TAB'] = baseitem._getSecurity(self, user) return params
def properties(self): "Displays the application's properties form" context = HttpContext.current() sLang = context.request.getLang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = (iUserRole == 1) modified = date.Date(self.modified) return { 'ID' : self.id, 'IMG' : self.__image__, 'NAME' : xml.xml_encode(self.displayName.value), 'DESCRIPTION' : xml.xml_encode(self.description.value), 'ICON' : self.icon.value, 'LAUNCH_URL' : xml.xml_encode(self.launchUrl.value), 'MODIFIED' : modified.format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY' : xml.xml_encode(self.modifiedBy), 'CONTENTCLASS' : self.contentclass, 'SECURITY_TAB' : baseitem._getSecurity(self, context.user), 'READONLY' : str(readonly).lower() }
def properties(self): "Displays the application's properties form" sLang = context.request.get_lang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = (iUserRole == permsresolver.READER) admin = (iUserRole == permsresolver.COORDINATOR) modified = date.Date(self.modified) return { 'ID': self.id, 'IMG': self.__image__, 'NAME': xml.xml_encode(self.displayName.value), 'DESCRIPTION': xml.xml_encode(self.description.value), 'ICON': self.icon.value, 'LAUNCH_URL': xml.xml_encode(self.launchUrl.value), 'MODIFIED': modified.format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.contentclass, 'ADMIN': admin, 'ROLES_INHERITED': str(self.inheritRoles).lower(), 'READONLY': str(readonly).lower()}
def properties(self): "Displays a generic edit form based on the object's schema" context = HttpContext.current() context.response.setHeader('Cache-Control', 'no-cache') sLang = context.request.getLang() user = context.user iUserRole = objectAccess.getAccess(self, user) readonly = (iUserRole==1) modified = date.Date(self.modified) params = { 'ID': self.id, 'ICON': self.__image__, 'NAME': xml.xml_encode(self.displayName.value), 'MODIFIED': modified.format(DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.contentclass, 'PROPERTIES_TAB': '', 'EXTRA_TABS': '', 'SECURITY_TAB': _getSecurity(self, context.user), 'UPDATE_DISABLED': str(readonly).lower() } # inspect item properties sProperties = '' for attr_name in self.__props__: attr = getattr(self, attr_name) if isinstance(attr, datatypes.DataType): control, tab = \ _getControlFromAttribute(self, attr_name, attr, readonly) sProperties += control params['EXTRA_TABS'] += tab params['PROPERTIES'] = sProperties return params
def properties(self): "Displays the user's properties form" sLang = context.request.get_lang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = (iUserRole == permsresolver.READER) admin = (iUserRole == permsresolver.COORDINATOR) params = { 'ID': self.id, 'ICON': self.__image__, 'NAME': xml.xml_encode(self.displayName.value), 'FULL_NAME': xml.xml_encode(self.fullName.value), 'EMAIL': self.email.value, 'DESCRIPTION': xml.xml_encode(self.description.value), 'MODIFIED': date.Date(self.modified).format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.contentclass, 'SELECT_FROM': self.parentid, 'REL_CC': '|'.join(self.memberof.relCc), 'SELECT_FROM_POLICIES': 'policies', 'POLICIES_REL_CC': '|'.join(self.policies.relCc), 'READONLY': str(readonly).lower(), 'ADMIN': admin, 'ROLES_INHERITED': str(self.inheritRoles).lower() } memberof_options = [] memberof = self.memberof.get_items() for group in memberof: memberof_options += [ xml.xml_encode(group.__image__), group.id, xml.xml_encode(group.displayName.value) ] params['MEMBEROF'] = ';'.join(memberof_options) policies_options = [] policies = self.policies.get_items() for policy in policies: policies_options += [ xml.xml_encode(policy.__image__), policy.id, xml.xml_encode(policy.displayName.value) ] params['POLICIES'] = ';'.join(policies_options) return params
def emit(self, context=None, item=None): serverLogger = logging.getLogger('serverlog') serverLogger.log( self.severity, self.description, *(), **{'exc_info':self.outputTraceback} ) if context != None: context.response._reset() context.response.setHeader('Cache-Control', 'no-cache') code = self.code description = self.description request_type = context.request.type if request_type == 'xmlrpc': context.response.content_type = 'text/xml' error_template = 'conf/XMLRPCError.xml' #description = xmlUtils.XMLEncode(description) else: context.response.content_type = 'text/html' error_template = 'conf/errorpage.html' http_method = context.request.REQUEST_METHOD browser = context.request.HTTP_USER_AGENT lang = context.request.HTTP_ACCEPT_LANGUAGE method = context.request.method if item != None: contentclass = item.contentclass else: contentclass = '-' if self.outputTraceback: tbk = traceback.format_exception(*sys.exc_info()) tbk = '\n'.join(tbk) if request_type == 'xmlrpc': tbk = xml.xml_encode(tbk) info = tbk else: info = self file = open(error_template) body = file.read() file.close() context.response.write(body % vars())
def properties(self): "Displays the user's properties form" sLang = context.request.get_lang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = (iUserRole == permsresolver.READER) admin = (iUserRole == permsresolver.COORDINATOR) params = {'ID': self.id, 'ICON': self.__image__, 'NAME': xml.xml_encode(self.displayName.value), 'FULL_NAME': xml.xml_encode(self.fullName.value), 'EMAIL': self.email.value, 'DESCRIPTION': xml.xml_encode(self.description.value), 'MODIFIED': date.Date(self.modified).format( baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.contentclass, 'SELECT_FROM': self.parentid, 'REL_CC': '|'.join(self.memberof.relCc), 'SELECT_FROM_POLICIES': 'policies', 'POLICIES_REL_CC': '|'.join(self.policies.relCc), 'READONLY': str(readonly).lower(), 'ADMIN': admin, 'ROLES_INHERITED': str(self.inheritRoles).lower()} memberof_options = [] memberof = self.memberof.get_items() for group in memberof: memberof_options += [xml.xml_encode(group.__image__), group.id, xml.xml_encode(group.displayName.value)] params['MEMBEROF'] = ';'.join(memberof_options) policies_options = [] policies = self.policies.get_items() for policy in policies: policies_options += [xml.xml_encode(policy.__image__), policy.id, xml.xml_encode(policy.displayName.value)] params['POLICIES'] = ';'.join(policies_options) return params
def properties(self): "Displays the user's properties form" context = HttpContext.current() sLang = context.request.getLang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = iUserRole == 1 params = { "ID": self.id, "ICON": self.__image__, "NAME": xml.xml_encode(self.displayName.value), "FULL_NAME": xml.xml_encode(self.fullName.value), "EMAIL": self.email.value, "DESCRIPTION": xml.xml_encode(self.description.value), "MODIFIED": date.Date(self.modified).format(baseitem.DATES_FORMAT, sLang), "MODIFIED_BY": xml.xml_encode(self.modifiedBy), "CONTENTCLASS": self.contentclass, "SELECT_FROM": self.parentid, "REL_CC": "|".join(self.memberof.relCc), "SELECT_FROM_POLICIES": "policies", "POLICIES_REL_CC": "|".join(self.policies.relCc), "READONLY": str(readonly).lower(), } memberof_options = [] memberof = self.memberof.get_items() for group in memberof: memberof_options += [xml.xml_encode(group.__image__), group.id, xml.xml_encode(group.displayName.value)] params["MEMBEROF"] = ";".join(memberof_options) policies_options = [] policies = self.policies.get_items() for policy in policies: policies_options += [xml.xml_encode(policy.__image__), policy.id, xml.xml_encode(policy.displayName.value)] params["POLICIES"] = ";".join(policies_options) params["SECURITY_TAB"] = baseitem._getSecurity(self, user) return params
def __serializeParam(self, param): if type(param)==str: return '<value>%s</value>' % xml.xml_encode(param) elif type(param)==unicode: return '<value>%s</value>' % xml.xml_encode(param.encode(self.encoding)) elif type(param)==int or type(param)==long: return '<value><i4>%i</i4></value>' % param elif type(param)==bool: return '<value><boolean>%i</boolean></value>' % param elif type(param)==float: return '<value><double>%f</double></value>' % param elif type(param)==list or type(param)==tuple: s = ['<value><array><data>'] s += filter(None, [self.__serializeParam(x) for x in param]) s += ['</data></array></value>'] return ''.join(s) elif type(param) == dict: s = ['<value><struct>'] for member, value in param.items(): serialized = self.__serializeParam(value) if serialized: s.append('<member><name>%s</name>%s</member>' % (member.encode(self.encoding), serialized)) s.append('</struct></value>') return ''.join(s) elif isinstance(param, objectSet.ObjectSet): s = ['<value><array><data>'] s += [self.__serializeParam(x) for x in param] s += ['</data></array></value>'] return ''.join(s) elif isinstance(param, (systemObjects.GenericItem, systemObjects.Composite)): xmlrpc_object = {} for attr in param.__props__ + self.default_props: try: oAttr = getattr(param, attr) except AttributeError: continue if isinstance(oAttr, datatypes.ExternalAttribute): xmlrpc_object[attr] = '[EXTERNAL STREAM]' elif isinstance(oAttr, datatypes.ReferenceN): xmlrpc_object[attr] = [{'id': x._id, 'displayName': x.displayName.value} for x in oAttr.get_items()] elif isinstance(oAttr, datatypes.Reference1): item_ref = oAttr.get_item() xmlrpc_object[attr] = {'id': oAttr.value} if item_ref != None: xmlrpc_object[attr]['displayName'] = \ item_ref.displayName.value elif isinstance(oAttr, datatypes.Date): xmlrpc_object[attr] = oAttr elif isinstance(oAttr, datatypes.DataType): xmlrpc_object[attr] = oAttr.value elif attr in ('created', 'modified'): xmlrpc_object[attr] = date.Date(oAttr) else: xmlrpc_object[attr] = oAttr return self.__serializeParam(xmlrpc_object) elif isinstance(param, date.Date): return '<value><dateTime.iso8601>%s</dateTime.iso8601></value>' % \ param.to_iso_8601() else: return None#self.__serializeParam(str(param))
def _getControlFromAttribute(item, attrname, attr, readonly, isNew=False): attrlabel = "@@%s@@" % attrname sControl = "" sTab = "" if isinstance(attr, datatypes.String): sControl = AUTO_CONTROLS[datatypes.String] % ( attrlabel, attrname, xml.xml_encode(attr.value), str(readonly).lower(), ) elif isinstance(attr, datatypes.Boolean): sControl = AUTO_CONTROLS[datatypes.Boolean] % ( attrlabel, attrname, str(attr.value).lower(), str(readonly).lower(), ) elif isinstance(attr, datatypes.Date): sControl = AUTO_CONTROLS[datatypes.Date] % (attrlabel, attrname, attr.to_iso_8601(), str(readonly).lower()) elif isinstance(attr, datatypes.File): if isNew: href = "" else: href = item.id + "?cmd=getfile" sControl = AUTO_CONTROLS[datatypes.File] % ( attrlabel, attrname, attr.filename, len(attr), href, str(readonly).lower(), ) elif isinstance(attr, datatypes.Text): sTab = AUTO_CONTROLS[datatypes.Text] % (attrlabel, attrname, str(readonly).lower(), xml.xml_encode(attr.value)) elif isinstance(attr, datatypes.Reference1): oRefItem = attr.get_item() if oRefItem: refid = oRefItem.id refname = oRefItem.displayName.value else: refid = refname = "" sReadonly = str(readonly).lower() sControl = AUTO_CONTROLS[datatypes.Reference1] % ( "|".join(attr.relCc), attrlabel, attrname, refid, refname, sReadonly, ) elif isinstance(attr, datatypes.ReferenceN): options = [] rel_items = attr.get_items() for item in rel_items: options += [xml.xml_encode(item.__image__), item.id, xml.xml_encode(item.displayName.value)] sTab = AUTO_CONTROLS[datatypes.ReferenceN] % ( attrlabel, "|".join(attr.relCc), attrname, str(readonly).lower(), ";".join(options), ) return (sControl, sTab)