~sirn/fanboi2

ref: 834edf0edc5dd633c0ecea16231b6ed2d728476d fanboi2/fanboi2/services/page.py -rw-r--r-- 1.1 KiB
834edf0eKridsada Thanabulpong Massive cleanup in preparation for 0.30 (#25) 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from ..models import Page


class PageQueryService(object):
    """Page query service provides a service for querying a page
    or a collection of pages from the database.
    """

    def __init__(self, dbsession):
        self.dbsession = dbsession

    def list_public(self):
        """Query all public pages."""
        return list(
            self.dbsession.query(Page).
            order_by(Page.title).
            filter_by(namespace='public'))

    def public_page_from_slug(self, page_slug):
        """Query a public page from the given page slug.

        :param page_slug: A slug :type:`str` identifying the page.
        """
        return self.dbsession.query(Page).\
            filter_by(namespace='public', slug=page_slug).\
            one()

    def internal_page_from_slug(self, page_slug):
        """Query an internal page from the given page slug.

        :param page_slug: A slug :type:`str` identifying the page.
        """
        return self.dbsession.query(Page).\
            filter_by(namespace='internal', slug=page_slug).\
            one()