How to use the publ.utils function in Publ

To help you get started, we’ve selected a few Publ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlaidWeb / Publ / publ / user.py View on Github external
@utils.stash
def get_active() -> typing.Optional[User]:
    """ Get the active user """
    if 'Authorization' in flask.request.headers:
        parts = flask.request.headers['Authorization'].split()
        if parts[0].lower() == 'bearer':
            token = tokens.parse_token(parts[1])
            return User(token['me'], 'token', token.get('scope'))

    if flask.session.get('me'):
        return User(flask.session['me'], 'session')

    return None
github PlaidWeb / Publ / publ / entry.py View on Github external
    @utils.stash
    def load(record: model.Entry):
        """ Get a pooled Entry wrapper

        record -- the index record to use as the basis
        """
        return Entry(Entry.load.__name__, record)
github PlaidWeb / Publ / publ / image / image.py View on Github external
def _wrap_link_target(self, kwargs,
                          text: str,
                          title: typing.Optional[str]) -> str:
        if kwargs.get('link') is not None:
            if not text or kwargs['link'] is False:
                return text

            return '{}{}'.format(
                utils.make_tag(
                    'a', {
                        'href': utils.remap_link_target(
                            kwargs['link'],
                            kwargs.get('absolute')),
                        'class': kwargs.get('link_class', False)
                    }),
                text)

        if kwargs.get('gallery_id'):
            return f'{self._fullsize_link_tag(kwargs, title)}{text}'

        return text
github PlaidWeb / Publ / publ / image / local.py View on Github external
def _get_renditions(self, kwargs):
        """ Get a bunch of renditions; returns a tuple of 1x, 2x, size """
        img_1x, size = self.get_rendition(
            1, **utils.remap_args(kwargs, {"quality": "quality_ldpi"}))
        img_2x, _ = self.get_rendition(
            2, **utils.remap_args(kwargs, {"quality": "quality_hdpi"}))

        return (img_1x, img_2x, size)
github PlaidWeb / Publ / publ / view.py View on Github external
    @utils.stash
    def load(input_spec: ViewSpec):
        """ Generate a view.

        input_spec -- the parameters to the view. In addition to the values provided
        to queries.build_query, this also takes the following keys:
            count -- How many entries to include in a page
            order -- How to order the entries ('newest' or 'oldest')
        """
        return View(View.load.__name__, input_spec)