def articles(request, format=None): """DOCUMENTATION GOES HERE. """ data = [ { 'title': article.title, 'url': reverse('wikiprox-api-page', args=([article.url_title]), request=request), } for article in Page.pages() ] return Response(data)
def articles(report=False, dryrun=False, force=False): index = set_hosts_index() logprint('debug', '------------------------------------------------------------------------') # authors need to be refreshed logprint('debug', 'getting mw_authors,articles...') mw_author_titles = Proxy().authors(cached_ok=False) mw_articles = Proxy().articles_lastmod() logprint('debug', 'getting es_articles...') es_articles = Page.pages() if force: logprint('debug', 'forcibly update all articles') articles_update = [page['title'] for page in es_articles] articles_delete = [] else: logprint('debug', 'determining new,delete...') articles_update,articles_delete = Elasticsearch.articles_to_update( mw_author_titles, mw_articles, es_articles) logprint('debug', 'mediawiki articles: %s' % len(mw_articles)) logprint('debug', 'elasticsearch articles: %s' % len(es_articles)) logprint('debug', 'articles to update: %s' % len(articles_update)) logprint('debug', 'articles to delete: %s' % len(articles_delete)) if report: return logprint('debug', 'adding articles...') posted = 0 could_not_post = [] for n,title in enumerate(articles_update): logprint('debug', '--------------------') logprint('debug', '%s/%s %s' % (n+1, len(articles_update), title)) logprint('debug', 'getting from mediawiki') mwpage = Proxy().page(title) try: existing_page = Page.get(title) logprint('debug', 'exists in elasticsearch') except: existing_page = None if (mwpage.published or settings.MEDIAWIKI_SHOW_UNPUBLISHED): page_sources = [source['encyclopedia_id'] for source in mwpage.sources] for mwsource in mwpage.sources: logprint('debug', '- source %s' % mwsource['encyclopedia_id']) source = Source.from_mw(mwsource, title) if not dryrun: source.save() logprint('debug', 'creating page') page = Page.from_mw(mwpage, page=existing_page) if not dryrun: logprint('debug', 'saving') page.save() try: p = Page.get(title) except NotFoundError: logprint('error', 'ERROR: Page(%s) NOT SAVED!' % title) else: logprint('debug', 'not publishable: %s' % mwpage) could_not_post.append(mwpage) if could_not_post: logprint('debug', '========================================================================') logprint('debug', 'Could not post these: %s' % could_not_post) logprint('debug', 'DONE')
def contents(request, template_name="wikiprox/contents.html"): return render_to_response(template_name, {"articles": Page.pages()}, context_instance=RequestContext(request))