Mercurial > hg-website
annotate 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 |
rev | line source |
---|---|
26
b3d9cbb33d54
adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff
changeset
|
1 from django.db import models |
70
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
2 from django.utils import simplejson |
71
9be94f3dcaa0
downloads: fix import and paths
David Soria Parra <dsp@php.net>
parents:
70
diff
changeset
|
3 from django.conf import settings |
78
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
4 import os, re |
26
b3d9cbb33d54
adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff
changeset
|
5 |
70
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
6 def get_download(platform, version): |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
7 '''get the download for the right version''' |
71
9be94f3dcaa0
downloads: fix import and paths
David Soria Parra <dsp@php.net>
parents:
70
diff
changeset
|
8 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json")) |
70
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
9 list = simplejson.load(f) |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
10 f.close() |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
11 latest = version == 'latest' or not version |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
12 for entry in list: |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
13 if (latest and entry['latest'] == 'true') or entry['version'] == version: |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
14 for version in entry['versions']: |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
15 if version['identifier'] == platform: |
78
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
16 return version |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
17 def get_download_for_agent(agent, version): |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
18 '''get the download for the right version''' |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
19 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json")) |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
20 list = simplejson.load(f) |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
21 f.close() |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
22 latest = version == 'latest' or not version |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
23 for entry in list: |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
24 if (latest and entry['latest'] == 'true') or entry['version'] == version: |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
25 for version in entry['versions']: |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
26 if re.search(version['system'], agent): |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
27 return version |
8d25e34c21c2
templatetags: Add DownloadButton tag to display a download button according to operating system
David Soria Parra <dsp@php.net>
parents:
71
diff
changeset
|
28 |
70
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
29 def get_latest_version(): |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
30 '''return the latest available version''' |
71
9be94f3dcaa0
downloads: fix import and paths
David Soria Parra <dsp@php.net>
parents:
70
diff
changeset
|
31 f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json")) |
70
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
32 list = simplejson.load(f) |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
33 f.close() |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
34 for entry in list: |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
35 if entry['latest'] == 'true': |
bef09338eceb
downloads: add initial handling for downloads
David Soria Parra <dsp@php.net>
parents:
26
diff
changeset
|
36 return entry['version'] |