Mercurial > hg-website
changeset 70:bef09338eceb
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.
author | David Soria Parra <dsp@php.net> |
---|---|
date | Wed, 18 Feb 2009 15:32:57 +0100 |
parents | a7dceecdbd46 |
children | 9be94f3dcaa0 |
files | hgscm/apps/www/models.py hgscm/apps/www/urls.py hgscm/apps/www/views.py hgscm/downloads.json hgscm/media/css/styles.css hgscm/templates/base.html hgscm/templates/downloads.html hgscm/templates/frontpage.html |
diffstat | 8 files changed, 132 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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']
--- 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<version>.*?)/(?P<platform>.*?)$', 'download', name='download'), )
--- 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))
--- /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" + }] + } +]
--- 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; } /*
--- 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 @@ <ul id="nav" class="typeface-js"> <li><a href="{% url about %}">about</a></li> - <li><a href="javascript:void(0);">download</a></li> + <li><a href="{% url downloads %}">download</a></li> <li><a href="javascript:void(0);">extensions</a></li> <li><a href="javascript:void(0);">docs</a></li> <li><a href="javascript:void(0);">community</a></li>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgscm/templates/downloads.html Wed Feb 18 15:32:57 2009 +0100 @@ -0,0 +1,63 @@ +{% extends "base.html" %} + +{% block content %} + +<div class="row"> + <div class="big col"> + <h1>Mercurial downloads</h1> + {% for d in downloads %} + {% ifequal d.latest "true" %} + <table border="0" cellspacing="0" cellpadding="0" class="latest" width="100%"> + {% else %} + <table border="0" cellspacing="0" cellpadding="0" width="100%"> + {% endifequal %} + <thead> + <tr> + <th>Mercurial {{ d.version }}</th> + <th></th> + <th></th> + </tr> + </thead> + <tbody> + {% for v in d.versions %} + <tr> + <td>{{ v.system }}</td> + <td>{{ v.language }}</td> + <td><a href="download/{{d.version}}/{{v.identifier}}">download</a></td> + </tr> + {% endfor %} + </tbody> + </table> + {% endfor %} + </div> +<div class="col"> + <h3>Get started</h3> + <p>Mercurial is written in python with platform independence in mind. + As a result, Mercurial is available on + <a href="http://www.microsoft.com/windows">Microsoft Windows</a>, + <a href="http://kernel.org">GNU/Linux</a>, + <a href="http://www.apple.com">MacOS X</a>, + <a href="http://www.opensolaris.org">OpenSolaris</a> and others. + You can either download a binary package for the system of your choice or + build if from sources.</p> + + <p>Packages for common Linux, BSD and Solaris distributions can be + installed from the system specific repositories</p> + <p> +<pre> +# Debian/ubuntu +$ apt-get install mercurial + +# Fedora +$ yum install mercurial + +# Gentoo +$ emerge mercurial + +# OpenSolaris +$ pkg install SUNWmercurial + </p> +</div> +</div> + +{% endblock %}
--- a/hgscm/templates/frontpage.html Wed Feb 18 09:01:30 2009 +0100 +++ b/hgscm/templates/frontpage.html Wed Feb 18 15:32:57 2009 +0100 @@ -8,10 +8,10 @@ <h2>Mercurial is a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface. <strong>Please notice, this page is currently under development and based on a mockup.</strong></h2> </div> <div class="col"> - <a class="download typeface-js" href="javascript:void(0);"> + <a class="download typeface-js" href="{% url download "latest" "source"%}"> <strong>Download now</strong> - Mercurial <em>2.42</em> - <span>Windows XP | Vista | 7</span> + Mercurial <em>{{ latest_version }}</em> + <span>Source</span> </a> <dl> <dt class="typeface-js">Requirements</dt> @@ -19,9 +19,9 @@ <!--2.4 is necessary for TortoiseHG, Mercurial only needs 2.3--> <dt>Another OS?<br><em>Get mercurial for:</em></dt> - <dd><a href="javascript:void(0);">Mac OS X</a></dd> - <dd><a href="javascript:void(0);">Linux</a></dd> - <dd><a href="javascript:void(0);">other</a></dd> + <dd><a href="{% url download "latest" "macosx" %}">Mac OS X</a></dd> + <dd><a href="{% url download "latest" "windows" %}">Windows</a></dd> + <dd><a href="{% url downloads %}">other</a></dd> </dl> </div> </div>