def manage_beforeDelete(self, item, container):

        # manage_beforeDelete is deprecated in Zope 2.11+

        ### remove associated PDF file if any
        ###
        ### BEWARE: to debug this code go into 
        ###         portal_skins/plone_scripts/object_delete 
        ###         and comment out the
        ###         fallback exception or use PloneTestCase
        ###

        bibfolder = self.getBibFolder()

        # delete PDF file (if any) only if _delete_associated_pdffile 
        # flag in bibfolder is set
        pdf_file = self.getPdf_file()
        if pdf_file:
            if bibfolder._delete_associated_pdffiles:

                bibfolder = self.getBibFolder()
                pdf_folder = bibfolder.getPdfFolder()
                pdf_file = self.getPdf_file()
                pdf_folder.manage_delObjects(ids=[pdf_file.getId()])
                bibfolder._delete_associated_pdffiles = False

            if bibfolder._move_associated_pdffiles:

                setattr(item, '_temp_pdffile_UID', pdf_file.UID())

        BaseContent.manage_beforeDelete(self, item, container)
Beispiel #2
0
    def manage_beforeDelete(self, item, container):

        # manage_beforeDelete is deprecated in Zope 2.11+

        ### remove associated PDF file if any
        ###
        ### BEWARE: to debug this code go into
        ###         portal_skins/plone_scripts/object_delete
        ###         and comment out the
        ###         fallback exception or use PloneTestCase
        ###

        bibfolder = self.getBibFolder()

        # delete PDF file (if any) only if _delete_associated_pdffile
        # flag in bibfolder is set
        pdf_file = self.getPdf_file()
        if pdf_file:
            if bibfolder._delete_associated_pdffiles:

                bibfolder = self.getBibFolder()
                pdf_folder = bibfolder.getPdfFolder()
                pdf_file = self.getPdf_file()
                pdf_folder.manage_delObjects(ids=[pdf_file.getId()])
                bibfolder._delete_associated_pdffiles = False

            if bibfolder._move_associated_pdffiles:

                setattr(item, '_temp_pdffile_UID', pdf_file.UID())

        BaseContent.manage_beforeDelete(self, item, container)
Beispiel #3
0
    def initializeArchetype(self, **kwargs):
        """ Translate the adapter in the current langage
        """

        ATCTContent.initializeArchetype(self, **kwargs)

        self.setNoSubmitMessage(zope.i18n.translate(_(u'pfg_thankspage_nosubmitmessage', u'<p>No input was received. Please <a title="Test Folder" href=".">visit the form</a>.</p>'), context=self.REQUEST))
Beispiel #4
0
    def initializeArchetype(self, **kwargs):
        """ Translate the adapter in the current langage
        """

        ATCTContent.initializeArchetype(self, **kwargs)

        self.setNoSubmitMessage(zope.i18n.translate(_(u'pfg_thankspage_nosubmitmessage', u'<p>No input was received. Please visit the form.</p>'), context=self.REQUEST))
Beispiel #5
0
    def at_post_edit_script(self):

        bib_tool = getToolByName(self, 'portal_bibliography')
        plone_utils = getToolByName(self, 'plone_utils')
        bibfolder = self.getBibFolder()

        # id cooking
        if (bibfolder.getCookIdsOnBibRefCreation()
                and plone_utils.isIDAutoGenerated(
                    self.getId())) or bibfolder.getCookIdsAfterBibRefEdit():
            new_id = bib_tool.cookReferenceId(
                ref=self, idcooker_id=bibfolder.getReferenceIdCookingMethod())
            if new_id != 'nobody1000':

                # this will implicitly call the PDF File rename code
                # via self.manage_renameObject
                self.bibliography_entry_cookId()

            else:
                # no author, no publication year, do not know what to do
                BaseContent._renameAfterCreation(self, check_auto_id=True)

        # infer member references after edit
        if bib_tool.inferAuthorReferencesAfterEdit():
            self.inferAuthorReferences()
Beispiel #6
0
    def manage_afterAdd(self, item, container):
        # TODO: when we're done with 2.1.x, implement this via event subscription

        ATCTContent.manage_afterAdd(self, item, container)

        id = self.getId()
        if self.fgField.__name__ != id:
            self.fgField.__name__ = id
    def at_post_create_script(self):
        """ activate action adapter in parent folder """
        
        # XXX TODO - change to use events when we give up on Plone 2.1.x
        
        ATCTContent.at_post_create_script(self)

        self.aq_parent.addActionAdapter(self.id)
    def manage_afterAdd(self, item, container):
        # TODO: when we're done with 2.1.x, implement this via event subscription

        ATCTContent.manage_afterAdd(self, item, container)

        id = self.getId()
        if self.fgField.__name__ != id:
            self.fgField.__name__ = id
    def at_post_create_script(self):
        # """ activate action adapter in parent folder """

        # XXX TODO - change to use events when we give up on Plone 2.1.x

        ATCTContent.at_post_create_script(self)

        self.aq_parent.addActionAdapter(self.id)
 def setFormat(self, value):
     """
     Method for CMF compatibility, set for body format
     """
     if not value:
         value = 'text/html'
     else:
         value = translateMimetypeAlias(value)
     ATCTContent.setFormat(self, value)
 def setFormat(self, value):
     """
     Method for CMF compatibility, set for body format
     """
     if not value:
         value = "text/html"
     else:
         value = translateMimetypeAlias(value)
     ATCTContent.setFormat(self, value)
Beispiel #12
0
 def update(self, event=None, **kwargs):
     # Clashes with BaseObject.update, so
     # we handle gracefully
     info = {}
     if event is not None:
         for field in event.Schema().fields():
             info[field.getName()] = event[field.getName()]
     elif kwargs:
         info = kwargs
     ATCTContent.update(self, **info)
Beispiel #13
0
 def update(self, event=None, **kwargs):
     # Clashes with BaseObject.update, so
     # we handle gracefully
     info = {}
     if event is not None:
         for field in event.Schema().fields():
             info[field.getName()] = event[field.getName()]
     elif kwargs:
         info = kwargs
     ATCTContent.update(self, **info)
Beispiel #14
0
    def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
        # override base so that we can selectively redirect back to the form
        # rather than to the thanks page view.

        # base processing
        ATCTContent.processForm(self, data, metadata, REQUEST, values)

        # if the referer is the item itself, let nature take its course;
        # if not, redirect to form after a commit.
        referer = self.REQUEST.form.get('last_referer', None)
        if referer is not None and referer.split('/')[-1] != self.getId():
            transaction.commit()
            raise zExceptions.Redirect, "%s#qedit" % self.formFolderObject().absolute_url()
    def manage_afterAdd(self, item, container):

        # manage_afterAdd is deprecated in Zope 2.11+

        ### copy PDF file if bibreference has been copied

        ###
        ### BEWARE: to debug this code go into 
        ###         portal_skins/plone_scripts/folder_paste 
        ###         and comment out the
        ###         fallback exception or use PloneTestCase
        ###

        reference_catalog = getToolByName(self, 'reference_catalog')
        bib_tool = getToolByName(self, 'portal_bibliography')
        bibfolder = container

        # grab the PDF file and its back references before the reference is removed by
        # BaseContent.manage_afterAdd
        pdf_file = self.getPdf_file() or None
        pdf_file_uid = ''
        if pdf_file:
            pdf_file_uid = pdf_file.UID()
            pdf_file_brefs = [ bref.UID() for bref in pdf_file.getBRefs('printable_version_of') if bref is not None ]

        if not pdf_file_uid and shasattr(self, '_temp_pdffile_UID') and self._temp_pdffile_UID:
            pdf_file_uid = self._temp_pdffile_UID
            pdf_file_brefs = [ bref.UID() for bref in reference_catalog.lookupObject(pdf_file_uid).getBRefs('printable_version_of') if bref is not None ]
            delattr(self, '_temp_pdffile_UID')

        # first do all necessary ATCT, Archetypes, etc. things...
        BaseContent.manage_afterAdd(self, item, container)

        # we have to set another transaction savepoint here, 
        # before we can cut or copy the associated PDF file
        bib_tool.transaction_savepoint(optimistic=True)

        # then check PDF file association
        pdf_file = pdf_file_uid and reference_catalog.lookupObject(pdf_file_uid)
        if pdf_file and pdf_file_brefs and (self.UID() not in pdf_file_brefs):

            # bibref item has been copied and UID of bibref item has changed
            # => copy PDF file
            new_pdf_file = self.relocatePdfFile(pdf_file=pdf_file, op=0)
            self.setPdf_file(value=new_pdf_file.UID())

        elif pdf_file and (pdf_file.aq_inner.aq_parent.aq_inner.aq_parent.getPhysicalPath() != self.aq_inner.aq_parent.getPhysicalPath()):

            # PDF file and bibref item are not in the same bibfolder
            # => move PDF file!!!
            moved_pdf_file = self.relocatePdfFile(pdf_file=reference_catalog.lookupObject(pdf_file_uid), op=1)
    def manage_beforeDelete(self, item, container):
        #
        # Hook method, called before object deletion
        #

        # Get list for ids of referenced comments,trackbacks
        ids = [obj.id for obj in self.getComment()]
        ids += [obj.id for obj in self.getTrackback()]

        # Now delete them all!
        self.aq_parent.getCommentFolder().manage_delObjects(ids)

        # Call superclass method
        ATCTContent.manage_beforeDelete(self, item, container)
Beispiel #17
0
 def setFormat(self, value):
     # CMF compatibility method.
     #
     # The default mutator is overwritten to:
     #
     #   o add a conversion from stupid CMF content type
     #     (e.g. structured-text) to real mime types used by MTR.
     #
     #   o Set format to default format if value is empty
     if not value:
         value = zconf.ATDocument.default_content_type
     else:
         value = translateMimetypeAlias(value)
     ATCTContent.setFormat(self, value)
    def manage_beforeDelete(self, item, container):
        #
        # Hook method, called before object deletion
        #

        # Get list for ids of referenced comments,trackbacks
        ids = [obj.id for obj in self.getComment()]
        ids += [obj.id for obj in self.getTrackback()]

        # Now delete them all!
        self.aq_parent.getCommentFolder().manage_delObjects(ids)

        # Call superclass method
        ATCTContent.manage_beforeDelete(self, item, container)
 def setFormat(self, value):
     # CMF compatibility method.
     #
     # The default mutator is overwritten to:
     #
     #   o add a conversion from stupid CMF content type
     #     (e.g. structured-text) to real mime types used by MTR.
     #
     #   o Set format to default format if value is empty
     if not value:
         value = zconf.ATDocument.default_content_type
     else:
         value = translateMimetypeAlias(value)
     ATCTContent.setFormat(self, value)
    def widget(self, field_name, mode='view', field=None, **kwargs):
        """ special handling for uploaded_pdfFile widget
        """
        bib_tool = getToolByName(self, 'portal_bibliography')
        pdf_file = self.getPdf_file()
        if (pdf_file and self.isPdfUploadAllowedForThisType() and \
            bib_tool.allowPdfUploadPortalPolicy()) and \
            ((field_name == 'uploaded_pdfFile') or \
             (field == self.Schema().getField('uploaded_pdfFile'))):

            if pdf_file:
                field_name = 'uploaded_pdfFile'
                if field is None:
                    field = pdf_file.Schema()['file']
                widget = field.widget
                return renderer.render(field_name,
                                       mode,
                                       widget,
                                       pdf_file,
                                       field=field,
                                       **kwargs)

        else:

            return BaseContent.widget(self,
                                      field_name=field_name,
                                      mode=mode,
                                      field=field,
                                      **kwargs)
Beispiel #21
0
    def __bobo_traverse__(self, REQUEST, name):
        """Transparent access to image scales
        """
        list_field_image = [
            'imagem_1',
            'imagem_2',
            'imagem_3',
            'imagem_4',
            'imagem_5',
            'imagem_6',
            'imagem_7',
            'imagem_8',
            'imagem_9',
            'imagem_10',
        ]
        for field_image in list_field_image:
            if name.startswith(field_image):
                field = self.getField(field_image)
                image = None
                if name == field_image:
                    image = field.getScale(self)
                else:
                    name_scale = field_image + '_'
                    scalename = name[len(name_scale):]
                    if scalename in field.getAvailableSizes(self):
                        image = field.getScale(self, scale=scalename)
                if image is not None and not isinstance(image, basestring):
                    # image might be None or '' for empty images
                    return image

        return ATCTContent.__bobo_traverse__(self, REQUEST, name)
 def _notifyOfCopyTo(self, container, op=0):
     """Override this to store a flag when we are copied, to be able
     to discriminate the right thing to do in manage_afterAdd here
     below.
     """
     self._v_renamed = 1
     return ATCTContent._notifyOfCopyTo(self, container, op=op)
Beispiel #23
0
    def __bobo_traverse__(self, REQUEST, name):
        """
        Transparent access to image scales of image fields
        on content.
        """
        if name.startswith('image_'):
            name = name[len('image_'):]
            split = name.rsplit('_', 1)
            if len(split) == 2:
                # has scale with it
                fieldname, scale = split
            else:
                fieldname = name
                scale = None
            field = self.getField(fieldname)
            image = None
            if field and \
                    field.getType() == 'uwosh.pfg.d2c.extender.XImageField':
                if scale is None:
                    image = field.getScale(self)
                else:
                    if scale in field.getAvailableSizes(self):
                        image = field.getScale(self, scale=scale)
            if image is not None and not isinstance(image, basestring):
                # image might be None or '' for empty images
                return image

        return ATCTContent.__bobo_traverse__(self, REQUEST, name)
Beispiel #24
0
 def _notifyOfCopyTo(self, container, op=0):
     """Override this to store a flag when we are copied, to be able
     to discriminate the right thing to do in manage_afterAdd here
     below.
     """
     self._v_renamed = 1
     return ATCTContent._notifyOfCopyTo(self, container, op=op)
Beispiel #25
0
    def widget(self, field_name, mode='view', field=None, **kwargs):
        """ special handling for uploaded_pdfFile widget
        """
        bib_tool = getToolByName(self, 'portal_bibliography')
        pdf_file = self.getPdf_file()
        if (pdf_file and self.isPdfUploadAllowedForThisType() and \
            bib_tool.allowPdfUploadPortalPolicy()) and \
            ((field_name == 'uploaded_pdfFile') or \
             (field == self.Schema().getField('uploaded_pdfFile'))):

            if pdf_file:
                field_name = 'uploaded_pdfFile'
                if field is None:
                    field = pdf_file.Schema()['file']
                widget = field.widget
                return renderer.render(field_name,
                                       mode,
                                       widget,
                                       pdf_file,
                                       field=field,
                                       **kwargs)

        else:

            return BaseContent.widget(self,
                                      field_name=field_name,
                                      mode=mode,
                                      field=field,
                                      **kwargs)
Beispiel #26
0
    def manage_afterAdd(self, item, container):
        # Fix text when created through webdav.
        # Guess the right mimetype from the id/data.
        ATCTContent.manage_afterAdd(self, item, container)
        field = self.getField('text')

        # hook for mxTidy / isTidyHtmlWithCleanup validator
        tidyOutput = self.getTidyOutput(field)
        if tidyOutput:
            if hasattr(self, '_v_renamed'):
                mimetype = field.getContentType(self)
                del self._v_renamed
            else:
                mimetype = self.guessMimetypeOfText()
            if mimetype:
                field.set(self, tidyOutput, mimetype=mimetype)  # set is ok
            elif tidyOutput:
                field.set(self, tidyOutput)  # set is ok
    def manage_afterAdd(self, item, container):
        # Fix text when created through webdav.
        # Guess the right mimetype from the id/data.
        ATCTContent.manage_afterAdd(self, item, container)
        field = self.getField("text")

        # hook for mxTidy / isTidyHtmlWithCleanup validator
        tidyOutput = self.getTidyOutput(field)
        if tidyOutput:
            if hasattr(self, "_v_renamed"):
                mimetype = field.getContentType(self)
                del self._v_renamed
            else:
                mimetype = self.guessMimetypeOfText()
            if mimetype:
                field.set(self, tidyOutput, mimetype=mimetype)  # set is ok
            elif tidyOutput:
                field.set(self, tidyOutput)  # set is ok
    def manage_afterPUT(self, data, marshall_data, file, context, mimetype, filename, REQUEST, RESPONSE):
        # After webdav/ftp PUT method.
        # Set title according to the id on webdav/ftp PUTs.
        if "" == data:
            file.seek(0)
            content = file.read(65536)
        else:
            content = data

        if -1 != content.lower().find("<html"):
            parser = etree.HTMLParser()
            tree = etree.fromstring(content, parser=parser)
            titletag = tree.xpath("//title")
            if titletag:
                self.setTitle(titletag[0].text)
            return

        ATCTContent.manage_afterPUT(self, data, marshall_data, file, context, mimetype, filename, REQUEST, RESPONSE)
Beispiel #29
0
    def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
                        filename, REQUEST, RESPONSE):
        # After webdav/ftp PUT method.
        # Set title according to the id on webdav/ftp PUTs.
        if '' == data:
            file.seek(0)
            content = file.read(65536)
        else:
            content = data

        if -1 != content.lower().find("<html"):
            parser = SimpleHTMLParser()
            parser.feed(content)
            if parser.title:
                self.setTitle(parser.title)
            return

        ATCTContent.manage_afterPUT(self, data, marshall_data, file,
                                    context, mimetype, filename, REQUEST,
                                    RESPONSE)
    def at_post_edit_script(self):

        bib_tool = getToolByName(self, 'portal_bibliography')
        plone_utils = getToolByName(self, 'plone_utils')
        bibfolder = self.getBibFolder()

        # id cooking
        if (bibfolder.getCookIdsOnBibRefCreation() and plone_utils.isIDAutoGenerated(self.getId())) or bibfolder.getCookIdsAfterBibRefEdit():
            new_id = bib_tool.cookReferenceId(ref=self, idcooker_id=bibfolder.getReferenceIdCookingMethod())
            if new_id != 'nobody1000':

                # this will implicitly call the PDF File rename code 
                # via self.manage_renameObject
                self.bibliography_entry_cookId()

            else:
                # no author, no publication year, do not know what to do
                BaseContent._renameAfterCreation(self, check_auto_id=True)

        # infer member references after edit
        if bib_tool.inferAuthorReferencesAfterEdit():
            self.inferAuthorReferences()
Beispiel #31
0
    def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
                        filename, REQUEST, RESPONSE):
        """After webdav/ftp PUT method

        Set title according to the id on webdav/ftp PUTs.
        """

        if '' == data:
            file.seek(0)
            content = file.read(65536)
        else:
            content = data

        if -1 != content.lower().find("<html"):
            parser = etree.HTMLParser()
            tree = etree.fromstring(content, parser=parser)
            titletag = tree.xpath('//title')
            if titletag:
                self.setTitle(titletag[0].text)
            return

        ATCTContent.manage_afterPUT(self, data, marshall_data, file, context,
                                    mimetype, filename, REQUEST, RESPONSE)
Beispiel #32
0
 def __bobo_traverse__(self, REQUEST, name):
     try:
         return self[name]
     except KeyError:
         pass
     if hasattr(aq_base(self), name):
         return getattr(self, name)
     # webdav
     """
     method = REQUEST.get('REQUEST_METHOD', 'GET').upper()
     if (method not in ('GET', 'POST') and not
           isinstance(REQUEST.RESPONSE, xmlrpc.Response) and
           REQUEST.maybe_webdav_client and not REQUEST.path):
         return ReflectoNullResource(self, name, REQUEST).__of__(self)
     """
     return ATCTContent.__bobo_traverse__(self, REQUEST, name)
Beispiel #33
0
 def __bobo_traverse__(self, REQUEST, name):
     try:
         return self[name]
     except KeyError:
         pass        
     if hasattr(aq_base(self), name):
         return getattr(self, name)
     # webdav
     """
     method = REQUEST.get('REQUEST_METHOD', 'GET').upper()
     if (method not in ('GET', 'POST') and not
           isinstance(REQUEST.RESPONSE, xmlrpc.Response) and
           REQUEST.maybe_webdav_client and not REQUEST.path):
         return ReflectoNullResource(self, name, REQUEST).__of__(self)
     """
     return ATCTContent.__bobo_traverse__(self, REQUEST, name)
Beispiel #34
0
    def __bobo_traverse__(self, REQUEST, name):
        """Transparent access to image scales
        """
        if name.startswith('backgroundImage'):
            field = self.getField('backgroundImage')
            image = None
            if name == 'backgroundImage':
                image = field.getScale(self)
            else:
                scalename = name[len('backgroundImage_'):]
                if scalename in field.getAvailableSizes(self):
                    image = field.getScale(self, scale=scalename)
            if image is not None and not isinstance(image, basestring):
                # image might be None or '' for empty images
                return image

        return ATCTContent.__bobo_traverse__(self, REQUEST, name)
Beispiel #35
0
    def __bobo_traverse__(self, REQUEST, name):
        """Transparent access to image scales
        """
        if name.startswith('image'):
            field = self.getField('image')
            image = None
            if name == 'image':
                image = field.getScale(self)
            else:
                scalename = name[len('image_'):]
                if scalename in field.getAvailableSizes(self):
                    image = field.getScale(self, scale=scalename)
            if image is not None and not isinstance(image, basestring):
                # image might be None or '' for empty images
                return image

        return ATCTContent.__bobo_traverse__(self, REQUEST, name)
 def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
     ATCTContent.processForm(self, data, metadata, REQUEST, values)
 def initializeArchetype(self, **kwargs):
     self.allow_discussion = False
     ATCTContent.initializeArchetype(self, **kwargs)
     self._ping_sent = False
Beispiel #38
0
 def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
     ATCTContent.processForm(self, data, metadata, REQUEST, values)
Beispiel #39
0
 def initializeArchetype(self, **kwargs):
     ATCTContent.initializeArchetype(self, **kwargs)
 def initializeArchetype(self, **kwargs):
     self.allow_discussion = False
     ATCTContent.initializeArchetype(self, **kwargs)
     self._ping_sent = False
Beispiel #41
0
    def manage_afterAdd(self, item, container):

        # manage_afterAdd is deprecated in Zope 2.11+

        ### copy PDF file if bibreference has been copied

        ###
        ### BEWARE: to debug this code go into
        ###         portal_skins/plone_scripts/folder_paste
        ###         and comment out the
        ###         fallback exception or use PloneTestCase
        ###

        reference_catalog = getToolByName(self, 'reference_catalog')
        bib_tool = getToolByName(self, 'portal_bibliography')
        bibfolder = container

        # grab the PDF file and its back references before the reference is removed by
        # BaseContent.manage_afterAdd
        pdf_file = self.getPdf_file() or None
        pdf_file_uid = ''
        if pdf_file:
            pdf_file_uid = pdf_file.UID()
            pdf_file_brefs = [
                bref.UID()
                for bref in pdf_file.getBRefs('printable_version_of')
                if bref is not None
            ]

        if not pdf_file_uid and shasattr(
                self, '_temp_pdffile_UID') and self._temp_pdffile_UID:
            pdf_file_uid = self._temp_pdffile_UID
            pdf_file_brefs = [
                bref.UID() for bref in reference_catalog.lookupObject(
                    pdf_file_uid).getBRefs('printable_version_of')
                if bref is not None
            ]
            delattr(self, '_temp_pdffile_UID')

        # first do all necessary ATCT, Archetypes, etc. things...
        BaseContent.manage_afterAdd(self, item, container)

        # we have to set another transaction savepoint here,
        # before we can cut or copy the associated PDF file
        bib_tool.transaction_savepoint(optimistic=True)

        # then check PDF file association
        pdf_file = pdf_file_uid and reference_catalog.lookupObject(
            pdf_file_uid)
        if pdf_file and pdf_file_brefs and (self.UID() not in pdf_file_brefs):

            # bibref item has been copied and UID of bibref item has changed
            # => copy PDF file
            new_pdf_file = self.relocatePdfFile(pdf_file=pdf_file, op=0)
            self.setPdf_file(value=new_pdf_file.UID())

        elif pdf_file and (pdf_file.aq_inner.aq_parent.aq_inner.aq_parent.
                           getPhysicalPath() !=
                           self.aq_inner.aq_parent.getPhysicalPath()):

            # PDF file and bibref item are not in the same bibfolder
            # => move PDF file!!!
            moved_pdf_file = self.relocatePdfFile(
                pdf_file=reference_catalog.lookupObject(pdf_file_uid), op=1)