How to use the publ.queries.build_query 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 / rendering.py View on Github external
def latest_entry():
        # Cache-busting query based on most recently-visible entry
        cb_query = queries.build_query({})
        cb_query = cb_query.order_by(orm.desc(model.Entry.utc_date))
        latest = cb_query.first()
        if latest:
            LOGGER.debug("Most recently-scheduled entry: %s", latest)
            return latest.id
        return None
github PlaidWeb / Publ / publ / view.py View on Github external
def deleted(self) -> typing.List[Entry]:
        """ Gets the deleted entries from the view """
        query = queries.build_query({**self.spec,
                                     'future': False,
                                     '_deleted': True})
        if self.spec.get('count'):
            # We're using a count constraint, so we'll want to limit this to
            # entries that come before our next page of non-deleted results.
            #
            # We only use the next-page start because our pagination constraint
            # (if any) will have already limited this query appropriately, and
            # we consider deleted entries in the gap between two views to
            # belong to the first page of views.
            if self._order_by == 'oldest' and self.next:
                query = queries.where_before_entry(query, self.next.first)
            elif self._order_by == 'newest' and self.next:
                query = queries.where_after_entry(query, self.next.first)

        return [Entry.load(e) for e in query]
github PlaidWeb / Publ / publ / entry.py View on Github external
def _get_attachments(order=None, **kwargs) -> typing.List:
            query = queries.build_query({**kwargs,
                                         'attachments': self._record
                                         })
            if order:
                query = query.order_by(*queries.ORDER_BY[order])
            return [Entry.load(e) for e in query]
github PlaidWeb / Publ / publ / entry.py View on Github external
def _next(**kwargs) -> typing.Optional["Entry"]:
            """ Get the next item in any particular category """
            spec = self._pagination_default_spec(kwargs)
            spec.update(kwargs)

            query = queries.build_query(spec)
            query = queries.where_after_entry(query, self._record)

            cur_user = user.get_active()
            for record in query.order_by(model.Entry.local_date,
                                         model.Entry.id):
                if record.is_authorized(cur_user):
                    return Entry.load(record)

                LOGGER.debug("User unauthorized for entry %d", record.id)
                tokens.request(cur_user)
            return None
        return CallableProxy(_next)
github PlaidWeb / Publ / publ / category.py View on Github external
def _entries(self, spec):
        """ Return a model query to get our entry records """
        return queries.build_query({**spec, 'category': self})