Beispiel #1
0
    def render(self, ctx, key, args, errors):
        """
            Render the data.

            This either renders a link to the original file, if specified, and
            no new file has been uploaded. Or a link to the uploaded file.

            The request to get the data should be routed to the getResouce
            method.
        """
        form = iformal.IForm(ctx)

        namer = self._namer(key)
        resourceIdName = namer('resource_id')
        originalIdName = namer('original_id')

        # get the resource id first from the resource manager
        # then try the request
        resourceId = form.resourceManager.getResourceId(key)
        if resourceId is None:
            resourceId = self._getFromArgs(args, resourceIdName)
        resourceId = self._blankField(resourceId)

        # Get the original key from a hidden field in the request,
        # then try the request file.data initial data.
        originalKey = self._getFromArgs(args, originalIdName)
        if not errors and not originalKey:
            originalKey = args.get(key)
        originalKey = self._blankField(originalKey)

        if resourceId:
            # Have an uploaded file, so render a URL to the uploaded file
            tmpURL = widgetResourceURL(form.name).child(key).child(
                self.FROM_RESOURCE_MANAGER).child(resourceId)
            yield T.p[T.img(src=tmpURL)]
        elif originalKey:
            # The is no uploaded file, but there is an original, so render a
            # URL to it
            if self.originalKeyIsURL:
                tmpURL = originalKey
            else:
                tmpURL = widgetResourceURL(form.name).child(key).child(
                    self.FROM_CONVERTIBLE).child(originalKey)
            yield T.p[T.img(src=tmpURL)]
        else:
            # No uploaded file, no original
            yield T.p[T.strong['Nothing uploaded']]

        yield T.input(name=key, id=render_cssid(key), type='file')

        # Id of uploaded file in the resource manager
        yield T.input(name=resourceIdName, value=resourceId, type='hidden')
        if originalKey:
            # key of the original that can be used to get a file later
            yield T.input(name=originalIdName,
                          value=originalKey,
                          type='hidden')
Beispiel #2
0
    def render(self, ctx, key, args, errors):
        """
            Render the data.

            This either renders a link to the original file, if specified, and
            no new file has been uploaded. Or a link to the uploaded file.

            The request to get the data should be routed to the getResouce
            method.
        """
        form = iformal.IForm( ctx )

        namer = self._namer( key )
        resourceIdName = namer( 'resource_id' )
        originalIdName = namer( 'original_id' )

        # get the resource id first from the resource manager
        # then try the request
        resourceId = form.resourceManager.getResourceId( key )
        if resourceId is None:
            resourceId = self._getFromArgs( args, resourceIdName )
        resourceId = self._blankField( resourceId )

        # Get the original key from a hidden field in the request,
        # then try the request file.data initial data.
        originalKey = self._getFromArgs( args, originalIdName )
        if not errors and not originalKey:
            originalKey = args.get( key )
        originalKey = self._blankField( originalKey )

        if resourceId:
            # Have an uploaded file, so render a URL to the uploaded file
            tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId)
            yield T.p[T.img(src=tmpURL)]
        elif originalKey:
            # The is no uploaded file, but there is an original, so render a
            # URL to it
            if self.originalKeyIsURL:
                tmpURL = originalKey
            else:
                tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_CONVERTIBLE ).child( originalKey )
            yield T.p[T.img(src=tmpURL)]
        else:
            # No uploaded file, no original
            yield T.p[T.strong['Nothing uploaded']]

        yield T.input(name=key, id=render_cssid(key),type='file')

        # Id of uploaded file in the resource manager
        yield T.input(name=resourceIdName,value=resourceId,type='hidden')
        if originalKey:
            # key of the original that can be used to get a file later
            yield T.input(name=originalIdName,value=originalKey,type='hidden')
Beispiel #3
0
    def renderImmutable(self, ctx, key, args, errors):
        form = iformal.IForm(ctx)

        namer = self._namer(key)
        originalIdName = namer('original_id')

        # Get the original key from a hidden field in the request,
        # then try the request form.data initial data.
        originalKey = self._getFromArgs( args, originalIdName )
        if not errors and not originalKey:
            originalKey = args.get( key )
        originalKey = self._blankField( originalKey )

        if originalKey:
            # The is no uploaded file, but there is an original, so render a
            # URL to it
            if self.originalKeyIsURL:
                tmpURL = originalKey
            else:
                tmpURL = widgetResourceURL(form.name).child(key).child(self.FROM_CONVERTIBLE).child(originalKey)
            yield T.p[T.img(src=tmpURL)]
        else:
            # No uploaded file, no original
            yield T.p[T.strong['Nothing uploaded']]

        if originalKey:
            # key of the original that can be used to get a file later
            yield T.input(name=originalIdName,value=originalKey,type='hidden')
Beispiel #4
0
    def renderImmutable(self, ctx, key, args, errors):
        form = iformal.IForm(ctx)

        namer = self._namer(key)
        originalIdName = namer('original_id')

        # Get the original key from a hidden field in the request,
        # then try the request form.data initial data.
        originalKey = self._getFromArgs(args, originalIdName)
        if not errors and not originalKey:
            originalKey = args.get(key)
        originalKey = self._blankField(originalKey)

        if originalKey:
            # The is no uploaded file, but there is an original, so render a
            # URL to it
            if self.originalKeyIsURL:
                tmpURL = originalKey
            else:
                tmpURL = widgetResourceURL(form.name).child(key).child(
                    self.FROM_CONVERTIBLE).child(originalKey)
            yield T.p[T.img(src=tmpURL)]
        else:
            # No uploaded file, no original
            yield T.p[T.strong['Nothing uploaded']]

        if originalKey:
            # key of the original that can be used to get a file later
            yield T.input(name=originalIdName,
                          value=originalKey,
                          type='hidden')
Beispiel #5
0
    def render(self, ctx, key, args, errors):
        """
            Render the data.

            This either renders a link to the original file, if specified, and
            no new file has been uploaded. Or a link to the uploaded file.

            The request to get the data should be routed to the getResouce
            method.
        """
        form = iformal.IForm( ctx )

        namer = self._namer( key )
        resourceIdName = namer( 'resource_id' )
        originalIdName = namer( 'original_id' )

        # get the resource id first from the resource manager
        # then try the request
        resourceId = form.resourceManager.getResourceId( key )
        if resourceId is None:
            resourceId = self._getFromArgs( args, resourceIdName )
        resourceId = self._blankField( resourceId )

        # Get the original key from a hidden field in the request,
        # then try the request file.data initial data.
        originalKey = self._getFromArgs( args, originalIdName )
        if not errors and not originalKey:
            originalKey = args.get( key )
        originalKey = self._blankField( originalKey )

        # if we have a removeable attribute, generate the html
        if self.removeable is True:
            checkbox = T.input(type='checkbox', name='%s_remove'%key, id=render_cssid('%s_remove'%key),class_='upload-checkbox-remove',value='remove')
            if args.get('%s_remove'%key, [None])[0] is not None:
                checkbox = checkbox = checkbox(checked='checked')
            removeableHtml = T.p[ 'check to remove', checkbox]
        else:
            removeableHtml = ''
            
        if resourceId:
            # Have an uploaded file, so render a link to the uploaded file
            tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId)
            value = form.resourceManager.getResourceForWidget( key )
            yield [ T.p[T.a(href=tmpURL)[value[2]]], removeableHtml]
        elif originalKey:
            # The is no uploaded file, but there is an original, so render a
            # URL to it
            if self.originalKeyIsURL:
                tmpURL = originalKey
                yield [ T.p[T.img(src=tmpURL)], removeableHtml ]
            else:
                # Copy the data to the resource manager and render from there
                resourceId = self._storeInResourceManager(ctx, key, originalKey)
                tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId)
                yield [ T.p[T.a(href=tmpURL)[originalKey[2]]], removeableHtml]
        else:
            # No uploaded file, no original
            yield T.p[T.strong['Nothing uploaded']]

        yield T.input(name=key, id=render_cssid(key),type='file')

        # Id of uploaded file in the resource manager
        yield T.input(name=resourceIdName,value=resourceId,type='hidden')
        if originalKey and self.originalKeyIsURL:
            # key of the original that can be used to get a file later
            yield T.input(name=originalIdName,value=originalKey,type='hidden')
Beispiel #6
0
    def render(self, ctx, key, args, errors):
        """
            Render the data.

            This either renders a link to the original file, if specified, and
            no new file has been uploaded. Or a link to the uploaded file.

            The request to get the data should be routed to the getResouce
            method.
        """
        form = iformal.IForm( ctx )

        namer = self._namer( key )
        resourceIdName = namer( 'resource_id' )
        originalIdName = namer( 'original_id' )

        # get the resource id first from the resource manager
        # then try the request
        resourceId = form.resourceManager.getResourceId( key )
        if resourceId is None:
            resourceId = self._getFromArgs( args, resourceIdName )
        resourceId = self._blankField( resourceId )

        # Get the original key from a hidden field in the request,
        # then try the request file.data initial data.
        originalKey = self._getFromArgs( args, originalIdName )
        if not errors and not originalKey:
            originalKey = args.get( key )
        originalKey = self._blankField( originalKey )

        # if we have a removeable attribute, generate the html
        if self.removeable is True:
            checkbox = T.input(type='checkbox', name='%s_remove'%key, id=render_cssid('%s_remove'%key),class_='upload-checkbox-remove',value='remove')
            if args.get('%s_remove'%key, [None])[0] is not None:
                checkbox = checkbox = checkbox(checked='checked')
            removeableHtml = T.p[ 'check to remove', checkbox]
        else:
            removeableHtml = ''
            
        if resourceId:
            # Have an uploaded file, so render a link to the uploaded file
            tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId)
            value = form.resourceManager.getResourceForWidget( key )
            yield [ T.p[T.a(href=tmpURL)[value[2]]], removeableHtml]
        elif originalKey:
            # The is no uploaded file, but there is an original, so render a
            # URL to it
            if self.originalKeyIsURL:
                tmpURL = originalKey
                yield [ T.p[T.img(src=tmpURL)], removeableHtml ]
            else:
                # Copy the data to the resource manager and render from there
                resourceId = self._storeInResourceManager(ctx, key, originalKey)
                tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId)
                yield [ T.p[T.a(href=tmpURL)[originalKey[2]]], removeableHtml]
        else:
            # No uploaded file, no original
            yield T.p[T.strong['Nothing uploaded']]

        yield T.input(name=key, id=render_cssid(key),type='file')

        # Id of uploaded file in the resource manager
        yield T.input(name=resourceIdName,value=resourceId,type='hidden')
        if originalKey and self.originalKeyIsURL:
            # key of the original that can be used to get a file later
            yield T.input(name=originalIdName,value=originalKey,type='hidden')