From 6a3274dea1836009d220665369ea6235d7843813 Mon Sep 17 00:00:00 2001
From: Dan McGee <dan@archlinux.org>
Date: Wed, 21 Jan 2009 20:44:56 -0600
Subject: 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>
---
 main/admin.py | 16 ++++++++++++++--
 1 file 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):
-- 
cgit v1.2.3-54-g00ecf