Commit f5f83aca authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

slugify_with_dots

parent 5eefc019
# Generated by Django 2.0.1 on 2018-01-29 16:43
import autoslug.fields
from django.db import migrations
import rainboard.utils
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0002_forges'),
]
operations = [
migrations.AlterField(
model_name='repo',
name='slug',
field=autoslug.fields.AutoSlugField(editable=False, populate_from='name', slugify=rainboard.utils.slugify_with_dots),
),
]
......@@ -10,7 +10,7 @@ from ndh.models import Links, NamedModel, TimeStampedModel
from ndh.utils import enum_to_choices
import git
from .utils import SOURCES, TARGETS
from .utils import SOURCES, TARGETS, slugify_with_dots
logger = logging.getLogger('rainboard.models')
......@@ -165,7 +165,7 @@ class Forge(Links, NamedModel):
class Repo(TimeStampedModel):
name = models.CharField(max_length=200)
slug = AutoSlugField(populate_from='name')
slug = AutoSlugField(populate_from='name', slugify=slugify_with_dots)
forge = models.ForeignKey(Forge, on_delete=models.CASCADE)
namespace = models.ForeignKey(Namespace, on_delete=models.CASCADE)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
......@@ -245,7 +245,7 @@ class Repo(TimeStampedModel):
try:
return git.remote(remote)
except ValueError:
logger.info(f'Creating remote {self.forge.slug}/{self.namespace.slug}/{self.project.slug}')
logger.info(f'Creating remote {remote}')
return git.create_remote(remote, self.get_clone_url())
......
from enum import IntEnum
import unicodedata
import re
from django.utils.safestring import mark_safe
SOURCES = IntEnum('Sources', 'github gitlab redmine robotpkg')
TARGETS = IntEnum('Targets', '12.04 14.04 16.04 dubnium')
def slugify_with_dots(value):
"""
slugify a name but keep dots
"""
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub(r'[^\w\s\.-]', '', value).strip().lower()
return mark_safe(re.sub(r'[-\s]+', '-', value))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment