Add color to Epics

remotes/origin/issue/4795/notification_even_they_are_disabled
David Barragán Merino 2016-07-27 12:09:17 +02:00
parent ff7d241a37
commit f5f8f66b57
6 changed files with 83 additions and 5 deletions

View File

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2016 Andrey Antukh <niwi@niwi.nz>
# Copyright (C) 2014-2016 Jesús Espino <jespinog@gmail.com>
# Copyright (C) 2014-2016 David Barragán <bameda@dbarragan.com>
# Copyright (C) 2014-2016 Alejandro Alonso <alejandro.alonso@kaleidos.net>
# 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 <http://www.gnu.org/licenses/>.
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)

View File

@ -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'),
),
]

View File

@ -22,6 +22,7 @@ from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils import timezone 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.tagging.models import TaggedMixin
from taiga.projects.occ import OCCModelMixin from taiga.projects.occ import OCCModelMixin
from taiga.projects.notifications.mixins import WatchedModelMixin 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, subject = models.TextField(null=False, blank=False,
verbose_name=_("subject")) verbose_name=_("subject"))
description = models.TextField(null=False, blank=True, verbose_name=_("description")) 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, assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,
default=None, related_name="epics_assigned_to_me", default=None, related_name="epics_assigned_to_me",
verbose_name=_("assigned to")) verbose_name=_("assigned to"))

View File

@ -40,6 +40,7 @@ class EpicListSerializer(VoteResourceSerializerMixin, WatchedResourceSerializer,
created_date = Field() created_date = Field()
modified_date = Field() modified_date = Field()
subject = Field() subject = Field()
color = Field()
epics_order = Field() epics_order = Field()
client_requirement = Field() client_requirement = Field()
team_requirement = Field() team_requirement = Field()

View File

@ -553,7 +553,6 @@ class Command(BaseCommand):
if self.sd.choice([True, True, False, True, True]): if self.sd.choice([True, True, False, True, True]):
filters = {"project": epic.project} filters = {"project": epic.project}
n = self.sd.choice(list(range(self.sd.int(*NUM_USS_EPICS)))) n = self.sd.choice(list(range(self.sd.int(*NUM_USS_EPICS))))
print (n)
user_stories = UserStory.objects.filter(**filters).order_by("?")[:n] user_stories = UserStory.objects.filter(**filters).order_by("?")[:n]
for idx, us in enumerate(list(user_stories)): for idx, us in enumerate(list(user_stories)):
RelatedUserStory.objects.create(epic=epic, RelatedUserStory.objects.create(epic=epic,

View File

@ -38,6 +38,7 @@ from django_pgjson.fields import JsonField
from django_pglocks import advisory_lock from django_pglocks import advisory_lock
from taiga.auth.tokens import get_token_for_user 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.slug import slugify_uniquely
from taiga.base.utils.files import get_file_path from taiga.base.utils.files import get_file_path
from taiga.permissions.choices import MEMBERS_PERMISSIONS from taiga.permissions.choices import MEMBERS_PERMISSIONS
@ -82,10 +83,6 @@ def get_user_model_safe():
raise raise
def generate_random_hex_color():
return "#{:06x}".format(random.randint(0,0xFFFFFF))
def get_user_file_path(instance, filename): def get_user_file_path(instance, filename):
return get_file_path(instance, filename, "user") return get_file_path(instance, filename, "user")