Skip to content

Commit

Permalink
Merge pull request #3440 from rtfd/fix-alias-slugify
Browse files Browse the repository at this point in the history
Properly slugify the alias on Project Relationships.
  • Loading branch information
ericholscher authored Dec 21, 2017
2 parents 5901dcb + 961aa1f commit 9f4519b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import socket
from datetime import datetime

from django.utils.text import slugify
from readthedocs.core.utils import slugify
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from docker import Client
from docker.utils import create_host_config
Expand Down
20 changes: 20 additions & 0 deletions readthedocs/projects/migrations/0022_add-alias-slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-12-21 16:30
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('projects', '0021_add-webhook-deprecation-feature'),
]

operations = [
migrations.AlterField(
model_name='projectrelationship',
name='alias',
field=models.SlugField(blank=True, max_length=255, null=True, verbose_name='Alias', db_index=False),
),
]
33 changes: 33 additions & 0 deletions readthedocs/projects/migrations/0023_migrate-alias-slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-12-21 16:31
from __future__ import unicode_literals

from django.db import migrations

import re


class Migration(migrations.Migration):

def migrate_data(apps, schema_editor):
# Keep things that slugify wouldn't normally accept,
# so that we don't break a bunch of folks URL's.
# They will have to change them on update.
invalid_chars_re = re.compile('[^-._a-zA-Z0-9]')
ProjectRelationship = apps.get_model("projects", "ProjectRelationship")
for p in ProjectRelationship.objects.all():
if p.alias and invalid_chars_re.match(p.alias):
new_alias = invalid_chars_re.sub('', p.alias)
p.alias = new_alias
p.save()

def reverse(apps, schema_editor):
pass

dependencies = [
('projects', '0022_add-alias-slug'),
]

operations = [
migrations.RunPython(migrate_data, reverse)
]
2 changes: 1 addition & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ProjectRelationship(models.Model):
related_name='subprojects')
child = models.ForeignKey('Project', verbose_name=_('Child'),
related_name='superprojects')
alias = models.CharField(_('Alias'), max_length=255, null=True, blank=True)
alias = models.SlugField(_('Alias'), max_length=255, null=True, blank=True, db_index=False)

objects = ChildRelatedProjectQuerySet.as_manager()

Expand Down

0 comments on commit 9f4519b

Please sign in to comment.