|
a/Allura/allura/model/discuss.py |
|
b/Allura/allura/model/discuss.py |
1 |
import sys
|
|
|
2 |
import logging
|
1 |
import logging
|
3 |
from datetime import datetime
|
2 |
from datetime import datetime
|
4 |
|
3 |
|
5 |
import pymongo
|
4 |
import pymongo
|
6 |
from pymongo.errors import DuplicateKeyError
|
5 |
from pymongo.errors import DuplicateKeyError
|
|
... |
|
... |
288 |
result.append(pi)
|
287 |
result.append(pi)
|
289 |
return result
|
288 |
return result
|
290 |
|
289 |
|
291 |
def query_posts(self, page=None, limit=None,
|
290 |
def query_posts(self, page=None, limit=None,
|
292 |
timestamp=None, style='threaded'):
|
291 |
timestamp=None, style='threaded'):
|
293 |
if limit is None:
|
|
|
294 |
limit = 50
|
|
|
295 |
limit = int(limit)
|
|
|
296 |
if timestamp:
|
292 |
if timestamp:
|
297 |
terms = dict(discussion_id=self.discussion_id, thread_id=self._id,
|
293 |
terms = dict(discussion_id=self.discussion_id, thread_id=self._id,
|
298 |
status={'$in': ['ok', 'pending']}, timestamp=timestamp)
|
294 |
status={'$in': ['ok', 'pending']}, timestamp=timestamp)
|
299 |
else:
|
295 |
else:
|
300 |
terms = dict(discussion_id=self.discussion_id, thread_id=self._id,
|
296 |
terms = dict(discussion_id=self.discussion_id, thread_id=self._id,
|
|
... |
|
... |
302 |
q = self.post_class().query.find(terms)
|
298 |
q = self.post_class().query.find(terms)
|
303 |
if style == 'threaded':
|
299 |
if style == 'threaded':
|
304 |
q = q.sort('full_slug')
|
300 |
q = q.sort('full_slug')
|
305 |
else:
|
301 |
else:
|
306 |
q = q.sort('timestamp')
|
302 |
q = q.sort('timestamp')
|
307 |
if page is not None:
|
|
|
308 |
q = q.skip(page * limit)
|
|
|
309 |
if limit is not None:
|
303 |
if limit is not None:
|
|
|
304 |
limit = int(limit)
|
|
|
305 |
if page is not None:
|
|
|
306 |
q = q.skip(page * limit)
|
310 |
q = q.limit(limit)
|
307 |
q = q.limit(limit)
|
311 |
return q
|
308 |
return q
|
312 |
|
309 |
|
313 |
def find_posts(self, page=None, limit=None, timestamp=None,
|
310 |
def find_posts(self, page=None, limit=None, timestamp=None,
|
314 |
style='threaded'):
|
311 |
style='threaded'):
|
|
... |
|
... |
516 |
limit, p, s = g.handle_paging(None, 0) # get paging limit
|
513 |
limit, p, s = g.handle_paging(None, 0) # get paging limit
|
517 |
if self.query.find(dict(thread_id=self.thread._id)).count() <= limit:
|
514 |
if self.query.find(dict(thread_id=self.thread._id)).count() <= limit:
|
518 |
# all posts in a single page
|
515 |
# all posts in a single page
|
519 |
page = 0
|
516 |
page = 0
|
520 |
else:
|
517 |
else:
|
521 |
posts = self.thread.find_posts(None, sys.maxint)
|
518 |
posts = self.thread.find_posts()
|
522 |
posts = self.thread.create_post_threads(posts)
|
519 |
posts = self.thread.create_post_threads(posts)
|
523 |
|
520 |
|
524 |
def find_i(posts):
|
521 |
def find_i(posts):
|
525 |
'''Find the index number of this post in the display order'''
|
522 |
'''Find the index number of this post in the display order'''
|
526 |
q = []
|
523 |
q = []
|