Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #662 from alonisser/bugfix_635_629
Browse files Browse the repository at this point in the history
Bugfix 635 629 Bill statistics calculation and bill queryset  display fixing logic
  • Loading branch information
OriHoch committed May 1, 2016
2 parents 4877802 + 25a893a commit dfa66e7
Show file tree
Hide file tree
Showing 38 changed files with 1,852 additions and 1,600 deletions.
281 changes: 150 additions & 131 deletions agendas/models.py

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions knesset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def reverse_with_query(viewname, args=None, kwargs=None, query_kwargs=None):

return requested_url


def send_chat_notification(file, text, data):
from django_slack import slack_message
if getattr(settings, 'SLACK_BACKEND', None) in (None, 'django_slack.backends.DisabledBackend'):
Expand All @@ -183,8 +184,21 @@ def send_chat_notification(file, text, data):
print text
print "----"
else:
slack_message('django-slack/text.slack', {"text" : text})
slack_message('django-slack/text.slack', {"text": text})


def send_chat_exception_notification(file, text_prefix, data, exception):
data.update({'traceback': traceback.format_exc()})
send_chat_notification(file, text_prefix+" "+str(exception.message), data)
send_chat_notification(file, text_prefix + " " + str(exception.message), data)


def get_thousands_string(f):
"""
Get a nice string representation of a field of 1000's of NIS, which is int or None.
"""
if f is None:
return "N/A"
elif f == 0:
return "0 NIS"
else:
return "%d000 NIS" % f
1 change: 1 addition & 0 deletions laws/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
'''
API for the laws app
'''
Expand Down
2 changes: 2 additions & 0 deletions laws/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# encoding: utf-8
import datetime

STANDS_FOR_THRESHOLD = 0.66
FIRST_KNESSET_START = datetime.date(1948, 5, 13)
CONVERT_TO_DISCUSSION_HEADERS = ('להעביר את הנושא'.decode('utf8'), 'העברת הנושא'.decode('utf8'))
10 changes: 10 additions & 0 deletions laws/enums.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.utils.translation import ugettext_lazy as _

from knesset.enums import Enum


Expand All @@ -14,3 +16,11 @@ class BillStages(Enum):
COMMITTEE_CORRECTIONS = u'5'
APPROVED = u'6'
FAILED_APPROVAL = u'-6'


VOTE_ACTION_TYPE_CHOICES = (
(u'for', _('For')),
(u'against', _('Against')),
(u'abstain', _('Abstain')),
(u'no-vote', _('No Vote')),
)
5 changes: 3 additions & 2 deletions laws/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# encoding: utf-8
from datetime import date

from django import forms
from django.utils.translation import ugettext_lazy as _
from tagging.models import Tag

from laws.constants import CONVERT_TO_DISCUSSION_HEADERS
from mks.models import Knesset
from models import (Vote, Bill, BillBudgetEstimation,
CONVERT_TO_DISCUSSION_HEADERS)
from models import (Vote, Bill, BillBudgetEstimation)
from vote_choices import (ORDER_CHOICES, TAGGED_CHOICES, TYPE_CHOICES,
SIMPLE_TYPE_CHOICES, BILL_TAGGED_CHOICES,
BILL_STAGE_CHOICES, BILL_AGRR_STAGES)
Expand Down
54 changes: 41 additions & 13 deletions laws/listeners.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,87 @@
#encoding: utf-8
# encoding: utf-8
from django.db.models.signals import m2m_changed, post_save
from django.contrib.contenttypes.models import ContentType
from actstream import action
from actstream.models import Action
from tagging.models import TaggedItem

from knesset.utils import cannonize, disable_for_loaddata
from laws.models.bill import Bill
from laws.models.candidate_list_model_statistics import CandidateListVotingStatistics
from laws.models.member_voting_statistics import MemberVotingStatistics
from laws.models.party_voting_statistics import PartyVotingStatistics
from laws.models.proposal import PrivateProposal
from laws.models.vote_action import VoteAction
from mks.models import Member, Party
from laws.models import PrivateProposal, VoteAction, MemberVotingStatistics,\
PartyVotingStatistics, CandidateListVotingStatistics

from polyorg.models import CandidateList
from ok_tag.models import add_tags_to_related_objects

def record_bill_proposal(**kwargs):
if kwargs['action'] != "post_add":
return
private_proposal_ct = ContentType.objects.get(app_label="laws", model="privateproposal")
member_ct = ContentType.objects.get(app_label="mks", model="member")
proposal = kwargs['instance']
if str(kwargs['sender']).find('proposers')>=0:
if str(kwargs['sender']).find('proposers') >= 0:
verb = 'proposed'
else:
verb = 'joined'
for mk_id in kwargs['pk_set']:
if Action.objects.filter(actor_object_id=mk_id, actor_content_type=member_ct, verb=verb, target_object_id=proposal.id,
target_content_type=private_proposal_ct).count()==0:
if Action.objects.filter(actor_object_id=mk_id, actor_content_type=member_ct, verb=verb,
target_object_id=proposal.id,
target_content_type=private_proposal_ct).count() == 0:
mk = Member.objects.get(pk=mk_id)
action.send(mk, verb=verb, target=proposal, timestamp=proposal.date)


m2m_changed.connect(record_bill_proposal, sender=PrivateProposal.proposers.through)
m2m_changed.connect(record_bill_proposal, sender=PrivateProposal.joiners.through) # same code handles both events
m2m_changed.connect(record_bill_proposal, sender=PrivateProposal.joiners.through) # same code handles both events


@disable_for_loaddata
def record_vote_action(sender, created, instance, **kwargs):
if created:
action.send(instance.member, verb='voted',
description=instance.get_type_display(),
target = instance.vote,
target=instance.vote,
timestamp=instance.vote.time)
post_save.connect(record_vote_action, sender=VoteAction,
dispatch_uid='vote_action_record_member' )


post_save.connect(record_vote_action, sender=VoteAction,
dispatch_uid='vote_action_record_member')


@disable_for_loaddata
def handle_candiate_list_save(sender, created, instance, **kwargs):
if instance._state.db=='default':
if instance._state.db == 'default':
CandidateListVotingStatistics.objects.get_or_create(candidates_list=instance)


post_save.connect(handle_candiate_list_save, sender=CandidateList)


@disable_for_loaddata
def handle_party_save(sender, created, instance, **kwargs):
if created and instance._state.db=='default':
if created and instance._state.db == 'default':
PartyVotingStatistics.objects.get_or_create(party=instance)


post_save.connect(handle_party_save, sender=Party)


@disable_for_loaddata
def handle_mk_save(sender, created, instance, **kwargs):
if created and instance._state.db=='default':
if created and instance._state.db == 'default':
MemberVotingStatistics.objects.get_or_create(member=instance)


post_save.connect(handle_mk_save, sender=Member)


def add_tags_to_bill_related_objects(sender, instance, **kwargs):
bill_ct = ContentType.objects.get_for_model(instance)
for ti in TaggedItem.objects.filter(content_type=bill_ct, object_id=instance.id):
add_tags_to_related_objects(sender, ti, **kwargs)

post_save.connect(add_tags_to_bill_related_objects, sender=Bill)
20 changes: 7 additions & 13 deletions laws/management/commands/export_votes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# encoding: utf-8
import os, csv
from operator import attrgetter
from django.core.management.base import NoArgsCommand
from django.conf import settings

from tagging.models import Tag, TaggedItem
from tagging.models import Tag

from mks.models import Member,Party
from laws.models import Vote,VoteAction,Bill
from mks.models import Member
from laws.models import Vote, Bill

class Command(NoArgsCommand):

class Command(NoArgsCommand):
def handle_noargs(self, **options):
mks = Member.objects.order_by('current_party__is_coalition','current_party__name')\
.values('id','name','current_party__name')
mks = Member.objects.order_by('current_party__is_coalition', 'current_party__name') \
.values('id', 'name', 'current_party__name')
f = open(os.path.join(settings.DATA_ROOT, 'mks.csv'), 'wt')
mk_writer = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
for mk in mks:
Expand Down Expand Up @@ -73,10 +74,3 @@ def handle_noargs(self, **options):

f.close()
f2.close()







1 change: 1 addition & 0 deletions laws/management/commands/freeze_bills.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
from __future__ import print_function

from django.core.management.base import BaseCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
from __future__ import print_function

from django.core.management.base import BaseCommand
Expand Down
5 changes: 1 addition & 4 deletions laws/management/commands/scrape_votes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8
from knesset_data.dataservice.votes import Vote as DataserviceVote, VoteMember as DataserviceVoteMember
from knesset_data.dataservice.votes import Vote as DataserviceVote
from knesset_data.html_scrapers.votes import HtmlVote
from laws.models import Vote, VoteAction
from simple.scrapers import hebrew_strftime
Expand All @@ -8,9 +8,6 @@
from simple.management.commands.syncdata import Command as SyncdataCommand
from links.models import Link
from django.contrib.contenttypes.models import ContentType
from optparse import make_option
from sys import stdout
import csv


class VoteScraperException(Exception):
Expand Down
52 changes: 26 additions & 26 deletions laws/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from south.db import db
from django.db import models
from laws.models import *


class Migration:

def forwards(self, orm):

# Adding model 'VoteAction'
db.create_table('laws_voteaction', (
('id', orm['laws.VoteAction:id']),
Expand All @@ -17,14 +14,14 @@ def forwards(self, orm):
('against_opposition', orm['laws.VoteAction:against_opposition']),
))
db.send_create_signal('laws', ['VoteAction'])

# Adding model 'PartyVotingStatistics'
db.create_table('laws_partyvotingstatistics', (
('id', orm['laws.PartyVotingStatistics:id']),
('party', orm['laws.PartyVotingStatistics:party']),
))
db.send_create_signal('laws', ['PartyVotingStatistics'])

# Adding model 'Vote'
db.create_table('laws_vote', (
('id', orm['laws.Vote:id']),
Expand All @@ -41,55 +38,55 @@ def forwards(self, orm):
('full_text_url', orm['laws.Vote:full_text_url']),
))
db.send_create_signal('laws', ['Vote'])

# Adding model 'MemberVotingStatistics'
db.create_table('laws_membervotingstatistics', (
('id', orm['laws.MemberVotingStatistics:id']),
('member', orm['laws.MemberVotingStatistics:member']),
))
db.send_create_signal('laws', ['MemberVotingStatistics'])




def backwards(self, orm):

# Deleting model 'VoteAction'
db.delete_table('laws_voteaction')

# Deleting model 'PartyVotingStatistics'
db.delete_table('laws_partyvotingstatistics')

# Deleting model 'Vote'
db.delete_table('laws_vote')

# Deleting model 'MemberVotingStatistics'
db.delete_table('laws_membervotingstatistics')




models = {
'laws.membervotingstatistics': {
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'member': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'voting_statistics'", 'unique': 'True', 'to': "orm['mks.Member']"})
'member': ('django.db.models.fields.related.OneToOneField', [],
{'related_name': "'voting_statistics'", 'unique': 'True', 'to': "orm['mks.Member']"})
},
'laws.partyvotingstatistics': {
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'party': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'voting_statistics'", 'unique': 'True', 'to': "orm['mks.Party']"})
'party': ('django.db.models.fields.related.OneToOneField', [],
{'related_name': "'voting_statistics'", 'unique': 'True', 'to': "orm['mks.Party']"})
},
'laws.vote': {
'full_text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'full_text_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'full_text_url': (
'django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'importance': ('django.db.models.fields.FloatField', [], {}),
'meeting_number': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'src_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'src_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'src_url': (
'django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'summary': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'time': ('django.db.models.fields.DateTimeField', [], {}),
'time_string': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'vote_number': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'votes': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['mks.Member']", 'blank': 'True'})
'votes': (
'django.db.models.fields.related.ManyToManyField', [], {'to': "orm['mks.Member']", 'blank': 'True'})
},
'laws.voteaction': {
'against_coalition': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
Expand All @@ -101,12 +98,14 @@ def backwards(self, orm):
'vote': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['laws.Vote']"})
},
'mks.member': {
'current_party': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'members'", 'null': 'True', 'to': "orm['mks.Party']"}),
'current_party': ('django.db.models.fields.related.ForeignKey', [],
{'blank': 'True', 'related_name': "'members'", 'null': 'True', 'to': "orm['mks.Party']"}),
'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'date_of_death': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'family_status': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
'family_status': (
'django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
'fax': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'img_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
Expand All @@ -115,7 +114,8 @@ def backwards(self, orm):
'number_of_children': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'parties': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['mks.Party']"}),
'phone': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
'place_of_birth': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'place_of_birth': (
'django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'start_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'year_of_aliyah': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
Expand All @@ -130,5 +130,5 @@ def backwards(self, orm):
'start_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'})
}
}

complete_apps = ['laws']
Loading

0 comments on commit dfa66e7

Please sign in to comment.