paul@5 | 1 | # -*- coding: iso-8859-1 -*- |
paul@5 | 2 | """ |
paul@5 | 3 | MoinMoin - SubpageComments common functionality |
paul@5 | 4 | |
paul@6 | 5 | @copyright: 2013, 2018 by Paul Boddie <paul@boddie.org.uk> |
paul@5 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@5 | 7 | """ |
paul@5 | 8 | |
paul@5 | 9 | from MoinSupport import getPagesForSearch |
paul@6 | 10 | import re |
paul@5 | 11 | |
paul@5 | 12 | def get_comment_numbers(pagename, request): |
paul@5 | 13 | |
paul@5 | 14 | """ |
paul@5 | 15 | Return a list of comment numbers associated with the given 'pagename', using |
paul@5 | 16 | the 'request' provided. |
paul@5 | 17 | """ |
paul@5 | 18 | |
paul@5 | 19 | pagenames = [] |
paul@5 | 20 | |
paul@6 | 21 | pattern = "^%s" % re.escape("%s/" % pagename) |
paul@6 | 22 | regex = re.compile(pattern) |
paul@6 | 23 | |
paul@6 | 24 | for page in getPagesForSearch("title:%s" % pagename, request): |
paul@6 | 25 | |
paul@6 | 26 | # Avoid "title:regex:^%s/" problems by filtering a broader result set. |
paul@6 | 27 | |
paul@6 | 28 | if not regex.search(page.page_name): |
paul@6 | 29 | continue |
paul@6 | 30 | |
paul@5 | 31 | basename, number = page.page_name.rsplit("/", 1) |
paul@5 | 32 | if basename == pagename and number.isdigit(): |
paul@5 | 33 | pagenames.append(int(number)) |
paul@5 | 34 | |
paul@5 | 35 | pagenames.sort() |
paul@5 | 36 | return pagenames |
paul@5 | 37 | |
paul@5 | 38 | # vim: tabstop=4 expandtab shiftwidth=4 |