def get_decisions(self):
        from ecolex.search import get_documents_by_field

        if not self.informea_id():
            return []
        return get_documents_by_field('decTreatyId',
                                      [self.informea_id()], rows=100)
Beispiel #2
0
    def update_status(self):
        logger.info('[Treaty] Update status started.')
        rows = 50
        index = 0
        treaties = []
        while True:
            docs = self.solr.solr.search('type:treaty', rows=rows, start=index)
            for treaty in docs:
                treaty = cleanup_copyfields(treaty)
                treaty.pop('_version_')
                if treaty.get('trTypeOfText_en', '') == 'Bilateral':
                    treaty['trStatus'] = 'In force'
                else:
                    treaty_id = treaty.get('trElisId')
                    results = get_documents_by_field('trSupersedesTreaty',
                                                     [treaty_id],
                                                     rows=100)
                    if len(results):
                        treaty['trStatus'] = 'Superseded'
                    else:
                        if 'trEntryIntoForceDate' in treaty:
                            treaty['trStatus'] = 'In force'
                        else:
                            treaty['trStatus'] = 'Not in force'

                treaties.append(treaty)

            if len(docs) < rows:
                break
            index += rows
        self.solr.add_bulk(treaties)
        logger.info('[Treaty] Update status finished.')
Beispiel #3
0
 def parent_url(self):
     # only for chapters
     from ecolex.search import get_documents_by_field
     if self.lit_is_chapter:
         parent_elis_id = self.solr.get('litRelatedMonograph')
         docs = get_documents_by_field('litId', [parent_elis_id], rows=1)
         doc = [x for x in docs][0]
         return doc.details_url()
     return None
Beispiel #4
0
 def get_legislation_references(self):
     from ecolex.search import get_documents_by_field
     references = {}
     for field, label in self.LEGISLATION_REFERENCE_FIELDS.items():
         ids = [v for v in self.solr.get(field, [])]
         results = get_documents_by_field(self.ID_FIELD, ids, rows=100)
         if results:
             references[label] = results
     return references
Beispiel #5
0
 def get_legislation_back_references(self):
     from ecolex.search import get_documents_by_field
     references = {}
     leg_id = first(self.solr.get('legId'))
     for field, label in self.LEGISLATION_BACK_REFERENCE.items():
         results = get_documents_by_field(field, [leg_id], rows=100)
         if results:
             references[label] = results
     return references
Beispiel #6
0
 def get_treaty_back_references(self):
     from ecolex.search import get_documents_by_field
     references = {}
     tr_id = self.solr.get('trElisId')
     for label, field in self.BACK_REFERENCE_LABELS.items():
         results = get_documents_by_field(field, [tr_id], rows=100)
         if results:
             references[label] = results
     return references
Beispiel #7
0
 def get_treaty_references(self):
     from ecolex.search import get_documents_by_field
     references = {}
     for label, field in self.REFERENCE_LABELS.items():
         ids = [v for v in self.solr.get(field, [])]
         results = get_documents_by_field(self.ID_FIELD, ids, rows=100)
         if results:
             references[label] = results
     return references
Beispiel #8
0
 def parent_url(self):
     # only for chapters
     from ecolex.search import get_documents_by_field
     if self.is_chapter and self.related_monograph:
         docs = get_documents_by_field('litId', [self.related_monograph],
                                       rows=1)
         if len(docs) > 0:
             doc = [x for x in docs][0]
             return doc.details_url
     return None
Beispiel #9
0
    def get_references_from(self):
        from ecolex.search import get_documents_by_field
        lit_id = self.document_id()
        references = {}

        for field, doc_type in self.REFERENCE_FROM_FIELDS.items():
            results = get_documents_by_field(field, [lit_id])
            if results:
                references[doc_type] = results
        return references
Beispiel #10
0
 def get_redirect_url(self, doc_type, doc_id):
     doc_type = self.doc_type_map.get(doc_type)
     search_field = self.doc_id_map.get(doc_type)
     if not doc_type or not search_field:
         return reverse('results')
     results = get_documents_by_field(search_field, [doc_id], rows=1)
     if not results:
         return reverse('results')
     doc = [x for x in results][0]
     doc_details = doc_type + '_details'
     return reverse(doc_details, kwargs={'slug': doc.slug})
Beispiel #11
0
 def get_referenced_by(self):
     from ecolex.search import get_documents_by_field
     references = {}
     original_id = first(self.solr.get('cdOriginalId'))
     if not original_id:
         return []
     for doc_type, ref_field in self.REFERENCED_BY_FIELDS.items():
         docs = get_documents_by_field(ref_field, [original_id], rows=100)
         if docs:
             references[doc_type] = docs
     return references
Beispiel #12
0
 def get_references(self):
     from ecolex.search import get_documents_by_field
     references = {}
     for doc_type, ref_field in self.REFERENCE_FIELDS.items():
         ref_id = first(self.solr.get(ref_field))
         if not ref_id:
             continue
         docs = get_documents_by_field(self.SOURCE_REF_FIELDS[doc_type],
                                       [ref_id], rows=100)
         if docs:
             references[doc_type] = docs
     return references
Beispiel #13
0
 def get_redirect_url(self, *args, **kwargs):
     doc_id = kwargs.pop('doc_id', None)
     doc_type = kwargs.pop('doc_type', None)
     if not doc_id or not doc_type:
         return None
     search_field = self.doc_type_map.get(doc_type)
     results = get_documents_by_field(search_field, [doc_id], rows=1)
     if not results:
         return None
     leg = [x for x in results][0]
     doc_details = doc_type + '_details'
     return reverse(doc_details, kwargs={'slug': leg.slug})
Beispiel #14
0
 def get_references_to(self):
     from ecolex.search import get_documents_by_field
     ids_dict = {}
     for field, doc_type in self.REFERENCE_TO_FIELDS.items():
         values = self.solr.get(field, [])
         if not isinstance(values, list):
             values = [values]
         else:
             values = [v for v in values]
         if values and any(values):
             ids_dict[doc_type] = values
     references = {}
     for doc_type, ids in ids_dict.items():
         results = get_documents_by_field(self.REFERENCE_MAPPING[doc_type],
                                          ids, rows=10)
         if results:
             references[doc_type] = results
     return references
Beispiel #15
0
 def get_context_data(self, **kwargs):
     ctx = super(TreatyParticipantView, self).get_context_data(**kwargs)
     ctx['results'] = get_documents_by_field('partyCountry',
                                             [kwargs['id']],
                                             1000000)  # get all results
     return ctx
Beispiel #16
0
 def get_context_data(self, **kwargs):
     ctx = super(DecMeetingView, self).get_context_data(**kwargs)
     ctx['results'] = get_documents_by_field('decMeetingId',
                                             [kwargs['id']],
                                             1000000)  # get all results
     return ctx
Beispiel #17
0
 def get_decisions(self):
     from ecolex.search import get_documents_by_field
     if not self.informea_id():
         return []
     return get_documents_by_field('decTreatyId',
                                   [self.informea_id()], rows=100)
Beispiel #18
0
 def get_literatures(self):
     from ecolex.search import get_documents_by_field
     return get_documents_by_field('litTreatyReference',
                                   [self.solr.get('trElisId')], rows=100)
Beispiel #19
0
 def get_court_decisions(self):
     from ecolex.search import get_documents_by_field
     return get_documents_by_field('cdTreatyReference',
                                   [self.solr.get('trElisId')], rows=100)