diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-10-09 12:37:30 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-10-30 13:39:51 +0000 |
commit | 97c0beb0eb127f05e70a9c3a7202b0cba16d7152 (patch) | |
tree | c5cffbe87a84d8b118a60ca1ea29c02b9cf46280 /bitbake/lib/toaster | |
parent | a1f7a09801c2240b5f9a29683a2b538fcb9991d6 (diff) | |
download | poky-97c0beb0eb127f05e70a9c3a7202b0cba16d7152.tar.gz |
bitbake: toaster: use modified validators for git url fields
The default django URL validator marks git URLs as not valid,
so we change the default validators to a URLValidator-derived
that adds git and ssh protocol schemas and inhibits the
frontend URL validator.
(Bitbake rev: 7223619505c0939358287e5baf84da0a91cb8d34)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r-- | bitbake/lib/toaster/orm/admin.py | 23 | ||||
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 27 |
2 files changed, 45 insertions, 5 deletions
diff --git a/bitbake/lib/toaster/orm/admin.py b/bitbake/lib/toaster/orm/admin.py index 9383630486..6739980bfc 100644 --- a/bitbake/lib/toaster/orm/admin.py +++ b/bitbake/lib/toaster/orm/admin.py | |||
@@ -1,17 +1,34 @@ | |||
1 | from django.contrib import admin | 1 | from django.contrib import admin |
2 | from django.contrib.admin.filters import RelatedFieldListFilter | 2 | from django.contrib.admin.filters import RelatedFieldListFilter |
3 | from .models import Branch, LayerSource, ToasterSetting | 3 | from .models import BitbakeVersion, Release, LayerSource, ToasterSetting |
4 | from django.forms.widgets import Textarea | ||
5 | from django import forms | ||
6 | import django.db.models as models | ||
7 | |||
8 | from django.contrib.admin import widgets, helpers | ||
4 | 9 | ||
5 | class LayerSourceAdmin(admin.ModelAdmin): | 10 | class LayerSourceAdmin(admin.ModelAdmin): |
6 | pass | 11 | pass |
7 | 12 | ||
8 | class BranchAdmin(admin.ModelAdmin): | 13 | class BitbakeVersionAdmin(admin.ModelAdmin): |
14 | |||
15 | # we override the formfield for db URLField because of broken URL validation | ||
16 | |||
17 | def formfield_for_dbfield(self, db_field, **kwargs): | ||
18 | if isinstance(db_field, models.fields.URLField): | ||
19 | return forms.fields.CharField() | ||
20 | return super(BitbakeVersionAdmin, self).formfield_for_dbfield(db_field, **kwargs) | ||
21 | |||
22 | |||
23 | |||
24 | class ReleaseAdmin(admin.ModelAdmin): | ||
9 | pass | 25 | pass |
10 | 26 | ||
11 | class ToasterSettingAdmin(admin.ModelAdmin): | 27 | class ToasterSettingAdmin(admin.ModelAdmin): |
12 | pass | 28 | pass |
13 | 29 | ||
14 | admin.site.register(LayerSource, LayerSourceAdmin) | 30 | admin.site.register(LayerSource, LayerSourceAdmin) |
15 | admin.site.register(Branch, BranchAdmin) | 31 | admin.site.register(BitbakeVersion, BitbakeVersionAdmin) |
32 | admin.site.register(Release, ReleaseAdmin) | ||
16 | admin.site.register(ToasterSetting, ToasterSettingAdmin) | 33 | admin.site.register(ToasterSetting, ToasterSettingAdmin) |
17 | 34 | ||
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 3c7f6611dc..309f8ea5be 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -24,6 +24,28 @@ from django.db.models import F | |||
24 | from django.utils.encoding import python_2_unicode_compatible | 24 | from django.utils.encoding import python_2_unicode_compatible |
25 | from django.utils import timezone | 25 | from django.utils import timezone |
26 | 26 | ||
27 | |||
28 | from django.core import validators | ||
29 | |||
30 | class GitURLValidator(validators.URLValidator): | ||
31 | import re | ||
32 | regex = re.compile( | ||
33 | r'^(?:ssh|git|http|ftp)s?://' # http:// or https:// | ||
34 | r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... | ||
35 | r'localhost|' # localhost... | ||
36 | r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4 | ||
37 | r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6 | ||
38 | r'(?::\d+)?' # optional port | ||
39 | r'(?:/?|[/?]\S+)$', re.IGNORECASE) | ||
40 | |||
41 | def GitURLField(**kwargs): | ||
42 | r = models.URLField(**kwargs) | ||
43 | for i in xrange(len(r.validators)): | ||
44 | if isinstance(r.validators[i], validators.URLValidator): | ||
45 | r.validators[i] = GitURLValidator() | ||
46 | return r | ||
47 | |||
48 | |||
27 | class ToasterSetting(models.Model): | 49 | class ToasterSetting(models.Model): |
28 | name = models.CharField(max_length=63) | 50 | name = models.CharField(max_length=63) |
29 | helptext = models.TextField() | 51 | helptext = models.TextField() |
@@ -663,8 +685,9 @@ class LayerIndexLayerSource(LayerSource): | |||
663 | pass | 685 | pass |
664 | 686 | ||
665 | class BitbakeVersion(models.Model): | 687 | class BitbakeVersion(models.Model): |
688 | |||
666 | name = models.CharField(max_length=32, unique = True) | 689 | name = models.CharField(max_length=32, unique = True) |
667 | giturl = models.URLField() | 690 | giturl = GitURLField() |
668 | branch = models.CharField(max_length=32) | 691 | branch = models.CharField(max_length=32) |
669 | dirpath = models.CharField(max_length=255) | 692 | dirpath = models.CharField(max_length=255) |
670 | 693 | ||
@@ -708,7 +731,7 @@ class Layer(models.Model): | |||
708 | name = models.CharField(max_length=100) | 731 | name = models.CharField(max_length=100) |
709 | local_path = models.FilePathField(max_length=255, null = True, default = None) | 732 | local_path = models.FilePathField(max_length=255, null = True, default = None) |
710 | layer_index_url = models.URLField() | 733 | layer_index_url = models.URLField() |
711 | vcs_url = models.URLField(default = None, null = True) | 734 | vcs_url = GitURLField(default = None, null = True) |
712 | vcs_web_file_base_url = models.URLField(null = True, default = None) | 735 | vcs_web_file_base_url = models.URLField(null = True, default = None) |
713 | 736 | ||
714 | summary = models.CharField(max_length=200, help_text='One-line description of the layer', null = True, default = None) | 737 | summary = models.CharField(max_length=200, help_text='One-line description of the layer', null = True, default = None) |