summaryrefslogtreecommitdiff
path: root/main/admin.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-02-07 16:32:41 -0600
committerDan McGee <dan@archlinux.org>2009-02-07 16:32:41 -0600
commit8d53e928f6fb41954c8f6c1ffd3449b360b7978b (patch)
treeb9fb6668452085c5ac351e8a8e2e2662bb948377 /main/admin.py
parent12c98d268496ec6914ceb42a66f89706559e6e4c (diff)
Mirror rsync IP: allow netmask specification
Noticed this was necessary while trying to get all the rsync IPs into the database. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main/admin.py')
-rw-r--r--main/admin.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/main/admin.py b/main/admin.py
index c2a4054b..20532090 100644
--- a/main/admin.py
+++ b/main/admin.py
@@ -1,3 +1,4 @@
+import re
from django import forms
from django.contrib import admin
from django.contrib.auth.models import User
@@ -31,8 +32,24 @@ class MirrorUrlInlineAdmin(admin.TabularInline):
form = MirrorUrlForm
extra = 3
+# ripped off from django.forms.fields, adding netmask ability
+ipv4nm_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}(/(\d|[1-2]\d|3[0-2])){0,1}$')
+class IPAddressNetmaskField(forms.fields.RegexField):
+ default_error_messages = {
+ 'invalid': u'Enter a valid IPv4 address, possibly including netmask.',
+ }
+
+ def __init__(self, *args, **kwargs):
+ super(IPAddressNetmaskField, self).__init__(ipv4nm_re, *args, **kwargs)
+
+class MirrorRsyncForm(forms.ModelForm):
+ class Meta:
+ model = MirrorRsync
+ ip = IPAddressNetmaskField(label='IP')
+
class MirrorRsyncInlineAdmin(admin.TabularInline):
model = MirrorRsync
+ form = MirrorRsyncForm
extra = 2
class MirrorAdmin(admin.ModelAdmin):