コード例 #1
0
class EventIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    # faceting fields
    date = indexes.FacetDateField(model_attr='date')
    institution = indexes.FacetCharField(model_attr='institution')

    title = indexes.CharField(indexed=False,
                              stored=True,
                              model_attr='title',
                              default='')
    address = indexes.CharField(indexed=False,
                                stored=True,
                                model_attr='address')

    url = indexes.CharField(indexed=False, stored=True)
    n_acts = indexes.IntegerField()

    def get_model(self):
        return Event

    def prepare_url(self, obj):
        return obj.get_absolute_url()

    def prepare_n_acts(self, obj):
        return obj.eventact_set.count()
コード例 #2
0
ファイル: search_indexes.py プロジェクト: wica128/openkamer
class KamerstukIndex(indexes.SearchIndex, indexes.Indexable):
    title = indexes.CharField(model_attr='document')
    text = indexes.CharField(use_template=True, document=True)
    publication_type = indexes.CharField(model_attr='type', faceted=True)
    submitters = indexes.MultiValueField(model_attr='document', faceted=True)

    parties = indexes.MultiValueField(model_attr='document', faceted=True)
    dossier = indexes.CharField(model_attr='document', faceted=True)
    decision = indexes.CharField(model_attr='document', faceted=True)
    date = indexes.FacetDateField(model_attr='document')

    def prepare_date(self, obj):
        return '' if not obj.document else obj.document.date_published.strftime(
            '%Y-%m-%dT%H:%M:%SZ')

    def prepare_dossier(self, obj):
        return '' if not obj.document else [
            '' if not obj.document.dossier else obj.document.dossier.dossier_id
        ]

    def prepare_decision(self, obj):
        return '' if not obj.document else [
            '' if not obj.document.dossier else
            obj.document.dossier.get_status_display()
        ]

    def prepare_title(self, obj):
        return '' if not obj.document else obj.document.title_short

    def prepare_submitters(self, obj):
        return '' if not obj.document else [
            n.person.fullname() if n.person else ''
            for n in obj.document.submitters
        ]

    def prepare_parties(self, obj):
        return '' if not obj.document else [
            n.party.name_short if n.party else ''
            for n in obj.document.submitters
        ]

    def get_model(self):
        return Kamerstuk

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()
コード例 #3
0
class CommentWithMoodIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    # faceting fields
    date = indexes.FacetDateField(indexed=True, stored=False)

    # needed to filter votations by person
    #user = indexes.MultiValueField(indexed=True, stored=False)
    month = indexes.FacetCharField()

    def get_model(self):
        return CommentWithMood

    def prepare_date(self, obj):
        return obj.submit_date.date()

    def prepare_month(self, obj):
        return obj.submit_date.strftime("%B")
コード例 #4
0
ファイル: search_indexes.py プロジェクト: wica128/openkamer
class KamervraagIndex(indexes.SearchIndex, indexes.Indexable):

    title = indexes.CharField(model_attr='document')
    text = indexes.CharField(use_template=True, document=True)
    publication_type = indexes.CharField(faceted=True)
    submitters = indexes.MultiValueField(model_attr='document', faceted=True)

    parties = indexes.MultiValueField(model_attr='document', faceted=True)
    dossier = indexes.CharField(model_attr='document', faceted=True)
    date = indexes.FacetDateField(model_attr='document')
    decision = indexes.CharField(faceted=True)
    receiver = indexes.CharField(model_attr='receiver', faceted=True)

    def prepare_receiver(self, obj):
        return obj.receiver

    def prepare_decision(self, obj):
        return "Onbeantwoord" if not obj.kamerantwoord else "Beantwoord"

    def prepare_publication_type(self, obj):
        return 'Kamervraag'

    def prepare_date(self, obj):
        return '' if not obj.document else obj.document.date_published.strftime(
            '%Y-%m-%dT%H:%M:%SZ')

    def prepare_dossier(self, obj):
        return '' if not obj.document else [
            '' if not obj.document.dossier else obj.document.dossier.dossier_id
        ]

    def prepare_title(self, obj):
        return '' if not obj.document else obj.document.title_short

    def prepare_submitters(self, obj):
        if not obj.document:
            submitters = ''
        else:
            if obj.kamerantwoord:
                submitters = [
                    n.person.fullname() if n.person else ''
                    for n in obj.document.submitters
                    | obj.kamerantwoord.document.submitters
                ]
            else:
                submitters = [
                    n.person.fullname() if n.person else ''
                    for n in obj.document.submitters
                ]

        return submitters

    def prepare_parties(self, obj):
        return '' if not obj.document else [
            n.party.name_short if n.party else ''
            for n in obj.document.submitters
        ]

    def get_model(self):
        return Kamervraag

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()
コード例 #5
0
class ActIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    # faceting fields
    act_type = indexes.FacetCharField()
    is_key = indexes.FacetCharField(model_attr='is_key_yesno')
    initiative = indexes.FacetCharField()
    is_proposal = indexes.FacetCharField()
    organ = indexes.FacetCharField(
        model_attr='emitting_institution__lowername')
    pub_date = indexes.FacetDateField(model_attr='presentation_date')
    person = indexes.MultiValueField(indexed=True, stored=False)
    tags_with_urls = indexes.MultiValueField(indexed=True, stored=True)
    categories_with_urls = indexes.MultiValueField(indexed=True, stored=True)
    locations_with_urls = indexes.MultiValueField(indexed=True, stored=True)

    # stored fields, used not to touch DB
    # while showing results
    url = indexes.CharField(indexed=False, stored=True)
    title = indexes.CharField(indexed=False, stored=True, model_attr='title')

    def get_model(self):
        return Act

    def prepare_tags_with_urls(self, obj):
        d_obj = obj.downcast()
        return [
            "%s|%s" % (t.name, t.get_absolute_url()) for t in list(d_obj.tags)
        ] if d_obj else None

    def prepare_categories_with_urls(self, obj):
        d_obj = obj.downcast()
        return [
            "%s|%s" % (t.name, t.get_absolute_url())
            for t in list(d_obj.categories)
        ] if d_obj else None

    def prepare_locations_with_urls(self, obj):
        d_obj = obj.downcast()
        return [
            "%s|%s" % (t.name, t.get_absolute_url())
            for t in list(d_obj.locations)
        ] if d_obj else None

    def prepare_act_type(self, obj):
        activate(settings.LANGUAGE_CODE)
        return obj.get_type_name() if obj else None

    def prepare_initiative(self, obj):
        if obj.get_type_name() == 'delibera':
            return obj.downcast().get_initiative_display().lower(
            ) if obj.downcast() else None
        else:
            return ''

    def prepare_is_proposal(self, obj):
        if obj.get_type_name() == 'delibera':
            if obj.downcast().final_idnum == '':
                return _('yes')
            else:
                return _('no')

        else:
            return ''

    def prepare_person(self, obj):
        return set([
            p['person__slug'] for p in
            list(obj.first_signers.values('person__slug').distinct()) +
            list(obj.co_signers.values('person__slug').distinct())
        ])

    def prepare_url(self, obj):
        return obj.downcast().get_absolute_url() if obj.downcast() else None
コード例 #6
0
class VotationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    # faceting fields
    act_type = indexes.FacetCharField(default='notlinked')
    is_key = indexes.FacetCharField(model_attr='is_key_yesno')
    organ = indexes.FacetCharField(
        model_attr='sitting__institution__lowername')
    votation_date = indexes.FacetDateField(model_attr='sitting__date')

    # stored fields, used not to touch DB
    # while showing results
    url = indexes.CharField(indexed=False, stored=True)
    act_url = indexes.CharField(indexed=True, stored=True, default='')
    title = indexes.CharField(indexed=False,
                              stored=True,
                              model_attr='act__title',
                              default='')
    votation_num = indexes.CharField(indexed=False,
                                     stored=True,
                                     model_attr='idnum')
    votation_sitting_num = indexes.IntegerField(indexed=False,
                                                stored=True,
                                                model_attr='sitting__number')
    votation_n_presents = indexes.IntegerField(indexed=False,
                                               stored=True,
                                               model_attr='n_presents')
    votation_n_yes = indexes.IntegerField(indexed=False,
                                          stored=True,
                                          model_attr='n_yes')
    votation_n_no = indexes.IntegerField(indexed=False,
                                         stored=True,
                                         model_attr='n_no')
    votation_n_abst = indexes.IntegerField(indexed=False,
                                           stored=True,
                                           model_attr='n_abst')
    votation_n_maj = indexes.IntegerField(indexed=False,
                                          stored=True,
                                          model_attr='n_maj')
    votation_n_rebels = indexes.IntegerField(indexed=False,
                                             stored=True,
                                             model_attr='n_rebels')
    votation_outcome = indexes.CharField(indexed=False,
                                         stored=True,
                                         default='')

    # needed to filter votations by person
    person = indexes.MultiValueField(indexed=True, stored=False)

    def get_model(self):
        return Votation

    def prepare_url(self, obj):
        return obj.get_absolute_url()

    def prepare_act_type(self, obj):
        activate(settings.LANGUAGE_CODE)
        if obj.act:
            return obj.act.get_type_name()

    def prepare_act_url(self, obj):
        if obj.act:
            return obj.act.downcast().get_absolute_url()

    def prepare_votation_outcome(self, obj):
        return obj.get_outcome_display()

    def prepare_person(self, obj):
        return set([
            p['person__slug']
            for p in obj.charge_set.values('person__slug').distinct()
        ])
コード例 #7
0
class InstitutionChargeIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)

    first_name = indexes.CharField(model_attr='person__first_name')
    last_name = indexes.CharField(model_attr='person__last_name')
    person = indexes.CharField(model_attr='person__slug')
    institution = indexes.FacetCharField()
    group = indexes.MultiValueField(indexed=True, stored=False)
    current_group = indexes.CharField(indexed=True, stored=False)
    responsability = indexes.FacetCharField()
    group_responsability = indexes.FacetCharField()
    level = indexes.IntegerField()

    start_date = indexes.FacetDateField(model_attr='start_date')
    end_date = indexes.FacetDateField(model_attr='end_date')

    is_active = indexes.FacetCharField()

    n_presented_acts = indexes.IntegerField(indexed=True,
                                            stored=True,
                                            model_attr='n_presented_acts')
    n_received_acts = indexes.IntegerField(indexed=True,
                                           stored=True,
                                           model_attr='n_received_acts')

    n_presented_acts_index = indexes.FloatField()
    n_received_acts_index = indexes.FloatField()

    n_rebel_votations = indexes.IntegerField(indexed=False,
                                             stored=True,
                                             model_attr='n_rebel_votations')
    n_present_votations = indexes.IntegerField(
        indexed=False, stored=True, model_attr='n_present_votations')
    n_absent_votations = indexes.IntegerField(indexed=False,
                                              stored=True,
                                              model_attr='n_absent_votations')
    n_present_attendances = indexes.IntegerField(
        indexed=False, stored=True, model_attr='n_present_attendances')
    n_absent_attendances = indexes.IntegerField(
        indexed=False, stored=True, model_attr='n_absent_attendances')
    n_presents = indexes.IntegerField()

    n_present_votations_percent = indexes.FloatField()
    n_present_attendances_percent = indexes.FloatField()
    n_presents_percent = indexes.FloatField()
    n_presents_bin = indexes.FacetCharField()

    n_deliberations = indexes.IntegerField()
    n_cgdeliberations = indexes.IntegerField()
    n_agendas = indexes.IntegerField()
    n_motions = indexes.IntegerField()
    n_motions_agendas = indexes.IntegerField()
    n_amendments = indexes.IntegerField()
    n_interrogations = indexes.IntegerField()
    n_interpellations = indexes.IntegerField()
    n_audits = indexes.IntegerField()
    n_inspection_acts = indexes.IntegerField()

    n_deliberations_index = indexes.FloatField()
    n_cgdeliberations_index = indexes.FloatField()
    n_agendas_index = indexes.FloatField()
    n_motions_index = indexes.FloatField()
    n_motions_agendas_index = indexes.FloatField()
    n_amendments_index = indexes.FloatField()
    n_interrogations_index = indexes.FloatField()
    n_interpellations_index = indexes.FloatField()
    n_audits_index = indexes.FloatField()
    n_inspection_index = indexes.FloatField()

    n_speeches = indexes.IntegerField()
    n_speeches_index = indexes.FloatField()
    speeches_minutes = indexes.IntegerField()
    speeches_minutes_index = indexes.FloatField()
    speeches_minutes_index_bin = indexes.FacetCharField()

    logger = logging.getLogger('import')

    def get_model(self):
        return InstitutionCharge

    def prepare_institution(self, obj):

        activate(settings.LANGUAGE_CODE)
        return obj.charge_type if obj.institution.institution_type <= Institution.COUNCIL else ''

    def prepare_group(self, obj):

        return [
            p['group__slug']
            for p in GroupCharge.objects.select_related().filter(
                charge__id=obj.id).values('group__slug').distinct()
        ]

    def prepare_current_group(self, obj):

        return obj.current_groupcharge.group.slug if obj.current_groupcharge else ''

    def prepare_responsability(self, obj):

        if obj.responsabilities.count() >= 1:
            return obj.responsabilities[0].get_charge_type_display()

    def prepare_group_responsability(self, obj):

        try:
            return obj.current_groupcharge.current_responsability.get_charge_type_display(
            )
        except Exception, e:
            return ''
コード例 #8
0
class VotationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    # faceting fields
    act_type = indexes.FacetCharField()
    is_key = indexes.FacetCharField(model_attr='is_key_yesno')
    organ = indexes.FacetCharField(model_attr='sitting__institution__lowername')
    votation_date = indexes.FacetDateField(model_attr='sitting__date')
    n_presents_range = indexes.FacetCharField()
    gap_yes_no = indexes.FacetIntegerField()
    gap_yes_no_range = indexes.FacetCharField()

    # stored fields, used not to touch DB
    # while showing results
    url = indexes.CharField(indexed=False, stored=True)
    act_rendered = indexes.CharField(use_template=True, indexed=False)

    act_url = indexes.MultiValueField(indexed=True, stored=True)
    act_descr = indexes.CharField(indexed=False, stored=True, default='')
    title = indexes.CharField(indexed=False, stored=True, model_attr='act__title', default='')
    votation_num = indexes.CharField(indexed=False, stored=True, model_attr='idnum')
    votation_sitting_num = indexes.IntegerField(indexed=False, stored=True, model_attr='sitting__number')
    votation_n_presents = indexes.IntegerField(indexed=True, stored=True, model_attr='n_presents')
    votation_n_yes = indexes.IntegerField(indexed=True, stored=True, model_attr='n_yes')
    votation_n_no = indexes.IntegerField(indexed=True, stored=True, model_attr='n_no')
    votation_n_abst = indexes.IntegerField(indexed=True, stored=True, model_attr='n_abst')
    votation_n_maj = indexes.IntegerField(indexed=True, stored=True, model_attr='n_maj')
    votation_n_rebels = indexes.IntegerField(indexed=True, stored=True, model_attr='n_rebels', faceted=True)
    votation_outcome = indexes.IntegerField(indexed=False, stored=True, model_attr='outcome')
    votation_outcome_display = indexes.FacetCharField(stored=True, default='')
    is_secret = indexes.FacetCharField(stored=True, default='')
    month = indexes.FacetCharField()

    # needed to filter votations by person or charge
    person = indexes.MultiValueField(indexed=True, stored=False)
    charge = indexes.MultiValueField(indexed=True, stored=False)
    charge_present = indexes.MultiValueField(indexed=True, stored=False)
    charge_absent = indexes.MultiValueField(indexed=True, stored=False)
    charge_rebel = indexes.MultiValueField(indexed=True, stored=False)

    def get_model(self):
        return Votation

    def prepare_url(self, obj):
        return obj.get_absolute_url()

    def prepare_act_type(self, obj):
        activate(settings.LANGUAGE_CODE)

        res = _('none')

        related_act = obj.act

        if not related_act:
            transitions = Transition.objects.filter(votation=obj)
            if len(transitions) > 0:
                related_act = transitions[0].act

        if related_act:
            res = related_act.get_type_name()

        return res


    def prepare_act_descr(self, obj):

        res = obj.act_descr

        related_act = obj.act

        if not related_act:
            transitions = Transition.objects.filter(votation=obj)

            if len(transitions) > 0:
                related_act = transitions[0].act

        if related_act:
            res = related_act.adj_title or related_act.title

        return res
        

    def prepare_act_url(self, obj):

        res = set([])

        related_act = obj.act

        if not related_act:

            transitions = Transition.objects.filter(votation=obj)
            if len(transitions) > 0:
                related_act = transitions[0].act

        if related_act:
            res = set([ related_act.downcast().get_absolute_url() ])

        return res


    def prepare_month(self, obj):
        return obj.sitting.date.strftime("%B")

    def prepare_votation_outcome_display(self, obj):
        return obj.get_outcome_display()

    def prepare_person(self, obj):
        return set(
            [p['person__slug'] for p in obj.charge_set.values('person__slug').distinct()]
        )

    def prepare_charge(self, obj):
        return set(
            [p['id'] for p in obj.charge_set.values('id').distinct()]
        ) | \
        set(
            [p['original_charge__id'] for p in obj.charge_set.values('original_charge__id').distinct()]
        )

    def prepare_charge_present(self, obj):
        s = set()
        
        for cv in obj.chargevote_set.filter(
            vote__in=[ChargeVote.VOTES.yes,
                      ChargeVote.VOTES.no,
                      ChargeVote.VOTES.abstained,
                      ChargeVote.VOTES.pres,
                      ChargeVote.VOTES.secret]):

            s.add(cv.charge.id)
            if cv.charge.original_charge: s.add(cv.charge.original_charge.id)
        
        return s

    def prepare_charge_absent(self, obj):
        s = set()
        
        for cv in obj.chargevote_set.filter(vote=ChargeVote.VOTES.absent):
            s.add(cv.charge.id)
            if cv.charge.original_charge: s.add(cv.charge.original_charge.id)
        
        return s

    def prepare_charge_rebel(self, obj):
        #return set(
        #    [cv['charge__id'] for cv in obj.chargevote_set.filter(is_rebel=True).values('charge__id').distinct()]
        #)
        s = set()
        for cv in obj.chargevote_set.filter(is_rebel=True):
            s.add(cv.charge.id)
        return s
 
    def prepare_n_presents_range(self, obj):

        charges_count = obj.charges_count
        if charges_count > 0:
            decimal = 10 * obj.n_presents / charges_count
            return str(10 * decimal) + '% - ' + str(10 * (decimal + 1) - 1) + '%' \
                if decimal < 10 else '100%'

    def prepare_gap_yes_no(self, obj):

        return abs(obj.n_yes - obj.n_no)

    def prepare_gap_yes_no_range(self, obj):

        v = abs(obj.n_yes - obj.n_no)

        if v <= 2: return '1 - 2'
        elif 3 <= v <= 6: return '3 - 6'
        elif 7 <= v <= 15: return '7 - 15'
        elif 16 <= v <= 22: return '16 - 22'
        else: return '23+'

    def prepare_is_secret(self, obj):

        activate(settings.LANGUAGE_CODE)

        if obj.is_secret:
            return _('yes')
        else:
            return _('no')
        

    def prepare_properties(self, obj):

        activate(settings.LANGUAGE_CODE)

        count = obj.majority_vs_minority

        may_presents = count['majority'].get('YES', 0) + count['majority'].get('NO', 0) + \
            count['majority'].get('ABSTAINED', 0) + count['majority'].get('PRES', 0) + \
            count['majority'].get('SECRET', 0)

        min_presents = count['minority'].get('YES', 0) + count['minority'].get('NO', 0) + \
            count['minority'].get('ABSTAINED', 0) + count['minority'].get('PRES', 0) + \
            count['minority'].get('SECRET', 0)

        total_presents = may_presents + min_presents

        may_partecipants = count['majority'].get('YES', 0) + count['majority'].get('NO', 0)
        min_partecipants = count['minority'].get('YES', 0) + count['minority'].get('NO', 0)
        total_partecipants = may_partecipants + min_partecipants

        quorum = (total_partecipants / 2) + 1

        total_yes = count['majority'].get('YES', 0) + count['minority'].get('YES', 0)
        total_no = count['majority'].get('NO', 0) + count['minority'].get('NO', 0)
        total_abst = count['majority'].get('ABSTAINED', 0) + count['minority'].get('ABSTAINED', 0)
        total_pres = count['majority'].get('PRES', 0) + count['minority'].get('PRES', 0)

        if obj.outcome == 1:
            outcome = 'YES'
        elif obj.outcome == 2:
            outcome = 'NO'

        properties = []

        # no numero legale
        if (may_presents < 16):
            properties.append(_("minority decisive for legal number"))

        if ('SECRET' not in count['majority']):

            # si e no si equivalgono: outcome NO
            if total_yes == total_no: quorum = total_yes;

            # minoranza decisiva
            if (count['majority'][outcome] < quorum):
                properties.append(_("minority decisive for outcome"))

        return set(properties)