Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/brands/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Meta:
widgets = {
'primary_color': TextInput(attrs={'class': 'colorpicker'}),
'secondary_color': TextInput(attrs={'class': 'colorpicker'}),
'background_color': TextInput(attrs={'class': 'colorpicker'}),
'topnav_logo_image': TextInput(attrs={'placeholder': 'Logo should be max height of 40px', 'size': 200}),
'hero_logo_image': TextInput(
attrs={'placeholder': 'Logo image should be max height of 100px', 'size': 200}
Expand Down
8 changes: 8 additions & 0 deletions admin/brands/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ def post(self, request, *args, **kwargs):
view = BrandChangeForm.as_view()
primary_color = request.POST.get('primary_color')
secondary_color = request.POST.get('secondary_color')
background_color = request.POST.get('background_color')

if not is_a11y(primary_color):
messages.warning(request, """The selected primary color is not a11y compliant.
For more information, visit https://color.a11y.com/""")
if not is_a11y(secondary_color):
messages.warning(request, """The selected secondary color is not a11y compliant.
For more information, visit https://color.a11y.com/""")
if background_color and not is_a11y(background_color):
messages.warning(request, """The selected background color is not a11y compliant.
For more information, visit https://color.a11y.com/""")
return view(request, *args, **kwargs)


Expand All @@ -109,11 +113,15 @@ def get_context_data(self, *args, **kwargs):
def post(self, request, *args, **kwargs):
primary_color = request.POST.get('primary_color')
secondary_color = request.POST.get('secondary_color')
background_color = request.POST.get('background_color')

if not is_a11y(primary_color):
messages.warning(request, """The selected primary color is not a11y compliant.
For more information, visit https://color.a11y.com/""")
if not is_a11y(secondary_color):
messages.warning(request, """The selected secondary color is not a11y compliant.
For more information, visit https://color.a11y.com/""")
if background_color and not is_a11y(background_color):
messages.warning(request, """The selected background color is not a11y compliant.
For more information, visit https://color.a11y.com/""")
return super().post(request, *args, **kwargs)
1 change: 1 addition & 0 deletions api/brands/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BrandSerializer(JSONAPISerializer):

primary_color = ser.CharField(read_only=True, max_length=7)
secondary_color = ser.CharField(read_only=True, max_length=7)
background_color = ser.CharField(read_only=True, allow_null=True, max_length=7)

links = LinksField({
'self': 'get_absolute_url',
Expand Down
18 changes: 18 additions & 0 deletions osf/migrations/0032_brand_background_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2025-08-12 12:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('osf', '0031_abstractprovider_registration_word'),
]

operations = [
migrations.AddField(
model_name='brand',
name='background_color',
field=models.CharField(blank=True, max_length=7, null=True),
),
]
1 change: 1 addition & 0 deletions osf/models/brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Meta:

primary_color = models.CharField(max_length=7)
secondary_color = models.CharField(max_length=7)
background_color = models.CharField(max_length=7, blank=True, null=True)

def __str__(self):
return f'{self.name} ({self.id})'
1 change: 1 addition & 0 deletions osf_tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ class Meta:

primary_color = factory.Faker('hex_color')
secondary_color = factory.Faker('hex_color')
background_color = factory.Faker('hex_color')


class SchemaResponseFactory(DjangoModelFactory):
Expand Down
Loading