| 1 |
# (C) Copyright 2004-2006 Nuxeo SAS <http://nuxeo.com> |
|---|
| 2 |
# Authors: |
|---|
| 3 |
# Stefane Fermigier <sf@nuxeo.com> |
|---|
| 4 |
# |
|---|
| 5 |
# This program is free software; you can redistribute it and/or modify |
|---|
| 6 |
# it under the terms of the GNU General Public License version 2 as published |
|---|
| 7 |
# by the Free Software Foundation. |
|---|
| 8 |
# |
|---|
| 9 |
# This program is distributed in the hope that it will be useful, |
|---|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
# GNU General Public License for more details. |
|---|
| 13 |
# |
|---|
| 14 |
# You should have received a copy of the GNU General Public License |
|---|
| 15 |
# along with this program; if not, write to the Free Software |
|---|
| 16 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|---|
| 17 |
# 02111-1307, USA. |
|---|
| 18 |
# |
|---|
| 19 |
# $Id$ |
|---|
| 20 |
|
|---|
| 21 |
__refresh_module__ = 0 |
|---|
| 22 |
|
|---|
| 23 |
import cgi |
|---|
| 24 |
|
|---|
| 25 |
def introspection(self): |
|---|
| 26 |
secman = getSecurityManager() |
|---|
| 27 |
if not secman.checkPermission("Manage properties", self.this()): |
|---|
| 28 |
raise Unauthorized("Permission denied") |
|---|
| 29 |
|
|---|
| 30 |
path = self.REQUEST.get('path', '') |
|---|
| 31 |
if not path: |
|---|
| 32 |
obj = self |
|---|
| 33 |
else: |
|---|
| 34 |
obj = self |
|---|
| 35 |
for id in path.split("/"): |
|---|
| 36 |
obj = getattr(obj, id) |
|---|
| 37 |
|
|---|
| 38 |
res = [] |
|---|
| 39 |
|
|---|
| 40 |
object_vars = vars(obj).items() |
|---|
| 41 |
object_vars.sort() |
|---|
| 42 |
for attr_name, attr_value in object_vars: |
|---|
| 43 |
if not path: |
|---|
| 44 |
attr_path = attr_name |
|---|
| 45 |
else: |
|---|
| 46 |
attr_path = path + '/' + attr_name |
|---|
| 47 |
try: |
|---|
| 48 |
attr_vars = vars(attr_value) |
|---|
| 49 |
except: |
|---|
| 50 |
attr_path = '' |
|---|
| 51 |
res.append({'attr_path': attr_path, |
|---|
| 52 |
'attr_name': attr_name, |
|---|
| 53 |
'attr_value': pprint.pformat(attr_value)}) |
|---|
| 54 |
return res |
|---|
| 55 |
|
|---|
| 56 |
# Monkey-patching. Yuck. |
|---|
| 57 |
try: |
|---|
| 58 |
import pprint |
|---|
| 59 |
from Globals import HTMLFile |
|---|
| 60 |
from App.Management import Tabs |
|---|
| 61 |
from OFS.SimpleItem import Item |
|---|
| 62 |
from AccessControl import getSecurityManager, Unauthorized |
|---|
| 63 |
|
|---|
| 64 |
def filtered_manage_options(self, REQUEST=None): |
|---|
| 65 |
# Append an Introspection tab to an object's management tabs |
|---|
| 66 |
tabs = self._oldxxx_filtered_manage_options(REQUEST) |
|---|
| 67 |
secman = getSecurityManager() |
|---|
| 68 |
if len(tabs) \ |
|---|
| 69 |
and secman.checkPermission("Manage properties", self.this()): |
|---|
| 70 |
tabs.append({'label': 'Introspection', |
|---|
| 71 |
'action': 'manage_introspection'}) |
|---|
| 72 |
return tabs |
|---|
| 73 |
|
|---|
| 74 |
Tabs._oldxxx_filtered_manage_options = Tabs.filtered_manage_options |
|---|
| 75 |
Tabs.filtered_manage_options = filtered_manage_options |
|---|
| 76 |
|
|---|
| 77 |
Item.manage_introspection = HTMLFile('zmi/manage_introspection', globals()) |
|---|
| 78 |
Item.introspection = introspection |
|---|
| 79 |
|
|---|
| 80 |
import logging |
|---|
| 81 |
logging.getLogger('ZMIntrospection').info("Applied patch.") |
|---|
| 82 |
|
|---|
| 83 |
except: |
|---|
| 84 |
import traceback |
|---|
| 85 |
traceback.print_exc() |
|---|
| 86 |
|
|---|