Skip to content

Commit

Permalink
chore: Fix E128
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Dec 10, 2023
1 parent 434238a commit ebd5ddc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 32 deletions.
83 changes: 57 additions & 26 deletions representatives/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ class MyAppConf(AppConf):


class BaseRepresentativeSet(models.Model):
name = models.CharField(max_length=300,
name = models.CharField(
max_length=300,
unique=True,
help_text="The name of the political body, e.g. House of Commons",
unique=True)
)
data_url = models.URLField(help_text="URL to a JSON array of individuals within this set")
data_about_url = models.URLField(blank=True, help_text="URL to information about the scraper used to gather data")
last_import_time = models.DateTimeField(blank=True, null=True)
last_import_successful = models.BooleanField(blank=True, null=True)
boundary_set = models.CharField(max_length=300, blank=True,
help_text="Name of the boundary set on the boundaries API, e.g. federal-electoral-districts")
boundary_set = models.CharField(
blank=True,
max_length=300,
help_text="Name of the boundary set on the boundaries API, e.g. federal-electoral-districts",
)
slug = models.SlugField(max_length=300, unique=True, db_index=True)
enabled = models.BooleanField(default=True, blank=True, db_index=True)

Expand Down Expand Up @@ -133,10 +138,21 @@ def update_from_data_source(self):

for source_rep in data:
rep = self.create_child()
for fieldname in ('name', 'district_name', 'elected_office',
'source_url', 'first_name', 'last_name', 'party_name',
'email', 'url', 'personal_url', 'photo_url', 'district_id',
'gender'):
for fieldname in (
'name',
'district_name',
'elected_office',
'source_url',
'first_name',
'last_name',
'party_name',
'email',
'url',
'personal_url',
'photo_url',
'district_id',
'gender',
):
if source_rep.get(fieldname) is not None:
setattr(rep, fieldname, source_rep[fieldname])
for json_fieldname in ('offices', 'extra'):
Expand Down Expand Up @@ -195,13 +211,13 @@ def create_child(self):
return Representative(representative_set=self)

def get_absolute_url(self):
return reverse('representatives_representative_set_detail',
kwargs={'slug': self.slug})
return reverse('representatives_representative_set_detail', kwargs={'slug': self.slug})

def as_dict(self):
r = super().as_dict()
r['related']['representatives_url'] = reverse(
'representatives_representative_list', kwargs={'set_slug': self.slug})
'representatives_representative_list', kwargs={'set_slug': self.slug}
)
return r


Expand All @@ -212,8 +228,7 @@ def create_child(self):
return Candidate(election=self)

def get_absolute_url(self):
return reverse('representatives_election_detail',
kwargs={'slug': self.slug})
return reverse('representatives_election_detail', kwargs={'slug': self.slug})

def as_dict(self):
r = super().as_dict()
Expand All @@ -240,19 +255,21 @@ class BaseRepresentative(models.Model):
district_name = models.CharField(max_length=300)
elected_office = models.CharField(max_length=200)
source_url = models.URLField(max_length=2048)
boundary = models.CharField(max_length=300, blank=True, db_index=True,
help_text="e.g. federal-electoral-districts/outremont")
first_name = models.CharField(max_length=200, blank=True)
last_name = models.CharField(max_length=200, blank=True)
party_name = models.CharField(max_length=200, blank=True)
boundary = models.CharField(
blank=True,
max_length=300,
db_index=True,
help_text="e.g. federal-electoral-districts/outremont",
)
first_name = models.CharField(blank=True, max_length=200)
last_name = models.CharField(blank=True, max_length=200)
party_name = models.CharField(blank=True, max_length=200)
email = models.EmailField(blank=True)
url = models.URLField(blank=True, max_length=2048)
personal_url = models.URLField(blank=True, max_length=2048)
photo_url = models.URLField(blank=True, max_length=2048)
district_id = models.CharField(max_length=200, blank=True)
gender = models.CharField(max_length=1, blank=True, choices=(
('F', 'Female'),
('M', 'Male')))
district_id = models.CharField(blank=True, max_length=200)
gender = models.CharField(blank=True, max_length=1, choices=(('F', 'Female'), ('M', 'Male')))
offices = JSONField(default=list)
extra = JSONField(default=dict)

Expand All @@ -268,10 +285,24 @@ def boundary_url(self):
return '/boundaries/%s/' % self.boundary if self.boundary else ''

def as_dict(self):
r = {f: getattr(self, f) for f in
('name', 'district_name', 'elected_office', 'source_url',
'first_name', 'last_name', 'party_name', 'email', 'url', 'personal_url',
'photo_url', 'gender', 'offices', 'extra')}
r = {
f: getattr(self, f) for f in (
'name',
'district_name',
'elected_office',
'source_url',
'first_name',
'last_name',
'party_name',
'email',
'url',
'personal_url',
'photo_url',
'gender',
'offices',
'extra',
)
}
set_obj = getattr(self, self.set_name)
r[self.set_name + '_name'] = set_obj.name
r['related'] = {
Expand Down
12 changes: 8 additions & 4 deletions representatives/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
re_path(r'^representatives/(?P<set_slug>[\w_-]+)/$', RepresentativeListView.as_view(), name='representatives_representative_list'),
re_path(r'^boundaries/(?P<slug>[\w_-]+/[\w_-]+)/representatives/', RepresentativeListView.as_view()),
path('representative-sets/', RepresentativeSetListView.as_view()),
re_path(r'^representative-sets/(?P<slug>[\w_-]+)/$', RepresentativeSetDetailView.as_view(),
name='representatives_representative_set_detail'),
re_path(
r'^representative-sets/(?P<slug>[\w_-]+)/$', RepresentativeSetDetailView.as_view(),
name='representatives_representative_set_detail'
),
]

if app_settings.ENABLE_CANDIDATES:
Expand All @@ -25,6 +27,8 @@
re_path(r'^candidates/(?P<set_slug>[\w_-]+)/$', CandidateListView.as_view(), name='representatives_candidate_list'),
re_path(r'^boundaries/(?P<slug>[\w_-]+/[\w_-]+)/candidates/$', CandidateListView.as_view()),
path('elections/', ElectionListView.as_view()),
re_path(r'^elections/(?P<slug>[\w_-]+)/$', ElectionDetailView.as_view(),
name='representatives_election_detail'),
re_path(
r'^elections/(?P<slug>[\w_-]+)/$', ElectionDetailView.as_view(),
name='representatives_election_detail'
),
]
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ profile = black
[flake8]
exclude = representatives/migrations
extend-ignore =
# E128 continuation line under-indented for visual indent
E128,
# E501 line too long (X > 79 characters)
E501

0 comments on commit ebd5ddc

Please sign in to comment.