diff --git a/representatives_recommendations/contrib/dossier_mappings.py b/representatives_recommendations/contrib/import_data.py similarity index 63% rename from representatives_recommendations/contrib/dossier_mappings.py rename to representatives_recommendations/contrib/import_data.py index 69d4e08d876e0ab104cbf1a6a8055e93657a40b8..889600d2f0bd54db62d86aaedd81ccf3c48ed706 100644 --- a/representatives_recommendations/contrib/dossier_mappings.py +++ b/representatives_recommendations/contrib/import_data.py @@ -11,5 +11,16 @@ dossier_mappings = { "Rapport Lambrinidis on strengthening security and fundamental freedoms on the Internet": "Strengthening security and fundamental freedoms on the Internet", "Criminal measures aimed at ensuring the enforcement of intellectual property rights (IPRED 2), 1st reading": - "Criminal measures aimed at ensuring the enforcement of intellectual property rights" + "Criminal measures aimed at ensuring the enforcement of intellectual property rights", + "A7-0204/2012": + "EU/Australia, Canada, Japan, Korea, Mexico, Morocco, New Zealand, Singapore, Switzerland and United States Anti-Counterfeiting Trade Agreement (ACTA)", + "A7-0001/2012": + "Enhanced cooperation in the area of the creation of unitary patent protection: implementation" } + +resolutions = [ + u'résolution législative', + u'résolution', + 'legislative resolution', + 'resolution' +] diff --git a/representatives_recommendations/contrib/import_recommendations.py b/representatives_recommendations/contrib/import_recommendations.py index ba6a1ccb5879199479d090c5bede1bad701f3be7..3c77e07eb60ada01a29a3769681143eeb7660185 100644 --- a/representatives_recommendations/contrib/import_recommendations.py +++ b/representatives_recommendations/contrib/import_recommendations.py @@ -9,7 +9,7 @@ import sys from representatives_recommendations.models import Recommendation from representatives_votes.models import Dossier, Proposal -from .dossier_mappings import dossier_mappings +from .import_data import dossier_mappings, resolutions logger = logging.getLogger(__name__) @@ -35,10 +35,21 @@ class RecommendationImporter: return dossier def get_proposal(self, dossier, kind): + kinds = [kind] + try: - return Proposal.objects.get(dossier=dossier, kind__iexact=kind) - except Proposal.DoesNotExist: - return None + resolutions.index(kind.lower()) + kinds.extend(resolutions) + except ValueError: + pass + + for k in kinds: + try: + return Proposal.objects.get(dossier=dossier, kind__iexact=k) + except Proposal.DoesNotExist: + continue + + return None def import_row(self, row): dossier = self.get_dossier(row['title'])