the sorting in the ftpbrowser for source tarballs has always been odd,

this is a small hack to make it better for the most common usecases...
This commit is contained in:
Stefan Kaltenbrunner
2014-02-28 21:51:50 +01:00
parent 5ace77f1d9
commit 1be7fe8e0c
2 changed files with 17 additions and 3 deletions

View File

@ -12,7 +12,7 @@ import cPickle as pickle
from pgweb.util.decorators import ssl_required, nocache from pgweb.util.decorators import ssl_required, nocache
from pgweb.util.contexts import NavContext from pgweb.util.contexts import NavContext
from pgweb.util.helpers import simple_form, PgXmlHelper, HttpServerError from pgweb.util.helpers import simple_form, PgXmlHelper, HttpServerError
from pgweb.util.misc import get_client_ip, varnish_purge from pgweb.util.misc import get_client_ip, varnish_purge, version_sort
from models import Mirror, Category, Product, StackBuilderApp from models import Mirror, Category, Product, StackBuilderApp
from forms import ProductForm from forms import ProductForm
@ -50,7 +50,6 @@ def ftpbrowser(request, subpath):
directories = [{'link': k, 'url': k} for k,v in node.items() if v['t'] == 'd'] directories = [{'link': k, 'url': k} for k,v in node.items() if v['t'] == 'd']
# Add all symlinks (only directoreis supported) # Add all symlinks (only directoreis supported)
directories.extend([{'link': k, 'url': v['d']} for k,v in node.items() if v['t'] == 'l']) directories.extend([{'link': k, 'url': v['d']} for k,v in node.items() if v['t'] == 'l'])
directories.sort()
# Add a link to the parent directory # Add a link to the parent directory
if subpath: if subpath:
@ -81,7 +80,7 @@ def ftpbrowser(request, subpath):
return render_to_response('downloads/ftpbrowser.html', { return render_to_response('downloads/ftpbrowser.html', {
'basepath': subpath.rstrip('/'), 'basepath': subpath.rstrip('/'),
'directories': directories, 'directories': sorted(directories, key = version_sort, reverse=True),
'files': sorted(files), 'files': sorted(files),
'breadcrumbs': breadcrumbs, 'breadcrumbs': breadcrumbs,
'readme': file_readme, 'readme': file_readme,

View File

@ -3,6 +3,7 @@ from django.conf import settings
from pgweb.mailqueue.util import send_simple_mail from pgweb.mailqueue.util import send_simple_mail
from pgweb.util.helpers import template_to_string from pgweb.util.helpers import template_to_string
import re
def send_template_mail(sender, receiver, subject, templatename, templateattr={}, usergenerated=False): def send_template_mail(sender, receiver, subject, templatename, templateattr={}, usergenerated=False):
send_simple_mail(sender, receiver, subject, send_simple_mail(sender, receiver, subject,
@ -59,3 +60,17 @@ def varnish_purge(url):
""" """
url = '^%s' % url url = '^%s' % url
connection.cursor().execute("SELECT varnish_purge(%s)", (url, )) connection.cursor().execute("SELECT varnish_purge(%s)", (url, ))
def version_sort(l):
"""
map a directory name to a format that will show up sensibly in an ascii sort
"""
print l['url']
mkey = l['url']
m = re.match('v([0-9]+)\.([0-9]+)\.([0-9]+)$',l['url'])
if m:
mkey = m.group(1) + '%02d' % int(m.group(2)) + '%02d' % int(m.group(3));
m = re.match('v([0-9]+)\.([0-9]+)$',l['url'])
if m:
mkey = m.group(1) + '%02d' % int(m.group(2));
return mkey