Skip to content

Commit

Permalink
Vehicle Information (#30)
Browse files Browse the repository at this point in the history
* k8stests

* merge

* skaffold and envoy configuration

* testing works

* Added action-bar styling. Details page for the suppliers. Made the table clickable to go into details

* Added alternating rows for tables and clickable highlighting for tables

* Vehicle Form for front-end

* Removed misspelled css

* Added styling for the front-end

* Thicker border

* fixed merge conflicts

* remove grpc/proto backend completely

* vehicle information

* list and detail views

Co-authored-by: Richard <[email protected]>
  • Loading branch information
2 people authored and kuanfandevops committed Jan 14, 2020
1 parent 6f69ea3 commit d3d4819
Show file tree
Hide file tree
Showing 78 changed files with 863 additions and 2,472 deletions.
39 changes: 39 additions & 0 deletions backend/api/fixtures/test/0001_add_sample_development_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.db import transaction

from api.management.data_script import OperationalDataScript
from api.models.organization import Organization
from api.models.organization_address import OrganizationAddress
from api.models.user_profile import UserProfile


class AddSampleUsers(OperationalDataScript):
"""
Adds a couple of users as sample data
"""
is_revertable = False
comment = 'Adds Sample Users'

def check_run_preconditions(self):
return True

@transaction.atomic
def run(self):

mitsubishi = Organization.objects.get(
name="Mitsubishi Motors"
)

tesla = Organization.objects.get(
name="Tesla, Inc."
)

gov = Organization.objects.get(
name="Government of British Columbia"
)

vs1 = UserProfile.objects.create(username='fs1', is_active=True, organization=mitsubishi)
vs2 = UserProfile.objects.create(username='fs2', is_active=True, organization=tesla)
analyst = UserProfile.objects.create(username='analyst', is_active=True, organization=gov)


script_class = AddSampleUsers
69 changes: 69 additions & 0 deletions backend/api/fixtures/test/0002_sample_vehicles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from datetime import timedelta, datetime
import random

from django.db import transaction

from api.management.data_script import OperationalDataScript
from api.models.credit_value import CreditValue
from api.models.vehicle import Make, Model, Trim, Type, Vehicle, ModelYear


class AddSampleVehicles(OperationalDataScript):
"""
Adds a couple of vehicles as sample data
"""
is_revertable = False
comment = 'Adds Sample Vehicles'

def check_run_preconditions(self):
return True

@transaction.atomic
def run(self):

my2020 = ModelYear.objects.create(name='2020',
effective_date=datetime(2020, 1, 1),
expiration_date=datetime(2020, 12, 31))

make_names = ['Homemade', 'Organic']
model_names = ['Canyonero', 'Delorean', 'Optimus Prime', 'Scooty Puff Jr.', 'Thundercougarfalconbird']
trims = ['Basic', 'Fancy', 'Super Fancy']
types = ['Battery Electric', 'Plugin Hybrid', 'Hydrogen Fuel Cell', 'Mr. Fusion']

created_tuples = []

for make in make_names:
make_ref = Make.objects.create(name=make)
for model in model_names:
model_ref = Model.objects.create(name=model, make=make_ref)
for trim in trims:
trim_ref = Trim.objects.create(name=trim, model=model_ref)
created_tuples.append((make_ref, model_ref, trim_ref))

created_types = []

for type in types:
created_types.append(Type.objects.create(name=type))

random.shuffle(created_tuples)

for i in range(0, 20):
v = created_tuples.pop()

credit_roll = [lambda: None,
lambda: CreditValue.objects.create(a=random.random()*100),
lambda: CreditValue.objects.create(b=random.random()*100)]

Vehicle.objects.create(
type=random.choice(created_types),
make=v[0],
model=v[1],
trim=v[2],
range=50 + (random.random() * 1000),
model_year=my2020,
validated=random.choice([True, False]),
credit_value=random.choice(credit_roll)()
)


script_class = AddSampleVehicles
6 changes: 6 additions & 0 deletions backend/api/managers/uniquely_named.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.db import models


class UniquelyNamedManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
18 changes: 18 additions & 0 deletions backend/api/migrations/0005_auto_20200113_0612.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.2 on 2020-01-13 06:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0004_organization_is_government'),
]

operations = [
migrations.AlterField(
model_name='organization',
name='name',
field=models.CharField(max_length=500, unique=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Generated by Django 3.0.2 on 2020-01-13 10:53

import db_comments.model_mixins
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0005_auto_20200113_0612'),
]

operations = [
migrations.CreateModel(
name='CreditValue',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('a', models.DecimalField(decimal_places=3, max_digits=5, null=True)),
('b', models.DecimalField(decimal_places=3, max_digits=5, null=True)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_creditvalue_CREATE_USER', to='api.UserProfile')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_creditvalue_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'credits',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
migrations.CreateModel(
name='Make',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('name', models.CharField(max_length=250)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_make_CREATE_USER', to='api.UserProfile')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_make_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'make',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
migrations.CreateModel(
name='Model',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('name', models.CharField(max_length=250)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_model_CREATE_USER', to='api.UserProfile')),
('make', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='valid_models', to='api.Make')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_model_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'model',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
migrations.CreateModel(
name='ModelYear',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('effective_date', models.DateField(blank=True, null=True)),
('expiration_date', models.DateField(blank=True, null=True)),
('name', models.CharField(max_length=250, unique=True)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_modelyear_CREATE_USER', to='api.UserProfile')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_modelyear_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'model_year',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
migrations.CreateModel(
name='Trim',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('name', models.CharField(max_length=250)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_trim_CREATE_USER', to='api.UserProfile')),
('model', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='valid_trims', to='api.Model')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_trim_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'trim',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
migrations.CreateModel(
name='Type',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('name', models.CharField(max_length=250)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_type_CREATE_USER', to='api.UserProfile')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_type_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'type',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
migrations.CreateModel(
name='Vehicle',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('range', models.IntegerField()),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_vehicle_CREATE_USER', to='api.UserProfile')),
('credit_value', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='api.CreditValue')),
('make', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Make')),
('model', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Model')),
('model_year', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ModelYear')),
('trim', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Trim')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_vehicle_UPDATE_USER', to='api.UserProfile')),
],
options={
'db_table': 'vehicle',
'unique_together': {('make', 'model', 'trim', 'model_year')},
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
]
19 changes: 19 additions & 0 deletions backend/api/migrations/0007_vehicle_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.0.2 on 2020-01-13 11:03

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0006_creditvalue_make_model_modelyear_trim_type_vehicle'),
]

operations = [
migrations.AddField(
model_name='vehicle',
name='type',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Type')
),
]
24 changes: 24 additions & 0 deletions backend/api/migrations/0008_auto_20200113_1107.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.0.2 on 2020-01-13 11:07

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0007_vehicle_type'),
]

operations = [
migrations.AddField(
model_name='vehicle',
name='validated',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='vehicle',
name='credit_value',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.CreditValue'),
),
]
1 change: 1 addition & 0 deletions backend/api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import organization, organization_address
from . import user_creation_request, user_profile
from . import vehicle, credit_value
18 changes: 18 additions & 0 deletions backend/api/models/credit_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from datetime import date
from django.db import models
from django.db.models import F

from auditable.models import Auditable
from .mixins.Named import UniquelyNamed
from .organization_address import OrganizationAddress
from .user_profile import UserProfile
from ..managers.organization import OrganizationManager


class CreditValue(Auditable):

class Meta:
db_table = 'credits'

a = models.DecimalField(null=True, blank=False, decimal_places=3, max_digits=5)
b = models.DecimalField(null=True, blank=False, decimal_places=3, max_digits=5)
24 changes: 24 additions & 0 deletions backend/api/models/mixins/Named.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models

from api.managers.uniquely_named import UniquelyNamedManager


class Named(models.Model):
name = models.CharField(blank=False,
null=False,
max_length=250)

class Meta:
abstract = True


class UniquelyNamed(models.Model):
name = models.CharField(blank=False,
unique=True,
null=False,
max_length=250)

objects = UniquelyNamedManager()

class Meta:
abstract = True
5 changes: 0 additions & 5 deletions backend/api/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@


class Organization(Auditable):
"""
Contains a list of all of the recognized Part 3 fuel suppliers, both
past and present, as well as an entry for the government which is also
considered an organization.
"""
name = models.CharField(
max_length=500,
db_comment="Name of the organization",
Expand Down
3 changes: 0 additions & 3 deletions backend/api/models/organization_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@


class OrganizationAddress(Auditable, EffectiveDates):
"""
Address(es) of the Fuel Supplier
"""
organization = models.ForeignKey(
'Organization',
related_name='addresses',
Expand Down
Loading

0 comments on commit d3d4819

Please sign in to comment.