Ejemplo n.º 1
0
class IClassificationFolder(IClassificationCategory):
    """ """

    form.widget(classification_folders=FolderAutocompleteMultiFieldWidget)
    classification_folders = schema.List(
        title=_(u"Classification folders"),
        description=_(
            u"List of folders / subfolders in which this content is filed"),
        value_type=schema.Choice(source=ClassificationFolderSourceBinder(), ),
        required=False,
    )
Ejemplo n.º 2
0
class IClassificationConfig(model.Schema):

    folder_number = schema.Int(
        title=_(u"Number of next folder"),
        description=_(
            u"This value is used as 'number' variable in linked tal expression"
        ),
    )

    folder_talexpression = schema.TextLine(
        title=_(u"Folder internal reference default value expression"),
        description=_(
            u"Tal expression where you can use portal, number, context, request, "
            "date as variable"
        ),
    )

    subfolder_number = schema.Int(
        title=_(u"Number of next subfolder"),
        description=_(
            u"This value is used as 'number' variable in linked tal expression"
        ),
    )

    subfolder_talexpression = schema.TextLine(
        title=_(u"Subfolder internal reference default value expression"),
        description=_(
            u"Tal expression where you can use portal, number, context, request, "
            "date as variable"
        ),
    )
Ejemplo n.º 3
0
def create_classification_folder_facet():
    portal = api.portal.get()
    folder_id = "classification_folder_faceted_configuration"
    if folder_id in portal:
        return
    folder = api.content.create(
        container=portal,
        id=folder_id,
        title=_(u"Classification folder faceted configuration"),
        type="Folder",
    )
    folder.exclude_from_nav = True

    # backup location to avoid redirection after enabling the facets
    response_status = folder.REQUEST.RESPONSE.getStatus()
    response_location = folder.REQUEST.RESPONSE.getHeader("location")

    faceted_subtyper = folder.unrestrictedTraverse("@@faceted_subtyper")
    faceted_subtyper.enable()
    faceted_exportimport = folder.unrestrictedTraverse("@@faceted_exportimport")
    xml = folder.unrestrictedTraverse("classification-folder-faceted.xml")()
    faceted_exportimport._import_xml(import_file=xml)

    folder.REQUEST.RESPONSE.status = response_status
    folder.REQUEST.RESPONSE.setHeader("location", response_location or "")
Ejemplo n.º 4
0
class SettingsEditForm(controlpanel.RegistryEditForm):
    """
    Define form logic
    """

    schema = IClassificationConfig
    label = _(u"Classification Config")
Ejemplo n.º 5
0
class ClassificationFolderIdColumn(BaseColumn):
    header = _(u"Classification identifier")
    sort_index = "internal_reference_no"

    def renderCell(self, item):
        value = self.getValue(item)
        if not value:
            value = u"-"
        value = safe_unicode(value)
        return value
Ejemplo n.º 6
0
class ClassificationTreatingGroupColumn(VocabularyColumn):
    header = _(u"Service in charge")
    attrName = u"treating_groups"

    @property
    def _cached_vocab_instance(self):
        if not hasattr(self, "_cached_vocab_instance_value"):
            vocabulary = ServiceInChargeSource(self.context).vocabulary
            self._cached_vocab_instance_value = vocabulary
        return self._cached_vocab_instance_value
Ejemplo n.º 7
0
 def validate_columns(obj):
     columns = [
         v for k, v in obj._Data_data___.items() if k.startswith("column_")
     ]
     if obj._Data_data___.get(
             'treating_groups'
     ) is not None and u'treating_groups_title' in columns:
         raise Invalid(
             _("You can't select both a treating_groups and a column associated to treating groups title"
               ))
     required = extract_required_columns(obj)
     return tree_utils.validate_csv_columns(obj, required)
Ejemplo n.º 8
0
class IImportSecondStepBase(Interface):

    replace_slash = GeneratedBool(
        title=_ct(u"Replace slash in title"),
        default=True,
        required=False,
    )

    treating_groups = GeneratedChoice(  # this overrided Choice field is adapted to folders (see tree importform)
        title=_(u"Service in charge"),
        description=_(u"Service that will be set on all imported folders"),
        source=ServiceInChargeSourceBinder(),
        required=False,
    )

    @invariant
    def validate_columns(obj):
        columns = [
            v for k, v in obj._Data_data___.items() if k.startswith("column_")
        ]
        if obj._Data_data___.get(
                'treating_groups'
        ) is not None and u'treating_groups_title' in columns:
            raise Invalid(
                _("You can't select both a treating_groups and a column associated to treating groups title"
                  ))
        required = extract_required_columns(obj)
        return tree_utils.validate_csv_columns(obj, required)

    @invariant
    def validate_data(obj):
        annotations = IAnnotations(obj.__context__)
        required = extract_required_columns(obj)
        # required.remove("folder_title")  # folder title may be empty #TODO which case ??
        return tree_utils.validate_csv_content(
            obj,
            annotations[ANNOTATION_KEY],
            required,
        )
Ejemplo n.º 9
0
class SubfolderClassificationFoldersColumn(ClassificationFoldersColumn):
    header = _(u"Classification Subfolder")

    def _get_title(self, obj):
        """Extract title from object"""
        if obj.portal_type == "ClassificationFolder":
            return
        if aq_parent(obj).UID() == self.context.UID():
            return obj.title
        if hasattr(obj, "get_full_title"):
            title = obj.get_full_title()
        else:
            title = obj.title
        return title
Ejemplo n.º 10
0
def on_delete(obj, event):
    obj_uid = api.content.get_uuid(obj)
    try:
        linked_content = api.content.find(classification_folders=obj_uid)
    except api.exc.CannotGetPortalError:
        # This happen when we try to remove plone object
        return
    if linked_content:
        IStatusMessage(obj.REQUEST).addStatusMessage(
            _(
                "cannot_delete_referenced_folder",
                default=
                "This folder cannot be deleted because it is referenced elsewhere",
            ),
            type="warning",
        )
        view_url = getMultiAdapter((obj, obj.REQUEST),
                                   name=u"plone_context_state").view_url()
        raise Redirect(view_url)
Ejemplo n.º 11
0
    def unique_identifier_invariant(data):
        data_uuid = None
        portal_types = ("ClassificationFolder", "ClassificationSubfolder")
        if getattr(data, "__context__", None):
            try:
                data_uuid = api.content.get_uuid(data.__context__)
            except TypeError:
                # This can happen during creation with API
                pass
        elif getattr(data, "portal_type", None) in portal_types:
            try:
                data_uuid = api.content.get_uuid(data)
            except TypeError:
                # This can happen during creation with API
                pass

        brains = api.content.find(
            context=api.portal.get(),
            internal_reference_no=data.internal_reference_no,
        )
        if len([b for b in brains if b.UID != data_uuid]) != 0:
            raise Invalid(
                _(u"The classification identifier must be unique to this folder."
                  ))
Ejemplo n.º 12
0
class ClassificationTreeIdentifiersColumn(VocabularyColumn):
    header = _(u"Classification categories")
    attrName = u"classification_categories"
    vocabulary = u"collective.classification.vocabularies:tree"
Ejemplo n.º 13
0
class ClassificationFoldersColumn(VocabularyColumn):
    header = _(u"Classification folders")
    attrName = u"classification_folders"

    @property
    def _cached_vocab_instance(self):
        if not hasattr(self, "_cached_vocab_instance_value"):
            vocabulary = ClassificationFolderSource(self.context).vocabulary
            self._cached_vocab_instance_value = vocabulary
        return self._cached_vocab_instance_value

    def _render_link(self, value):
        obj = api.content.get(UID=value)
        if not obj:
            return
        title = self._get_title(obj)
        if not title:
            return
        return u"<a href='{url}' target='_blank'>{obj}</a>".format(
            url=obj.absolute_url(),
            obj=safe_unicode(title),
        )

    def _get_title(self, obj):
        """Extract title from object"""
        if hasattr(obj, "get_full_title"):
            title = obj.get_full_title()
        else:
            title = obj.title
        return title

    def _filter_values(self, value):
        if value.startswith("p:"):
            # We don't want to display indexed parents
            return True
        return False

    def renderCell(self, item):
        value = self.getValue(item)
        if not value or value == self.ignored_value:
            return u"-"

        # caching when several same values in same column
        if self.use_caching:
            res = self._get_cached_result(value)
            if res:
                return res

        # make sure we have an iterable
        if not hasattr(value, "__iter__"):
            value = [value]
        res = []
        for v in value:
            if self._filter_values(v):
                continue
            try:
                link = self._render_link(v)
                if link:
                    res.append(safe_unicode(link))
            except Exception:
                # in case an error occured during link creation
                res.append(safe_unicode(v))
        res = ", ".join(res)
        if not res:
            return u"-"
        if self.use_caching:
            self._store_cached_result(value, res)
        return res
Ejemplo n.º 14
0
class IClassificationFolders(model.Schema):
    """Marker interface and Dexterity Python Schema for ClassificationFolders"""

    title = schema.TextLine(title=_(u"Title"),
                            # description=_(u"Name of the folders container"),
                            )
Ejemplo n.º 15
0
def import_keys_vocabulary_factory(context):
    values = (
        # common
        (u"treating_groups_title", _(u"Treating groups title")),
        # _process_with_ref
        (u"parent_identifier", _(u"Parent Identifier")),
        (u"internal_reference_no", _(u"Identifier")),
        (u"classification_categories", _(u"Classification categories")),
        (u"title", _(u"Name")),
        (u"classification_informations", _(u"Informations")),
        (u"archived", _(u"Archived")),
        # _process_without_ref
        (u"folder_internal_reference_no", _(u"Folder identifier")),
        (u"subfolder_internal_reference_no", _(u"Subfolder identifier")),
        (u"folder_categories", _(u"Folder classification categories")),
        (u"subfolder_categories", _(u"Subfolder classification categories")),
        (u"folder_title", _(u"Folder Name")),
        (u"subfolder_title", _(u"Subfolder Name")),
        (u"folder_informations", _(u"Folder Informations")),
        (u"subfolder_informations", _(u"Subfolder Informations")),
        (u"folder_archived", _(u"Archived folder")),
        (u"subfolder_archived", _(u"Archived subfolder")),
    )
    return iterable_to_vocabulary(values)
Ejemplo n.º 16
0
class IClassificationFolder(model.Schema):
    """Marker interface and Dexterity Python Schema for ClassificationFolder"""

    dexteritytextindexer.searchable("title")
    title = schema.TextLine(title=_(u"Name"),
                            # description=_(u"Name of the folder"),
                            )

    dexteritytextindexer.searchable("internal_reference_no")
    internal_reference_no = schema.TextLine(
        title=_(u"Classification identifier"),
        # description=_(u"Unique identifier of the folder"),
        required=False,
    )

    dexteritytextindexer.searchable("classification_categories")
    form.widget(classification_categories=AutocompleteMultiFieldWidget)
    classification_categories = schema.List(
        title=_(u"Classification categories"),
        # description=_(u"List of categories / subcategories"),
        value_type=schema.Choice(
            source=ClassificationTreeSourceBinder(enabled=True), ),
        min_length=1,
    )

    treating_groups = LocalRoleField(
        title=_(u"Service in charge"),
        # description=_(u"ID of the service that are in charge of this folder"),
        source=ServiceInChargeSourceBinder(),
        required=False,
    )

    form.widget(recipient_groups=ChosenMultiFieldWidget)
    recipient_groups = LocalRolesField(
        title=_(u"Services in copy"),
        # description=_(u"ID of the services that can access this folder"),
        value_type=schema.Choice(source=ServiceInCopySourceBinder(), ),
        required=False,
    )

    dexteritytextindexer.searchable("classification_informations")
    classification_informations = schema.Text(
        title=_(u"Classification informations"),
        # description=_(u"Informations"),
        required=False,
    )

    archived = schema.Bool(
        title=_(u"Archived"),
        required=False,
        default=False,
    )

    @invariant
    def unique_identifier_invariant(data):
        data_uuid = None
        portal_types = ("ClassificationFolder", "ClassificationSubfolder")
        if getattr(data, "__context__", None):
            try:
                data_uuid = api.content.get_uuid(data.__context__)
            except TypeError:
                # This can happen during creation with API
                pass
        elif getattr(data, "portal_type", None) in portal_types:
            try:
                data_uuid = api.content.get_uuid(data)
            except TypeError:
                # This can happen during creation with API
                pass

        brains = api.content.find(
            context=api.portal.get(),
            internal_reference_no=data.internal_reference_no,
        )
        if len([b for b in brains if b.UID != data_uuid]) != 0:
            raise Invalid(
                _(u"The classification identifier must be unique to this folder."
                  ))
Ejemplo n.º 17
0
 def label(self):
     return _(u"Import folders")