Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_references(article, references):
- if article.id:
- Reference.query.filter_by(from_article=article).delete()
- known_to_article_ids = set()
- for ref in references:
- fingerprint = get_reference_meta_fingerprint(ref)
- if fingerprint:
- ref['to_origin_ids'][Origins.fingerprint.name] = fingerprint
- try:
- to_article = get_article(ref['to_origin_ids'])
- if to_article:
- if to_article.id in known_to_article_ids:
- references_duplicates_logger.warn(
- 'article has duplicate references',
- article_id=article.id,
- ref_to_origin_ids=ref['to_origin_ids'])
- continue
- known_to_article_ids.add(to_article.id)
- except MultipleResultsFound as e:
- # We have the following problem with origin_ids:
- # Multiple article can have same origin_id
- #
- # If we find such articles, we will assign the reference to the first
- # of them and write warning to log
- to_article = (
- Article.query.filter(column_contains_origins(
- Article.origin_ids, ref['to_origin_ids'])).first())
- origin_ids_duplicates_logger.warn(
- 'origin_ids references multiple articles',
- origin_ids=ref['to_origin_ids'])
- Reference(
- from_article=article,
- to_article=to_article,
- raw_ref=ref['raw_ref'],
- format_type=ref['format_type'],
- origin=ref['origin'],
- order=ref['order'],
- from_origin_ids=ref['from_origin_ids'],
- to_origin_ids=ref['to_origin_ids'],
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement