diff 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
line wrap: on
line diff
--- a/hgscm/apps/www/models.py	Fri Feb 20 15:12:33 2009 +0100
+++ b/hgscm/apps/www/models.py	Fri Feb 20 15:12:43 2009 +0100
@@ -1,7 +1,7 @@
 from django.db import models
 from django.utils import simplejson
 from django.conf import settings
-import os
+import os, re
 
 def get_download(platform, version):
     '''get the download for the right version'''
@@ -13,7 +13,19 @@
         if (latest and entry['latest'] == 'true') or entry['version'] == version:
             for version in entry['versions']:
                 if version['identifier'] == platform:
-                    return version['url']
+                    return version
+def get_download_for_agent(agent, version):
+    '''get the download for the right version'''
+    f = open(os.path.join(settings.MEDIA_ROOT, "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 re.search(version['system'], agent):
+                    return version
+
 def get_latest_version():
     '''return the latest available version'''
     f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))