From cef4ac83ea6e9946fbec4bd9ff41e7385720ee3f Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Sun, 10 Dec 2023 00:36:10 -0500 Subject: [PATCH] chore: Fix E501 --- representatives/admin.py | 10 ++++++---- .../commands/updaterepresentatives.py | 8 ++++++-- representatives/models.py | 11 ++++++----- representatives/urls.py | 18 ++++++++++++++---- representatives/views.py | 7 +++++-- setup.cfg | 4 +--- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/representatives/admin.py b/representatives/admin.py index c304348..888aa34 100644 --- a/representatives/admin.py +++ b/representatives/admin.py @@ -25,15 +25,17 @@ def update_from_data_source(self, request, queryset): try: count = individual_set.update_from_data_source() except Exception: - messages.error(request, "Couldn't update individuals in {}: {}".format(individual_set, traceback.format_exc())) + messages.error(request, f"Couldn't update individuals in {individual_set}: {traceback.format_exc()}") continue if count is False: - messages.error(request, "Couldn't update individuals in %s." % individual_set) + messages.error(request, f"Couldn't update individuals in {individual_set}.") else: - message = "Updated {} individuals in {}.".format(count, individual_set) + message = f"Updated {count} individuals in {individual_set}." no_boundaries = individual_set.individuals.filter(boundary='').values_list('name', flat=True) if no_boundaries: - messages.warning(request, message + " %d match no boundary (%s)." % (len(no_boundaries), ', '.join(no_boundaries))) + messages.warning( + request, message + f" {len(no_boundaries)} match no boundary ({', '.join(no_boundaries)})." + ) else: messages.success(request, message) diff --git a/representatives/management/commands/updaterepresentatives.py b/representatives/management/commands/updaterepresentatives.py index 4623b74..cee7f11 100644 --- a/representatives/management/commands/updaterepresentatives.py +++ b/representatives/management/commands/updaterepresentatives.py @@ -12,9 +12,13 @@ class Command(BaseCommand): help = 'Updates representatives from sources.' def handle(self, *args, **options): - for representative_set in itertools.chain(RepresentativeSet.objects.filter(enabled=True), Election.objects.filter(enabled=True)): + for representative_set in itertools.chain( + RepresentativeSet.objects.filter(enabled=True), Election.objects.filter(enabled=True) + ): try: representative_set.update_from_data_source() except Exception: log.error("Couldn't update representatives in %s." % representative_set) - representative_set.__class__.objects.filter(pk=representative_set.pk).update(last_import_successful=False) + representative_set.__class__.objects.filter(pk=representative_set.pk).update( + last_import_successful=False + ) diff --git a/representatives/models.py b/representatives/models.py index 1add873..6509727 100644 --- a/representatives/models.py +++ b/representatives/models.py @@ -160,7 +160,7 @@ def update_from_data_source(self): try: setattr(rep, json_fieldname, json.loads(source_rep.get(json_fieldname))) except ValueError: - raise Exception("Invalid JSON in {}: {}".format(json_fieldname, source_rep.get(json_fieldname))) + raise Exception(f"Invalid JSON in {json_fieldname}: {source_rep.get(json_fieldname)}") if isinstance(getattr(rep, json_fieldname), list): for d in getattr(rep, json_fieldname): if isinstance(d, dict): @@ -175,7 +175,7 @@ def update_from_data_source(self): rep.incumbent = False if not source_rep.get('name'): - rep.name = ' '.join([component for component in [source_rep.get('first_name'), source_rep.get('last_name')] if component]) + rep.name = ' '.join([c for c in [source_rep.get('first_name'), source_rep.get('last_name')] if c]) if not source_rep.get('first_name') and not source_rep.get('last_name'): (rep.first_name, rep.last_name) = split_name(rep.name) @@ -190,7 +190,9 @@ def update_from_data_source(self): boundary_url = boundary_names.get(get_comparison_string(rep.district_name)) if not boundary_url: - logger.warning("{}: Couldn't find district boundary {} in {}".format(self.slug, rep.district_name, self.boundary_set)) + logger.warning( + "%s: Couldn't find district boundary %s in %s", self.slug, rep.district_name, self.boundary_set + ) else: rep.boundary = boundary_url_to_name(boundary_url) if not rep.district_name: @@ -277,8 +279,7 @@ class Meta: abstract = True def __str__(self): - return "{} ({} for {})".format( - self.name, self.elected_office, self.district_name) + return f"{self.name} ({self.elected_office} for {self.district_name})" @property def boundary_url(self): diff --git a/representatives/urls.py b/representatives/urls.py index addbb50..10ae039 100644 --- a/representatives/urls.py +++ b/representatives/urls.py @@ -12,11 +12,16 @@ urlpatterns = [ path('representatives/', RepresentativeListView.as_view()), - re_path(r'^representatives/(?P[\w_-]+)/$', RepresentativeListView.as_view(), name='representatives_representative_list'), + re_path( + r'^representatives/(?P[\w_-]+)/$', + RepresentativeListView.as_view(), + name='representatives_representative_list', + ), re_path(r'^boundaries/(?P[\w_-]+/[\w_-]+)/representatives/', RepresentativeListView.as_view()), path('representative-sets/', RepresentativeSetListView.as_view()), re_path( - r'^representative-sets/(?P[\w_-]+)/$', RepresentativeSetDetailView.as_view(), + r'^representative-sets/(?P[\w_-]+)/$', + RepresentativeSetDetailView.as_view(), name='representatives_representative_set_detail' ), ] @@ -24,11 +29,16 @@ if app_settings.ENABLE_CANDIDATES: urlpatterns += [ path('candidates/', CandidateListView.as_view()), - re_path(r'^candidates/(?P[\w_-]+)/$', CandidateListView.as_view(), name='representatives_candidate_list'), + re_path( + r'^candidates/(?P[\w_-]+)/$', + CandidateListView.as_view(), + name='representatives_candidate_list', + ), re_path(r'^boundaries/(?P[\w_-]+/[\w_-]+)/candidates/$', CandidateListView.as_view()), path('elections/', ElectionListView.as_view()), re_path( - r'^elections/(?P[\w_-]+)/$', ElectionDetailView.as_view(), + r'^elections/(?P[\w_-]+)/$', + ElectionDetailView.as_view(), name='representatives_election_detail' ), ] diff --git a/representatives/views.py b/representatives/views.py index e792d66..b995fe2 100644 --- a/representatives/views.py +++ b/representatives/views.py @@ -50,11 +50,14 @@ def filter(self, request, qs): if 'point' in request.GET: if app_settings.RESOLVE_POINT_REQUESTS_OVER_HTTP: url = app_settings.BOUNDARYSERVICE_URL + 'boundaries/?' + urlencode({'contains': request.GET['point']}) - boundaries = [boundary_url_to_name(boundary['url']) for boundary in json.loads(urlopen(url).read().decode())['objects']] + boundaries = [ + boundary_url_to_name(boundary['url']) + for boundary in json.loads(urlopen(url).read().decode())['objects'] + ] else: try: latitude, longitude = re.sub(r'[^\d.,-]', '', request.GET['point']).split(',') - wkt = 'POINT({} {})'.format(longitude, latitude) + wkt = f'POINT({longitude} {latitude})' boundaries = Boundary.objects.filter(shape__contains=wkt).values_list('set_id', 'slug') except ValueError: raise BadRequest("Invalid latitude,longitude '%s' provided." % request.GET['point']) diff --git a/setup.cfg b/setup.cfg index bdd9d69..95cada6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,5 @@ install_requires = profile = black [flake8] +max-line-length = 119 exclude = representatives/migrations -extend-ignore = - # E501 line too long (X > 79 characters) - E501