Esempio n. 1
0
def get_category(id_value, description=True):
    form = get_prismic_form()
    form.query(
            predicates.at('document.type', 'category'),
            predicates.at('document.id', id_value)
        ).page(1).page_size(1).fetch(["category.name", "category.description"] if description else ["category.name"])
    try:
        response = form.submit()
        if response.documents:
            return format_category(response.documents[0])
    except:
        return None
Esempio n. 2
0
def get_post(id_value):
    form = get_prismic_form()
    form.query(
            predicates.at('document.type', 'post'),
            predicates.at('document.id', id_value)
        ).page(1).page_size(1)
    try:
        response = form.submit()
        if response.documents:
            return format_post(response.documents[0])
    except:
        return None
Esempio n. 3
0
async def test_form(api_url):
    async with prismic.get(api_url) as api:
        query = api.form("everything").ref(api.get_master()).query(
            predicates.at("document.type", "all"))
        response = await query.submit()

    assert response.results_size >= 2
Esempio n. 4
0
def get_categories(filters):
    form = get_prismic_form()
    page = filters.get("page", "1")
    if page.isdigit():
        page = int(page)
    else:
        page = 1
    page_size = filters.get("limit", "10")
    if page_size.isdigit():
        page_size = int(page_size)

    form.query(
            predicates.at('document.type', 'category')
        ).page(page).fetch(["category.name"]).page_size(page_size)
    try:
        response = form.submit()
        results = map(format_category, response.documents)
        return {
            "results": results,
            "total_pages": response.total_pages,
            "page": page
        }
    except:
        return {
            "results": [],
            "total_pages": 0,
            "page": page
        }
Esempio n. 5
0
    def test_date_timestamp(self):
        api = prismic.get('https://lesbonneschoses.prismic.io/api')
        response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbl"))\
            .ref(api.get_master()).submit()
        doc = response.documents[0]
        # startgist:d0df1672e30871ab6517:prismic-dateTimestamp.py
        # Date and Timestamp predicates
        date_before = predicates.date_before("my.product.releaseDate", datetime.datetime(2014, 6, 1))
        date_after = predicates.date_after("my.product.releaseDate", datetime.datetime(2014, 1, 1))
        date_Between = predicates.date_between("my.product.releaseDate", datetime.datetime(2014, 1, 1), datetime.datetime(2014, 6, 1))
        day_of_month = predicates.day_of_month("my.product.releaseDate", 14)
        day_of_month_after = predicates.day_of_month_after("my.product.releaseDate", 14)
        day_of_month_before = predicates.day_of_month_before("my.product.releaseDate", 14)
        day_of_week = predicates.day_of_week("my.product.releaseDate", "Tuesday")
        day_of_week_after = predicates.day_of_week_after("my.product.releaseDate", "Wednesday")
        day_of_week_before = predicates.day_of_month_before("my.product.releaseDate", "Wednesday")
        month = predicates.month("my.product.releaseDate", "June")
        month_before = predicates.month_before("my.product.releaseDate", "June")
        month_after = predicates.month_after("my.product.releaseDate", "June")
        year = predicates.year("my.product.releaseDate", 2014)
        hour = predicates.hour("my.product.releaseDate", 12)
        hour_before = predicates.hour_before("my.product.releaseDate", 12)
        hour_after = predicates.hour_after("my.product.releaseDate", 12)

        # Accessing Date and Timestamp fields
        date = doc.get_date("blog-post.date")
        date_year = date and date.as_datetime.year
        update_time = doc.get_timestamp("blog-post.update")
        update_hour = update_time and update_time.as_datetime.hours
        # endgist
        self.assertEqual(date_year, 2013)
Esempio n. 6
0
 def test_references(self):
     preview_token = 'MC5VcXBHWHdFQUFONDZrbWp4.77-9cDx6C3lgJu-_vXZafO-_vXPvv73vv73vv70777-9Ju-_ve-_vSLvv73vv73vv73vv70O77-977-9Me-_vQ'
     api = prismic.get('https://micro.prismic.io/api', preview_token)
     release_ref = api.get_ref('myrelease')
     response = api.query(predicates.at("document.type", "all"),
                          ref=release_ref)
     self.assertGreaterEqual(response.results_size, 1)
Esempio n. 7
0
 def test_at(self):
     f = self.api\
         .form("everything")\
         .ref(self.api.get_master())\
         .query(predicates.at('document.id', 'UlfoxUnM0wkXYXbZ'))
     self.assertEqual(f.data['q'],
                      ["[[:d = at(document.id, \"UlfoxUnM0wkXYXbZ\")]]"])
Esempio n. 8
0
async def test_references(api_url):
    preview_token = 'MC5VcXBHWHdFQUFONDZrbWp4.77-9cDx6C3lgJu-_vXZafO-_vXPvv73vv73vv70777-9Ju-_ve-_vSLvv73vv73vv73vv70O77-977-9Me-_vQ'
    async with prismic.get(api_url, preview_token) as api:
        release_ref = api.get_ref('myrelease')
        response = await api.query(predicates.at("document.type", "all"),
                                   ref=release_ref)

    assert response.results_size >= 1
Esempio n. 9
0
 def test_simplequery(self):
     # startgist:ab49f6c00b8688fe876b:prismic-simplequery.py
     api = prismic.get("https://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master())\
         .query(predicates.at("document.type", "product"))\
         .submit()
     # endgist
     self.assertEqual(response.results_size, 16)
Esempio n. 10
0
 def get_document(self, document_id, form_name="everything"):
     form = self.form(form_name)
     form.query(predicates.at("document.id", document_id))
     document = form.submit().documents
     if document:
         return document[0]
     else:
         raise Http404
Esempio n. 11
0
 def test_simplequery(self):
     # startgist:ab49f6c00b8688fe876b:prismic-simplequery.py
     api = prismic.get("https://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master())\
         .query(predicates.at("document.type", "product"))\
         .submit()
     # endgist
     self.assertEqual(response.results_size, 16)
Esempio n. 12
0
 def test_predicates(self):
     # startgist:771a09b9d88e0fb53705:prismic-predicates.py
     api = prismic.get("http://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master()) \
         .query(predicates.at("document.type", "product"),
                predicates.date_after("my.blog-post.date", 1401580800000))\
         .submit()
     # endgist
     self.assertEqual(response.results_size, 0)
Esempio n. 13
0
 def test_orderings(self):
     api = prismic.get('https://micro.prismic.io/api')
     response = api.query(predicates.at("document.type", "all"),
                          page_size=2,
                          orderings='[my.all.number desc]')
     # The documents are now ordered using the 'number' field, highest first
     docs = response.documents
     self.assertGreaterEqual(docs[0].get_number('all.number').value,
                             docs[1].get_number('all.number').value)
Esempio n. 14
0
 def test_predicates(self):
     # startgist:771a09b9d88e0fb53705:prismic-predicates.py
     api = prismic.get("http://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master()) \
         .query(predicates.at("document.type", "product"),
                predicates.date_after("my.blog-post.date", 1401580800000))\
         .submit()
     # endgist
     self.assertEqual(response.results_size, 0)
Esempio n. 15
0
async def test_fetch_links(integration_api):
    resp = await integration_api\
        .form('everything')\
        .ref(integration_api.get_master())\
        .fetch_links('all.text')\
        .query(predicates.at('document.id', 'WHx-gSYAAMkyXYX_')) \
        .submit()
    article = resp.documents[0]
    links = article.get_all('all.link_document')
    assert links[0].get_text('all.text') == 'all1'
Esempio n. 16
0
 def test_fetch_links(self):
     article = self.api\
         .form('everything')\
         .ref(self.api.get_master())\
         .fetch_links('all.text')\
         .query(predicates.at('document.id', 'WHx-gSYAAMkyXYX_')) \
         .submit()\
         .documents[0]
     links = article.get_all('all.link_document')
     self.assertEqual(links[0].get_text('all.text'), 'all1')
Esempio n. 17
0
 def test_fetch_links(self):
     article = self.api\
         .form('everything')\
         .ref(self.api.get_master())\
         .fetch_links('all.text')\
         .query(predicates.at('document.id', 'WHx-gSYAAMkyXYX_')) \
         .submit()\
         .documents[0]
     links = article.get_all('all.link_document')
     self.assertEqual(links[0].get_text('all.text'), 'all1')
Esempio n. 18
0
 def test_fetch_links_list(self):
     article = self.api\
         .form('everything')\
         .ref(self.api.get_master())\
         .fetch_links(['blog-post.author', 'blog-post.title'])\
         .query(predicates.at('document.id', 'UlfoxUnM0wkXYXbt')) \
         .submit()\
         .documents[0]
     links = article.get_all('blog-post.relatedpost')
     self.assertEqual(links[0].get_text('blog-post.author'), 'John M. Martelle, Fine Pastry Magazine')
Esempio n. 19
0
async def test_orderings(api_url):
    async with prismic.get(api_url) as api:
        response = await api.query(predicates.at("document.type", "all"),
                                   page_size=2,
                                   orderings='[my.all.number desc]')

    # The documents are now ordered using the 'number' field, highest first
    docs = response.documents
    assert docs[0].get_number('all.number').value >= docs[1].get_number(
        'all.number').value
Esempio n. 20
0
def get_posts(filters, full=False):
    form = get_prismic_form()
    preds = []
    preds.append(predicates.at('document.type', 'post'))
    page = filters.get("page", "1")
    if page.isdigit():
        page = int(page)
    else:
        page = 1
    page_size = filters.get("limit", "10")
    if page_size.isdigit():
        page_size = int(page_size)
    else:
        page_size = 1
    if "category" in filters:
        preds.append(predicates.at('my.post.category', filters["category"]))
    q = filters.get("q")
    if q:
        preds.append(predicates.fulltext('document', unidecode.unidecode(q)))
    similar = filters.get("similar")
    if similar:
        preds.append(predicates.similar(similar, 5))
    form.query(*preds).page(page).page_size(page_size).orderings('[my.post.posted_at desc]')
    if not full:
        form.fetch(["post.title", "post.summary", "post.posted_at"])
    try:
        response = form.submit()
        if full:
            results = map(format_post, response.documents, [True]*len(response.documents))
        else:
            results = map(format_post, response.documents)
        return {
            "results": results,
            "total_pages": response.total_pages,
            "page": page
        }
    except:
        return {
            "results": [],
            "total_pages": 0,
            "page": page
        }
Esempio n. 21
0
 def test_fetch_links_list(self):
     article = self.api\
         .form('everything')\
         .ref(self.api.get_master())\
         .fetch_links(['all.text', 'all.number'])\
         .query(predicates.at('document.id', 'WH2PaioAALYBEgug')) \
         .submit()\
         .documents[0]
     links = article.get_all('all.link_document')
     self.assertEqual(links[0].get_text('all.text'), 'all')
     self.assertEqual(links[0].get_text('all.number'), 20)
Esempio n. 22
0
 def test_fetch_links_list(self):
     article = self.api\
         .form('everything')\
         .ref(self.api.get_master())\
         .fetch_links(['all.text', 'all.number'])\
         .query(predicates.at('document.id', 'WH2PaioAALYBEgug')) \
         .submit()\
         .documents[0]
     links = article.get_all('all.link_document')
     self.assertEqual(links[0].get_text('all.text'), 'all')
     self.assertEqual(links[0].get_text('all.number'), 20)
Esempio n. 23
0
 def test_fetch_links_list(self):
     article = self.api\
         .form('everything')\
         .ref(self.api.get_master())\
         .fetch_links(['blog-post.author', 'blog-post.title'])\
         .query(predicates.at('document.id', 'UlfoxUnM0wkXYXbt')) \
         .submit()\
         .documents[0]
     links = article.get_all('blog-post.relatedpost')
     self.assertEqual(links[0].get_text('blog-post.author'),
                      'John M. Martelle, Fine Pastry Magazine')
Esempio n. 24
0
async def test_fetch_links_list(integration_api):
    resp = await integration_api\
        .form('everything')\
        .ref(integration_api.get_master())\
        .fetch_links(['all.text', 'all.number'])\
        .query(predicates.at('document.id', 'WH2PaioAALYBEgug')) \
        .submit()
    article = resp.documents[0]
    links = article.get_all('all.link_document')
    assert links[0].get_text('all.text') == 'all'
    assert links[0].get_text('all.number') == 20
Esempio n. 25
0
 def test_as_html(self):
     api = prismic.get("http://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master())\
         .query(predicates.at("document.id", "UlfoxUnM0wkXYXbX")).submit()
     # startgist:35dfff6b09283752ac88:prismic-asHtml.py
     def link_resolver(document_link):
         return "/document/%s/%s" % (document_link.id, document_link.slug)
     doc = response.documents[0]
     html = doc.as_html(link_resolver)
     # endgist
     self.assertIsNotNone(html)
Esempio n. 26
0
 def test_get_text(self):
     api = prismic.get('https://lesbonneschoses.prismic.io/api')
     response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbl"))\
         .ref(api.get_master()).submit()
     doc = response.documents[0]
     # // startgist:f092312c243181a45ebf:prismic-getText.py
     author = doc.get_text("blog-post.author")
     if author is None:
         author = "Anonymous"
     # endgist
     self.assertEqual(author, "John M. Martelle, Fine Pastry Magazine")
Esempio n. 27
0
 def test_get_text(self):
     api = prismic.get('https://lesbonneschoses.prismic.io/api')
     response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbl"))\
         .ref(api.get_master()).submit()
     doc = response.documents[0]
     # // startgist:f092312c243181a45ebf:prismic-getText.py
     author = doc.get_text("blog-post.author")
     if author is None:
         author = "Anonymous"
     # endgist
     self.assertEqual(author, "John M. Martelle, Fine Pastry Magazine")
Esempio n. 28
0
 def test_orderings(self):
     # startgist:f2c310e66a5c13e225ae:prismic-orderings.py
     api = prismic.get('https://lesbonneschoses.prismic.io/api')
     response = api.form('everything')\
         .ref(api.get_master())\
         .query(predicates.at("document.type", "product"))\
         .pageSize(100)\
         .orderings('[my.product.price desc]')\
         .submit()
     # The products are now ordered by price, highest first
     results = response.results
     # endgist
     self.assertEqual(response.results_per_page, 100)
Esempio n. 29
0
 def test_all_predicates(self):
     # startgist:d0f7e2b2ae7bd3fefc94:prismic-allPredicates.py
     # "at" predicate: equality of a fragment to a value.
     at = predicates.at("document.type", "article")
     # "any" predicate: equality of a fragment to a value.
     any = predicates.any("document.type", ["article", "blog-post"])
     # "fulltext" predicate: fulltext search in a fragment.
     fulltext = predicates.fulltext("my.article.body", "sausage")
     # "similar" predicate, with a document id as reference
     similar = predicates.similar("UXasdFwe42D", 10)
     # endgist
     self.assertEqual(at, ["at", "document.type", "article"])
     self.assertEqual(any, ["any", "document.type", ["article", "blog-post"]])
Esempio n. 30
0
 def test_orderings(self):
     # startgist:f2c310e66a5c13e225ae:prismic-orderings.py
     api = prismic.get('https://lesbonneschoses.prismic.io/api')
     response = api.form('everything')\
         .ref(api.get_master())\
         .query(predicates.at("document.type", "product"))\
         .pageSize(100)\
         .orderings('[my.product.price desc]')\
         .submit()
     # The products are now ordered by price, highest first
     results = response.results
     # endgist
     self.assertEqual(response.results_per_page, 100)
Esempio n. 31
0
    def test_as_html(self):
        api = prismic.get("http://lesbonneschoses.prismic.io/api")
        response = api.form("everything").ref(api.get_master())\
            .query(predicates.at("document.id", "UlfoxUnM0wkXYXbX")).submit()

        # startgist:35dfff6b09283752ac88:prismic-asHtml.py
        def link_resolver(document_link):
            return "/document/%s/%s" % (document_link.id, document_link.slug)

        doc = response.documents[0]
        html = doc.as_html(link_resolver)
        # endgist
        self.assertIsNotNone(html)
Esempio n. 32
0
 def test_all_predicates(self):
     # startgist:d0f7e2b2ae7bd3fefc94:prismic-allPredicates.py
     # "at" predicate: equality of a fragment to a value.
     at = predicates.at("document.type", "article")
     # "any" predicate: equality of a fragment to a value.
     any = predicates.any("document.type", ["article", "blog-post"])
     # "fulltext" predicate: fulltext search in a fragment.
     fulltext = predicates.fulltext("my.article.body", "sausage")
     # "similar" predicate, with a document id as reference
     similar = predicates.similar("UXasdFwe42D", 10)
     # endgist
     self.assertEqual(at, ["at", "document.type", "article"])
     self.assertEqual(any,
                      ["any", "document.type", ["article", "blog-post"]])
Esempio n. 33
0
 def test_images(self):
     api = prismic.get('https://lesbonneschoses.prismic.io/api')
     response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbO")) \
         .ref(api.get_master()).submit()
     doc = response.documents[0]
     # startgist:4871fb63a54185ee562f:prismic-images.py
     # Accessing image fields
     image = doc.get_image('product.image')
     # By default the 'main' view is returned
     url = image.url
     # endgist
     self.assertEqual(
         url,
         'https://prismic-io.s3.amazonaws.com/lesbonneschoses/f606ad513fcc2a73b909817119b84d6fd0d61a6d.png')
Esempio n. 34
0
 def test_references(self):
     # startgist:81d114ef589118245811:prismic-references.py
     preview_token = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70'
     api = prismic.get('https://lesbonneschoses.prismic.io/api', preview_token)
     st_patrick_ref = api.get_ref('St-Patrick specials')
     # Now we'll use this reference for all our calls
     response = api.form("everything")\
         .ref(st_patrick_ref)\
         .query(predicates.at("document.type", "product"))\
         .submit()
     # The documents object contains a Response object with all documents of type "product"
     # including the new "Saint-Patrick's Cupcake"
     # endgist
     self.assertEqual(response.results_size, 17)
Esempio n. 35
0
 def test_references(self):
     # startgist:81d114ef589118245811:prismic-references.py
     preview_token = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70'
     api = prismic.get('https://lesbonneschoses.prismic.io/api',
                       preview_token)
     st_patrick_ref = api.get_ref('St-Patrick specials')
     # Now we'll use this reference for all our calls
     response = api.form("everything")\
         .ref(st_patrick_ref)\
         .query(predicates.at("document.type", "product"))\
         .submit()
     # The documents object contains a Response object with all documents of type "product"
     # including the new "Saint-Patrick's Cupcake"
     # endgist
     self.assertEqual(response.results_size, 17)
Esempio n. 36
0
    def test_get_number(self):
        api = prismic.get('https://lesbonneschoses.prismic.io/api')
        response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbO"))\
            .ref(api.get_master()).submit()
        doc = response.documents[0]
        # startgist:2d89caba900bb897e72b:prismic-getNumber.py
        # Number predicates
        gt = predicates.gt("my.product.price", 10)
        lt = predicates.lt("my.product.price", 20)
        in_range = predicates.in_range("my.product.price", 10, 20)

        # Accessing number fields
        price = doc.get_number("product.price").value
        # endgist
        self.assertEqual(price, 2.5)
Esempio n. 37
0
 def test_images(self):
     api = prismic.get('https://lesbonneschoses.prismic.io/api')
     response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbO")) \
         .ref(api.get_master()).submit()
     doc = response.documents[0]
     # startgist:4871fb63a54185ee562f:prismic-images.py
     # Accessing image fields
     image = doc.get_image('product.image')
     # By default the 'main' view is returned
     url = image.url
     # endgist
     self.assertEqual(
         url,
         'https://prismic-io.s3.amazonaws.com/lesbonneschoses/f606ad513fcc2a73b909817119b84d6fd0d61a6d.png'
     )
Esempio n. 38
0
    def test_get_number(self):
        api = prismic.get('https://lesbonneschoses.prismic.io/api')
        response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbO"))\
            .ref(api.get_master()).submit()
        doc = response.documents[0]
        # startgist:2d89caba900bb897e72b:prismic-getNumber.py
        # Number predicates
        gt = predicates.gt("my.product.price", 10)
        lt = predicates.lt("my.product.price", 20)
        in_range = predicates.in_range("my.product.price", 10, 20)

        # Accessing number fields
        price = doc.get_number("product.price").value
        # endgist
        self.assertEqual(price, 2.5)
Esempio n. 39
0
    def test_date_timestamp(self):
        api = prismic.get('https://lesbonneschoses.prismic.io/api')
        response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbl"))\
            .ref(api.get_master()).submit()
        doc = response.documents[0]
        # startgist:d0df1672e30871ab6517:prismic-dateTimestamp.py
        # Date and Timestamp predicates
        date_before = predicates.date_before("my.product.releaseDate",
                                             datetime.datetime(2014, 6, 1))
        date_after = predicates.date_after("my.product.releaseDate",
                                           datetime.datetime(2014, 1, 1))
        date_Between = predicates.date_between("my.product.releaseDate",
                                               datetime.datetime(2014, 1, 1),
                                               datetime.datetime(2014, 6, 1))
        day_of_month = predicates.day_of_month("my.product.releaseDate", 14)
        day_of_month_after = predicates.day_of_month_after(
            "my.product.releaseDate", 14)
        day_of_month_before = predicates.day_of_month_before(
            "my.product.releaseDate", 14)
        day_of_week = predicates.day_of_week("my.product.releaseDate",
                                             "Tuesday")
        day_of_week_after = predicates.day_of_week_after(
            "my.product.releaseDate", "Wednesday")
        day_of_week_before = predicates.day_of_month_before(
            "my.product.releaseDate", "Wednesday")
        month = predicates.month("my.product.releaseDate", "June")
        month_before = predicates.month_before("my.product.releaseDate",
                                               "June")
        month_after = predicates.month_after("my.product.releaseDate", "June")
        year = predicates.year("my.product.releaseDate", 2014)
        hour = predicates.hour("my.product.releaseDate", 12)
        hour_before = predicates.hour_before("my.product.releaseDate", 12)
        hour_after = predicates.hour_after("my.product.releaseDate", 12)

        # Accessing Date and Timestamp fields
        date = doc.get_date("blog-post.date")
        date_year = date and date.as_datetime.year
        update_time = doc.get_timestamp("blog-post.update")
        update_hour = update_time and update_time.as_datetime.hours
        # endgist
        self.assertEqual(date_year, 2013)
Esempio n. 40
0
    def test_html_serializer(self):
        # startgist:7314e2bf9d81e750280f:prismic-htmlSerializer.py
        api = prismic.get("http://lesbonneschoses.prismic.io/api")
        response = api.form("everything").ref(api.get_master()) \
            .query(predicates.at("document.id", "UlfoxUnM0wkXYXbX")).submit()

        def link_resolver(document_link):
            return "/document/%s/%s" % (document_link.id, document_link.slug)

        def html_serializer(element, content):
            if isinstance(element, prismic.fragments.Block.Image):
                # Don't wrap images in a <p> tag
                return element.get_view().as_html(link_resolver)
            if isinstance(element, prismic.fragments.Span.Hyperlink):
                # Add a class to links
                return """<a class="some-link" href="%s">""" % element.get_url(link_resolver) + content + "</a>"
            return None

        doc = response.documents[0]
        html = doc.get_structured_text("blog-post.body").as_html(link_resolver, html_serializer)
        # endgist
        self.assertIsNotNone(html)
Esempio n. 41
0
    def test_html_serializer(self):
        # startgist:7314e2bf9d81e750280f:prismic-htmlSerializer.py
        api = prismic.get("http://lesbonneschoses.prismic.io/api")
        response = api.form("everything").ref(api.get_master()) \
            .query(predicates.at("document.id", "UlfoxUnM0wkXYXbX")).submit()

        def link_resolver(document_link):
            return "/document/%s/%s" % (document_link.id, document_link.slug)

        def html_serializer(element, content):
            if isinstance(element, prismic.fragments.Block.Image):
                # Don't wrap images in a <p> tag
                return element.get_view().as_html(link_resolver)
            if isinstance(element, prismic.fragments.Span.Hyperlink):
                # Add a class to links
                return """<a class="some-link" href="%s">""" % element.get_url(
                    link_resolver) + content + "</a>"
            return None

        doc = response.documents[0]
        html = doc.get_structured_text("blog-post.body").as_html(
            link_resolver, html_serializer)
        # endgist
        self.assertIsNotNone(html)
Esempio n. 42
0
 def test_references(self):
     preview_token = 'MC5VcXBHWHdFQUFONDZrbWp4.77-9cDx6C3lgJu-_vXZafO-_vXPvv73vv73vv70777-9Ju-_ve-_vSLvv73vv73vv73vv70O77-977-9Me-_vQ'
     api = prismic.get('https://micro.prismic.io/api', preview_token)
     release_ref = api.get_ref('myrelease')
     response = api.query(predicates.at("document.type", "all"), ref=release_ref)
     self.assertGreaterEqual(response.results_size, 1)
Esempio n. 43
0
 def test_orderings(self):
     api = prismic.get('https://micro.prismic.io/api')
     response = api.query(predicates.at("document.type", "all"), page_size=2, orderings='[my.all.number desc]')
     # The documents are now ordered using the 'number' field, highest first
     docs = response.documents
     self.assertGreaterEqual(docs[0].get_number('all.number').value, docs[1].get_number('all.number').value)
Esempio n. 44
0
 def test_query(self):
     doc = self.api\
         .query(predicates.at('document.id', 'WHx-gSYAAMkyXYX_'))\
         .documents[0]
     self.assertEqual(doc.id, 'WHx-gSYAAMkyXYX_')
Esempio n. 45
0
 def test_query(self):
     doc = self.api\
         .query(predicates.at('document.id', 'WHx-gSYAAMkyXYX_'))\
         .documents[0]
     self.assertEqual(doc.id, 'WHx-gSYAAMkyXYX_')
Esempio n. 46
0
async def test_query_first(integration_api):
    doc = await integration_api.query_first(predicates.at('document.id', 'WHx-gSYAAMkyXYX_'))
    assert doc.id == 'WHx-gSYAAMkyXYX_'
Esempio n. 47
0
async def test_query_first_no_result(integration_api):
    doc = await integration_api.query_first(predicates.at('document.id', 'NotAValidId'))
    assert doc is None
Esempio n. 48
0
 def test_query_first_no_result(self):
     doc = self.api.query_first(predicates.at('document.id', 'NotAValidId'))
     self.assertIsNone(doc)
Esempio n. 49
0
 def test_at(self):
     f = self.api\
         .form("everything")\
         .ref(self.api.get_master())\
         .query(predicates.at('document.id', 'UlfoxUnM0wkXYXbZ'))
     self.assertEqual(f.data['q'], ["[[:d = at(document.id, \"UlfoxUnM0wkXYXbZ\")]]"])
Esempio n. 50
0
 def test_query_first(self):
     doc = self.api.query_first(
         predicates.at('document.id', 'WHx-gSYAAMkyXYX_'))
     self.assertEqual(doc.id, 'WHx-gSYAAMkyXYX_')
Esempio n. 51
0
 def test_form(self):
     api = prismic.get("https://micro.prismic.io/api")
     response = api.form("everything").ref(api.get_master())\
         .query(predicates.at("document.type", "all"))\
         .submit()
     self.assertGreaterEqual(response.results_size, 2)
Esempio n. 52
0
 def test_query_first(self):
     doc = self.api.query_first(predicates.at('document.id', 'WHx-gSYAAMkyXYX_'))
     self.assertEqual(doc.id, 'WHx-gSYAAMkyXYX_')
Esempio n. 53
0
def test_at(api):
    f = api\
        .form("everything")\
        .ref(api.get_master())\
        .query(predicates.at('document.id', 'UlfoxUnM0wkXYXbZ'))
    assert f.data['q'] == ["[[:d = at(document.id, \"UlfoxUnM0wkXYXbZ\")]]"]
Esempio n. 54
0
 def test_query_first_no_result(self):
     doc = self.api.query_first(predicates.at('document.id', 'NotAValidId'))
     self.assertIsNone(doc)
Esempio n. 55
0
 def test_form(self):
     api = prismic.get("https://micro.prismic.io/api")
     response = api.form("everything").ref(api.get_master())\
         .query(predicates.at("document.type", "all"))\
         .submit()
     self.assertGreaterEqual(response.results_size, 2)