summaryrefslogtreecommitdiff
path: root/mirrors/admin.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-09-06 12:01:46 -0500
committerDan McGee <dan@archlinux.org>2010-09-06 12:01:46 -0500
commit7dba848eaf12f7b5274b04a1d5aff38bc42a1d55 (patch)
tree1e90c292fedeb3cbfdf75e16893f03c9821721eb /mirrors/admin.py
parentfae66679318dbd3f5be2f96747e79676a0795fe6 (diff)
Move mirror models out of main app
South actually makes this relatively painless if you get everything right, so might as well start getting these out of the legacy main application to eventually eliminate models being separate from their views. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors/admin.py')
-rw-r--r--mirrors/admin.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/mirrors/admin.py b/mirrors/admin.py
new file mode 100644
index 00000000..394b3508
--- /dev/null
+++ b/mirrors/admin.py
@@ -0,0 +1,61 @@
+import re
+
+from django import forms
+from django.contrib import admin
+
+from .models import Mirror, MirrorProtocol, MirrorUrl, MirrorRsync
+
+class MirrorUrlForm(forms.ModelForm):
+ class Meta:
+ model = MirrorUrl
+ def clean_url(self):
+ # ensure we always save the URL with a trailing slash
+ url = self.cleaned_data["url"].strip()
+ if url[-1] == '/':
+ return url
+ return url + '/'
+
+class MirrorUrlInlineAdmin(admin.TabularInline):
+ model = MirrorUrl
+ 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 MirrorAdminForm(forms.ModelForm):
+ class Meta:
+ model = Mirror
+ upstream = forms.ModelChoiceField(queryset=Mirror.objects.filter(tier__gte=0, tier__lte=1), required=False)
+
+class MirrorAdmin(admin.ModelAdmin):
+ form = MirrorAdminForm
+ list_display = ('name', 'tier', 'country', 'active', 'public', 'isos', 'admin_email', 'supported_protocols')
+ list_filter = ('tier', 'country', 'active', 'public')
+ search_fields = ('name',)
+ inlines = [
+ MirrorUrlInlineAdmin,
+ MirrorRsyncInlineAdmin,
+ ]
+
+admin.site.register(Mirror, MirrorAdmin)
+admin.site.register(MirrorProtocol)
+
+# vim: set ts=4 sw=4 et: