本文整理汇总了Python中eulexistdb.query.QuerySet.count方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.count方法的具体用法?Python QuerySet.count怎么用?Python QuerySet.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eulexistdb.query.QuerySet
的用法示例。
在下文中一共展示了QuerySet.count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: text_view
# 需要导入模块: from eulexistdb.query import QuerySet [as 别名]
# 或者: from eulexistdb.query.QuerySet import count [as 别名]
def text_view(request, title):
qs = QuerySet(using=ExistDB(), xpath='/tei:TEI', collection='docker/texts/', model=RocheTEI)
# filter by title
qs = qs.filter(title=title).order_by('chapter')
max_juan = qs.count()
result = ""
for q in qs:
result = result + q.body.xsl_transform(xsl=XSL_TRANSFORM_1).serialize()
text_title = qs[0].title
data = {'tei_documents': qs, 'tei_transform': result,
'text_title': text_title, 'max_juan': max_juan, }
return render_to_response('browser/text_view.html', data,
context_instance=RequestContext(request))
示例2: index
# 需要导入模块: from eulexistdb.query import QuerySet [as 别名]
# 或者: from eulexistdb.query.QuerySet import count [as 别名]
def index(request):
# XML and SPARQL numbers
# Count texts and authors
qs = QuerySet(using=ExistDB(), xpath='/tei:TEI', collection='docker/texts/', model=RocheTEI)
qs = qs.filter(chapter='1')
qs = qs.only('title', 'title_en', 'author')
# TODO: order by title
qs = qs.order_by('title_en')
number_texts = qs.count()
number_authors = qs.distinct().count()
wiki_pages = []
for page in sorted(os.listdir("/docker/dublin-store/sinology/mainSpace")):
wiki_pages.append([page.replace(" ", "%20"), page])
data = {'number_texts': number_texts, 'number_authors': number_authors,
'tei_documents': qs, "wiki_pages": wiki_pages, }
return render(request, 'roche/index.html', data)
示例3: ExistQueryTest
# 需要导入模块: from eulexistdb.query import QuerySet [as 别名]
# 或者: from eulexistdb.query.QuerySet import count [as 别名]
class ExistQueryTest(unittest.TestCase):
def setUp(self):
self.db = ExistDB(server_url=EXISTDB_SERVER_URL)
load_fixtures(self.db)
self.qs = QuerySet(using=self.db, xpath='/root', collection=COLLECTION, model=QueryTestModel)
def tearDown(self):
self.db.removeCollection(COLLECTION)
def test_count(self):
load_fixtures(self.db)
self.assertEqual(NUM_FIXTURES, self.qs.count(), "queryset count returns number of fixtures")
def test_getitem(self):
qs = self.qs.order_by('id') # adding sort order to test reliably
self.assertEqual("abc", qs[0].id)
self.assertEqual("def", qs[1].id)
self.assertEqual("one", qs[2].id)
self.assertEqual("xyz", qs[3].id)
def test_getitem_typeerror(self):
self.assertRaises(TypeError, self.qs.__getitem__, "foo")
def test_getitem_indexerror(self):
self.assertRaises(IndexError, self.qs.__getitem__, -1)
self.assertRaises(IndexError, self.qs.__getitem__, 23)
def test_getslice(self):
slice = self.qs.order_by('id')[0:2]
self.assert_(isinstance(slice, QuerySet))
self.assert_(isinstance(slice[0], QueryTestModel))
self.assertEqual(2, slice.count())
self.assertEqual(2, len(slice))
self.assertEqual('abc', slice[0].id)
self.assertEqual('def', slice[1].id)
self.assertRaises(IndexError, slice.__getitem__, 2)
slice = self.qs.order_by('id')[1:3]
self.assertEqual('def', slice[0].id)
self.assertEqual('one', slice[1].id)
slice = self.qs.order_by('id')[3:5]
self.assertEqual(1, slice.count())
self.assertEqual('xyz', slice[0].id)
self.assertRaises(IndexError, slice.__getitem__, 1)
# test slicing with unspecified bounds
slice = self.qs.order_by('id')[:2]
self.assertEqual(2, slice.count())
self.assertEqual('def', slice[1].id)
slice = self.qs.order_by('id')[1:]
self.assertEqual(3, slice.count())
self.assertEqual('one', slice[1].id)
self.assertEqual('xyz', slice[2].id)
def test_filter(self):
fqs = self.qs.filter(contains="two")
self.assertEqual(1, fqs.count(), "count returns 1 when filtered - contains 'two'")
self.assertEqual("two", fqs[0].name, "name matches filter")
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
def test_filter_field(self):
fqs = self.qs.filter(name="one")
self.assertEqual(1, fqs.count(), "count returns 1 when filtered on name = 'one' (got %s)"
% self.qs.count())
self.assertEqual("one", fqs[0].name, "name matches filter")
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
def test_filter_field_xpath(self):
fqs = self.qs.filter(id="abc")
self.assertEqual(1, fqs.count(), "count returns 1 when filtered on @id = 'abc' (got %s)"
% self.qs.count())
self.assertEqual("two", fqs[0].name, "name returned is correct for id filter")
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
def test_filter_field_contains(self):
fqs = self.qs.filter(name__contains="o")
self.assertEqual(3, fqs.count(),
"should get 3 matches for filter on name contains 'o' (got %s)" % fqs.count())
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
def test_filter_field_contains_special(self):
fqs = self.qs.filter(description__contains=' "quote" ')
self.assertEqual(1, fqs.count(),
"should get 1 match for filter on desc contains ' \"quote\" ' (got %s)" % fqs.count())
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
fqs = self.qs.filter(description__contains=' &!')
self.assertEqual(1, fqs.count(),
"should get 1 match for filter on desc contains ' &!' (got %s)" % fqs.count())
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
def test_filter_field_startswith(self):
fqs = self.qs.filter(name__startswith="o")
self.assertEqual(1, fqs.count(),
"should get 1 match for filter on name starts with 'o' (got %s)" % fqs.count())
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
#.........这里部分代码省略.........