Package Products :: Package ZenModel :: Module Report |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.Report

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007, Zenoss Inc.
      5  #
      6  # This program is free software; you can redistribute it and/or modify it
      7  # under the terms of the GNU General Public License version 2 as published by
      8  # the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     11  #
     12  ###########################################################################
     13
     14  __doc__="""Report
     15
     16  Report represents a group of devices
     17
     18  $Id: Report.py,v 1.3 2004/04/06 02:19:04 edahl Exp $"""
     19
     20  __version__ = "$Revision: 1.3 $"[11:-2]
     21
     22  from urllib import quote
     23
     24  from Globals import InitializeClass
     25  from AccessControl import ClassSecurityInfo
     26
     27  from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
     28  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
     29
     30  from ZenModelRM import ZenModelRM
     31  from ZenPackable import ZenPackable
     32
     33 -def manage_addReport(context, id, title = None, text=None,
     34                      REQUEST = None, submit=None):
     35      """make a Report"""
     36      id = str(id)
     37      if REQUEST is None:
     38          context._setObject(id, Report(id, text))
     39          ob = getattr(context, id)
     40          if title:
     41              ob.pt_setTitle(title)
     42          return ob
     43      else:
     44          file = REQUEST.form.get('file')
     45          headers = getattr(file, 'headers', None)
     46          if headers is None or not file.filename:
     47              zpt = Report(id)
     48          else:
     49              zpt = Report(id, file, headers.get('content_type'))
     50
     51          context._setObject(id, zpt)
     52
     53          try:
     54              u = context.DestinationURL()
     55          except AttributeError:
     56              u = REQUEST['URL1']
     57
     58          if submit == " Add and Edit ":
     59              u = "%s/%s" % (u, quote(id))
     60          REQUEST.RESPONSE.redirect(u+'/manage_main')
     61      return ''
     62
     63
     64  addReport = PageTemplateFile('www/reportAdd', globals(),
     65                              __name__='addReport')
     66
     67
     68 -class Report(ZenModelRM, ZenPackable):
     69      """Report object"""
     70
     71      __pychecker__ = 'no-override'
     72
     73      meta_type = 'Report'
     74
     75      # this is deprecated don't use!!!
     76      description = ""
     77
     78      security = ClassSecurityInfo()
     79
     80      _relations = ZenPackable._relations
     81
     82 -    def __init__(self, id, title = None, text=None, content_type='text/html'):
     83          ZenModelRM.__init__(self, id);
     84          self._template = ZopePageTemplate(id, text, content_type)
     85          self.title = title
     86
     87 -    def __call__(self, *args, **kwargs):
     88          """Return our rendered template not our default page
     89          """
     90          if not kwargs.has_key('args'):
     91              kwargs['args'] = args
     92          template = self._template.__of__(self)
     93          return template.pt_render(extra_context={'options': kwargs})
     94
     95
     96 -    def ZScriptHTML_tryForm(self, *args, **kwargs):
     97          """Test form called from ZMI test tab
     98          """
     99          return self.__call__(self, args, kwargs)
    100
    101
    102 -    def manage_main(self):
    103          """Return the ZMI edit page of our template not ourself
    104          """
    105          template = self._template.__of__(self)
    106          return template.pt_editForm()
    107      pt_editForm = manage_main
    108
    109
    110 -    def pt_editAction(self, REQUEST, title, text, content_type, expand):
    111          """Send changes to our template instead of ourself"""
    112          template = self._template.__of__(self)
    113          return template.pt_editAction(REQUEST,
    114              title, text, content_type, expand)
    115
    116
    117  InitializeClass(Report)
    118