示例#1
0
    def wrapTestUsers(self):
        """Present a widget to select a test user for login.

        !!! caution
            In production this will do nothing.
            Only in development mode one can select a test user.
        """
        if not self.isDevel:
            return E

        db = self.db

        testUsers = {
            record[N.eppn]: record
            for record in db.user.values()
            if N.eppn in record and G(record, N.authority) == N.local
        }
        return H.join(
            [
                H.div(H.a(u, href=f"/login?eppn={u}", cls="button small"))
                for u in testUsers
            ]
            + [
                H.div(
                    H.input(
                        E,
                        placeholder="email",
                        onchange="window.location.href=`/login?email=${this.value}`",
                    )
                )
            ]
        )
示例#2
0
    def widget(self, val):
        """Constructs and edit widget around for this type.

        Parameters
        ----------
        val: string
            The initial value for the widget.

        Returns
        -------
        string(html)
            Dependent on a batch of Javascript in `index.js`, look for `const widgets`.
        """

        atts = {}
        if self.pattern:
            atts[N.pattern] = self.pattern
        validationMsg = TypeBase.validationMsg(self.name)

        widgetElem = H.input(self.toEdit(val),
                             type=N.text,
                             cls="wvalue",
                             **atts)
        validationElem = H.span(E,
                                valmsg=validationMsg) if validationMsg else E
        return H.join([widgetElem, validationElem])
示例#3
0
    def widget(self, val, multiple, extensible, constrain):
        context = self.context
        db = context.db
        table = self.name

        valueRecords = db.getValueRecords(table, constrain=constrain)

        filterControl = (
            [
                H.input(
                    E,
                    type=N.text,
                    placeholder=G(MESSAGES, N.filter, default=E),
                    cls="wfilter",
                ),
                H.iconx(N.add, cls="small wfilter add", title="add value")
                if extensible
                else E,
                H.iconx(N.clear, cls="small wfilter clear", title="clear filter"),
            ]
            if len(valueRecords) > FILTER_THRESHOLD
            else []
        )
        atts = dict(
            markup=True,
            clickable=True,
            multiple=multiple,
            active=val,
            hideInActual=True,
            hideBlockedUsers=True,
        )
        return H.div(
            filterControl
            + [
                formatted
                for (text, formatted) in (
                    ([] if multiple else [self.title(record={}, **atts)])
                    + sorted(
                        (self.title(record=record, **atts) for record in valueRecords),
                        key=lambda x: x[0].lower(),
                    )
                )
            ],
            cls="wvalue",
        )
示例#4
0
    def makeOptions(self):
        """Produce an options widget.

        The options are defined in web.yaml, under the key `options`.
        """

        options = self.options

        filterRep = [
            H.input(E, type=N.text, id="cfilter", placeholder="match title"),
        ]
        optionsRep = [
            H.span(
                [H.checkbox(name, trival=value),
                 G(G(OPTIONS, name), N.label)],
                cls=N.option,
            ) for (name, value) in options.items()
        ]

        return [("XXX", rep) for rep in filterRep + optionsRep]