This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
forked from ofri/Open-Knesset
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #763 from alonisser/master
Mostly vote issues + syncdata cleanup
- Loading branch information
Showing
15 changed files
with
252 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -* | ||
from laws.enums import VOTE_TYPES | ||
|
||
|
||
def resolve_vote_type_by_title(title): | ||
if type(title) == str: | ||
transform_func = str.decode | ||
else: # its already unicode, do nothing | ||
transform_func = lambda x, y: x | ||
for vtype, vtype_prefix in VOTE_TYPES.items(): | ||
if transform_func(title, 'utf8').startswith(vtype_prefix): | ||
return vtype | ||
return '' | ||
|
||
|
||
class MissingVotePartyException(Exception): | ||
pass | ||
|
||
|
||
def party_at_or_error(member, vote_date, vote_id): | ||
party = member.party_at(vote_date) | ||
if party: | ||
return party | ||
else: | ||
raise MissingVotePartyException( | ||
'could not find which party member %s belonged to during vote %s' % (member.pk, vote_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# encoding: utf-8 | ||
from __future__ import print_function | ||
from laws.management.commands.scrape_votes import Command as ScrapeVotesCommand | ||
from django.core.management.base import BaseCommand | ||
from optparse import make_option | ||
|
||
from django.db.models import Q | ||
|
||
from laws.models import Vote | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Rescrape data for votes missing actual voting data" | ||
|
||
option_list = BaseCommand.option_list + ( | ||
make_option( | ||
'-n', action='store_true', dest="dryrun", default=False, | ||
help='Dry run, changes nothing in the db, just display results' | ||
), | ||
) | ||
|
||
def handle(self, *args, **options): | ||
votes_to_update = Vote.objects.filter(Q(votes_count=0) | Q(votes_count=None)) | ||
logger.info('Found %s votes with missing data' % votes_to_update.count()) | ||
if options['dryrun']: | ||
logger.info("Not updating the db, dry run was specified") | ||
return | ||
|
||
votes_ids = votes_to_update.values_list('pk', flat=True) | ||
ScrapeVotesCommand().recreate_objects(votes_ids) | ||
logger.info(u'Completed re scraping votes %s' % votes_ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.