Merge lp:~phill-ridout/openlp/issue-507 into lp:openlp

Proposed by Phill
Status: Merged
Approved by: Jonathan Corwin
Approved revision: 1998
Merged at revision: 2001
Proposed branch: lp:~phill-ridout/openlp/issue-507
Merge into: lp:openlp
Diff against target: 35 lines (+17/-1)
1 file modified
openlp/plugins/bibles/lib/opensong.py (+17/-1)
To merge this branch: bzr merge lp:~phill-ridout/openlp/issue-507
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Jonathan Corwin (community) Approve
Andreas Preikschat (community) Approve
Review via email: mp+110858@code.launchpad.net

This proposal supersedes a proposal from 2012-06-17.

Description of the change

A fix for issue 507. http://support.openlp.org/issues/507
The opensong database file contained verses containing sub-elements such as <i> tags. lxml considders the text of an element up until the first sub element.

To post a comment you must log in.
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal

9 +from lxml import objectify, etree

No need for the etree import.

27 +

Double new line.

Please also add a docstring to your method.

review: Needs Fixing
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) :
review: Approve
Revision history for this message
Jonathan Corwin (j-corwin) wrote :

If the text looks something like
AAA<i>BBB</i>CCC<i>DDD</i>EEE

Is CCC one of the subelements?

review: Needs Information
Revision history for this message
Phill (phill-ridout) wrote :

So assuming this was all wrapped in a verse tag, the <I> tags are
considered children. AAA is the text of the verse element.BBB is the text
of the first <I> element. CCC is the tail to the first <I> element. DDD is
the text of the second <I> element. EEE is the tail to the second <I>
element.
On Jun 18, 2012 11:36 PM, "Jonathan Corwin" <email address hidden> wrote:

> Review: Needs Information
>
> If the text looks something like
> AAA<i>BBB</i>CCC<i>DDD</i>EEE
>
> Is CCC one of the subelements?
> --
> https://code.launchpad.net/~phill-ridout/openlp/issue-507/+merge/110858
> You are the owner of lp:~phill-ridout/openlp/issue-507.
>

Revision history for this message
Jonathan Corwin (j-corwin) :
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/bibles/lib/opensong.py'
2--- openlp/plugins/bibles/lib/opensong.py 2012-04-04 07:26:51 +0000
3+++ openlp/plugins/bibles/lib/opensong.py 2012-06-18 16:43:21 +0000
4@@ -46,6 +46,22 @@
5 BibleDB.__init__(self, parent, **kwargs)
6 self.filename = kwargs['filename']
7
8+ def get_text(self, element):
9+ """
10+ Recursively get all text in an objectify element and its child elements.
11+
12+ ``element``
13+ An objectify element to get the text from
14+ """
15+ verse_text = u''
16+ if element.text:
17+ verse_text = element.text
18+ for sub_element in element.iterchildren():
19+ verse_text += self.get_text(sub_element)
20+ if element.tail:
21+ verse_text += element.tail
22+ return verse_text
23+
24 def do_import(self, bible_name=None):
25 """
26 Loads a Bible from file.
27@@ -89,7 +105,7 @@
28 db_book.id,
29 int(chapter.attrib[u'n'].split()[-1]),
30 int(verse.attrib[u'n']),
31- unicode(verse.text))
32+ unicode(self.get_text(verse)))
33 self.wizard.incrementProgressBar(unicode(translate(
34 'BiblesPlugin.Opensong', 'Importing %s %s...',
35 'Importing <book name> <chapter>...')) %