# HG changeset patch # User David Soria Parra # Date 1234967577 -3600 # Node ID bef09338ecebc59b0390c3f4ae7b574f38c15e4e # Parent a7dceecdbd466212ca014272e17c404715b1198c downloads: add initial handling for downloads We are using json as a format to store our download information as the format is rather simple and can be parsed without problems and dependencies. diff -r a7dceecdbd46 -r bef09338eceb hgscm/apps/www/models.py --- a/hgscm/apps/www/models.py Wed Feb 18 09:01:30 2009 +0100 +++ b/hgscm/apps/www/models.py Wed Feb 18 15:32:57 2009 +0100 @@ -1,3 +1,22 @@ from django.db import models +from django.utils import simplejson -# Create your models here. +def get_download(platform, version): + '''get the download for the right version''' + f = open('downloads.json') + list = simplejson.load(f) + f.close() + latest = version == 'latest' or not version + for entry in list: + if (latest and entry['latest'] == 'true') or entry['version'] == version: + for version in entry['versions']: + if version['identifier'] == platform: + return version['url'] +def get_latest_version(): + '''return the latest available version''' + f = open('downloads.json') + list = simplejson.load(f) + f.close() + for entry in list: + if entry['latest'] == 'true': + return entry['version'] diff -r a7dceecdbd46 -r bef09338eceb hgscm/apps/www/urls.py --- a/hgscm/apps/www/urls.py Wed Feb 18 09:01:30 2009 +0100 +++ b/hgscm/apps/www/urls.py Wed Feb 18 15:32:57 2009 +0100 @@ -4,4 +4,6 @@ url(r'^$', 'frontpage', name='frontpage'), url(r'^about$', 'about', name='about'), url(r'^thepage$', 'thepage', name='thepage'), + url(r'^downloads$', 'downloads', name='downloads'), + url(r'^download/(?P.*?)/(?P.*?)$', 'download', name='download'), ) diff -r a7dceecdbd46 -r bef09338eceb hgscm/apps/www/views.py --- a/hgscm/apps/www/views.py Wed Feb 18 09:01:30 2009 +0100 +++ b/hgscm/apps/www/views.py Wed Feb 18 15:32:57 2009 +0100 @@ -1,8 +1,11 @@ from django.shortcuts import render_to_response from django.template import RequestContext +from django.http import HttpResponseRedirect +from django.utils import simplejson +from apps.www.models import get_download, get_latest_version def frontpage(request): - return render_to_response("frontpage.html", { }, + return render_to_response("frontpage.html", { 'latest_version': get_latest_version() }, RequestContext(request)) def about(request): return render_to_response("about.html", { }, @@ -10,3 +13,11 @@ def thepage(request): return render_to_response("thepage.html", { }, RequestContext(request)) +def download(request, platform, version): + return HttpResponseRedirect(get_download(platform, version)) +def downloads(request): + f = open("downloads.json") + list = simplejson.load(f) + f.close() + return render_to_response("downloads.html", {'downloads': list}, + RequestContext(request)) diff -r a7dceecdbd46 -r bef09338eceb hgscm/downloads.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgscm/downloads.json Wed Feb 18 15:32:57 2009 +0100 @@ -0,0 +1,26 @@ +[{ + "latest": "true", + "version": "1.1.2", + "versions": [{ + "system": "FreeBSD", + "identifier": "freebsd", + "url": "ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-stable/devel/mercurial-1.1.2.tbz" + },{ + "system": "MacOS X 10.5", + "identifier": "macosx", + "url": "http://mercurial.berkwood.com/binaries/Mercurial-1.1.1-py2.5-macosx10.5.zip" + },{ + "system": "MacOS X 10.4", + "identifier": "macosx104", + "url": "http://mercurial.berkwood.com/binaries/Mercurial-1.1.1-py2.5-macosx10.4.zip" + },{ + "system": "Microsoft Windows", + "identifier": "windows", + "url": "http://mercurial.berkwood.com/binaries/Mercurial-1.1.1.exe" + },{ + "system": "Source", + "identifier": "source", + "url": "http://www.selenic.com/mercurial/release/mercurial-1.1.2.tar.gz" + }] + } +] diff -r a7dceecdbd46 -r bef09338eceb hgscm/media/css/styles.css --- a/hgscm/media/css/styles.css Wed Feb 18 09:01:30 2009 +0100 +++ b/hgscm/media/css/styles.css Wed Feb 18 15:32:57 2009 +0100 @@ -62,7 +62,8 @@ table { border-collapse: separate; border-spacing: 0; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: .7875em; } caption, th, td { text-align: left; font-weight: normal; } td, th { padding: 6px 8px; } -thead td, thead th { background: #00B5F1; color: #fff; font-weight: bold; } +.latest thead td, .latest thead th { background: #00B5F1; color: #fff; font-weight: bold; } +thead td, thead th { background: #999; color: #fff; font-weight: bold; } tbody td { border-bottom: 1px solid #ccc; } /* diff -r a7dceecdbd46 -r bef09338eceb hgscm/templates/base.html --- a/hgscm/templates/base.html Wed Feb 18 09:01:30 2009 +0100 +++ b/hgscm/templates/base.html Wed Feb 18 15:32:57 2009 +0100 @@ -14,7 +14,7 @@