diff options
author | Dan McGee <dan@archlinux.org> | 2010-09-06 19:01:46 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-09-06 19:01:46 +0200 |
commit | 7dba848eaf12f7b5274b04a1d5aff38bc42a1d55 (patch) | |
tree | 1e90c292fedeb3cbfdf75e16893f03c9821721eb | |
parent | fae66679318dbd3f5be2f96747e79676a0795fe6 (diff) | |
download | archweb-7dba848eaf12f7b5274b04a1d5aff38bc42a1d55.tar.gz archweb-7dba848eaf12f7b5274b04a1d5aff38bc42a1d55.tar.xz |
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>
-rw-r--r-- | devel/views.py | 2 | ||||
-rw-r--r-- | main/admin.py | 59 | ||||
-rw-r--r-- | main/migrations/0030_move_mirror_models.py | 161 | ||||
-rw-r--r-- | main/models.py | 54 | ||||
-rw-r--r-- | mirrors/admin.py | 61 | ||||
-rw-r--r-- | mirrors/migrations/0002_rename_model_tables.py | 57 | ||||
-rw-r--r-- | mirrors/models.py | 57 | ||||
-rw-r--r-- | mirrors/views.py | 2 | ||||
-rw-r--r-- | packages/views.py | 2 | ||||
-rw-r--r-- | public/views.py | 4 |
10 files changed, 342 insertions, 117 deletions
diff --git a/devel/views.py b/devel/views.py index 1f43b87..eea90e3 100644 --- a/devel/views.py +++ b/devel/views.py @@ -10,7 +10,7 @@ from django.views.generic.simple import direct_to_template from main.models import Package, Todolist, TodolistPkg from main.models import Arch, Repo from main.models import UserProfile -from main.models import Mirror +from mirrors.models import Mirror from packages.models import PackageRelation import random diff --git a/main/admin.py b/main/admin.py index bfed459..712cec8 100644 --- a/main/admin.py +++ b/main/admin.py @@ -1,66 +1,12 @@ -import re -from django import forms from django.contrib import admin from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin -from main.models import (Arch, Donor, - Mirror, MirrorProtocol, MirrorUrl, MirrorRsync, - Package, Repo, UserProfile) +from main.models import Arch, Donor, Package, Repo, UserProfile class DonorAdmin(admin.ModelAdmin): ordering = ['name'] search_fields = ('name',) -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, - ] - class RepoAdmin(admin.ModelAdmin): list_display = ('name', 'testing', 'bugs_project', 'svn_root') list_filter = ('testing',) @@ -85,9 +31,6 @@ class UserProfileAdmin(UserAdmin): admin.site.register(User, UserProfileAdmin) admin.site.register(Donor, DonorAdmin) -admin.site.register(Mirror, MirrorAdmin) -admin.site.register(MirrorProtocol) - admin.site.register(Package, PackageAdmin) admin.site.register(Arch) admin.site.register(Repo, RepoAdmin) diff --git a/main/migrations/0030_move_mirror_models.py b/main/migrations/0030_move_mirror_models.py new file mode 100644 index 0000000..998ff6a --- /dev/null +++ b/main/migrations/0030_move_mirror_models.py @@ -0,0 +1,161 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + depends_on = ( + ('mirrors', '0002_rename_model_tables'), + ) + + def forwards(self, orm): + pass + + def backwards(self, orm): + pass + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'main.arch': { + 'Meta': {'ordering': "['name']", 'object_name': 'Arch', 'db_table': "'arches'"}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) + }, + 'main.donor': { + 'Meta': {'ordering': "['name']", 'object_name': 'Donor', 'db_table': "'donors'"}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) + }, + 'main.news': { + 'Meta': {'ordering': "['-postdate', '-id']", 'object_name': 'News', 'db_table': "'news'"}, + 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'news_author'", 'to': "orm['auth.User']"}), + 'content': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'postdate': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'main.package': { + 'Meta': {'ordering': "('pkgname',)", 'object_name': 'Package', 'db_table': "'packages'"}, + 'arch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Arch']"}), + 'build_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'compressed_size': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}), + 'filename': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'files_last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'flag_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'installed_size': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}), + 'last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'license': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), + 'packager': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}), + 'packager_str': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'pkgdesc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), + 'pkgname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'repo': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Repo']"}), + 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}) + }, + 'main.packagedepend': { + 'Meta': {'object_name': 'PackageDepend', 'db_table': "'package_depends'"}, + 'depname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'depvcmp': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Package']"}) + }, + 'main.packagefile': { + 'Meta': {'object_name': 'PackageFile', 'db_table': "'package_files'"}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'path': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Package']"}) + }, + 'main.repo': { + 'Meta': {'ordering': "['name']", 'object_name': 'Repo', 'db_table': "'repos'"}, + 'bugs_project': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), + 'svn_root': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'}) + }, + 'main.signoff': { + 'Meta': {'object_name': 'Signoff'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'packager': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Package']"}), + 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'main.todolist': { + 'Meta': {'object_name': 'Todolist', 'db_table': "'todolists'"}, + 'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'date_added': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'main.todolistpkg': { + 'Meta': {'unique_together': "(('list', 'pkg'),)", 'object_name': 'TodolistPkg', 'db_table': "'todolist_pkgs'"}, + 'complete': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'list': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Todolist']"}), + 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Package']"}) + }, + 'main.userprofile': { + 'Meta': {'object_name': 'UserProfile', 'db_table': "'user_profiles'"}, + 'alias': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'allowed_repos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['main.Repo']", 'symmetrical': 'False', 'blank': 'True'}), + 'favorite_distros': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'interests': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'languages': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}), + 'notify': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'occupation': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}), + 'other_contact': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'picture': ('django.db.models.fields.files.FileField', [], {'default': "'devs/silhouette.png'", 'max_length': '100'}), + 'public_email': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'roles': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'userprofile_user'", 'unique': 'True', 'to': "orm['auth.User']"}), + 'website': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'yob': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['main'] diff --git a/main/models.py b/main/models.py index 1633db7..f6777f9 100644 --- a/main/models.py +++ b/main/models.py @@ -45,60 +45,6 @@ class PackageManager(models.Manager): return self.get_query_set().filter(flag_date__isnull=False) -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' - class Donor(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=255, unique=True) diff --git a/mirrors/admin.py b/mirrors/admin.py new file mode 100644 index 0000000..394b350 --- /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 0000000..2041cd6 --- /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 e69de29..94256a9 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 b9a02d2..ff22dd5 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) diff --git a/packages/views.py b/packages/views.py index 37f5a20..6f05cb8 100644 --- a/packages/views.py +++ b/packages/views.py @@ -18,8 +18,8 @@ import string from main.models import Package, PackageFile from main.models import Arch, Repo, Signoff -from main.models import MirrorUrl from main.utils import make_choice +from mirrors.models import MirrorUrl from .models import PackageRelation from .utils import get_group_info, get_differences_info diff --git a/public/views.py b/public/views.py index f1d08a2..96c75d6 100644 --- a/public/views.py +++ b/public/views.py @@ -1,5 +1,5 @@ -from main.models import Arch, Donor, MirrorUrl, News -from main.models import Repo +from main.models import Arch, Repo, Donor, News +from mirrors.models import MirrorUrl from . import utils from django.contrib.auth.models import User |