示例#1
0
 def actions(self):
     """
     gives us the action dict of the object
     """
     try:
         objId = getUtility(IIntIds).getId(self.context)
     except KeyError:
         objId = 1000
     retList = []
     adapSize = ISized(self.context)
     # adapSize.sizeForSorting() returns ('item', n)
     if checkPermission('org.ict_ok.components.host.Add', self.context) and \
        (adapSize.sizeForSorting()[1] < 1):
         tmpDict = {}
         tmpDict['oid'] = u"c%sstart_scanner" % objId
         tmpDict['title'] = _(u"start scanner")
         tmpDict['href'] = u"%s/@@start_scanner.html" % \
                zapi.absoluteURL(self.context, self.request)
         tmpDict['tooltip'] = _(u"starts the network scanner (as user:%s)"\
                                % self.request.principal.title)
         retList.append(tmpDict)
     #tmpDict = {}
     #tmpDict['oid'] = u"a%s" % objId
     #tmpDict['title'] = u"ich bin ein Titel"
     #tmpDict['href'] = u"http://www.essen.de"
     #tmpDict['tooltip'] = u"ich bin der \"aa\" 'bb' dazugehörige T"
     #retList.append(tmpDict)
     return retList
    def getAttachments(self):
        context = self.context
        request = self.request
        extension = IAttachmentsExtension(context)

        ids = getUtility(IIntIds)
        url = "%s/@@content.attachment" % absoluteURL(getSite(), self.request)

        attachments = []
        for aId in self.model.attachments:
            attach = extension.get(aId)
            aurl = "%s/content.attachments/%s" % (url, ids.getId(attach))

            size = ISized(attach)
            if size.sizeForSorting()[0] is not None:
                size = size.sizeForDisplay()
            else:
                size = ""

            attachments.append(
                {
                    "name": aId,
                    "title": attach.title or aId,
                    "description": attach.description,
                    "url": aurl,
                    "size": size,
                    "icon": queryMultiAdapter((attach, request), name="zmi_icon"),
                }
            )

        return attachments
    def getAttachments(self):
        context = self.context
        request = self.request
        extension = IAttachmentsExtension(context)

        ids = getUtility(IIntIds)
        url = '%s/@@content.attachment'%absoluteURL(getSite(), request)

        attachments = []
        for name in self.model.attachments:
            attach = extension.get(name)

            aurl = '%s/%s'%(url, ids.getId(attach))

            size = ISized(attach)
            if size.sizeForSorting()[0] is not None:
                size = size.sizeForDisplay()
            else:
                size = ''

            attachments.append(
                {'name': name,
                 'title': attach.title or name,
                 'description': attach.description,
                 'url': aurl,
                 'size': size,
                 'icon': queryMultiAdapter((attach, request), name='zmi_icon')})

        return attachments
示例#4
0
def get_size(self):
    size = ISized(self, None)
    if size is not None:
	unit, amount = size.sizeForSorting()
	if unit == 'byte':
	    return amount
    method = getattr(self, '__five_original_get_size', None)
    if method is not None:
        return self.__five_original_get_size()
    def get_size(self):
        """Get the size of the content item in bytes. Used both in folder
        listings and in DAV PROPFIND requests.

        The default implementation delegates to an ISized adapter and calls
        getSizeForSorting(). This returns a tuple (unit, value). If the unit
        is 'bytes', the value is returned, otherwise the size is 0.
        """
        sized = ISized(self, None)
        if sized is None:
            return 0
        unit, size = sized.sizeForSorting()
        if unit == 'bytes':
            return size
        return 0
示例#6
0
 def get_size(self):
     # Get the size of the content item in bytes.
     #
     # Used both in folder listings and in DAV PROPFIND requests.
     #
     # The default implementation delegates to an ISized adapter and calls
     # getSizeForSorting(). This returns a tuple (unit, value). If the unit
     # is 'bytes', the value is returned, otherwise the size is 0.
     sized = ISized(self, None)
     if sized is None:
         return 0
     unit, size = sized.sizeForSorting()
     if unit == 'bytes':
         return size
     return 0
    def get_history(self):
        """ Gets all history entries of the page """
        objects = []
        publishedItem = None
        items = self.pageHistory.get_versions()
        items.reverse()
        for item in items:
            authorInfo = createObject('groupserver.UserFromId',
              self.context, item.editor)
            editor = {
              'name': authorInfo.name,
              'id': authorInfo.id,
              'url': authorInfo.url,
              'anonymous': authorInfo.anonymous
            }
            d = munge_date(self.context, item.creationDate)
            entry = {'editor': editor,
                      'size': ISized(item).sizeForDisplay(),
                      'modified': '',
                      'id': item.id,
                      'date': d,
                      'published': item.published,
                      'changing': self.changedVersion == item.id,
                      'children': [],
                      }
            if ((not item.published) and (publishedItem is not None)):
                publishedItem['children'].append(entry)
            else:
                objects.append(entry)
                publishedItem = entry

        return objects
示例#8
0
 def actions(self):
     """
     gives us the action dict of the object
     """
     try:
         objId = getUtility(IIntIds).getId(self.context)
     except KeyError:
         objId = 1000
     retList = []
     adapSize = ISized(self.context)
     if checkPermission('org.ict_ok.admin_utils.supervisor.ReindexDB',
                        self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%sreindex_db" % objId
         tmpDict['title'] = _(u"reindex database")
         tmpDict['href'] = u"%s/@@reindex_db?nextURL=%s" % \
                (zapi.getPath( self.context),
                 quoter.quote())
         tmpDict['tooltip'] = _(u"will reindex the catalogs of all "\
                                u"tables in database")
         retList.append(tmpDict)
     if checkPermission('org.ict_ok.admin_utils.supervisor.PackDB',
                        self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%spack_db" % objId
         tmpDict['title'] = _(u"pack database")
         tmpDict['href'] = u"%s/@@pack_db?nextURL=%s" % \
                (zapi.getPath( self.context),
                 quoter.quote())
         tmpDict['tooltip'] = _(u"will pack the database and delete "\
                                u"all backups")
         retList.append(tmpDict)
     return retList
示例#9
0
 def size(self):
     # This is common pattern. If you have defined adapter to ISized
     # then you needn't to reimplement this method in subclasses.
     try:
         return ISized(self.context).sizeForDisplay()
     except TypeError:
         return u''
示例#10
0
 def actions(self):
     """
     gives us the action dict of the object
     """
     try:
         objId = self.context.objectID
     except KeyError:
         objId = 1000
     retList = []
     adapSize = ISized(self.context)
     if checkPermission('org.ict_ok.admin_utils.supervisor.ReindexDB',
                        self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%sreindex_db" % objId
         tmpDict['title'] = _(u"reindex database")
         tmpDict['href'] = u"%s/@@reindex_db?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         tmpDict['tooltip'] = _(u"will reindex the catalogs of all "\
                                u"tables in database")
         retList.append(tmpDict)
     if checkPermission('org.ict_ok.admin_utils.supervisor.RemoveIndices',
                        self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%sremove_indices" % objId
         tmpDict['title'] = _(u"Remove indices")
         tmpDict['href'] = u"%s/@@remove_indices?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         tmpDict['tooltip'] = _(u"will remove all indices of all "\
                                u"tables in database")
         retList.append(tmpDict)
     if checkPermission('org.ict_ok.admin_utils.supervisor.CreateIndices',
                        self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%screate_indices" % objId
         tmpDict['title'] = _(u"Create indices")
         tmpDict['href'] = u"%s/@@create_indices?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         tmpDict['tooltip'] = _(u"will create all indices in database")
         retList.append(tmpDict)
     if not self.isInIctSite() and \
         checkPermission('org.ict_ok.admin_utils.supervisor.PackDB',
                         self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%spack_db" % objId
         tmpDict['title'] = _(u"pack database")
         tmpDict['href'] = u"%s/@@pack_db?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         tmpDict['tooltip'] = _(u"will pack the database and delete "\
                                u"all backups")
         retList.append(tmpDict)
     return retList
示例#11
0
def getSize(item, formatter):
    """display size of object"""
    try:
        return translate(ISized(item).sizeForDisplay())
    except AttributeError:
        return "--"
    except TypeError:
        return "--"
示例#12
0
 def actions(self):
     """
     gives us the action dict of the object
     """
     try:
         objId = getUtility(IIntIds).getId(self.context)
     except:
         objId = 1000
     retList = []
     if appsetup.getConfigContext().hasFeature('devmode') and \
        checkPermission('org.ict_ok.components.host.Edit', self.context):
         quoter = URLQuote(self.request.getURL())
         tmpDict = {}
         tmpDict['oid'] = u"c%strigger_online" % objId
         tmpDict['title'] = _(u"Trigger online")
         tmpDict['href'] = u"%s/@@trigger_online?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         retList.append(tmpDict)
         tmpDict = {}
         tmpDict['oid'] = u"c%strigger_offline" % objId
         tmpDict['title'] = _(u"Trigger offline")
         tmpDict['href'] = u"%s/@@trigger_offline?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         retList.append(tmpDict)
         tmpDict = {}
         tmpDict['oid'] = u"c%strigger_not1" % objId
         tmpDict['title'] = _(u"Trigger notification1")
         tmpDict['href'] = u"%s/@@trigger_not1?nextURL=%s" % \
                (zapi.absoluteURL(self.context, self.request),
                 quoter.quote())
         retList.append(tmpDict)
     adapSize = ISized(self.context)
     if checkPermission('org.ict_ok.components.interface.Add', self.context) and \
        (adapSize.sizeForSorting()[1] < 1):
         tmpDict = {}
         tmpDict['oid'] = u"c%sstart_snmp_if_scanner" % objId
         tmpDict['title'] = _(u"start snmp interface scanner")
         tmpDict['href'] = u"%s/@@start_snmp_if_scanner.html" % \
                zapi.absoluteURL(self.context, self.request)
         tmpDict['tooltip'] = _(u"starts the interface scanner with snmp scan (as user:%s)"\
                                % self.request.principal.title)
         retList.append(tmpDict)
     return retList
示例#13
0
    def _extractContentInfo(self, item):
        request = self.request

        rename_ids = {}
        if "container_rename_button" in request:
            for rename_id in request.get('ids', ()):
                rename_ids[rename_id] = rename_id
        elif "rename_ids" in request:
            for rename_id in request.get('rename_ids', ()):
                rename_ids[rename_id] = rename_id

        retitle_id = request.get('retitle_id')

        id, obj = item
        info = {}
        info['id'] = info['cb_id'] = id
        info['object'] = obj

        info['url'] = urllib.quote(id.encode('utf-8'))
        info['rename'] = rename_ids.get(id)
        info['retitle'] = id == retitle_id

        zmi_icon = queryMultiAdapter((obj, self.request), name='zmi_icon')
        if zmi_icon is None:
            info['icon'] = None
        else:
            info['icon'] = zmi_icon()

        dc = IZopeDublinCore(obj, None)
        if dc is not None:
            info['retitleable'] = canWrite(dc, 'title')
            info['plaintitle'] = not info['retitleable']

            title = self.safe_getattr(dc, 'title', None)
            if title:
                info['title'] = title

            formatter = self.request.locale.dates.getFormatter(
                'dateTime', 'short')

            created = self.safe_getattr(dc, 'created', None)
            if created is not None:
                info['created'] = formatter.format(created)

            modified = self.safe_getattr(dc, 'modified', None)
            if modified is not None:
                info['modified'] = formatter.format(modified)
        else:
            info['retitleable'] = 0
            info['plaintitle'] = 1

        sized_adapter = ISized(obj, None)
        if sized_adapter is not None:
            info['size'] = sized_adapter
        return info
示例#14
0
 def getStateDict(self):
     """get the object state in form of a dict
     """
     overviewNum = 0  # 0: ok, 1: warn, 2: error
     warnList = []
     errorList = []
     retDict = {}
     adapSize = ISized(self.context)
     # adapSize.sizeForSorting() returns ('item', n)
     if adapSize.sizeForSorting()[1] < 1:
         if overviewNum < 1:
             overviewNum = 1
         mesg = _(u'Warning: ')
         mesg += _(u"'no hosts in net'")
         warnList.append(mesg)
     retDict['overview'] = ('ok', 'warn', 'error')[overviewNum]
     retDict['warnings'] = warnList
     retDict['errors'] = errorList
     if overviewNum == 0:
         return None
     return retDict
示例#15
0
    def update(self):
        DisplayFieldWidget.update(self)
        content = self.form.getContentData().getContent()
        fileobj = self.component._field.get(content)

        if fileobj:
            if IFile.providedBy(fileobj):
                self.filename = fileobj.filename
                self.filesize = ISized(fileobj, None)

            self.url = get_absolute_url(content, self.request)
            self.download = "%s/++download++%s" % (
                self.url, self.component.identifier)
示例#16
0
    def update(self):
        SchemaFieldWidget.update(self)

        if not self.form.ignoreContent:
            content = self.form.getContentData().getContent()
            fileobj = self.component._field.get(content)

            if fileobj:
                self.allow_action = True
                if IFile.providedBy(fileobj):
                    self.filename = fileobj.filename
                    self.filesize = ISized(fileobj, None)
                else:
                    self.filename = _(u'download', default=u"Download")

                if ILocation.providedBy(content):
                    self.url = get_absolute_url(content, self.request)
                    self.download = "%s/++download++%s" % (
                        self.url, self.component.identifier)
示例#17
0
文件: tests.py 项目: kislovm/findburo
 def testImplementsISized(self):
     from zope.size import DefaultSized
     sized = DefaultSized(object())
     self.assert_(ISized.providedBy(sized))
示例#18
0
def testImplementsISized():
    sized = ContainerSized(DummyContainer(23))
    assert ISized.providedBy(sized)
示例#19
0
 def testImplementsISized(self):
     from zope.size import DefaultSized
     sized = DefaultSized(object())
     self.assertTrue(ISized.providedBy(sized))
示例#20
0
 def testInterface(self):
     from zope.size.interfaces import ISized
     self.assertTrue(ISized.implementedBy(ImageSized))
     self.assertTrue(verifyClass(ISized, ImageSized))
示例#21
0
 def testInterface(self):
     from zope.size.interfaces import ISized
     self.failUnless(ISized.implementedBy(ImageSized))
     self.failUnless(verifyClass(ISized, ImageSized))
示例#22
0
 def testInterface(self):
     from zope.size.interfaces import ISized
     self.failUnless(ISized.implementedBy(Sized))
     self.failUnless(verifyClass(ISized, Sized))
示例#23
0
 def size(self):
     a = ISized(self.context, None)
     if a is None:
         raise AttributeError('size')
     return a.sizeForDisplay()
示例#24
0
 def format(self, value):
     sz = ISized(value, None)
     if sz is None:
         return value
     return sz.sizeForDisplay()
示例#25
0
 def size(self):
     a = ISized(self.context, None)
     if a is None:
         raise AttributeError('size')
     return a.sizeForDisplay()
示例#26
0
 def size(self):
     sized = ISized(self.context)
     return sized.sizeForDisplay()
示例#27
0
 def testImplementsISized(self):
     from zope.container.size import ContainerSized
     sized = ContainerSized(DummyContainer(23))
     self.assertTrue(ISized.providedBy(sized))
示例#28
0
 def testImplementsISized(self):
     from zope.container.size import ContainerSized
     sized = ContainerSized(DummyContainer(23))
     self.assert_(ISized.providedBy(sized))
示例#29
0
 def size(self):
     sized = ISized(self.context)
     return sized.sizeForDisplay()