models.py 1.03 KB
Newer Older
Jamesie Pic's avatar
Jamesie Pic committed
1
2
3
4
5
6
# coding: utf-8
from django.db import models

from representatives_votes.contrib.parltrack.import_votes import \
    vote_pre_import
from representatives_votes.models import Dossier, Proposal, Vote
7

Jamesie Pic's avatar
Jamesie Pic committed
8
9
10
11
12
13
14
15
16
17

class Recommendation(models.Model):
    proposal = models.OneToOneField(
        Proposal,
        related_name='recommendation'
    )

    recommendation = models.CharField(max_length=10, choices=Vote.VOTECHOICES)
    title = models.CharField(max_length=1000, blank=True)
    description = models.TextField(blank=True)
18
    weight = models.FloatField(default=0)
Jamesie Pic's avatar
Jamesie Pic committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

    class Meta:
        ordering = ['proposal__datetime']


def skip_votes(sender, vote_data=None, **kwargs):
    dossiers = getattr(sender, 'memopol_filters', None)

    if dossiers is None:
        sender.memopol_filters = dossiers = Dossier.objects.filter(
            proposals__recommendation__in=Recommendation.objects.all()
        ).values_list('reference', flat=True)

    if vote_data.get('epref', None) not in dossiers:
        return False
alexandre.jauneau's avatar
alexandre.jauneau committed
34
35


Jamesie Pic's avatar
Jamesie Pic committed
36
vote_pre_import.connect(skip_votes)