From 7ee38a871a94a317fd463a5dc8d116817276132c Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 20 Jan 2009 23:12:55 -0600 Subject: Refactor mirror model Break the original model down into a few different components that should give us a lot more flexibility. Mirror is now the top level entity with one-to-many relationships to both URLs and rsync IP addresses. This should allow the DB model to serve all of our currently unsynced needs. Signed-off-by: Dan McGee --- main/admin.py | 28 +++++++++++++++++++++++----- main/models.py | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 12 deletions(-) (limited to 'main') diff --git a/main/admin.py b/main/admin.py index 72de847..69a5e7d 100644 --- a/main/admin.py +++ b/main/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from archweb_dev.main.models import (AltForum, Arch, Donor, Mirror, +from archweb_dev.main.models import (AltForum, Arch, Donor, + Mirror, MirrorProtocol, MirrorUrl, MirrorRsync, Package, Press, Repo, UserProfile) from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin @@ -14,11 +15,23 @@ class DonorAdmin(admin.ModelAdmin): ordering = ['name'] search_fields = ('name',) +class MirrorUrlInlineAdmin(admin.TabularInline): + model = MirrorUrl + extra = 3 + +class MirrorRsyncInlineAdmin(admin.TabularInline): + model = MirrorRsync + extra = 2 + class MirrorAdmin(admin.ModelAdmin): - list_display = ('domain', 'country') - list_filter = ('country',) - ordering = ['domain'] - search_fields = ('domain',) + list_display = ('name', 'country', 'active', 'public', 'isos', 'notes') + list_filter = ('country', 'active', 'public') + ordering = ['country', 'name'] + search_fields = ('name',) + inlines = [ + MirrorUrlInlineAdmin, + MirrorRsyncInlineAdmin, + ] class PackageAdmin(admin.ModelAdmin): list_display = ('pkgname', '_reponame', '_archname', '_maintainername') @@ -42,8 +55,13 @@ class UserProfileAdmin(UserAdmin): admin.site.register(User, UserProfileAdmin) admin.site.register(AltForum, AltForumAdmin) admin.site.register(Donor, DonorAdmin) + admin.site.register(Mirror, MirrorAdmin) +admin.site.register(MirrorProtocol) + admin.site.register(Package, PackageAdmin) admin.site.register(Press, PressAdmin) admin.site.register(Arch) admin.site.register(Repo) + +# vim: set ts=4 sw=4 et: diff --git a/main/models.py b/main/models.py index bcd8ddb..7f7f42d 100644 --- a/main/models.py +++ b/main/models.py @@ -51,16 +51,40 @@ class PackageManager(models.Manager): ### General Model Classes ### ############################# class Mirror(models.Model): - id = models.AutoField(primary_key=True) - domain = models.CharField(max_length=255) + name = models.CharField(max_length=255) country = models.CharField(max_length=255) + admin_email = models.EmailField(max_length=255, blank=True) + notes = models.CharField(max_length=255, blank=True) + public = models.BooleanField(default=True) + active = models.BooleanField(default=True) + isos = models.BooleanField(default=True) + def __unicode__(self): + return self.name + +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_list = models.CharField(max_length=255, null=True, blank=True) - admin_email = models.CharField(max_length=255, null=True, blank=True) - def __str__(self): - return self.domain + 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): + hostname = models.CharField(max_length=255) + ip = models.IPAddressField() + mirror = models.ForeignKey(Mirror, related_name="rsync_ips") + def __unicode__(self): + return "%s (%s)" % (self.ip, self.hostname) class Meta: - db_table = 'mirrors' + verbose_name = 'Mirror Rsync IP' class Press(models.Model): id = models.AutoField(primary_key=True) -- cgit v1.2.3-24-g4f1b