Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. def set_references(article, references):
  2. if article.id:
  3. Reference.query.filter_by(from_article=article).delete()
  4.  
  5. known_to_article_ids = set()
  6.  
  7. for ref in references:
  8. fingerprint = get_reference_meta_fingerprint(ref)
  9. if fingerprint:
  10. ref['to_origin_ids'][Origins.fingerprint.name] = fingerprint
  11.  
  12. try:
  13. to_article = get_article(ref['to_origin_ids'])
  14. if to_article:
  15. if to_article.id in known_to_article_ids:
  16. references_duplicates_logger.warn(
  17. 'article has duplicate references',
  18. article_id=article.id,
  19. ref_to_origin_ids=ref['to_origin_ids'])
  20. continue
  21.  
  22. known_to_article_ids.add(to_article.id)
  23. except MultipleResultsFound as e:
  24. # We have the following problem with origin_ids:
  25. # Multiple article can have same origin_id
  26. #
  27. # If we find such articles, we will assign the reference to the first
  28. # of them and write warning to log
  29. to_article = (
  30. Article.query.filter(column_contains_origins(
  31. Article.origin_ids, ref['to_origin_ids'])).first())
  32. origin_ids_duplicates_logger.warn(
  33. 'origin_ids references multiple articles',
  34. origin_ids=ref['to_origin_ids'])
  35.  
  36. Reference(
  37. from_article=article,
  38. to_article=to_article,
  39. raw_ref=ref['raw_ref'],
  40. format_type=ref['format_type'],
  41. origin=ref['origin'],
  42. order=ref['order'],
  43. from_origin_ids=ref['from_origin_ids'],
  44. to_origin_ids=ref['to_origin_ids'],
  45. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement