Skip to content

Commit

Permalink
start css and colour(s) fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jclgoodwin committed Jan 19, 2025
1 parent e9d8a5d commit 7b1f6e3
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 11 deletions.
13 changes: 13 additions & 0 deletions vehicles/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from django import forms
from django.utils.text import normalize_newlines
from django.db.models import CharField


class RegField(forms.CharField):
Expand All @@ -21,3 +22,15 @@ def to_python(self, value):
value = re.sub(r"/in/photolist(-\w+)+", "", value)

return value


class ColourField(CharField):
pass


class ColoursField(CharField):
pass


class CSSField(CharField):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Generated by Django 5.1.5 on 2025-01-19 03:57

import vehicles.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('vehicles', '0010_remove_historicallivery_css_remove_livery_css_and_more'),
]

operations = [
migrations.AddField(
model_name='historicallivery',
name='show_name',
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name='livery',
name='show_name',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='historicallivery',
name='colour',
field=vehicles.fields.ColourField(help_text='For the most simplified version of the livery'),
),
migrations.AlterField(
model_name='historicallivery',
name='colours',
field=vehicles.fields.ColoursField(blank=True, help_text='Left and right CSS will be generated from this', max_length=512),
),
migrations.AlterField(
model_name='historicallivery',
name='left_css',
field=vehicles.fields.CSSField(blank=True, help_text='Automatically generated from colours and angle', max_length=1024, verbose_name='Left CSS'),
),
migrations.AlterField(
model_name='historicallivery',
name='right_css',
field=vehicles.fields.CSSField(blank=True, help_text='Should be a mirror image of the left CSS', max_length=1024, verbose_name='Right CSS'),
),
migrations.AlterField(
model_name='historicallivery',
name='stroke_colour',
field=vehicles.fields.ColourField(blank=True, help_text='Use sparingly, often looks shit'),
),
migrations.AlterField(
model_name='historicallivery',
name='text_colour',
field=vehicles.fields.ColourField(blank=True),
),
migrations.AlterField(
model_name='livery',
name='colour',
field=vehicles.fields.ColourField(help_text='For the most simplified version of the livery'),
),
migrations.AlterField(
model_name='livery',
name='colours',
field=vehicles.fields.ColoursField(blank=True, help_text='Left and right CSS will be generated from this', max_length=512),
),
migrations.AlterField(
model_name='livery',
name='left_css',
field=vehicles.fields.CSSField(blank=True, help_text='Automatically generated from colours and angle', max_length=1024, verbose_name='Left CSS'),
),
migrations.AlterField(
model_name='livery',
name='right_css',
field=vehicles.fields.CSSField(blank=True, help_text='Should be a mirror image of the left CSS', max_length=1024, verbose_name='Right CSS'),
),
migrations.AlterField(
model_name='livery',
name='stroke_colour',
field=vehicles.fields.ColourField(blank=True, help_text='Use sparingly, often looks shit'),
),
migrations.AlterField(
model_name='livery',
name='text_colour',
field=vehicles.fields.ColourField(blank=True),
),
migrations.AlterField(
model_name='vehicle',
name='colours',
field=vehicles.fields.ColoursField(blank=True, max_length=255),
),
]
20 changes: 9 additions & 11 deletions vehicles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from busstops.models import DataSource, Operator, Service
from bustimes.utils import get_trip
from .fields import ColourField, ColoursField, CSSField


def format_reg(reg):
Expand Down Expand Up @@ -119,32 +120,29 @@ def __str__(self):

class Livery(models.Model):
name = models.CharField(max_length=255, db_index=True)
colour = models.CharField(
max_length=7, help_text="For the most simplified version of the livery"
)
colours = models.CharField(
show_name = models.BooleanField(default=True)
colour = ColourField(help_text="For the most simplified version of the livery")
colours = ColoursField(
max_length=512,
blank=True,
help_text="""Left and right CSS will be generated from this""",
)
angle = models.PositiveSmallIntegerField(null=True, blank=True)
left_css = models.CharField(
left_css = CSSField(
max_length=1024,
blank=True,
verbose_name="Left CSS",
help_text="Automatically generated from colours and angle",
)
right_css = models.CharField(
right_css = CSSField(
max_length=1024,
blank=True,
verbose_name="Right CSS",
help_text="Should be a mirror image of the left CSS",
)
white_text = models.BooleanField(default=False)
text_colour = models.CharField(max_length=7, blank=True)
stroke_colour = models.CharField(
max_length=7, blank=True, help_text="Use sparingly, often looks shit"
)
text_colour = ColourField(blank=True)
stroke_colour = ColourField(blank=True, help_text="Use sparingly, often looks shit")
horizontal = models.BooleanField(
default=False, help_text="Equivalent to setting the angle to 90"
)
Expand Down Expand Up @@ -268,7 +266,7 @@ class Vehicle(models.Model):
vehicle_type = models.ForeignKey(
VehicleType, models.SET_NULL, null=True, blank=True
)
colours = models.CharField(max_length=255, blank=True)
colours = ColoursField(max_length=255, blank=True)
livery = models.ForeignKey(Livery, models.SET_NULL, null=True, blank=True)
name = models.CharField(max_length=255, blank=True)
branding = models.CharField(max_length=255, blank=True)
Expand Down

0 comments on commit 7b1f6e3

Please sign in to comment.