def parse_dossier_data(data, ep): """Parse data from parltarck dossier export (1 dossier) Update dossier if it existed before, this function goal is to import and update a dossier, not to import all parltrack data """ changed = False doc_changed = False ref = data['procedure']['reference'] logger.debug('Processing dossier %s', ref) with transaction.atomic(): try: dossier = Dossier.objects.get(reference=ref) except Dossier.DoesNotExist: dossier = Dossier(reference=ref) logger.debug('Dossier did not exist') changed = True if dossier.title != data['procedure']['title']: logger.debug('Title changed from "%s" to "%s"', dossier.title, data['procedure']['title']) dossier.title = data['procedure']['title'] changed = True if changed: logger.info('Updated dossier %s', ref) dossier.save() source = data['meta']['source'].replace('&l=en', '') try: doc = Document.objects.get(dossier=dossier, kind='procedure-file') except Document.DoesNotExist: doc = Document(dossier=dossier, kind='procedure-file', chamber=ep) logger.debug('Document for dossier %s did not exist', ref) doc_changed = True if doc.link != source: logger.debug('Link changed from %s to %s', doc.link, source) doc.link = source doc_changed = True if doc_changed: logger.info('Updated document %s for dossier %s', doc.link, ref) doc.save() if 'votes' in data.keys() and 'epref' in data['votes']: command = Command() command.init_cache() command.parse_vote_data(data['votes'])
def handle_document(dossier, chamber, url): doc_changed = False try: doc = Document.objects.get(chamber=chamber, dossier=dossier, kind='procedure-file') except Document.DoesNotExist: doc = Document(chamber=chamber, dossier=dossier, kind='procedure-file') logger.debug('Created %s document for dossier %s' % (chamber.abbreviation, dossier.title)) doc_changed = True if doc.link != url: logger.debug('Changing %s url from %s to %s' % (chamber.abbreviation, doc.link, url)) doc.link = url doc_changed = True if doc_changed: doc.save()