Skip to content

Commit

Permalink
Include N/A party, load parties if missing when loading candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonje committed May 19, 2017
1 parent f83e458 commit 33a3e8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
12 changes: 11 additions & 1 deletion calaccess_processed/management/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from bs4 import BeautifulSoup
from datetime import datetime
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.core.exceptions import MultipleObjectsReturned
from django.utils.termcolors import colorize
from calaccess_raw import get_download_directory
from calaccess_raw.models import FilerToFilerTypeCd
from calaccess_processed.decorators import retry
from django.core.management.base import BaseCommand
from opencivicdata.management.commands.loaddivisions import load_divisions
from opencivicdata.models import (
Division,
Expand Down Expand Up @@ -519,6 +520,15 @@ def lookup_party(self, party):
"""
Return a Party with a name or abbreviation that matches party.
"""
if not Party.objects.exists():
if self.verbosity > 2:
self.log(" No parties loaded.")
call_command(
'loadparties',
verbosity=self.verbosity,
no_color=self.no_color,
)

try:
# first by full name
party = Party.objects.get(name=party)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ def load(self):
ocd_election = self.get_ocd_election(scraped_election)
# then over candidates in the scraped_election
for scraped_candidate in scraped_election.candidates.all():
if self.verbosity > 2:
self.log(
' Processing ScrapedCandidate.id %s' % scraped_candidate.id
)
candidacy = self.add_scraped_candidate_to_election(
scraped_candidate,
ocd_election
Expand Down
9 changes: 3 additions & 6 deletions calaccess_processed/management/commands/loadparties.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ def load(self):
"""
Insert Party records from the raw LOOKUP_CODES_CD table.
"""
q = LookupCodesCd.objects.filter(
code_type=16000,
code_id__gt=16000,
)
q = LookupCodesCd.objects.filter(code_type=16000).exclude(code_id=16000)

for lc in q:
party, created = Party.objects.get_or_create(
Expand All @@ -53,10 +50,10 @@ def load(self):
party.color = '1d0ee9'
if party.name == 'REPUBLICAN':
party.color = 'e91d0e'
party.save()
elif party.name == 'UNKNOWN':
party.name = 'UNKNOWN PARTY'
party.save()

party.save()

# keep the code_id too
p_id, created = party.identifiers.get_or_create(
Expand Down

0 comments on commit 33a3e8b

Please sign in to comment.