summaryrefslogtreecommitdiff
path: root/mirrors
diff options
context:
space:
mode:
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/admin.py61
-rw-r--r--mirrors/migrations/0002_rename_model_tables.py57
-rw-r--r--mirrors/models.py57
-rw-r--r--mirrors/views.py2
4 files changed, 176 insertions, 1 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:
diff --git a/mirrors/migrations/0002_rename_model_tables.py b/mirrors/migrations/0002_rename_model_tables.py
new file mode 100644
index 00000000..2041cd69
--- /dev/null
+++ b/mirrors/migrations/0002_rename_model_tables.py
@@ -0,0 +1,57 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ db.rename_table('main_mirror', 'mirrors_mirror')
+ db.rename_table('main_mirrorurl', 'mirrors_mirrorurl')
+ db.rename_table('main_mirrorrsync', 'mirrors_mirrorrsync')
+ db.rename_table('main_mirrorprotocol', 'mirrors_mirrorprotocol')
+
+ def backwards(self, orm):
+ db.rename_table('mirrors_mirror', 'main_mirror')
+ db.rename_table('mirrors_mirrorurl', 'main_mirrorurl')
+ db.rename_table('mirrors_mirrorrsync', 'main_mirrorrsync')
+ db.rename_table('mirrors_mirrorprotocol', 'main_mirrorprotocol')
+
+ models = {
+ 'mirrors.mirror': {
+ 'Meta': {'ordering': "('country', 'name')", 'object_name': 'Mirror'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'admin_email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'isos': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'notes': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'rsync_password': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '50', 'blank': 'True'}),
+ 'rsync_user': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '50', 'blank': 'True'}),
+ 'tier': ('django.db.models.fields.SmallIntegerField', [], {'default': '2'}),
+ 'upstream': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mirrors.Mirror']", 'null': 'True'})
+ },
+ 'mirrors.mirrorprotocol': {
+ 'Meta': {'object_name': 'MirrorProtocol'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'protocol': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '10'})
+ },
+ 'mirrors.mirrorrsync': {
+ 'Meta': {'object_name': 'MirrorRsync'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'ip': ('django.db.models.fields.CharField', [], {'max_length': '24'}),
+ 'mirror': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'rsync_ips'", 'to': "orm['mirrors.Mirror']"})
+ },
+ 'mirrors.mirrorurl': {
+ 'Meta': {'object_name': 'MirrorUrl'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mirror': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'urls'", 'to': "orm['mirrors.Mirror']"}),
+ 'protocol': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'urls'", 'to': "orm['mirrors.MirrorProtocol']"}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ }
+ }
+
+ complete_apps = ['mirrors']
diff --git a/mirrors/models.py b/mirrors/models.py
index e69de29b..94256a9c 100644
--- a/mirrors/models.py
+++ b/mirrors/models.py
@@ -0,0 +1,57 @@
+from django.db import models
+
+TIER_CHOICES = (
+ (0, 'Tier 0'),
+ (1, 'Tier 1'),
+ (2, 'Tier 2'),
+ (-1, 'Untiered'),
+)
+
+class Mirror(models.Model):
+ name = models.CharField(max_length=255)
+ tier = models.SmallIntegerField(default=2, choices=TIER_CHOICES)
+ upstream = models.ForeignKey('self', null=True)
+ country = models.CharField(max_length=255, db_index=True)
+ admin_email = models.EmailField(max_length=255, blank=True)
+ public = models.BooleanField(default=True)
+ active = models.BooleanField(default=True)
+ isos = models.BooleanField(default=True)
+ rsync_user = models.CharField(max_length=50, blank=True, default='')
+ rsync_password = models.CharField(max_length=50, blank=True, default='')
+ notes = models.TextField(blank=True)
+
+ class Meta:
+ ordering = ('country', 'name')
+
+ def __unicode__(self):
+ return self.name
+
+ def supported_protocols(self):
+ protocols = MirrorProtocol.objects.filter(urls__mirror=self).distinct()
+ return ", ".join([p.protocol for p in protocols])
+
+class MirrorProtocol(models.Model):
+ protocol = models.CharField(max_length=10, unique=True)
+ def __unicode__(self):
+ return self.protocol
+ class Meta:
+ verbose_name = 'Mirror Protocol'
+
+class MirrorUrl(models.Model):
+ url = models.CharField(max_length=255)
+ protocol = models.ForeignKey(MirrorProtocol, related_name="urls")
+ mirror = models.ForeignKey(Mirror, related_name="urls")
+ def __unicode__(self):
+ return self.url
+ class Meta:
+ verbose_name = 'Mirror URL'
+
+class MirrorRsync(models.Model):
+ ip = models.CharField(max_length=24)
+ mirror = models.ForeignKey(Mirror, related_name="rsync_ips")
+ def __unicode__(self):
+ return "%s" % (self.ip)
+ class Meta:
+ verbose_name = 'Mirror Rsync IP'
+
+# vim: set ts=4 sw=4 et:
diff --git a/mirrors/views.py b/mirrors/views.py
index b9a02d27..ff22dd5c 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -2,8 +2,8 @@ from django import forms
from django.views.decorators.csrf import csrf_exempt
from django.views.generic.simple import direct_to_template
-from main.models import Mirror, MirrorUrl, MirrorProtocol
from main.utils import make_choice
+from .models import Mirror, MirrorUrl, MirrorProtocol
class MirrorlistForm(forms.Form):
country = forms.MultipleChoiceField(required=False)