コード例 #1
0
ファイル: encyc.py プロジェクト: densho/encyc-front
def authors(report=False, dryrun=False, force=False):
    index = set_hosts_index()

    logprint('debug', '------------------------------------------------------------------------')
    logprint('debug', 'getting mw_authors...')
    mw_author_titles = Proxy().authors(cached_ok=False)
    mw_articles = Proxy().articles_lastmod()
    logprint('debug', 'getting es_authors...')
    es_authors = Author.authors()
    if force:
        logprint('debug', 'forcibly update all authors')
        authors_new = [page['title'] for page in es_authors]
        authors_delete = []
    else:
        logprint('debug', 'determining new,delete...')
        authors_new,authors_delete = Elasticsearch.authors_to_update(
            mw_author_titles, mw_articles, es_authors)
    logprint('debug', 'mediawiki authors: %s' % len(mw_author_titles))
    logprint('debug', 'authors to add: %s' % len(authors_new))
    logprint('debug', 'authors to delete: %s' % len(authors_delete))
    if report:
        return
    
    logprint('debug', 'deleting...')
    for n,title in enumerate(authors_delete):
        logprint('debug', '--------------------')
        logprint('debug', '%s/%s %s' % (n, len(authors_delete), title))
        author = Author.get(title)
        if not dryrun:
            author.delete()
     
    logprint('debug', 'adding...')
    for n,title in enumerate(authors_new):
        logprint('debug', '--------------------')
        logprint('debug', '%s/%s %s' % (n, len(authors_new), title))
        logprint('debug', 'getting from mediawiki')
        mwauthor = Proxy().page(title)
        try:
            existing_author = Author.get(title)
            logprint('debug', 'exists in elasticsearch')
        except:
            existing_author = None
        logprint('debug', 'creating author')
        author = Author.from_mw(mwauthor, author=existing_author)
        if not dryrun:
            logprint('debug', 'saving')
            author.save()
            try:
                a = Author.get(title)
            except NotFoundError:
                logprint('error', 'ERROR: Author(%s) NOT SAVED!' % title)
    
    logprint('debug', 'DONE')
コード例 #2
0
ファイル: views.py プロジェクト: densho/encyc-front
def author(request, url_title, template_name="wikiprox/author.html"):
    try:
        author = Author.get(url_title)
        author.scrub()
    except NotFoundError:
        raise Http404
    return render_to_response(template_name, {"author": author}, context_instance=RequestContext(request))
コード例 #3
0
def author(request, url_title, format=None):
    """DOCUMENTATION GOES HERE.
    """
    try:
        author = Author.get(url_title)
    except NotFoundError:
        return Response(status=status.HTTP_404_NOT_FOUND)
    articles = [
        {
            'title': article.title,
            'url': reverse('wikiprox-api-page', args=([article.url_title]), request=request),
        }
        for article in author.articles()
    ]
    data = {
        'url_title': author.url_title,
        'url': reverse('wikiprox-api-author', args=([author.url_title]), request=request),
        'absolute_url': reverse('wikiprox-author', args=([author.url_title]), request=request),
        'title': author.title,
        'title_sort': author.title_sort,
        'body': author.body,
        'modified': author.modified,
        'articles': articles,
    }
    return Response(data)