comparison hgscm/apps/www/models.py @ 78:8d25e34c21c2

templatetags: Add DownloadButton tag to display a download button according to operating system This is somewhat a hacky way to do it, but it works, and we might redo it alter on.
author David Soria Parra <dsp@php.net>
date Fri, 20 Feb 2009 15:12:43 +0100
parents 9be94f3dcaa0
children
comparison
equal deleted inserted replaced
77:fb737a306703 78:8d25e34c21c2
1 from django.db import models 1 from django.db import models
2 from django.utils import simplejson 2 from django.utils import simplejson
3 from django.conf import settings 3 from django.conf import settings
4 import os 4 import os, re
5 5
6 def get_download(platform, version): 6 def get_download(platform, version):
7 '''get the download for the right version''' 7 '''get the download for the right version'''
8 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json")) 8 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))
9 list = simplejson.load(f) 9 list = simplejson.load(f)
11 latest = version == 'latest' or not version 11 latest = version == 'latest' or not version
12 for entry in list: 12 for entry in list:
13 if (latest and entry['latest'] == 'true') or entry['version'] == version: 13 if (latest and entry['latest'] == 'true') or entry['version'] == version:
14 for version in entry['versions']: 14 for version in entry['versions']:
15 if version['identifier'] == platform: 15 if version['identifier'] == platform:
16 return version['url'] 16 return version
17 def get_download_for_agent(agent, version):
18 '''get the download for the right version'''
19 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))
20 list = simplejson.load(f)
21 f.close()
22 latest = version == 'latest' or not version
23 for entry in list:
24 if (latest and entry['latest'] == 'true') or entry['version'] == version:
25 for version in entry['versions']:
26 if re.search(version['system'], agent):
27 return version
28
17 def get_latest_version(): 29 def get_latest_version():
18 '''return the latest available version''' 30 '''return the latest available version'''
19 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json")) 31 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))
20 list = simplejson.load(f) 32 list = simplejson.load(f)
21 f.close() 33 f.close()