-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management command to change consent_low_emission_accepted to False
Refs: PV-880
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
parking_permits/management/commands/disable_consent_low_emission.py
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 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
|
||
from parking_permits.models.vehicle import Vehicle | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Change consent_low_emission_accepted to False for non-electric vehicles" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("--dry_run", type=bool, default=False) | ||
|
||
@transaction.atomic | ||
def handle(self, *args, **options): | ||
dry_run = options["dry_run"] | ||
vehicles = Vehicle.objects.filter( | ||
consent_low_emission_accepted=True | ||
).select_related("power_type") | ||
i = 0 | ||
for vehicle in vehicles: | ||
if not vehicle.power_type.is_electric(): | ||
vehicle.consent_low_emission_accepted = False | ||
if not dry_run: | ||
vehicle.save() | ||
i = i + 1 | ||
|
||
if dry_run: | ||
self.stdout.write("This is a dry run!") | ||
self.stdout.write( | ||
f"Real run would change {i} vehicles to consent_low_emission_accepted=False" | ||
) | ||
else: | ||
self.stdout.write( | ||
f"Changed {i} vehicles to consent_low_emission_accepted=False" | ||
) |