diff --git a/taiga/base/utils/colors.py b/taiga/base/utils/colors.py new file mode 100644 index 00000000..517c8add --- /dev/null +++ b/taiga/base/utils/colors.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2014-2016 Andrey Antukh +# Copyright (C) 2014-2016 Jesús Espino +# Copyright (C) 2014-2016 David Barragán +# Copyright (C) 2014-2016 Alejandro Alonso +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import random + +from django.conf import settings + + +DEFAULT_PREDEFINED_COLORS = ( + "#fce94f", + "#edd400", + "#c4a000", + "#8ae234", + "#73d216", + "#4e9a06", + "#d3d7cf", + "#fcaf3e", + "#f57900", + "#ce5c00", + "#729fcf", + "#3465a4", + "#204a87", + "#888a85", + "#ad7fa8", + "#75507b", + "#5c3566", + "#ef2929", + "#cc0000", + "#a40000" +) + +PREDEFINED_COLORS = getattr(settings, "PREDEFINED_COLORS", DEFAULT_PREDEFINED_COLORS) + + +def generate_random_hex_color(): + return "#{:06x}".format(random.randint(0,0xFFFFFF)) + + +def generate_random_predefined_hex_color(): + return random.choice(PREDEFINED_COLORS) + diff --git a/taiga/projects/epics/migrations/0002_epic_color.py b/taiga/projects/epics/migrations/0002_epic_color.py new file mode 100644 index 00000000..b9cd2ced --- /dev/null +++ b/taiga/projects/epics/migrations/0002_epic_color.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-07-27 09:37 +from __future__ import unicode_literals + +from django.db import migrations, models +import taiga.base.utils.colors + + +class Migration(migrations.Migration): + + dependencies = [ + ('epics', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='epic', + name='color', + field=models.CharField(blank=True, default=taiga.base.utils.colors.generate_random_predefined_hex_color, max_length=32, verbose_name='color'), + ), + ] diff --git a/taiga/projects/epics/models.py b/taiga/projects/epics/models.py index 75380556..6b7d9231 100644 --- a/taiga/projects/epics/models.py +++ b/taiga/projects/epics/models.py @@ -22,6 +22,7 @@ from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.utils import timezone +from taiga.base.utils.colors import generate_random_predefined_hex_color from taiga.projects.tagging.models import TaggedMixin from taiga.projects.occ import OCCModelMixin from taiga.projects.notifications.mixins import WatchedModelMixin @@ -51,6 +52,9 @@ class Epic(OCCModelMixin, WatchedModelMixin, BlockedMixin, TaggedMixin, models.M subject = models.TextField(null=False, blank=False, verbose_name=_("subject")) description = models.TextField(null=False, blank=True, verbose_name=_("description")) + color = models.CharField(max_length=32, null=False, blank=True, + default=generate_random_predefined_hex_color, + verbose_name=_("color")) assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, default=None, related_name="epics_assigned_to_me", verbose_name=_("assigned to")) diff --git a/taiga/projects/epics/serializers.py b/taiga/projects/epics/serializers.py index 081245d9..9b845bbe 100644 --- a/taiga/projects/epics/serializers.py +++ b/taiga/projects/epics/serializers.py @@ -40,6 +40,7 @@ class EpicListSerializer(VoteResourceSerializerMixin, WatchedResourceSerializer, created_date = Field() modified_date = Field() subject = Field() + color = Field() epics_order = Field() client_requirement = Field() team_requirement = Field() diff --git a/taiga/projects/management/commands/sample_data.py b/taiga/projects/management/commands/sample_data.py index 54b4e027..b659096a 100644 --- a/taiga/projects/management/commands/sample_data.py +++ b/taiga/projects/management/commands/sample_data.py @@ -553,7 +553,6 @@ class Command(BaseCommand): if self.sd.choice([True, True, False, True, True]): filters = {"project": epic.project} n = self.sd.choice(list(range(self.sd.int(*NUM_USS_EPICS)))) - print (n) user_stories = UserStory.objects.filter(**filters).order_by("?")[:n] for idx, us in enumerate(list(user_stories)): RelatedUserStory.objects.create(epic=epic, diff --git a/taiga/users/models.py b/taiga/users/models.py index 98a71dc8..45908a10 100644 --- a/taiga/users/models.py +++ b/taiga/users/models.py @@ -38,6 +38,7 @@ from django_pgjson.fields import JsonField from django_pglocks import advisory_lock from taiga.auth.tokens import get_token_for_user +from taiga.base.utils.colors import generate_random_hex_color from taiga.base.utils.slug import slugify_uniquely from taiga.base.utils.files import get_file_path from taiga.permissions.choices import MEMBERS_PERMISSIONS @@ -82,10 +83,6 @@ def get_user_model_safe(): raise -def generate_random_hex_color(): - return "#{:06x}".format(random.randint(0,0xFFFFFF)) - - def get_user_file_path(instance, filename): return get_file_path(instance, filename, "user")