Exemplo n.º 1
0
 def authors(self, num_columns=0):
     """
     @param num_columns: int If non-zero, break up list into columns
     """
     s = Search(
         using=docstore._get_connection(settings.DOCSTORE_HOSTS),
         index=settings.DOCSTORE_INDEX,
         doc_type='authors'
     ).fields([
         'url_title', 'title', 'title_sort', 'lastmod'
     ])[0:docstore.MAX_SIZE]
     response = s.execute()
     authors = []
     for hit in response:
         url_title = hit.url_title[0]
         title = hit.title[0]
         title_sort = hit.title_sort[0]
         lastmod = hit.lastmod[0]
         if title and title_sort:
             author = Author()
             author.url_title = url_title
             author.title = title
             author.title_sort = title_sort
             author.lastmod = datetime.strptime(lastmod, mediawiki.TS_FORMAT)
             authors.append(author)
     authors = sorted(authors, key=lambda a: a.title_sort)
     if num_columns:
         return _columnizer(authors, num_columns)
     return authors
Exemplo n.º 2
0
 def categories(self):
     s = Search(
         using=docstore._get_connection(settings.DOCSTORE_HOSTS),
         index=settings.DOCSTORE_INDEX,
         doc_type='articles'
     ).fields([
         'title', 'title_sort', 'categories',
     ])[0:docstore.MAX_SIZE]
     if not settings.MEDIAWIKI_SHOW_UNPUBLISHED:
         s = s.query('match', published=True)
     response = s.execute()
     pages = []
     for hit in response:
         page = Page()
         page.url_title = hit.title[0]
         page.title = hit.title[0]
         page.title_sort = hit.title_sort[0]
         page.categories = hit.get('categories', [])
         pages.append(page)
     articles = sorted(pages, key=lambda page: page.title_sort)
     categories = {}
     for page in articles:
         for category in page.categories:
             # exclude internal editorial categories
             if category not in settings.MEDIAWIKI_HIDDEN_CATEGORIES:
                 if category not in categories.keys():
                     categories[category] = []
                 # pages already sorted so category lists will be sorted
                 if page not in categories[category]:
                     categories[category].append(page)
     return categories
Exemplo n.º 3
0
 def articles(self):
     s = Search(
         using=docstore._get_connection(settings.DOCSTORE_HOSTS),
         index=settings.DOCSTORE_INDEX,
         doc_type='articles'
     ).fields([
         'title', 'title_sort', 'lastmod',
     ])[0:docstore.MAX_SIZE]
     response = s.execute()
     pages = []
     for hit in response:
         page = Page()
         page.url_title = hit.title[0]
         page.title = hit.title[0]
         page.title_sort = hit.title_sort[0]
         page.first_letter = page.title_sort[0]
         page.lastmod = datetime.strptime(hit.lastmod[0], mediawiki.TS_FORMAT)
         pages.append(page)
     return sorted(pages, key=lambda page: page.title_sort)