Exemplo n.º 1
0
    def archive(cls):
        """Delete all Todo items that are done."""

        req = datastore.BeginTransactionRequest()
        resp = datastore.begin_transaction(req)
        tx = resp.transaction
        req = datastore.RunQueryRequest()
        req.read_options.transaction = tx
        q = req.query
        set_kind(q, kind='Todo')
        add_projection(q, '__key__')
        set_composite_filter(
            q.filter, datastore.CompositeFilter.AND,
            set_property_filter(datastore.Filter(), 'done',
                                datastore.PropertyFilter.EQUAL, True),
            set_property_filter(datastore.Filter(), '__key__',
                                datastore.PropertyFilter.HAS_ANCESTOR,
                                default_todo_list.key))
        resp = datastore.run_query(req)
        keys = [r.entity.key for r in resp.batch.entity_result]
        req = datastore.CommitRequest()
        req.transaction = tx
        req.mutation.delete.extend(keys)
        resp = datastore.commit(req)
        return ''
Exemplo n.º 2
0
 def testFilter(self):
     f = datastore.Filter()
     set_composite_filter(
         f, datastore.CompositeFilter.AND,
         set_property_filter(datastore.Filter(), 'foo',
                             datastore.PropertyFilter.EQUAL, u'bar'),
         set_property_filter(datastore.Filter(), 'hop',
                             datastore.PropertyFilter.GREATER_THAN, 2.0))
     cf = f.composite_filter
     pf = cf.filter[0].property_filter
     self.assertEquals('foo', pf.property.name)
     self.assertEquals('bar', pf.value.string_value)
     self.assertEquals(datastore.PropertyFilter.EQUAL, pf.operator)
     pf = cf.filter[1].property_filter
     self.assertEquals('hop', pf.property.name)
     self.assertEquals(2.0, pf.value.double_value)
     self.assertEquals(datastore.PropertyFilter.GREATER_THAN, pf.operator)
     self.assertEquals(datastore.CompositeFilter.AND, cf.operator)