diff --git a/mayan/apps/tags/literals.py b/mayan/apps/tags/literals.py deleted file mode 100644 index d7b0996cc3..0000000000 --- a/mayan/apps/tags/literals.py +++ /dev/null @@ -1,40 +0,0 @@ -from __future__ import unicode_literals - -from django.utils.translation import ugettext_lazy as _ - -COLOR_RED = 'red' -COLOR_BLUE = 'blu' -COLOR_MAGENTA = 'mag' -COLOR_CYAN = 'cya' -COLOR_YELLOW = 'yel' -COLOR_GREENYELLOW = 'gry' -COLOR_CORAL = 'crl' -COLOR_KHAKI = 'kki' -COLOR_LIGHTGREY = 'lig' -COLOR_ORANGE = 'org' - -COLOR_CHOICES = ( - (COLOR_BLUE, _('Blue')), - (COLOR_CYAN, _('Cyan')), - (COLOR_CORAL, _('Coral')), - (COLOR_GREENYELLOW, _('Green-Yellow')), - (COLOR_KHAKI, _('Khaki')), - (COLOR_LIGHTGREY, _('LightGrey')), - (COLOR_MAGENTA, _('Magenta')), - (COLOR_RED, _('Red')), - (COLOR_ORANGE, _('Orange')), - (COLOR_YELLOW, _('Yellow')) -) - -COLOR_CODES = ( - (COLOR_RED, 'red'), - (COLOR_BLUE, 'blue'), - (COLOR_MAGENTA, 'magenta'), - (COLOR_CYAN, 'cyan'), - (COLOR_YELLOW, 'yellow'), - (COLOR_GREENYELLOW, 'greenyellow '), - (COLOR_CORAL, 'coral'), - (COLOR_KHAKI, 'khaki'), - (COLOR_ORANGE, 'orange'), - (COLOR_LIGHTGREY, 'lightgrey'), -) diff --git a/mayan/apps/tags/migrations/0002_tag_selection.py b/mayan/apps/tags/migrations/0002_tag_selection.py new file mode 100644 index 0000000000..34811471a7 --- /dev/null +++ b/mayan/apps/tags/migrations/0002_tag_selection.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + +import colorful.fields + + +COLOR_BLUE = 'blu' +COLOR_CORAL = 'crl' +COLOR_CYAN = 'cya' +COLOR_GREENYELLOW = 'gry' +COLOR_KHAKI = 'kki' +COLOR_LIGHTGREY = 'lig' +COLOR_MAGENTA = 'mag' +COLOR_ORANGE = 'org' +COLOR_RED = 'red' +COLOR_YELLOW = 'yel' + +RGB_VALUES = { + COLOR_BLUE: '#0000ff', + COLOR_CORAL: '#ff7f50', + COLOR_CYAN: '#00ffff', + COLOR_GREENYELLOW: '#adff2f', + COLOR_KHAKI: '#f0e68c', + COLOR_LIGHTGREY: '#d3d3d3', + COLOR_MAGENTA: '#ff00ff', + COLOR_ORANGE: '#ffa500', + COLOR_RED: '#ff0000', + COLOR_YELLOW: '#ffff00', +} + + +def convert_color_names_to_rgb(apps, schema_editor): + Tag = apps.get_model('tags', 'Tag') + + for tag in Tag.objects.all(): + tag.selection = RGB_VALUES[tag.color] + tag.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('tags', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='tag', + name='selection', + field=colorful.fields.RGBColorField(default='#FFFFFF'), + preserve_default=False, + ), + migrations.RunPython(convert_color_names_to_rgb), + ] diff --git a/mayan/apps/tags/migrations/0003_remove_tag_color.py b/mayan/apps/tags/migrations/0003_remove_tag_color.py new file mode 100644 index 0000000000..fa18cbb14e --- /dev/null +++ b/mayan/apps/tags/migrations/0003_remove_tag_color.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tags', '0002_tag_selection'), + ] + + operations = [ + migrations.RemoveField( + model_name='tag', + name='color', + ), + ] diff --git a/mayan/apps/tags/migrations/0004_auto_20150717_2336.py b/mayan/apps/tags/migrations/0004_auto_20150717_2336.py new file mode 100644 index 0000000000..bd70b4100f --- /dev/null +++ b/mayan/apps/tags/migrations/0004_auto_20150717_2336.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tags', '0003_remove_tag_color'), + ] + + operations = [ + migrations.RenameField( + model_name='tag', + old_name='selection', + new_name='color', + ), + ] diff --git a/mayan/apps/tags/models.py b/mayan/apps/tags/models.py index 18e5cff998..767ccd528f 100644 --- a/mayan/apps/tags/models.py +++ b/mayan/apps/tags/models.py @@ -4,15 +4,15 @@ from django.db import models from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ -from documents.models import Document +from colorful.fields import RGBColorField -from .literals import COLOR_CHOICES, COLOR_CODES +from documents.models import Document @python_2_unicode_compatible class Tag(models.Model): label = models.CharField(db_index=True, max_length=128, unique=True, verbose_name=_('Label')) - color = models.CharField(choices=COLOR_CHOICES, max_length=3, verbose_name=_('Color')) + color = RGBColorField(verbose_name=_('Color')) documents = models.ManyToManyField(Document, related_name='tags', verbose_name=_('Documents')) class Meta: @@ -21,6 +21,3 @@ class Tag(models.Model): def __str__(self): return self.label - - def get_color_code(self): - return dict(COLOR_CODES)[self.color] diff --git a/mayan/apps/tags/widgets.py b/mayan/apps/tags/widgets.py index fb22fd5c83..3afb666ad1 100644 --- a/mayan/apps/tags/widgets.py +++ b/mayan/apps/tags/widgets.py @@ -22,5 +22,5 @@ def widget_single_tag(tag): return mark_safe( ''' {} - '''.format(tag.get_color_code(), escape(tag.label).replace(' ', ' ')) + '''.format(tag.color, escape(tag.label).replace(' ', ' ')) ) diff --git a/mayan/settings/base.py b/mayan/settings/base.py index 5ee6df0e1e..eea9b8ef33 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -52,6 +52,7 @@ INSTALLED_APPS = ( # 3rd party 'actstream', 'autoadmin', + 'colorful', 'compressor', 'corsheaders', 'djcelery', diff --git a/requirements/common.txt b/requirements/common.txt index 62ce41a8a4..d0fad7b2cc 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -9,6 +9,7 @@ cssmin==0.2.0 django-activity-stream==0.6.0 django-autoadmin==1.0.1 django-celery==3.1.16 +django-colorful==1.1.0 django-compressor==1.5 django-cors-headers==1.1.0 django-filetransfers==0.1.0