-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add help text for color_code crmi field and make widget a color picker (
- Loading branch information
1 parent
8d76557
commit b404807
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
esp/esp/program/modules/migrations/0043_auto_20240321_2023.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,51 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.29 on 2024-03-21 20:23 | ||
from __future__ import unicode_literals | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
import re | ||
|
||
def set_my_defaults(apps, schema_editor): | ||
classregmoduleinfo = apps.get_model('modules', 'classregmoduleinfo') | ||
crmis = classregmoduleinfo.objects.filter(color_code_old__isnull = False) | ||
for crmi in crmis.all(): | ||
old_color_code = crmi.color_code_old | ||
# check the hex code is valid and then add # | ||
if re.match(r'^([a-zA-Z0-9]{3}){1,2}$', old_color_code): | ||
crmi.color_code = "#" + old_color_code | ||
crmi.save() | ||
|
||
def reverse_func(apps, schema_editor): | ||
classregmoduleinfo = apps.get_model('modules', 'classregmoduleinfo') | ||
crmis = classregmoduleinfo.objects.filter(color_code__isnull = False) | ||
for crmi in crmis.all(): | ||
# remove the # | ||
new_color_code = crmi.color_code | ||
crmi.color_code = new_color_code[1:] | ||
crmi.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('modules', '0042_delete_mailinglabels'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='classregmoduleinfo', | ||
old_name='color_code', | ||
new_name='color_code_old', | ||
), | ||
migrations.AddField( | ||
model_name='classregmoduleinfo', | ||
name='color_code', | ||
field=models.CharField(blank=True, help_text=b'The background color for class titles in the catalog and registration pages. If no color is chosen, the default light blue will be used.', | ||
max_length=7, null=True, validators=[django.core.validators.RegexValidator(r'^#([a-zA-Z0-9]{3}){1,2}$', message = 'Value must be a valid 3-character or 6-character hex color starting with "#".')]), | ||
), | ||
migrations.RunPython(set_my_defaults, reverse_func), | ||
migrations.RemoveField( | ||
model_name='classregmoduleinfo', | ||
name='color_code_old', | ||
) | ||
] |
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