[damned-lies] Allow '+' char in module names
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Allow '+' char in module names
- Date: Sun, 13 Sep 2015 19:39:59 +0000 (UTC)
commit 88cc35a5ad04daaa1e28d99025103f9c237a0f9d
Author: Claude Paroz <claude 2xlibre net>
Date: Sun Sep 13 21:11:28 2015 +0200
Allow '+' char in module names
Fixes bug #754967.
stats/migrations/0005_update_module_name_field.py | 21 +++++++++++++++++++++
stats/models.py | 12 +++++++++++-
2 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/stats/migrations/0005_update_module_name_field.py
b/stats/migrations/0005_update_module_name_field.py
new file mode 100644
index 0000000..f08b31b
--- /dev/null
+++ b/stats/migrations/0005_update_module_name_field.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import re
+import django.core.validators
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('stats', '0004_remove_old_cat_name'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='module',
+ name='name',
+ field=models.CharField(unique=True, max_length=50,
validators=[django.core.validators.RegexValidator(re.compile('^[-\\+a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug'
consisting of letters, numbers, underscores, hyphens or plus signs.", 'invalid')]),
+ ),
+ ]
diff --git a/stats/models.py b/stats/models.py
index 69390c0..fb2b57a 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -31,6 +31,7 @@ from urllib2 import URLError
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
+from django.core.validators import RegexValidator
from django.utils.translation import ungettext, ugettext as _, ugettext_noop
from django.utils import dateformat
from django.db import models, connection
@@ -42,6 +43,15 @@ from stats.doap import update_doap_infos
from people.models import Person
from languages.models import Language
+
+# Standard Django slug validation but also accept '+' (for gtk+)
+slug_re = re.compile(r'^[-\+a-zA-Z0-9_]+\Z')
+validate_slug = RegexValidator(
+ slug_re,
+ "Enter a valid 'slug' consisting of letters, numbers, underscores, hyphens or plus signs.",
+ 'invalid'
+)
+
VCS_TYPE_CHOICES = (
('cvs', 'CVS'),
('svn', 'Subversion'),
@@ -57,7 +67,7 @@ BRANCH_HEAD_NAMES = (
)
class Module(models.Model):
- name = models.SlugField(max_length=50, unique=True)
+ name = models.CharField(max_length=50, unique=True, validators=[validate_slug])
homepage = models.URLField(null=True, blank=True,
help_text="Automatically updated if the module contains a doap file.")
description = models.TextField(null=True, blank=True)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]