def process_citations(data, debug): """Walk through the citations and add them one at a time. """ updated_ids = set() for index, item in data.iterrows(): print("\nAdding citation from %s to %s" % (item['citing'], item['cited'])) try: cite = OpinionsCited.objects.get( citing_opinion_id=item['citing'], cited_opinion_id=item['cited'], ) msg = "Citation already exists. Doing nothing:\n" except OpinionsCited.DoesNotExist: cite = OpinionsCited(citing_opinion_id=item['citing'], cited_opinion_id=item['cited']) msg = "Created new citation:\n" if not debug: cite.save() updated_ids.add(cite.citing_opinion.pk) try: print( " %s" " %s: %s\n" " From: %s\n" " To: %s\n" % (msg, cite.pk, cite, cite.citing_opinion, cite.cited_opinion)) except Opinion.DoesNotExist: print(" Unable to create citation. Underlying Opinion doesn't " "exist.") print("\nUpdating Solr...") if not debug: add_or_update_opinions(updated_ids) print("Done.")
def _update_index(): # For now, until some model/api issues are worked out for Audio # objects, we'll avoid using the cl_update_index command and do # this the hard way using tasks opinion_keys = Opinion.objects.values_list('pk', flat=True) add_or_update_opinions(opinion_keys) audio_keys = Audio.objects.values_list('pk', flat=True) add_or_update_audio_files(audio_keys)
def process_citations(data, debug): """Walk through the citations and add them one at a time. """ updated_ids = set() for index, item in data.iterrows(): print("\nAdding citation from %s to %s" % (item['citing'], item['cited'])) try: cite = OpinionsCited.objects.get( citing_opinion_id=item['citing'], cited_opinion_id=item['cited'], ) msg = "Citation already exists. Doing nothing:\n" except OpinionsCited.DoesNotExist: cite = OpinionsCited(citing_opinion_id=item['citing'], cited_opinion_id=item['cited']) msg = "Created new citation:\n" if not debug: cite.save() updated_ids.add(cite.citing_opinion.pk) try: print( " %s" " %s: %s\n" " From: %s\n" " To: %s\n" % (msg, cite.pk, cite, cite.citing_opinion, cite.cited_opinion) ) except Opinion.DoesNotExist: print(" Unable to create citation. Underlying Opinion doesn't " "exist.") print("\nUpdating Solr...") if not debug: add_or_update_opinions(updated_ids) print("Done.")