def test_files_to_publish(self, mocksvnfiles, mocksvnclient, mocksvnremote, mocksvnwc):
        arch = Archive(label='Test', name='Test Archives and Collections',
            svn='http://svn.example.com/test/trunk', slug='test')

        # simulate up to date working copy
        mocksvnwc.WorkingCopy.return_value.entry.return_value.revision = 10
        mocksvnremote.return_value.get_latest_revnum.return_value = 10

        mocksvnfiles.return_value = ['file1', 'file2']  # not reflective of actual result
        result = files_to_publish(arch)
        # should not update
        mocksvnclient.return_value.update.assert_not_called()
        mocksvnfiles.assert_called_with(arch)
        self.assertEqual(mocksvnfiles.return_value, result)

        # simulate out of date working copy - should do an svn up
        mocksvnwc.WorkingCopy.return_value.entry.return_value.revision = 8
        result = files_to_publish(arch)
        mocksvnclient.return_value.update.assert_called_with(arch.svn_local_path)
Exemple #2
0
def list_files(request, archive):
    '''List files associated with an archive to be prepped and previewed
    for publication.  Expected to be retrieved via ajax and loaded in a
    jquery ui tab, so only returns a partial html page without site theme.
    '''
    archive = get_object_or_404(Archive, slug=archive)

    files = files_to_publish(archive)
    # sort by last modified time, most recent first
    files = sorted(files, key=lambda file: file.mtime, reverse=True)

    paginator = Paginator(files, 30, orphans=5)
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    show_pages = pages_to_show(paginator, page)
    # If page request (9999) is out of range, deliver last page of results.
    try:
        recent_files = paginator.page(page)
    except (EmptyPage, InvalidPage):
        recent_files = paginator.page(paginator.num_pages)

    # query for publish/preview modification time all at once
    # (more efficient than individual queries for each file)
    published = FindingAid.objects.only('document_name', 'last_modified') \
        .filter(document_name__in=[f.filename for f in recent_files.object_list])
    pubinfo = dict((r.document_name, r.last_modified) for r in published)
    # NOTE: if needed, we can also load preview info like this:
    # preview = published.using(settings.EXISTDB_PREVIEW_COLLECTION)

    for f in recent_files.object_list:
        f.published = pubinfo.get(f.filename, None)

    return render(request, 'fa_admin/snippets/list_files_tab.html', {
        'files': recent_files,
        'show_pages': show_pages})