Ejemplo n.º 1
0
    def render(self):

        # check whether we have paths or not
        paths = self.request.get('paths')

        # using "paths" is mandantory on any objects except for a document
        if not paths and not IDocumentSchema.providedBy(self.context):
            msg = _(u'You have not selected any documents')
            IStatusMessage(self.request).addStatusMessage(msg, type='error')

            # we assume the request came from the tabbed_view "documents"
            # tab on the dossier
            return self.request.RESPONSE.redirect('%s#documents' %
                                                  self.context.absolute_url())

        elif paths:
            # lookup the objects to be handled using the catalog
            catalog = getToolByName(self.context, 'portal_catalog')
            objects = []
            for path in paths:
                query = dict(path={'query': path, 'depth': 0})
                obj = catalog(query)[0].getObject()
                objects.append(obj)

        else:
            # the context is the document
            objects = [self.context]

        # now, lets checkout every document
        for obj in objects:
            if not IDocumentSchema.providedBy(obj):
                # notify the user. we have a no-checkoutable object
                msg = _(
                    u'Could not check out object: ${title}, '
                    'it is not a document',
                    mapping={'title': obj.Title().decode('utf-8')})
                IStatusMessage(self.request).addStatusMessage(msg,
                                                              type='error')
                continue

            self.checkout(obj)

        # lets register a redirector for starting external
        # editor - if requested
        external_edit = self.request.get('mode') == 'external'
        if len(objects) == 1 and external_edit:
            redirector = IRedirector(self.request)
            redirector.redirect('%s/external_edit' % objects[0].absolute_url(),
                                target='_self',
                                timeout=1000)

        # now lets redirect to an appropriate target..
        if len(objects) == 1:
            return self.request.RESPONSE.redirect(objects[0].absolute_url())

        else:
            return self.request.RESPONSE.redirect('%s#documents' %
                                                  self.context.absolute_url())
Ejemplo n.º 2
0
    def __call__(self):
        # check whether we have paths or not
        paths = self.request.get('paths')

        # using "paths" is mandantory on any objects except for a document
        if not paths and not IDocumentSchema.providedBy(self.context):
            msg = _(u'You have not selected any documents.')
            IStatusMessage(self.request).addStatusMessage(
                msg, type='error')

            # we assume the request came from the tabbed_view "documents"
            # tab on the dossier
            return self.request.RESPONSE.redirect(
                '%s#documents' % self.context.absolute_url())

        elif paths:
            # lookup the objects to be handled using the catalog
            catalog = getToolByName(self.context, 'portal_catalog')
            objects = []
            for path in paths:
                query = dict(path={'query': path, 'depth': 0})
                obj = catalog(query)[0].getObject()
                objects.append(obj)

        else:
            # the context is the document
            objects = [self.context]

        # now, lets checkout every document
        if not self.request.get('reauth') == '1':
            for obj in objects:
                if not IDocumentSchema.providedBy(obj):
                    # notify the user. we have a no-checkoutable object
                    msg = _(
                        u'Could not check out object: ${title}, '
                        'it is not a document.',
                        mapping={'title': obj.Title().decode('utf-8')})
                    IStatusMessage(
                        self.request).addStatusMessage(msg, type='error')
                    continue

                self.checkout(obj)

        # lets register a redirector for starting external
        # editor - if requested
        external_edit = self.request.get('mode') == 'external'

        # now lets redirect to an appropriate target..
        if len(objects) == 1:
            if external_edit:
                objects[0].setup_external_edit_redirect(self.request)
            return self.request.RESPONSE.redirect(
                objects[0].absolute_url())

        else:
            return self.request.RESPONSE.redirect(
                '%s#documents' % self.context.absolute_url())
Ejemplo n.º 3
0
    def __call__(self):
        parent = aq_parent(aq_inner(self.context))

        # not allowed for anonymous users
        mtool = getToolByName(self.context, 'portal_membership')
        if mtool.isAnonymousUser():
            return False

        # if webdav is not allowed, we cannot externally edit
        if not webdav_enabled(self.context, parent):
            return False

        # only allowed on documents
        if not IDocumentSchema.providedBy(self.context):
            return False

        # only allowed, when there already is a file
        if not self.context.file:
            return False

        # only allowed when the current user has checked out the document
        current_user_id = getSecurityManager().getUser().getId()
        manager = queryMultiAdapter((self.context, self.request),
                                    ICheckinCheckoutManager)

        if not manager or manager.get_checked_out_by() != current_user_id:
            return False

        # Content may provide data to the external editor ?
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        return not not portal.externalEditLink_(self.context)
Ejemplo n.º 4
0
def file_copy_downloaded(context, event):

    title_unversioned = _(u'label_file_copy_downloaded',
                          default=u'Download copy')

    if IDocumentSchema.providedBy(context):
        version_id = getattr(event, 'version_id')

        if version_id is not None:
            version_string = _(u'label_file_copy_downloaded_version',
                               default=u'version ${version_id}',
                               mapping={'version_id': version_id})
        else:
            version_string = _(u'label_file_copy_downloaded_actual_version',
                               default=u'current version (${version_id})',
                               mapping={'version_id': context.version_id})

        title = _(u'label_file_copy_downloaded_with_version',
                  default=u'${title} ${version_string}',
                  mapping={
                      'title': title_unversioned,
                      'version_string': version_string
                  })
    else:
        title = title_unversioned

    journal_entry_factory(context, FILE_COPY_DOWNLOADED, title)
Ejemplo n.º 5
0
 def is_download_pdfpreview_available(self):
     """PDF Preview link is only available for documents and
     opengever.pdfconverter is installed.
     """
     if self.is_preview_supported():
         return IDocumentSchema.providedBy(self.context)
     return False
Ejemplo n.º 6
0
    def cancel(self, action):
        # on a document? go back to the document
        if IDocumentSchema.providedBy(self.context):
            return self.request.RESPONSE.redirect(self.context.absolute_url())

        # otherwise to the dossier or task
        return get_containg_document_tab_url(self.context)
Ejemplo n.º 7
0
 def is_download_pdfpreview_available(self):
     """PDF Preview link is only available for documents and
     opengever.pdfconverter is installed.
     """
     if self.is_preview_supported():
         return IDocumentSchema.providedBy(self.context)
     return False
Ejemplo n.º 8
0
 def _add_descendants(self):
     objs = self.obj.objectValues()
     for obj in objs:
         if IDossierMarker.providedBy(obj):
             self.dossiers.append(Dossier(obj, self.path))
         elif IDocumentSchema.providedBy(obj):
             self.documents.append(Document(obj, self.path))
Ejemplo n.º 9
0
def file_copy_downloaded(context, event):

    title_unversioned = _(u'label_file_copy_downloaded',
                          default=u'Download copy')

    if IDocumentSchema.providedBy(context):
        version_id = getattr(event, 'version_id')

        if version_id is not None:
            version_string = _(u'label_file_copy_downloaded_version',
                               default=u'version ${version_id}',
                               mapping={'version_id': version_id})
        else:
            version_string = _(
                u'label_file_copy_downloaded_actual_version',
                default=u'current version (${version_id})',
                mapping={'version_id': getattr(context, 'version_id', 0)})

        title = _(u'label_file_copy_downloaded_with_version',
                  default=u'${title} ${version_string}',
                  mapping={'title': title_unversioned,
                           'version_string': version_string})
    else:
        title = title_unversioned

    journal_entry_factory(context, FILE_COPY_DOWNLOADED, title)
Ejemplo n.º 10
0
    def render(self):
        parent = aq_parent(aq_inner(self.context))

        # not allowed for anonymous users
        mtool = getToolByName(self.context, 'portal_membership')
        if mtool.isAnonymousUser():
            return False

        # if webdav is not allowed, we cannot externally edit
        if not webdav_enabled(self.context, parent):
            return False

        # only allowed on documents
        if not IDocumentSchema.providedBy(self.context):
            return False

        # only allowed, when there already is a file
        if not self.context.file:
            return False

        # only allowed when the current user has checked out the document
        current_user_id = getSecurityManager().getUser().getId()
        manager = queryMultiAdapter((self.context, self.request),
                                    ICheckinCheckoutManager)

        if not manager or manager.checked_out() != current_user_id:
            return False

        # Content may provide data to the external editor ?
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        return not not portal.externalEditLink_(self.context)
Ejemplo n.º 11
0
 def _add_descendants(self):
     objs = self.obj.objectValues()
     for obj in objs:
         if IDossierMarker.providedBy(obj):
             self.dossiers[obj.UID()] = Dossier(obj)
         elif IDocumentSchema.providedBy(obj):
             self.documents[obj.UID()] = Document(obj)
Ejemplo n.º 12
0
 def _add_descendants(self):
     objs = self.obj.objectValues()
     for obj in objs:
         if IDossierMarker.providedBy(obj):
             self.dossiers[obj.UID()] = Dossier(obj)
         elif IDocumentSchema.providedBy(obj):
             self.documents[obj.UID()] = Document(obj)
Ejemplo n.º 13
0
    def cancel(self, action):
        # on a document? go back to the document
        if IDocumentSchema.providedBy(self.context):
            return self.request.RESPONSE.redirect(
                self.context.absolute_url())

        # otherwise to the dossier or task
        return get_containg_document_tab_url(self.context)
Ejemplo n.º 14
0
    def handle_submit(self, action):
        data, errors = self.extractData()
        if len(errors) == 0:

            source = data['request_paths'].split(';;')
            destination = data['destination_folder']
            failed_objects = []
            failed_resource_locked_objects = []
            copied_items = 0

            for path in source:

                # Get source object
                src_object = self.context.unrestrictedTraverse(
                    path.encode('utf-8'))

                # Get parent object
                source_container = aq_parent(aq_inner(
                    self.context.unrestrictedTraverse(
                        path.encode('utf-8'))))

                src_name = src_object.title
                src_id = src_object.id

                # If parent isn't a dossier and obj is a document
                # it's connected to a task and shouldn't be moved
                if not IDossierMarker.providedBy(source_container) and \
                    IDocumentSchema.providedBy(src_object):
                    msg = _(u'Document ${name} is connected to a Task.\
                    Please move the Task.', mapping=dict(name=src_name))
                    IStatusMessage(self.request).addStatusMessage(
                        msg, type='error')
                    continue

                try:
                    # Try to cut and paste object
                    clipboard = source_container.manage_cutObjects(src_id)
                    destination.manage_pasteObjects(clipboard)
                    copied_items += 1

                except ResourceLockedError:
                    # The object is locket over webdav
                    failed_resource_locked_objects.append(src_name)
                    continue

                except (ValueError, CopyError):
                    # Catch exception and add title to a list of failed objects
                    failed_objects.append(src_name)
                    continue

            self.create_statusmessages(
                copied_items,
                failed_objects,
                failed_resource_locked_objects, )

            self.request.RESPONSE.redirect(destination.absolute_url())
Ejemplo n.º 15
0
    def handle_submit(self, action):
        data, errors = self.extractData()
        if len(errors) == 0:

            destination = data['destination_folder']
            failed_objects = []
            failed_resource_locked_objects = []
            copied_items = 0

            try:
                objs = self.extract_selected_objs(data)
            except KeyError:
                IStatusMessage(self.request).addStatusMessage(_(
                    u"The selected objects can't be found, please try it again."
                ),
                                                              type='error')
                return self.request.RESPONSE.redirect(
                    self.context.absolute_url())

            for obj in objs:
                parent = aq_parent(aq_inner(obj))

                if IDocumentSchema.providedBy(obj) and not obj.is_movable():
                    msg = _(u'Document ${name} is not movable.',
                            mapping=dict(name=obj.title))
                    IStatusMessage(self.request).addStatusMessage(msg,
                                                                  type='error')
                    continue

                try:
                    # Try to cut and paste object
                    clipboard = parent.manage_cutObjects(obj.id)
                    destination.manage_pasteObjects(clipboard)
                    copied_items += 1

                except ResourceLockedError:
                    # The object is locket over webdav
                    failed_resource_locked_objects.append(obj.title)
                    continue

                except (ValueError, CopyError):
                    # Catch exception and add title to a list of failed objects
                    failed_objects.append(obj.title)
                    continue

            self.create_statusmessages(
                copied_items,
                failed_objects,
                failed_resource_locked_objects,
            )

            self.request.RESPONSE.redirect(destination.absolute_url())
Ejemplo n.º 16
0
    def handle_submit(self, action):
        data, errors = self.extractData()
        if len(errors) == 0:

            destination = data['destination_folder']
            failed_objects = []
            failed_resource_locked_objects = []
            copied_items = 0

            try:
                objs = self.extract_selected_objs(data)
            except KeyError:
                IStatusMessage(self.request).addStatusMessage(
                    _(u"The selected objects can't be found, please try it again."),
                    type='error')
                return self.request.RESPONSE.redirect(self.context.absolute_url())

            for obj in objs:
                parent = aq_parent(aq_inner(obj))

                if IDocumentSchema.providedBy(obj) and not obj.is_movable():
                    msg = _(u'Document ${name} is connected to a Task. '
                            'Please move the Task.',
                            mapping=dict(name=obj.title))
                    IStatusMessage(self.request).addStatusMessage(msg, type='error')
                    continue

                try:
                    # Try to cut and paste object
                    clipboard = parent.manage_cutObjects(obj.id)
                    destination.manage_pasteObjects(clipboard)
                    copied_items += 1

                except ResourceLockedError:
                    # The object is locket over webdav
                    failed_resource_locked_objects.append(obj.title)
                    continue

                except (ValueError, CopyError):
                    # Catch exception and add title to a list of failed objects
                    failed_objects.append(obj.title)
                    continue

            self.create_statusmessages(
                copied_items,
                failed_objects,
                failed_resource_locked_objects, )

            self.request.RESPONSE.redirect(destination.absolute_url())
Ejemplo n.º 17
0
    def item_paths(self):
        # from the form?
        field_name = self.prefix + self.widgets.prefix + 'paths'
        value = self.request.get(field_name, False)
        if value:
            value = value.split(';;')
            return value

        # from folder_contents / tabbed_view?
        value = self.request.get('paths')
        if value:
            return value

        # from the context?
        if IDocumentSchema.providedBy(self.context):
            return ['/'.join(self.context.getPhysicalPath())]

        # nothing found..
        raise NoItemsSelected
Ejemplo n.º 18
0
    def item_paths(self):
        # from the form?
        field_name = self.prefix + self.widgets.prefix + 'paths'
        value = self.request.get(field_name, False)
        if value:
            value = value.split(';;')
            return value

        # from folder_contents / tabbed_view?
        value = self.request.get('paths')
        if value:
            return value

        # from the context?
        if IDocumentSchema.providedBy(self.context):
            return ['/'.join(self.context.getPhysicalPath())]

        # nothing found..
        raise NoItemsSelected
Ejemplo n.º 19
0
    def checkin_button_handler(self, action):
        """Handle checkin
        """

        data, errors = self.extractData()

        if len(errors) == 0:
            # check in each document
            for obj in self.objects:
                if IDocumentSchema.providedBy(obj):
                    manager = getMultiAdapter((obj, obj.REQUEST),
                                              ICheckinCheckoutManager)

                    if not manager.is_checkin_allowed():
                        msg = _(
                            u'Could not check in document ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='error')

                    else:
                        manager.checkin(data['comment'])
                        msg = _(
                            u'Checked in: ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='info')

                else:
                    title = obj.Title()
                    if not isinstance(title, unicode):
                        title = title.decode('utf-8')
                    msg = _(
                        u'Could not check in ${title}, it is not a document.',
                        mapping=dict(title=title))
                    IStatusMessage(self.request).addStatusMessage(msg,
                                                                  type='error')

            # redirect to dossier
            return self.request.RESPONSE.redirect(
                get_containg_document_tab_url(self.context))
Ejemplo n.º 20
0
    def checkin_button_handler(self, action):
        """Handle checkin
        """

        data, errors = self.extractData()

        if len(errors) == 0:
            # check in each document
            for obj in self.objects:
                if IDocumentSchema.providedBy(obj):
                    manager = getMultiAdapter((obj, obj.REQUEST),
                                              ICheckinCheckoutManager)

                    if not manager.is_checkin_allowed():
                        msg = _(
                            u'Could not check in document ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='error')

                    else:
                        manager.checkin(data['comment'])
                        msg = _(
                            u'Checked in: ${title}',
                            mapping=dict(title=obj.Title().decode('utf-8')))
                        IStatusMessage(self.request).addStatusMessage(
                            msg, type='info')

                else:
                    title = obj.Title()
                    if not isinstance(title, unicode):
                        title = title.decode('utf-8')
                    msg = _(
                        u'Could not check in ${title}, it is not a document.',
                        mapping=dict(title=title))
                    IStatusMessage(self.request).addStatusMessage(
                        msg, type='error')

            # redirect to dossier
            return self.request.RESPONSE.redirect(
                get_containg_document_tab_url(self.context))
Ejemplo n.º 21
0
    def render(self):

        # check whether we have paths or not
        paths = self.request.get('paths')

        # using "paths" is mandantory on any objects except for a document
        if not paths and not IDocumentSchema.providedBy(self.context):
            msg = _(u'You have not selected any documents')
            IStatusMessage(self.request).addStatusMessage(
                msg, type='error')

            # we assume the request came from the tabbed_view "documents"
            # tab on the dossier
            return self.request.RESPONSE.redirect(
                '%s#documents' % self.context.absolute_url())

        elif paths:
            # lookup the objects to be handled using the catalog
            catalog = getToolByName(self.context, 'portal_catalog')
            objects = []
            for path in paths:
                query = dict(path={'query': path, 'depth': 0})
                obj = catalog(query)[0].getObject()
                objects.append(obj)

        else:
            # the context is the document
            objects = [self.context]

        # now, lets cancel every document
        for obj in objects:
            self.cancel(obj)

        # now lets redirect to an appropriate target..
        if len(objects) == 1:
            return self.request.RESPONSE.redirect(
                objects[0].absolute_url())

        else:
            return self.request.RESPONSE.redirect(
                '%s#documents' % self.context.absolute_url())
Ejemplo n.º 22
0
    def __call__(self):
        # check whether we have paths or not
        paths = self.request.get('paths')

        # using "paths" is mandantory on any objects except for a document
        if not paths and not IDocumentSchema.providedBy(self.context):
            msg = _(u'You have not selected any documents.')
            api.portal.show_message(message=msg,
                                    request=self.request,
                                    type='error')

            # we assume the request came from the tabbed_view "documents"
            # tab on the dossier
            return self.request.RESPONSE.redirect('%s#documents' %
                                                  self.context.absolute_url())

        elif paths:
            # lookup the objects to be handled using the catalog
            catalog = api.portal.get_tool('portal_catalog')
            objects = []
            for path in paths:
                query = dict(path={'query': path, 'depth': 0})
                obj = catalog(query)[0].getObject()
                objects.append(obj)

        else:
            # the context is the document
            objects = [self.context]

        # now, lets cancel every document
        for obj in objects:
            self.cancel(obj)

        # now lets redirect to an appropriate target..
        if len(objects) == 1:
            return self.request.RESPONSE.redirect(objects[0].absolute_url())

        else:
            return self.request.RESPONSE.redirect('%s#documents' %
                                                  self.context.absolute_url())
Ejemplo n.º 23
0
 def process_document(self, obj, comment, force=False):
     if IDocumentSchema.providedBy(obj):
         self.perform_checkin(obj, comment, force)
     else:
         self.report_cannot_checkin_non_document(obj)
Ejemplo n.º 24
0
 def is_document(self):
     return IDocumentSchema.providedBy(self.context)
Ejemplo n.º 25
0
 def add_object(self, obj):
     if IDossierMarker.providedBy(obj):
         self.dossiers.append(Dossier(obj, u'files'))
     elif IDocumentSchema.providedBy(obj):
         self.documents.append(Document(obj, u'files'))
Ejemplo n.º 26
0
 def process_document(self, obj, comment, force=False):
     if IDocumentSchema.providedBy(obj):
         self.perform_checkin(obj, comment, force)
     else:
         self.report_cannot_checkin_non_document(obj)
Ejemplo n.º 27
0
    def handle_submit(self, action):
        data, errors = self.extractData()
        if len(errors) == 0:

            destination = data['destination_folder']
            failed_objects = []
            failed_resource_locked_objects = []
            copied_items = 0

            try:
                objs = self.extract_selected_objs(data)
            except KeyError:
                IStatusMessage(self.request).addStatusMessage(_(
                    u"The selected objects can't be found, please try it again."
                ),
                                                              type='error')
                return self.request.RESPONSE.redirect(
                    self.context.absolute_url())

            for obj in objs:
                parent = aq_parent(aq_inner(obj))

                if IDocumentSchema.providedBy(obj) and not obj.is_movable():
                    if obj.is_inside_a_task():
                        msg = _(
                            'label_not_movable_since_inside_task',
                            default=u'Document ${name} is inside a task and '
                            u'therefore not movable. Move the task '
                            u'instead',
                            mapping=dict(name=obj.title))
                    elif obj.is_inside_a_proposal():
                        msg = _(
                            'label_not_movable_since_inside_proposal',
                            default=u'Document ${name} is inside a proposal '
                            u'and therefore not movable. Move the '
                            u'proposal instead',
                            mapping=dict(name=obj.title))
                    else:
                        raise Exception(
                            'Failed to determine the reason for unmovable document. '
                            'Did IDocumentSchema.is_moveable change?')
                    IStatusMessage(self.request).addStatusMessage(msg,
                                                                  type='error')
                    continue

                try:
                    # Try to cut and paste object
                    clipboard = parent.manage_cutObjects(obj.id)
                    destination.manage_pasteObjects(clipboard)
                    copied_items += 1

                except ResourceLockedError:
                    # The object is locket over webdav
                    failed_resource_locked_objects.append(obj.title)
                    continue

                except (ValueError, CopyError):
                    # Catch exception and add title to a list of failed objects
                    failed_objects.append(obj.title)
                    continue

            self.create_statusmessages(
                copied_items,
                failed_objects,
                failed_resource_locked_objects,
            )

            self.request.RESPONSE.redirect(destination.absolute_url())
Ejemplo n.º 28
0
    def handle_submit(self, action):
        data, errors = self.extractData()
        if len(errors) == 0:

            destination = data['destination_folder']
            failed_objects = []
            failed_resource_locked_objects = []
            copied_items = 0

            try:
                objs = self.extract_selected_objs(data)
            except KeyError:
                IStatusMessage(self.request).addStatusMessage(
                    _(u"The selected objects can't be found, please try it again."),
                    type='error')
                return self.request.RESPONSE.redirect(self.context.absolute_url())

            for obj in objs:
                parent = aq_parent(aq_inner(obj))

                if IDocumentSchema.providedBy(obj) and not obj.is_movable():
                    if obj.is_inside_a_task():
                        msg = _(
                            'label_not_movable_since_inside_task',
                            default=u'Document ${name} is inside a task and '
                                    u'therefore not movable. Move the task '
                                    u'instead',
                            mapping=dict(name=obj.title))
                    elif obj.is_inside_a_proposal():
                        msg = _(
                            'label_not_movable_since_inside_proposal',
                            default=u'Document ${name} is inside a proposal '
                                    u'and therefore not movable. Move the '
                                    u'proposal instead',
                            mapping=dict(name=obj.title))
                    else:
                        raise Exception(
                            'Failed to determine the reason for unmovable document. '
                            'Did IDocumentSchema.is_moveable change?'
                        )
                    IStatusMessage(self.request).addStatusMessage(msg, type='error')
                    continue

                try:
                    # Try to cut and paste object
                    clipboard = parent.manage_cutObjects(obj.id)
                    destination.manage_pasteObjects(clipboard)
                    copied_items += 1

                except ResourceLockedError:
                    # The object is locket over webdav
                    failed_resource_locked_objects.append(obj.title)
                    continue

                except (ValueError, CopyError):
                    # Catch exception and add title to a list of failed objects
                    failed_objects.append(obj.title)
                    continue

            self.create_statusmessages(
                copied_items,
                failed_objects,
                failed_resource_locked_objects, )

            self.request.RESPONSE.redirect(destination.absolute_url())