-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
14 changed files
with
174 additions
and
109 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
17 changes: 8 additions & 9 deletions
17
backend/fleet_management/migrations/0011_add_default_groups.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
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
31 changes: 31 additions & 0 deletions
31
backend/fleet_management/migrations/0017_auto_20191002_1858.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,31 @@ | ||
# Generated by Django 2.1.2 on 2019-10-02 18:58 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_countries.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('fleet_management', '0016_auto_20190825_2051'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='drive', | ||
name='passenger', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='drives_taken', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AlterField( | ||
model_name='drive', | ||
name='driver', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='drives_driven', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AlterField( | ||
model_name='project', | ||
name='country', | ||
field=django_countries.fields.CountryField(default=None, max_length=2), | ||
), | ||
] |
44 changes: 44 additions & 0 deletions
44
backend/fleet_management/migrations/0018_passenger_to_user.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,44 @@ | ||
# Generated by Django 2.1.2 on 2019-10-02 19:00 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def migrate_passenger_to_user(apps, schema_editor): | ||
Passenger = apps.get_model("fleet_management", "Passenger") | ||
User = apps.get_model("fleet_management", "User") | ||
Group = apps.get_model("auth", "Group") | ||
Drive = apps.get_model("fleet_management", "Drive") | ||
g = Group.objects.get(name="Passenger") | ||
passengers = Passenger.objects.all() | ||
for p in passengers: | ||
u, created = User.objects.get_or_create( | ||
username=p.email, | ||
defaults={ | ||
'email': p.email, | ||
'is_superuser': False, | ||
'is_staff': False, | ||
'country': p.country, | ||
'is_active': True, | ||
'first_name': p.first_name, | ||
'last_name': p.last_name | ||
} | ||
) | ||
u.save() | ||
g.user_set.add(u) | ||
|
||
drives = Drive.objects.filter(passengers=p.id) | ||
for d in drives: | ||
assert d.passengers.all().count() == 1, f"Too many passengers in a drive {d.id}" | ||
d.passenger = u | ||
d.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('fleet_management', '0017_auto_20191002_1858'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_passenger_to_user), | ||
] |
20 changes: 20 additions & 0 deletions
20
backend/fleet_management/migrations/0019_remove_passenger_model.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,20 @@ | ||
# Generated by Django 2.1.2 on 2019-10-02 21:00 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('fleet_management', '0018_passenger_to_user'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='drive', | ||
name='passengers', | ||
), | ||
migrations.DeleteModel( | ||
name='Passenger', | ||
), | ||
] |
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.