summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-01-21 20:44:56 -0600
committerDusty Phillips <buchuki@gmail.com>2009-02-06 17:10:21 -0500
commit6a3274dea1836009d220665369ea6235d7843813 (patch)
tree11a6b533e3990a010894a420b6b941393e5227d7 /main
parent7ee38a871a94a317fd463a5dc8d116817276132c (diff)
Ensure all mirror URLs are saved with a trailing slash
Add a clean_url() function to a custom ModelForm to accomplish this. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r--main/admin.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/main/admin.py b/main/admin.py
index 69a5e7da..c2a4054b 100644
--- a/main/admin.py
+++ b/main/admin.py
@@ -1,9 +1,10 @@
+from django import forms
from django.contrib import admin
+from django.contrib.auth.models import User
+from django.contrib.auth.admin import UserAdmin
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
class AltForumAdmin(admin.ModelAdmin):
list_display = ('language', 'name')
@@ -15,8 +16,19 @@ 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
class MirrorRsyncInlineAdmin(admin.TabularInline):