Example #1
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)
Example #2
0
 def test_multiple_predicates(self):
     f = self.api \
         .form("everything") \
         .ref(self.api.get_master()) \
         .query(
             predicates.month_after('my.form-post.publication-date', 4),
             predicates.month_before('my.form-post.publication-date', 'December')
         )
     self.assertEqual(f.data['q'], ['[[:d = date.month-after(my.form-post.publication-date, 4)][:d = date.month-before(my.form-post.publication-date, "December")]]'])
Example #3
0
 def test_multiple_predicates(self):
     f = self.api \
         .form("everything") \
         .ref(self.api.get_master()) \
         .query(
             predicates.month_after('my.blog-post.publication-date', 4),
             predicates.month_before('my.blog-post.publication-date', 'December')
         )
     self.assertEqual(f.data['q'], ['[[:d = date.month-after(my.blog-post.publication-date, 4)][:d = date.month-before(my.blog-post.publication-date, "December")]]'])
Example #4
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)