Skip to content

Commit

Permalink
livery fields: revert max lengths, add show_name field
Browse files Browse the repository at this point in the history
  • Loading branch information
jclgoodwin committed Jan 20, 2025
1 parent 148f47f commit 5c8b320
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 18 deletions.
2 changes: 1 addition & 1 deletion busstops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class ServiceColour(models.Model):
foreground = models.CharField(max_length=20, blank=True)
background = models.CharField(max_length=20, blank=True)
border = models.CharField(max_length=20, blank=True)
use_name_as_brand = models.BooleanField(default=True)
use_name_as_brand = models.BooleanField(default=False)

def __str__(self):
return self.name
Expand Down
4 changes: 2 additions & 2 deletions vehicles/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django import forms
from django.utils.text import normalize_newlines
from django.db.models import CharField
from webcolors import html5_parse_legacy_color
from webcolors import html5_parse_simple_color


class RegField(forms.CharField):
Expand All @@ -28,7 +28,7 @@ def to_python(self, value):
def validate_colour(value):
if value:
try:
html5_parse_legacy_color(value)
html5_parse_simple_color(value)
except ValueError as e:
raise forms.ValidationError(str(e))

Expand Down
12 changes: 2 additions & 10 deletions vehicles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from busstops.models import Operator

from . import fields
from .models import Livery, Vehicle, VehicleFeature, VehicleType, get_text_colour
from .models import Livery, Vehicle, VehicleFeature, VehicleType


class AutocompleteWidget(forms.Select):
Expand Down Expand Up @@ -87,6 +87,7 @@ def media(self):
other_colour = forms.CharField(
label="Other colours",
help_text="E.g. '#c0c0c0 #ff0000 #ff0000' (red with a silver front)",
validators=[fields.validate_colours],
required=False,
max_length=255,
)
Expand Down Expand Up @@ -122,15 +123,6 @@ def media(self):
link to a picture to prove it. Be polite.""",
)

def clean_other_colour(self):
if self.cleaned_data["other_colour"]:
try:
get_text_colour(self.cleaned_data["other_colour"])
except ValueError as e:
raise ValidationError(str(e))

return self.cleaned_data["other_colour"]

def clean_reg(self):
reg = self.cleaned_data["reg"].replace(".", "")
if self.cleaned_data.get("spare_ticket_machine") and reg:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Generated by Django 5.1.5 on 2025-01-20 16:35

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', max_length=7),
),
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='published',
field=models.BooleanField(default=False, help_text='Tick to include in the CSS and be able to apply this livery to vehicles'),
),
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', max_length=7),
),
migrations.AlterField(
model_name='historicallivery',
name='text_colour',
field=vehicles.fields.ColourField(blank=True, max_length=7),
),
migrations.AlterField(
model_name='livery',
name='colour',
field=vehicles.fields.ColourField(help_text='For the most simplified version of the livery', max_length=7),
),
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='published',
field=models.BooleanField(default=False, help_text='Tick to include in the CSS and be able to apply this livery to vehicles'),
),
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', max_length=7),
),
migrations.AlterField(
model_name='livery',
name='text_colour',
field=vehicles.fields.ColourField(blank=True, max_length=7),
),
migrations.AlterField(
model_name='vehicle',
name='colours',
field=vehicles.fields.ColoursField(blank=True, max_length=255),
),
]
12 changes: 8 additions & 4 deletions vehicles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ def __str__(self):

class Livery(models.Model):
name = models.CharField(max_length=255, db_index=True)
# show_name = models.BooleanField(default=True)
colour = ColourField(help_text="For the most simplified version of the livery")
show_name = models.BooleanField(default=True)
colour = ColourField(
max_length=7, help_text="For the most simplified version of the livery"
)
colours = ColoursField(
max_length=512,
blank=True,
Expand All @@ -140,8 +142,10 @@ class Livery(models.Model):
help_text="Should be a mirror image of the left CSS",
)
white_text = models.BooleanField(default=False)
text_colour = ColourField(blank=True)
stroke_colour = ColourField(blank=True, help_text="Use sparingly, often looks shit")
text_colour = ColourField(max_length=7, blank=True)
stroke_colour = ColourField(
max_length=7, 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
2 changes: 1 addition & 1 deletion vehicles/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_livery_validation(self):
{
"stroke_colour": [
ValidationError(
'HTML5 legacy color parsing forbids "transparent" as a value.'
"An HTML5 simple color must be a Unicode string seven characters long."
)
]
},
Expand Down

0 comments on commit 5c8b320

Please sign in to comment.