summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-10-09 12:37:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-10-30 13:39:51 +0000
commit97c0beb0eb127f05e70a9c3a7202b0cba16d7152 (patch)
treec5cffbe87a84d8b118a60ca1ea29c02b9cf46280 /bitbake/lib/toaster
parenta1f7a09801c2240b5f9a29683a2b538fcb9991d6 (diff)
downloadpoky-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.py23
-rw-r--r--bitbake/lib/toaster/orm/models.py27
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 @@
1from django.contrib import admin 1from django.contrib import admin
2from django.contrib.admin.filters import RelatedFieldListFilter 2from django.contrib.admin.filters import RelatedFieldListFilter
3from .models import Branch, LayerSource, ToasterSetting 3from .models import BitbakeVersion, Release, LayerSource, ToasterSetting
4from django.forms.widgets import Textarea
5from django import forms
6import django.db.models as models
7
8from django.contrib.admin import widgets, helpers
4 9
5class LayerSourceAdmin(admin.ModelAdmin): 10class LayerSourceAdmin(admin.ModelAdmin):
6 pass 11 pass
7 12
8class BranchAdmin(admin.ModelAdmin): 13class 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
24class ReleaseAdmin(admin.ModelAdmin):
9 pass 25 pass
10 26
11class ToasterSettingAdmin(admin.ModelAdmin): 27class ToasterSettingAdmin(admin.ModelAdmin):
12 pass 28 pass
13 29
14admin.site.register(LayerSource, LayerSourceAdmin) 30admin.site.register(LayerSource, LayerSourceAdmin)
15admin.site.register(Branch, BranchAdmin) 31admin.site.register(BitbakeVersion, BitbakeVersionAdmin)
32admin.site.register(Release, ReleaseAdmin)
16admin.site.register(ToasterSetting, ToasterSettingAdmin) 33admin.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
24from django.utils.encoding import python_2_unicode_compatible 24from django.utils.encoding import python_2_unicode_compatible
25from django.utils import timezone 25from django.utils import timezone
26 26
27
28from django.core import validators
29
30class 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
41def 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
27class ToasterSetting(models.Model): 49class 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
665class BitbakeVersion(models.Model): 687class 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)