Exemplo n.º 1
0
class IInfocardContainerSearchForm(form.Schema):
    """ Define form fields """

    text = schema.TextLine(
        title=_("label_search_text", u"Search text"), required=False
    )
    servicetype = schema.Choice(
        title=_("label_servicetype", u"Service type"),
        vocabulary="redturtle.infocard.infocardcontainer.servicetypes",
        required=False,
    )
    recipient = schema.Choice(
        title=_("label_for_who_is_it", u"For who is it?"),
        vocabulary="redturtle.infocard.infocardcontainer.recipients",
        required=False,
    )

    @invariant
    def at_least_one(data):
        if data.servicetype or data.recipient or data.text:
            return
        raise Invalid(
            _(
                "label_at_least_one_search_parameter",
                u"You should specify at least one search parameter",
            )
        )
Exemplo n.º 2
0
class AddForm(base.AddForm):
    label = _(u"Add Infocard search portlet")
    description = _(u"This portlet displays a search form.")
    schema = IInfocardSearchPortlet
    form_fields = field.Fields(schema)

    def create(self, data):
        return Assignment(**data)
Exemplo n.º 3
0
class IInfocardContainer(model.Schema):
    """ Marker interface and Dexterity Python Schema for InfocardContainer
    """

    introduction = RichText(title=_(u"Introduction"), required=True)

    servicetypes = schema.List(
        title=_("label_available_servicetypes", u"Available service types"),
        description=_(
            "help_available_servicetypes",
            (
                u"Insert one service type per line. "
                u"They will be proposed "
                u"in the service type field of the infocards"
            ),
        ),
        value_type=schema.TextLine(title=_(u"service_type", "Service type")),
        default=[],
        required=True,
    )

    recipients = schema.List(
        title=_("label_available_recipients", u"Available recipients"),
        description=_(
            "help_available_recipients",
            (
                u"Insert one recipient per line. "
                u"They will be proposed "
                u"in the recipient field of the infocards"
            ),
        ),
        value_type=schema.TextLine(title=_(u"recipient", "Recipient")),
        default=[],
        required=True,
    )
Exemplo n.º 4
0
 def at_least_one(data):
     if data.servicetype or data.recipient or data.text:
         return
     raise Invalid(
         _(
             "label_at_least_one_search_parameter",
             u"You should specify at least one search parameter",
         )
     )
Exemplo n.º 5
0
class IInfocard(Interface):
    """ Marker interface and Dexterity Python Schema for Infocard
    """

    servicetypes = schema.Tuple(
        title=_("label_servicetypes", u"Service types"),
        value_type=schema.TextLine(),
        required=True,
        missing_value=None,
    )
    directives.widget(
        "servicetypes",
        AjaxSelectFieldWidget,
        vocabulary="redturtle.infocard.infocardcontainer.servicetypes",
        pattern_options={"allowNewItems": False},
    )

    recipients = schema.Tuple(
        title=_("label_recipients", u"Recipients"),
        value_type=schema.TextLine(),
        required=True,
        missing_value=None,
    )
    directives.widget(
        "recipients",
        AjaxSelectFieldWidget,
        vocabulary="redturtle.infocard.infocardcontainer.recipients",
        pattern_options={"allowNewItems": False},
    )

    order = schema.List(
        title=_(u"Cards"),
        required=False,
        value_type=DictRow(title=u"Card", schema=ICardOrder),
        missing_value=[],
    )
    form.widget(order=DataGridFieldFactory)
Exemplo n.º 6
0
class ICardOrder(Interface):
    publish = schema.Bool(title=_(u"Publish"), required=True)
    title_card = schema.TextLine(title=_(u"Title card"), required=False)
    uid_card = schema.ASCIILine(title=_("Uid card"), required=False)
Exemplo n.º 7
0
class EditForm(base.EditForm):
    label = _(u"Edit Recent Portlet")
    description = _(u"This portlet displays a search form.")
    schema = IInfocardSearchPortlet
    form_fields = field.Fields(schema)
Exemplo n.º 8
0
class InfocardContainerSearchForm(form.SchemaForm):

    ignoreContext = True
    schema = IInfocardContainerSearchForm
    searching = False

    table_fields = [
        {"id": "title", "label": _("title")},
        {"id": "description", "label": _("description")},
        {
            "id": "servicetypes",
            "label": _("label_servicetypes", u"Service types"),
        },
        {
            "id": "recipients",
            "label": _("label_for_who_is_it", u"For who is it?"),
        },
    ]

    def _init_(self, context, request):
        self.context = context
        self.request = request

    def accept_infocard(self, infocard, data):
        """ Given the data in the parameters filter the infocard
        """
        if data.get("servicetype"):
            if not data.get("servicetype") in infocard.servicetypes:
                return False
        if data.get("recipient"):
            if not data.get("recipient") in infocard.recipients:
                return False
        if data.get("text"):
            if not data.get("text").lower() in infocard.searched_text():
                return False
        return True

    def search_results(self, data):
        """
        """
        voc_recipients = InfocardContainerRecipientsFactory(self.context)
        voc_services = InfocardContainerServiceTypesFactory(self.context)

        infocards = self.context.listFolderContents(
            {"portal_type": "InformationCard"}
        )
        results = []
        for infocard in infocards:
            if self.accept_infocard(infocard, data):
                results.append(
                    {
                        "review_state": api.content.get_state(infocard),
                        "url": infocard.absolute_url,
                        "title": infocard.title,
                        "description": infocard.description,
                        "servicetypes": ", ".join(
                            sorted(
                                [
                                    voc_services.getTermByToken(x).title
                                    for x in infocard.servicetypes
                                ]
                            )
                        ),
                        "recipients": ", ".join(
                            sorted(
                                [
                                    voc_recipients.getTermByToken(x).title
                                    for x in infocard.recipients
                                ]
                            )
                        ),
                    }
                )
        sorted(results, key=lambda x: x["title"])
        return results

    @button.buttonAndHandler(_("label_search", u"Search"))
    def handleSearch(self, action):
        self.searching = True
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            self.results = []
            return
        self.results = self.search_results(data)
Exemplo n.º 9
0
class IInfocardSearchPortlet(IPortletDataProvider):

    """A portlet that allows searching in an infocard container
    """
    name = schema.TextLine(
        title=_(u"name", default=u"Portlet name"),
        default=u'Infocard search portlet',
        required=False,
    )

    display_title = schema.Bool(
        title=_(u"label_display_title", default=u"Display title"),
        description=_(
            u"help_display_title",
            u"If checked the portlet will display a title based on name"
        ),
        default=True,
        required=True,
    )

    target = schema.Choice(
        title=_(u"Target infocard container"),
        description=_(
            "help_target",
            u"Choose the infocard container in which you can search"
        ),
        vocabulary='redturtle.infocard.infocartcontainer.vocabulary',
        required=True
    )

    display_filters = schema.Bool(
        title=_('label_display_filters', u"Display filters"),
        description=_(
            "help_display_filters",
            u'By default the portlet displays one input '
            u'to search on infocard text. '
            u'If you select this checkbox two additional selects will appear. '
            u'They will allow to search in the fields '
            u'"Service type" and "Recipient".'
        ),
        default=False,
    )

    text_before = RichText(
        title=_(u"Text before search fields"),
        description=_(u"This text will appear before the search fields"),
        required=False
    )

    text_after = RichText(
        title=_(u"Text after search fields"),
        description=_(u"This text will appear after the search fields"),
        required=False
    )