def replace_bible_links(match): ref = match.group(1) #print "Replacing bible link", ref vk = VK(ref) return "href='book_%s.html#%s_start'" % (vk.getOSISBookName(), vk.getOSISRef())
def get_document(self, path): module_name, rest = path.split("/", 1) ref, direction = rest.rsplit("/", 1) assert direction in ("next", "previous") dir = {"next": 1, "previous": -1}[direction] book = biblemgr.get_module_book_wrapper(module_name) mod = book.mod no_more = False if book.is_verse_keyed: vk = VK(ref, headings=not book.chapter_view) if book.chapter_view: vk.chapter += dir if vk.Error(): print "No more in that direction", dir no_more = True else: # go back just a little, so that when we go forward on the module # we won't overshoot... (at least, that is our plan - we hope it # won't be baffled...) vk.Verse(vk.Verse() - dir) if vk.Error(): print "VK had an error taking away a verse", dir if not no_more: old_mod_skiplinks = mod.getSkipConsecutiveLinks() mod.setSkipConsecutiveLinks(True) try: vk.Persist(1) mod.setKey(vk) #print repr(mod.Error()) mod.increment(dir) if mod.Error() != '\x00': print "Mod had an error" no_more = True else: if book.chapter_view: new_ref = vk.get_chapter_osis_ref() else: new_ref = vk.getOSISRef() finally: mod.setKey(SW.Key()) mod.setSkipConsecutiveLinks(old_mod_skiplinks) elif book.is_dictionary: # XXX: Would using an index rather than a reference (as the XUL code did) be more efficient? book.snap_text(ref) book.mod.increment(dir) if mod.Error() == '\x00' and book.mod.getKey().getText(): new_ref = to_unicode(mod.getKey().getText(), mod) else: no_more = True elif book.is_genbook: ref = "/" + ref tk = book.GetKey() tk.Persist(1) assert tk.thisown newtk = book.GetKey() newtk.thisown = True mod.setKey(tk) print "Getting next for", ref tk.set_text(ref) print tk.getText() if mod.Error() != '\x00': print "Error on initial set?" mod.increment(dir) if mod.Error() == '\x00' and tk.getText(): new_ref = to_unicode(tk.getText(), mod)[1:] # trim off the leading / else: no_more = True mod.setKey(newtk) else: print "Book type not handled", module_name if no_more: message = (_("You are at the start of this book.") if dir == -1 else _("You are at the end of this book.")) class_name = "book-%s" % ("start" if dir == -1 else "end") return ''' <div class="page_segment" empty="true"> <div class='no_more_text %(class_name)s'> %(message)s </div> </div>''' % locals() return '<div class="page_segment">%(content)s%(timer)s</div>' % self._get_document_parts_for_ref( module_name, new_ref, do_current_ref=False)
def get_document(self, path): module_name, rest = path.split("/", 1) ref, direction = rest.rsplit("/", 1) assert direction in ("next", "previous") dir = {"next": 1, "previous": -1}[direction] book = biblemgr.get_module_book_wrapper(module_name) mod = book.mod no_more = False if book.is_verse_keyed: vk = VK(ref, headings=not book.chapter_view) if book.chapter_view: vk.chapter += dir if vk.Error(): print "No more in that direction", dir no_more = True else: # go back just a little, so that when we go forward on the module # we won't overshoot... (at least, that is our plan - we hope it # won't be baffled...) vk.Verse(vk.Verse() - dir) if vk.Error(): print "VK had an error taking away a verse", dir if not no_more: old_mod_skiplinks = mod.getSkipConsecutiveLinks() mod.setSkipConsecutiveLinks(True) try: vk.Persist(1) mod.setKey(vk) #print repr(mod.Error()) mod.increment(dir) if mod.Error() != '\x00': print "Mod had an error" no_more = True else: if book.chapter_view: new_ref = vk.get_chapter_osis_ref() else: new_ref = vk.getOSISRef() finally: mod.setKey(SW.Key()) mod.setSkipConsecutiveLinks(old_mod_skiplinks) elif book.is_dictionary: # XXX: Would using an index rather than a reference (as the XUL code did) be more efficient? book.snap_text(ref) book.mod.increment(dir) if mod.Error() == '\x00' and book.mod.getKey().getText(): new_ref = to_unicode(mod.getKey().getText(), mod) else: no_more = True elif book.is_genbook: ref = "/" + ref tk = book.GetKey() tk.Persist(1) assert tk.thisown newtk = book.GetKey() newtk.thisown = True mod.setKey(tk) print "Getting next for", ref tk.set_text(ref) print tk.getText() if mod.Error() != '\x00': print "Error on initial set?" mod.increment(dir) if mod.Error() == '\x00' and tk.getText(): new_ref = to_unicode(tk.getText(), mod)[1:] # trim off the leading / else: no_more = True mod.setKey(newtk) else: print "Book type not handled", module_name if no_more: message = (_("You are at the start of this book.") if dir == -1 else _("You are at the end of this book.")) class_name = "book-%s" % ("start" if dir == -1 else "end") return ''' <div class="page_segment" empty="true"> <div class='no_more_text %(class_name)s'> %(message)s </div> </div>''' % locals() return '<div class="page_segment">%(content)s%(timer)s</div>' % self._get_document_parts_for_ref(module_name, new_ref, do_current_ref=False)