예제 #1
0
파일: adding.py 프로젝트: bendavis78/zope
    def add(self, content):
        """See zope.app.container.interfaces.IAdding
        """
        container = self.context
        name = self.contentName
        chooser = INameChooser(container)

        # check precondition
        checkObject(container, name, content)

        if IContainerNamesContainer.providedBy(container):
            # The container picks it's own names.
            # We need to ask it to pick one.
            name = chooser.chooseName(self.contentName or '', content)
        else:
            request = self.request
            name = request.get('add_input_name', name)

            if name is None:
                name = chooser.chooseName(self.contentName or '', content)
            elif name == '':
                name = chooser.chooseName('', content)
            else:
                # Invoke the name chooser even when we have a
                # name. It'll do useful things with it like converting
                # the incoming unicode to an ASCII string.
                name = chooser.chooseName(name, container)

        content.id = name
        container._setObject(name, content)
        self.contentName = name  # Set the added object Name
        return container._getOb(name)
예제 #2
0
파일: adding.py 프로젝트: goschtl/zope
    def add(self, content):
        """See zope.app.container.interfaces.IAdding
        """
        container = self.context
        name = self.contentName
        chooser = INameChooser(container)

        # check precondition
        checkObject(container, name, content)

        if IContainerNamesContainer.providedBy(container):
            # The container picks it's own names.
            # We need to ask it to pick one.
            name = chooser.chooseName(self.contentName or '', content)
        else:
            request = self.request
            name = request.get('add_input_name', name)

            if name is None:
                name = chooser.chooseName(self.contentName or '', content)
            elif name == '':
                name = chooser.chooseName('', content)
            else:
                # Invoke the name chooser even when we have a
                # name. It'll do useful things with it like converting
                # the incoming unicode to an ASCII string.
                name = chooser.chooseName(name, container)
        
        content.id = name
        container._setObject(name, content)
        self.contentName = name # Set the added object Name
        return container._getOb(name)
예제 #3
0
    def add(self, content):
        """See zope.app.container.interfaces.IAdding
        """
        container = self.context
        name = self.contentName
        chooser = INameChooser(container)

        # check precondition
        checkObject(container, name, content)

        if IContainerNamesContainer.providedBy(container):
            # The container picks its own names.
            # We need to ask it to pick one.
            name = chooser.chooseName(self.contentName or "", content)
        else:
            request = self.request
            name = request.get("add_input_name", name)

            if name is None:
                name = chooser.chooseName(self.contentName or "", content)
            elif name == "":
                name = chooser.chooseName("", content)
            chooser.checkName(name, content)

        container[name] = content
        self.contentName = name  # Set the added object Name
        return container[name]
예제 #4
0
    def add(self, content):
        """See zope.app.container.interfaces.IAdding
        """
        container = self.context
        name = self.contentName
        chooser = INameChooser(container)

        # check precondition
        checkObject(container, name, content)

        if IContainerNamesContainer.providedBy(container):
            # The container picks its own names.
            # We need to ask it to pick one.
            name = chooser.chooseName(self.contentName or '', content)
        else:
            request = self.request
            name = request.get('add_input_name', name)

            if name is None:
                name = chooser.chooseName(self.contentName or '', content)
            elif name == '':
                name = chooser.chooseName('', content)
            chooser.checkName(name, content)

        container[name] = content
        self.contentName = name # Set the added object Name
        return container[name]
예제 #5
0
    def copyTo(self, target, new_name=None):
        """Copy this object to the `target` given.

        Returns the new name within the `target`.

        Typically, the `target` is adapted to `IPasteTarget`.
        After the copy is added to the `target` container, publish
        an `IObjectCopied` event in the context of the target container.
        If a new object is created as part of the copying process, then
        an `IObjectCreated` event should be published.
        """
        obj = self.context
        container = obj.__parent__

        orig_name = obj.__name__
        if new_name is None:
            new_name = orig_name

        checkObject(target, new_name, obj)

        chooser = INameChooser(target)
        new_name = chooser.chooseName(new_name, obj)

        copy = locationCopy(obj)
        copy.__parent__ = copy.__name__ = None
        notify(ObjectCopiedEvent(copy, obj))

        target[new_name] = copy
        return new_name
예제 #6
0
    def moveTo(self, target, new_name=None):
        """Move this object to the `target` given.

        Returns the new name within the `target`
        Typically, the `target` is adapted to `IPasteTarget`."""

        obj = self.context
        container = obj.__parent__

        orig_name = obj.__name__
        if new_name is None:
            new_name = orig_name

        checkObject(target, new_name, obj)

        if target is container and new_name == orig_name:
            # Nothing to do
            return

        chooser = INameChooser(target)
        new_name = chooser.chooseName(new_name, obj)

        target[new_name] = obj
        del container[orig_name]
        return new_name
예제 #7
0
    def copyableTo(self, target, name=None):
        """Say whether the object can be copied to the given `target`.

        Returns ``True`` if it can be copied there. Otherwise, returns
        ``False``.
        """
        if name is None:
            name = self.context.__name__
        try:
            checkObject(target, name, self.context)
        except Invalid:
            return False
        return True
예제 #8
0
파일: upload.py 프로젝트: a25kk/stv2
    def __call__(self):
        ticket = self.request.form.get('ticket',None)
       
        url = None
        if ticket is None:
            # we cannot set post headers in flash, so get the
            # querystring manually
            qs = self.request.get('QUERY_STRING','ticket=')
            ticket = qs.split('=')[-1] or None
            if ticket is None:
                raise Unauthorized
        else:
            url = absoluteURL(self,self.request)
            if not validateTicket(url,ticket):
                raise Unauthorized
        invalidateTicket(url,ticket)
        if self.request.form.get('Filedata', None) is None:
            # flash sends a emtpy form in a pre request in flash version 8.0
            return ""
        fileUpload = self.request.form['Filedata']
        fileName = self.request.form['Filename']
        contentType = self.request.form.get('Content-Type',None)
        factory = IFileFactory(self.context)
        f = factory(fileName, contentType, fileUpload)

        # get the namechooser for the container by adapting the
        # container to INameChooser
        nameChooser = INameChooser(self.context)
        
        # namechooser selects a name for us
        name = nameChooser.chooseName(fileName, f)

        # check precondition
        checkObject(self.context, name, f)
        
        # store the file inside the container
        removeSecurityProxy(self.context)[name]=f

        event.notify(FlashUploadedEvent(f))
        return "filename=%s" %name