spacepaste

  1.  
  2. #code
  3. ==========
  4. def article_text_to_partials(article, text):
  5. strings = re.findall(u'\[.*?\]', text)
  6. partials = []
  7. for string in strings:
  8. partial_string = string_to_partial_partial(string)
  9. if partial_string:
  10. book = Book.query.filter_by(serie_id=article.serie_id, title=partial_string['book_title']).one()
  11. chapter = Chapter.query.filter_by(book_id=book.id, title=partial_string['chapter_title']).one()
  12. partials.append(Partial(article=article, book=book, chapter=chapter, text=partial_string['text']))
  13. return partials
  14. #output
  15. ==========
  16. [<Partial 14>, <Partial 15>, <Partial (transient 140493407433232)>]
  17.