def test_BibRecDocs(self):
     """bibdocfile - BibRecDocs functions"""
     my_bibrecdoc = BibRecDocs(2)
     #add bibdoc
     my_bibrecdoc.add_new_file(CFG_PREFIX + '/lib/webtest/invenio/test.jpg', 'Main', 'img_test', False, 'test add new file', 'test', '.jpg')
     my_bibrecdoc.add_bibdoc(doctype='Main', docname='file', never_fail=False)
     self.assertEqual(len(my_bibrecdoc.list_bibdocs()), 3)
     my_added_bibdoc = my_bibrecdoc.get_bibdoc('file')
     #add bibdocfile in empty bibdoc
     my_added_bibdoc.add_file_new_version(CFG_PREFIX + '/lib/webtest/invenio/test.gif', \
     description= 'added in empty bibdoc', comment=None, format=None, flags=['PERFORM_HIDE_PREVIOUS'])
     #propose unique docname
     self.assertEqual(my_bibrecdoc.propose_unique_docname('file'), 'file_2')
     #has docname
     self.assertEqual(my_bibrecdoc.has_docname_p('file'), True)
     #merge 2 bibdocs
     my_bibrecdoc.merge_bibdocs('img_test', 'file')
     self.assertEqual(len(my_bibrecdoc.get_bibdoc("img_test").list_all_files()), 2)
     #check file exists
     self.assertEqual(my_bibrecdoc.check_file_exists(CFG_PREFIX + '/lib/webtest/invenio/test.jpg'), True)
     #get bibdoc names
     self.assertEqual(my_bibrecdoc.get_bibdoc_names('Main')[0], '0104007_02')
     self.assertEqual(my_bibrecdoc.get_bibdoc_names('Main')[1],'img_test')
     #get total size
     self.assertEqual(my_bibrecdoc.get_total_size(), 1647591)
     #get total size latest version
     self.assertEqual(my_bibrecdoc.get_total_size_latest_version(), 1647591)
     #display
     value = my_bibrecdoc.display(docname='img_test', version='', doctype='', ln='en', verbose=0, display_hidden=True)
     self.assert_("<small><b>Main</b>" in value)
     #get xml 8564
     value = my_bibrecdoc.get_xml_8564()
     self.assert_('/record/2/files/img_test.jpg</subfield>' in value)
     #check duplicate docnames
     self.assertEqual(my_bibrecdoc.check_duplicate_docnames(), True)
    def test_BibRecDocs(self):
        """bibdocfile - BibRecDocs functions"""
        from invenio.bibdocfile import BibRecDocs
        my_bibrecdoc = BibRecDocs(2)
        #add bibdoc
        my_bibrecdoc.add_new_file(CFG_PREFIX + '/lib/webtest/invenio/test.jpg',
                                  'Main', 'img_test', False,
                                  'test add new file', 'test', '.jpg')
        my_bibrecdoc.add_bibdoc(doctype='Main',
                                docname='file',
                                never_fail=False)
        self.assertEqual(len(my_bibrecdoc.list_bibdocs()), 3)
        my_added_bibdoc = my_bibrecdoc.get_bibdoc('file')
        #add bibdocfile in empty bibdoc
        my_added_bibdoc.add_file_new_version(CFG_PREFIX + '/lib/webtest/invenio/test.gif', \
        description= 'added in empty bibdoc', comment=None, docformat=None, flags=['PERFORM_HIDE_PREVIOUS'])
        #propose unique docname
        self.assertEqual(my_bibrecdoc.propose_unique_docname('file'), 'file_2')
        #has docname
        self.assertEqual(my_bibrecdoc.has_docname_p('file'), True)
        #merge 2 bibdocs
        my_bibrecdoc.merge_bibdocs('img_test', 'file')
        self.assertEqual(
            len(my_bibrecdoc.get_bibdoc("img_test").list_all_files()), 2)
        #check file exists
        self.assertEqual(
            my_bibrecdoc.check_file_exists(
                CFG_PREFIX + '/lib/webtest/invenio/test.jpg', '.jpg'), True)
        #get bibdoc names
        # we can not rely on the order !
        names = set([
            my_bibrecdoc.get_bibdoc_names('Main')[0],
            my_bibrecdoc.get_bibdoc_names('Main')[1]
        ])
        self.assertTrue('0104007_02' in names)
        self.assertTrue('img_test' in names)

        #get total size
        self.assertEqual(my_bibrecdoc.get_total_size(), 1647591)
        #get total size latest version
        self.assertEqual(my_bibrecdoc.get_total_size_latest_version(), 1647591)
        #display
        #value = my_bibrecdoc.display(docname='img_test', version='', doctype='', ln='en', verbose=0, display_hidden=True)
        #self.assert_("<small><b>Main</b>" in value)
        #get xml 8564
        value = my_bibrecdoc.get_xml_8564()
        self.assert_('/' + CFG_SITE_RECORD +
                     '/2/files/img_test.jpg</subfield>' in value)
        #check duplicate docnames
        self.assertEqual(my_bibrecdoc.check_duplicate_docnames(), True)
예제 #3
0
def format_element(bfo):
    """
    Prints buttons to download all photos for each size
    """
    current_bibrecdoc = BibRecDocs(bfo.recID)
    if len(current_bibrecdoc.bibdocs) < 2:
        # If we have less than 2 photos, there is no point in displaying the
        # "Download all" buttons
        return
    wrapper = '''<style>
                #downloadallphotos {
                    clear: both;
                    font-size: small;
                    color: #555444;
                    margin-left: 10px;
                }
                #downloadallphotos a {
                    border-radius: 5px;
                    box-shadow: 1px 1px 1px 1px #CCCCCC;
                    color: #222222;
                    display: inline-block;
                    margin: 2px 5px;
                    padding: 3px;
                    text-decoration: none;
                    background-color: #E6E6FA;
                }
                #downloadallphotos a:hover {
                    background: -moz-linear-gradient(center top , #3A3A3A 0%, #7D7E7D 100%) repeat scroll 0 0 rgba(0, 0, 0, 0);
                    color: #fff;
                }
                </style>'''
    wrapper += '''<div id="downloadallphotos">Download all pictures:'''
    buttons = ''
    for (size, internal_size) in CFG_BIBDOCFILE_SUBFORMATS_TRANSLATIONS:
        total = current_bibrecdoc.get_total_size_latest_version(
            bfo.user_info, internal_size)
        # don't display the button if the size will be 0
        if total:
            buttons += '<a %(original)s href="%(site)s/record/%(recID)s/files/allfiles-%(size)s">%(size)s (%(total)s)</a>' \
                % {'original': size == 'original' and 'data-size="Original"' or '',
                   'site': CFG_SITE_URL,
                   'recID': bfo.recID,
                   'size': size,
                   'total': nice_size(total)}
    # If there are no buttons to display, don't display the rest of the HTML
    if buttons:
        return wrapper + buttons
예제 #4
0
    def test_BibRecDocs(self):
        """bibdocfile - BibRecDocs functions"""
        my_bibrecdoc = BibRecDocs(2)
        # add bibdoc
        my_bibrecdoc.add_new_file(
            CFG_PREFIX + "/lib/webtest/invenio/test.jpg", "Main", "img_test", False, "test add new file", "test", ".jpg"
        )
        my_bibrecdoc.add_bibdoc(doctype="Main", docname="file", never_fail=False)
        self.assertEqual(len(my_bibrecdoc.list_bibdocs()), 3)
        my_added_bibdoc = my_bibrecdoc.get_bibdoc("file")
        # add bibdocfile in empty bibdoc
        my_added_bibdoc.add_file_new_version(
            CFG_PREFIX + "/lib/webtest/invenio/test.gif",
            description="added in empty bibdoc",
            comment=None,
            docformat=None,
            flags=["PERFORM_HIDE_PREVIOUS"],
        )
        # propose unique docname
        self.assertEqual(my_bibrecdoc.propose_unique_docname("file"), "file_2")
        # has docname
        self.assertEqual(my_bibrecdoc.has_docname_p("file"), True)
        # merge 2 bibdocs
        my_bibrecdoc.merge_bibdocs("img_test", "file")
        self.assertEqual(len(my_bibrecdoc.get_bibdoc("img_test").list_all_files()), 2)
        # check file exists
        self.assertEqual(my_bibrecdoc.check_file_exists(CFG_PREFIX + "/lib/webtest/invenio/test.jpg", ".jpg"), True)
        # get bibdoc names
        # we can not rely on the order !
        names = set([my_bibrecdoc.get_bibdoc_names("Main")[0], my_bibrecdoc.get_bibdoc_names("Main")[1]])
        self.assertTrue("0104007_02" in names)
        self.assertTrue("img_test" in names)

        # get total size
        self.assertEqual(my_bibrecdoc.get_total_size(), 1647591)
        # get total size latest version
        self.assertEqual(my_bibrecdoc.get_total_size_latest_version(), 1647591)
        # display
        # value = my_bibrecdoc.display(docname='img_test', version='', doctype='', ln='en', verbose=0, display_hidden=True)
        # self.assert_("<small><b>Main</b>" in value)
        # get xml 8564
        value = my_bibrecdoc.get_xml_8564()
        self.assert_("/" + CFG_SITE_RECORD + "/2/files/img_test.jpg</subfield>" in value)
        # check duplicate docnames
        self.assertEqual(my_bibrecdoc.check_duplicate_docnames(), True)