Merge pull request #852 from taigaio/refactor/project-slug-method
Clean duplicate code in project slug generation processremotes/origin/issue/4795/notification_even_they_are_disabled
commit
1bd8b59ea2
|
@ -20,7 +20,6 @@ import abc
|
||||||
|
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
from taiga.base.utils import sequence as sq
|
|
||||||
from taiga.permissions.services import user_has_perm, is_project_admin
|
from taiga.permissions.services import user_has_perm, is_project_admin
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
|
||||||
|
@ -112,7 +111,7 @@ class Not(PermissionOperator):
|
||||||
super().__init__(component)
|
super().__init__(component)
|
||||||
|
|
||||||
def check_permissions(self, *args, **kwargs):
|
def check_permissions(self, *args, **kwargs):
|
||||||
component = sq.first(self.components)
|
component = self.components[0]
|
||||||
return (not component.check_permissions(*args, **kwargs))
|
return (not component.check_permissions(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
# -*- 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/>.
|
|
||||||
|
|
||||||
|
|
||||||
def first(iterable):
|
|
||||||
if len(iterable) == 0:
|
|
||||||
return None
|
|
||||||
return iterable[0]
|
|
||||||
|
|
||||||
|
|
||||||
def next(data:list):
|
|
||||||
return data[1:]
|
|
||||||
|
|
||||||
|
|
||||||
def arithmetic_progression(step=1, start=1):
|
|
||||||
i = start
|
|
||||||
while True:
|
|
||||||
yield i
|
|
||||||
i += step
|
|
|
@ -35,7 +35,6 @@ from taiga.base.utils.time import timestamp_ms
|
||||||
from taiga.projects.tagging.models import TaggedMixin
|
from taiga.projects.tagging.models import TaggedMixin
|
||||||
from taiga.projects.tagging.models import TagsColorsdMixin
|
from taiga.projects.tagging.models import TagsColorsdMixin
|
||||||
from taiga.base.utils.files import get_file_path
|
from taiga.base.utils.files import get_file_path
|
||||||
from taiga.base.utils.sequence import arithmetic_progression
|
|
||||||
from taiga.base.utils.slug import slugify_uniquely
|
from taiga.base.utils.slug import slugify_uniquely
|
||||||
from taiga.base.utils.slug import slugify_uniquely_for_queryset
|
from taiga.base.utils.slug import slugify_uniquely_for_queryset
|
||||||
|
|
||||||
|
@ -287,14 +286,8 @@ class Project(ProjectDefaults, TaggedMixin, TagsColorsdMixin, models.Model):
|
||||||
|
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
with advisory_lock("project-creation"):
|
with advisory_lock("project-creation"):
|
||||||
base_name = "{}-{}".format(self.owner.username, self.name)
|
base_slug = "{}-{}".format(self.owner.username, self.name)
|
||||||
base_slug = slugify_uniquely(base_name, self.__class__)
|
self.slug = slugify_uniquely(base_slug, self.__class__)
|
||||||
slug = base_slug
|
|
||||||
for i in arithmetic_progression():
|
|
||||||
if not type(self).objects.filter(slug=slug).exists() or i > 100:
|
|
||||||
break
|
|
||||||
slug = "{}-{}".format(base_slug, i)
|
|
||||||
self.slug = slug
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue