def find_or_make_source(self):
        """ Find or create a source.
        returns handle to source."""
        for hndl in self.dbstate.db.get_source_handles():
            if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames':
                return hndl
        # No source found, lets add one with associated repo and note
        repo = Repository()
        repo.set_name("www.geonames.org")
        rtype = RepositoryType(RepositoryType.WEBSITE)
        repo.set_type(rtype)
        url = Url()
        url.set_path('http://www.geonames.org/')
        url.set_description(_('GeoNames web site'))
        url.set_type(UrlType(UrlType.WEB_HOME))
        repo.add_url(url)
        url = Url()
        url.set_path('*****@*****.**')
        url.set_description(_('GeoNames author'))
        url.set_type(UrlType(UrlType.EMAIL))
        repo.add_url(url)

        note_txt = StyledText(
            _('GeoNames was founded by Marc Wick. You can reach him at '))
        note_txt += StyledText('*****@*****.**' + '\n')
        note_txt += StyledText(
            _('GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,'
              ' 8708 Männedorf, Switzerland.\nThis work is licensed under a '))
        note_txt += linkst(
            _('Creative Commons Attribution 3.0 License'),
            'https://creativecommons.org/licenses/by/3.0/legalcode')

        new_note = Note()
        new_note.set_styledtext(note_txt)
        new_note.set_type(NoteType.REPO)
        src = Source()
        src.title = 'GeoNames'
        src.author = 'Marc Wick'
        repo_ref = RepoRef()
        mtype = SourceMediaType(SourceMediaType.ELECTRONIC)
        repo_ref.set_media_type(mtype)
        with DbTxn(
                _("Add Souce/Repo/Note (%s)") % "GeoNames",
                self.dbstate.db) as trans:

            self.dbstate.db.add_note(new_note, trans)
            repo.add_note(new_note.get_handle())
            self.dbstate.db.add_repository(repo, trans)
            repo_ref.set_reference_handle(repo.handle)
            src.add_repo_reference(repo_ref)
            self.dbstate.db.add_source(src, trans)
        return src.handle
Example #2
0
    def find_or_make_source(self):
        """ Find or create a source.
        returns handle to source."""
        for hndl in self.dbstate.db.get_source_handles():
            if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames':
                return hndl
        # No source found, lets add one with associated repo and note
        repo = Repository()
        repo.set_name("www.geonames.org")
        rtype = RepositoryType(RepositoryType.WEBSITE)
        repo.set_type(rtype)
        url = Url()
        url.set_path('http://www.geonames.org/')
        url.set_description(_('GeoNames web site'))
        url.set_type(UrlType(UrlType.WEB_HOME))
        repo.add_url(url)
        url = Url()
        url.set_path('*****@*****.**')
        url.set_description(_('GeoNames author'))
        url.set_type(UrlType(UrlType.EMAIL))
        repo.add_url(url)

        note_txt = StyledText(_(
            'GeoNames was founded by Marc Wick. You can reach him at '))
        note_txt += StyledText('*****@*****.**' + '\n')
        note_txt += StyledText(_(
            'GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,'
            ' 8708 Männedorf, Switzerland.\nThis work is licensed under a '))
        note_txt += linkst(
            _('Creative Commons Attribution 3.0 License'),
            'https://creativecommons.org/licenses/by/3.0/legalcode')

        new_note = Note()
        new_note.set_styledtext(note_txt)
        new_note.set_type(NoteType.REPO)
        src = Source()
        src.title = 'GeoNames'
        src.author = 'Marc Wick'
        repo_ref = RepoRef()
        mtype = SourceMediaType(SourceMediaType.ELECTRONIC)
        repo_ref.set_media_type(mtype)
        with DbTxn(_("Add Souce/Repo/Note (%s)") % "GeoNames",
                   self.dbstate.db) as trans:

            self.dbstate.db.add_note(new_note, trans)
            repo.add_note(new_note.get_handle())
            self.dbstate.db.add_repository(repo, trans)
            repo_ref.set_reference_handle(repo.handle)
            src.add_repo_reference(repo_ref)
            self.dbstate.db.add_source(src, trans)
        return src.handle