Exemple #1
0
def sherpa_romeo_journal_process(form, field, submit=False, fields=None):
    value = field.data or ''
    if value == "" or value.isspace():
        return

    s = SherpaRomeoSearch()
    s.search_journal(value, 'exact')
    if s.error:
        field.add_message(s.error_message, state='info')
        return

    if s.get_num_hits() == 1:
        issn = s.parser.get_journals(attribute='issn')
        if issn != [] and issn is not None:
            issn = issn[0]
            publisher = s.parser.get_publishers(journal=value)
            if publisher is not None and publisher != []:
                if hasattr(form, 'issn'):
                    form.issn.data = issn

                if hasattr(form, 'publisher'):
                    form.publisher.data = publisher['name']
                    form.publisher.post_process(form)
                return

            field.add_message("Journal's Publisher not found", state='info')
            if hasattr(form, 'issn'):
                form.issn.data = issn
            if hasattr(form, 'publisher'):
                form.publisher.data = publisher
                form.publisher.post_process(form)
        else:
            field.add_message("Couldn't find ISSN.", state='info')
Exemple #2
0
def sherpa_romeo_issn_process(form, field, submit=False):
    value = field.data or ''
    if value == "" or value.isspace():
        return dict(error=0, error_message='')
    s = SherpaRomeoSearch()
    s.search_issn(value)
    if s.error:
        field.add_message(s.error_message, state='info')
        return

    if s.get_num_hits() == 1:
        journal = s.parser.get_journals(attribute='jtitle')
        journal = journal[0]
        publisher = s.parser.get_publishers(journal=journal)
        if publisher is not None and publisher != []:
            if hasattr(form, 'journal'):
                form.journal.data = journal

            if hasattr(form, 'publisher'):
                form.publisher.data = publisher['name']
            return
        else:
            if hasattr(form, 'journal'):
                form.journal.data = journal
            return

    field.add_message("Couldn't find Journal.", state='info')
def sherpa_romeo_issn_process(form, field, submit=False):
    value = field.data or ''
    if value == "" or value.isspace():
        return dict(error=0, error_message='')
    s = SherpaRomeoSearch()
    s.search_issn(value)
    if s.error:
        field.add_message(s.error_message, state='info')
        return

    if s.get_num_hits() == 1:
        journal = s.parser.get_journals(attribute='jtitle')
        journal = journal[0]
        publisher = s.parser.get_publishers(journal=journal)
        if publisher is not None and publisher != []:
            if hasattr(form, 'journal'):
                form.journal.data = journal

            if hasattr(form, 'publisher'):
                form.publisher.data = publisher['name']
            return
        else:
            if hasattr(form, 'journal'):
                form.journal.data = journal
            return

    field.add_message("Couldn't find Journal.", state='info')
def sherpa_romeo_journal_process(form, field, submit=False, fields=None):
    value = field.data or ''
    if value == "" or value.isspace():
        return

    s = SherpaRomeoSearch()
    s.search_journal(value, 'exact')
    if s.error:
        field.add_message(s.error_message, state='info')
        return

    if s.get_num_hits() == 1:
        issn = s.parser.get_journals(attribute='issn')
        if issn != [] and issn is not None:
            issn = issn[0]
            publisher = s.parser.get_publishers(journal=value)
            if publisher is not None and publisher != []:
                if hasattr(form, 'issn'):
                    form.issn.data = issn

                if hasattr(form, 'publisher'):
                    form.publisher.data = publisher['name']
                    form.publisher.post_process(form)
                return

            field.add_message("Journal's Publisher not found", state='info')
            if hasattr(form, 'issn'):
                form.issn.data = issn
            if hasattr(form, 'publisher'):
                form.publisher.data = publisher
                form.publisher.post_process(form)
        else:
            field.add_message("Couldn't find ISSN.", state='info')
Exemple #5
0
def sherpa_romeo_publishers(dummy_form, dummy_field, term, limit=50):
    """Autocomplete publishers from SHERPA/RoMEO service."""
    if term:
        sherpa_romeo = SherpaRomeoSearch()
        publishers = sherpa_romeo.search_publisher(term)
        if publishers is None:
            return []
        return map(lambda x: {'value': x}, publishers[:limit])
    return []
def sherpa_romeo_publishers(dummy_form, dummy_field, term, limit=50):
    """Autocomplete publishers from SHERPA/RoMEO service."""
    if term:
        sherpa_romeo = SherpaRomeoSearch()
        publishers = sherpa_romeo.search_publisher(term)
        if publishers is None:
            return []
        return map(lambda x: {'value': x}, publishers[:limit])
    return []
Exemple #7
0
def sherpa_romeo_journals(dummy_form, dummy_field, term, limit=50):
    """Search SHERPA/RoMEO for journal name."""
    if term:
        # SherpaRomeoSearch doesnt' like unicode
        if isinstance(term, unicode):
            term = term.encode('utf8')
        s = SherpaRomeoSearch()
        journals = s.search_journal(term)
        if journals is not None:
            return map(lambda x: {'value': x}, journals[:limit])
    return []
def sherpa_romeo_journals(dummy_form, dummy_field, term, limit=50):
    """Search SHERPA/RoMEO for journal name."""
    if term:
        # SherpaRomeoSearch doesnt' like unicode
        if isinstance(term, unicode):
            term = term.encode('utf8')
        s = SherpaRomeoSearch()
        journals = s.search_journal(term)
        if journals is not None:
            return map(lambda x: {'value': x}, journals[:limit])
    return []
Exemple #9
0
def sherpa_romeo_publisher_process(form, field, submit=False, fields=None):
    value = field.data or ''
    if value == "" or value.isspace():
        return
    s = SherpaRomeoSearch()
    s.search_publisher(value)
    if s.error:
        field.add_message(s.error_message, state='info')

    conditions = s.parser.get_publishers(attribute='conditions')
    if conditions is not None and s.get_num_hits() == 1:
        conditions = conditions[0]
    else:
        conditions = []
    if conditions != []:
        conditions_html = "<u>Conditions</u><br><ol>"
        if isinstance(conditions['condition'], str):
            conditions_html += "<li>" + conditions['condition'] + "</li>"
        else:
            for condition in conditions['condition']:
                conditions_html += "<li>" + condition + "</li>"

        copyright_links = s.parser.get_publishers(attribute='copyrightlinks')
        if copyright_links is not None and copyright_links != []:
            copyright_links = copyright_links[0]
        else:
            copyright_links = None

        if isinstance(copyright_links, list):
            copyright_links_html = ""
            for copyright_link in copyright_links['copyrightlink']:
                copyright_links_html += (
                    '<a href="' + copyright_link['copyrightlinkurl'] +
                    '">' + copyright_link['copyrightlinktext'] + "</a><br>")
        elif isinstance(copyright_links, dict):
            if isinstance(copyright_links['copyrightlink'], list):
                for copyright_link in copyright_links['copyrightlink']:
                    copyright_links_html = (
                        '<a href="' + copyright_link['copyrightlinkurl'] +
                        '">' + copyright_link['copyrightlinktext'] +
                        "</a><br>")
            else:
                copyright_link = copyright_links['copyrightlink']
                copyright_links_html = (
                    '<a href="' + copyright_link['copyrightlinkurl'] +
                    '">' + copyright_link['copyrightlinktext'] + "</a><br>")

        home_url = s.parser.get_publishers(attribute='homeurl')
        if home_url is not None and home_url != []:
            home_url = home_url[0]
            home_url = '<a href="' + home_url + '">' + home_url + "</a>"
        else:
            home_url = None

        info_html = ""
        if home_url is not None:
            info_html += "<p>" + home_url + "</p>"

        if conditions is not None:
            info_html += "<p>" + conditions_html + "</p>"

        if copyright_links is not None:
            info_html += "<p>" + copyright_links_html + "</p>"

        if info_html != "":
            field.add_message(info_html, state='info')
Exemple #10
0
def sherpa_romeo_publisher_process(form, field, submit=False, fields=None):
    value = field.data or ''
    if value == "" or value.isspace():
        return
    s = SherpaRomeoSearch()
    s.search_publisher(value)
    if s.error:
        field.add_message(s.error_message, state='info')

    conditions = s.parser.get_publishers(attribute='conditions')
    if conditions is not None and s.get_num_hits() == 1:
        conditions = conditions[0]
    else:
        conditions = []
    if conditions != []:
        conditions_html = "<u>Conditions</u><br><ol>"
        if isinstance(conditions['condition'], str):
            conditions_html += "<li>" + conditions['condition'] + "</li>"
        else:
            for condition in conditions['condition']:
                conditions_html += "<li>" + condition + "</li>"

        copyright_links = s.parser.get_publishers(attribute='copyrightlinks')
        if copyright_links is not None and copyright_links != []:
            copyright_links = copyright_links[0]
        else:
            copyright_links = None

        if isinstance(copyright_links, list):
            copyright_links_html = ""
            for copyright_link in copyright_links['copyrightlink']:
                copyright_links_html += ('<a href="' +
                                         copyright_link['copyrightlinkurl'] +
                                         '">' +
                                         copyright_link['copyrightlinktext'] +
                                         "</a><br>")
        elif isinstance(copyright_links, dict):
            if isinstance(copyright_links['copyrightlink'], list):
                for copyright_link in copyright_links['copyrightlink']:
                    copyright_links_html = (
                        '<a href="' + copyright_link['copyrightlinkurl'] +
                        '">' + copyright_link['copyrightlinktext'] +
                        "</a><br>")
            else:
                copyright_link = copyright_links['copyrightlink']
                copyright_links_html = ('<a href="' +
                                        copyright_link['copyrightlinkurl'] +
                                        '">' +
                                        copyright_link['copyrightlinktext'] +
                                        "</a><br>")

        home_url = s.parser.get_publishers(attribute='homeurl')
        if home_url is not None and home_url != []:
            home_url = home_url[0]
            home_url = '<a href="' + home_url + '">' + home_url + "</a>"
        else:
            home_url = None

        info_html = ""
        if home_url is not None:
            info_html += "<p>" + home_url + "</p>"

        if conditions is not None:
            info_html += "<p>" + conditions_html + "</p>"

        if copyright_links is not None:
            info_html += "<p>" + copyright_links_html + "</p>"

        if info_html != "":
            field.add_message(info_html, state='info')
Exemple #11
0
 def __init__(self):
     self.sr = SherpaRomeoSearch()
     self.error_messages = []
     self.failed_tests = 0
     self.passed_tests = 0
Exemple #12
0
class SherpaRomeoTesting:

    def __init__(self):
        self.sr = SherpaRomeoSearch()
        self.error_messages = []
        self.failed_tests = 0
        self.passed_tests = 0

    def test_publishers_search_numhits(self):
        publishers = self.sr.search_publisher("american")
        num_hits = self.sr.parser.xml['header']['numhits']
        try:
            assert len(publishers) == 127 == int(num_hits)
            self.passed_tests = +1
        except AssertionError:
            self.failed_tests += 1
            self.error_messages.append("Wrong number of numhits " + \
                                       "while searching term 'american'" + \
                                       "in publishers: " + \
                                       str(len(publishers)) + \
                                       "\ncorrect: " + num_hits)

        publishers = self.sr.search_publisher(\
                                "American Academy of Audiology")
        num_hits = self.sr.parser.xml['header']['numhits']
        try:
            assert len(publishers) == 1 == int(num_hits)
            self.passed_tests = +1
        except AssertionError:
            self.failed_tests += 1
            self.error_messages.append("Wrong number of numhits " + \
                                       "while searching term " + \
                                       "American Academy of Audiology' " + \
                                       "in publishers: " + num_hits + \
                                       "\ncorrect: 1")

        publishers = self.sr.search_publisher("comput")
        num_hits = self.sr.parser.xml['header']['numhits']
        try:
            assert len(publishers) == 8 == int(num_hits)
            self.passed_tests = +1
        except AssertionError:
            self.failed_tests += 1
            self.error_messages.append("Wrong number of numhits " + \
                                       "while searching term " + \
                                       "'American Academy of Audiology' " + \
                                       "in publishers: " + \
                                       str(len(publishers)) + \
                                       "\ncorrect: " + num_hits)

    def test_publishers_search_conditions(self):
        self.sr.search_publisher("comput")
        for publisher, conditions in iteritems(
                self.sr.parser.get_conditions()):
            try:
                assert conditions != None
                self.passed_tests = +1
            except AssertionError:
                self.failed_tests += 1
                self.error_messages.append("Conditions not found " + \
                                           "when they should be! " + \
                                           publisher)
                break

        self.sr.search_publisher("American Academy of Audiology")
        conditions = self.sr.parser.get_conditions()
        try:
            assert conditions == {}
            self.passed_tests = +1
        except AssertionError:
            self.failed_tests += 1
            self.error_messages.append("Conditions found " + \
                                       "when they shouldn't be! " + \
                                       "American Academy of Audiology")

    def run_all_tests(self):
        self.test_publishers_search_numhits()
        self.test_publishers_search_conditions()

    def print_test_results(self):
        for err_msg in self.error_messages:
            print(err_msg)
            print("-----------------")

        if self.failed_tests > 0:
            print("Failed Tests: ", self.failed_tests)
        if self.passed_tests > 0:
            print("Passed Tests: ", self.passed_tests)