]> git.ipfire.org Git - ipfire.org.git/commitdiff
Add downloads again
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2018 11:41:38 +0000 (12:41 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2018 11:41:38 +0000 (12:41 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/releases.py
src/templates/download/base.html [new file with mode: 0644]
src/templates/download/index.html [new file with mode: 0644]
src/templates/download/modules/button.html [new file with mode: 0644]
src/templates/download/release.html [new file with mode: 0644]
src/templates/modules/download-button.html [deleted file]
src/web/__init__.py
src/web/download.py [new file with mode: 0644]

index ab39af06c75844ac40818a8b8d802ba011dcac0e..bd0b71d7a86d4cbbbefe7aa6f310811fa9118361 100644 (file)
@@ -75,6 +75,7 @@ backenddir = $(pythondir)/ipfire
 web_PYTHON = \
        src/web/__init__.py \
        src/web/blog.py \
+       src/web/download.py \
        src/web/handlers.py \
        src/web/handlers_accounts.py \
        src/web/handlers_admin.py \
@@ -123,6 +124,18 @@ templates_blog_modules_DATA = \
 
 templates_blog_modulesdir = $(templates_blogdir)/modules
 
+templates_download_DATA = \
+       src/templates/download/base.html \
+       src/templates/download/index.html \
+       src/templates/download/release.html
+
+templates_downloaddir = $(templatesdir)/download
+
+templates_download_modules_DATA = \
+       src/templates/download/modules/button.html
+
+templates_download_modulesdir = $(templates_downloaddir)/modules
+
 templates_location_DATA = \
        src/templates/location/lookup.html
 
index fdc9c09fad9e43d551d22cce1a33aecc8a7edef5..de3b630eac1074fd64a8add1a50ddfc610b59a07 100644 (file)
@@ -96,15 +96,15 @@ class File(Object):
                _ = lambda x: x
 
                descriptions = {
-                       "armv5tel"      : _("Image for the armv5tel architecture"),
-                       "armv5tel-scon" : _("armv5tel image for boards with serial console"),
-                       "iso"           : _("Installable CD image"),
-                       "torrent"       : _("Torrent file"),
-                       "flash"         : _("Flash image"),
-                       "alix"          : _("Flash image for devices with serial console"),
+                       "armv5tel"      : _("Flash Image"),
+                       "armv5tel-scon" : _("Flash Image with serial console"),
+                       "iso"           : _("CD Image"),
+                       "torrent"       : _("Torrent File"),
+                       "flash"         : _("Flash Image"),
+                       "alix"          : _("Flash Image with serial console"),
                        "usbfdd"        : _("USB FDD Image"),
                        "usbhdd"        : _("USB HDD Image"),
-                       "xen"           : _("Pregenerated Xen image"),
+                       "xen"           : _("Pre-generated Xen Image"),
                        "xen-downloader": _("Xen-Image Generator"),
                }
 
@@ -222,12 +222,21 @@ class Release(Object):
 
                self.__files = []
 
+       def __str__(self):
+               return self.name
+
        def __repr__(self):
                return "<%s %s>" % (self.__class__.__name__, self.name)
 
        def __cmp__(self, other):
                return cmp(self.id, other.id)
 
+       @property
+       def arches(self):
+               for arch in ("x86_64", "aarch64", "i586", "arm"):
+                       if arch in (f.arch for f in self.files):
+                               yield arch
+
        @property
        def files(self):
                if not self.__files:
@@ -239,6 +248,11 @@ class Release(Object):
 
                return self.__files
 
+       def get_files_by_arch(self, arch):
+               for f in self.files:
+                       if f.arch == arch:
+                               yield f
+
        @property
        def torrents(self):
                torrents = []
@@ -256,9 +270,18 @@ class Release(Object):
                return self.__data.name
 
        @property
-       def sname(self):
+       def slug(self):
                return self.__data.sname
 
+       # XXX compat
+       sname = slug
+
+       # XXX cache this
+       @property
+       def blog(self):
+               if self.__data.blog_id:
+                       return self.backend.blog.get_by_id(self.__data.blog_id)
+
        @property
        def fireinfo_id(self):
                name = self.sname.replace("ipfire-", "IPFire ").replace("-", " - ")
@@ -434,6 +457,12 @@ class Release(Object):
 
 
 class Releases(Object):
+       def _get_releases(self, query, *args):
+               res = self.db.query(query, *args)
+
+               for row in res:
+                       yield Release(self.backend, row.id, data=row)
+
        def get_by_id(self, id):
                ret = self.db.get("SELECT * FROM releases WHERE id = %s", id)
 
@@ -459,6 +488,11 @@ class Releases(Object):
                if ret:
                        return Release(self.backend, ret.id, data=ret)
 
+       def get_releases_older_than(self, release, limit=None):
+               return self._get_releases("SELECT * FROM releases \
+                       WHERE published IS NOT NULL AND published < %s \
+                               ORDER BY published DESC LIMIT %s", release.published, limit)
+
        def get_latest_unstable(self):
                ret = self.db.get("SELECT * FROM releases r1 \
                        WHERE r1.published IS NOT NULL AND r1.published <= NOW() \
diff --git a/src/templates/download/base.html b/src/templates/download/base.html
new file mode 100644 (file)
index 0000000..d108a0c
--- /dev/null
@@ -0,0 +1 @@
+{% extends "../base.html" %}
diff --git a/src/templates/download/index.html b/src/templates/download/index.html
new file mode 100644 (file)
index 0000000..2e20957
--- /dev/null
@@ -0,0 +1,34 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Download") }}{% end block %}
+
+{% block content %}
+       <div class="row justify-content-center my-5">
+               <div class="col col-sm-8 text-center">
+                       <h1>{{ _("Download IPFire") }}</h1>
+
+                       <p class="lead mb-5">
+                               As you download and use IPFire, the IPFire Project invites you to become
+                               an active contributor to our community.
+                       </p>
+
+                       {% module DownloadButton(release) %}
+
+                       <ul class="nav justify-content-center">
+                               {% if release.blog %}
+                                       <li class="nav-item">
+                                               <a class="nav-link" href="https://blog.ipfire.org/post/{{ release.blog.slug }}">
+                                                       {{ _("Release Notes") }}
+                                               </a>
+                                       </li>
+                               {% end %}
+
+                               <li class="nav-item">
+                                       <a class="nav-link" href="/download/{{ release.slug }}">
+                                               {{ _("More Download Options") }}
+                                       </a>
+                               </li>
+                       </nav>
+               </div>
+       </div>
+{% end block %}
diff --git a/src/templates/download/modules/button.html b/src/templates/download/modules/button.html
new file mode 100644 (file)
index 0000000..d8b190d
--- /dev/null
@@ -0,0 +1,3 @@
+<a class="btn btn-primary btn-lg download-splash my-2" href="{{ file.url }}">
+       {{ _("%s for %s") % (release, file.arch) }}
+</a>
diff --git a/src/templates/download/release.html b/src/templates/download/release.html
new file mode 100644 (file)
index 0000000..02130e3
--- /dev/null
@@ -0,0 +1,75 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Download %s") % release }}{% end block %}
+
+{% block content %}
+       <div class="text-center my-5">
+               <h1 class="mb-0">{{ release }}</h1>
+               <h6 class="text-muted">
+                       {{ _("Released %s") % locale.format_date(release.published, relative=False, shorter=True) }}
+
+                       {% if release.blog %}
+                               &bull;
+                               <a href="https://blog.ipfire.org/post/{{ release.blog.slug }}">{{ _("Release Notes") }}</a>
+                       {% end %}
+               </h6>
+       </div>
+
+       <div class="card-deck">
+               {% for arch in release.arches %}
+                       <div class="card">
+                               <div class="card-header text-center">
+                                       <h6 class="my-0">{{ arch }}</h6>
+                               </div>
+
+                               <ul class="list-group list-group-flush">
+                                       {% for file in release.get_files_by_arch(arch) %}
+                                               <li class="list-group-item d-flex flex-column align-items-start">
+                                                       <div class="d-flex w-100 justify-content-between">
+                                                               <a class="download-splash" href="{{ file.url }}">{{ _(file.desc) }}</a>
+
+                                                               {% if file.size >= 1024 * 1024 %}
+                                                                       <span class="text-muted">{{ format_size(file.size) }}</span>
+                                                               {% end %}
+                                                       </div>
+                                               </li>
+                                       {% end %}
+                               </ul>
+                       </div>
+               {% end %}
+       </div>
+
+       <ul class="nav justify-content-center my-3">
+               <li class="nav-item">
+                       <a class="nav-link" data-toggle="collapse" href="#checksums">
+                               {{ _("Checksums") }}
+                       </a>
+               </li>
+       </ul>
+
+       <div class="collapse" id="checksums">
+               <div class="card card-body">
+                       <h5 class="card-title text-center">{{ _("Checksums") }}</h5>
+
+                       <table class="table table-sm">
+                               <thead>
+                                       <tr>
+                                               <th scope="col"></th>
+                                               <th scope="col">{{ _("SHA 1") }}</th>
+                                       </tr>
+                               </thead>
+
+                               <tbody>
+                                       {% for f in release.files %}
+                                               <tr>
+                                                       <td>{{ f.basename }}</td>
+                                                       <td>
+                                                               <pre>{{ f.sha1 }}</pre>
+                                                       </td>
+                                               </tr>
+                                       {% end %}
+                               </tbody>
+                       </table>
+               </div>
+       </div>
+{% end block %}
diff --git a/src/templates/modules/download-button.html b/src/templates/modules/download-button.html
deleted file mode 100644 (file)
index 09667fd..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<a class="btn btn-primary btn-xlg m-5 d-flex justify-content-center" href="{{ escape(image.url) }}">
-       <div class="mr-3">
-               <svg class="icon i_lg i_white i_download"><use xlink:href="#download"/></svg>
-       </div>
-       <div>
-               {{ _("Download %s") % escape(release.name) }}<br>
-               <small>({{ _("ISO-Image") }} - {{ escape(image.arch) }} - {{ format_size(image.size) }})</small>
-       </div>
-</a>
\ No newline at end of file
index 2e1e9f052941a9937fabba8a69b0228b6188dde8..2aafc07bf58d4d9734e5972fd87e8ce2f90c73f5 100644 (file)
@@ -11,6 +11,7 @@ import ipfire
 from handlers import *
 
 from . import blog
+from . import download
 from . import location
 from . import ui_modules
 
@@ -46,11 +47,13 @@ class Application(tornado.web.Application):
                                "BlogPost"             : blog.PostModule,
                                "BlogPosts"            : blog.PostsModule,
 
+                               # Download
+                               "DownloadButton"       : download.ButtonModule,
+
                                # Location
                                "Map"                  : ui_modules.MapModule,
 
                                # Old modules
-                               "DownloadButton"       : ui_modules.DownloadButtonModule,
                                "LanguageName"         : ui_modules.LanguageNameModule,
 
                                "MirrorItem"           : ui_modules.MirrorItemModule,
@@ -86,8 +89,9 @@ class Application(tornado.web.Application):
                        (r"/", IndexHandler),
 
                        # Download sites
-                       (r"/download", DownloadHandler),
                        (r"/downloads", tornado.web.RedirectHandler, { "url" : "/download" }),
+                       (r"/download", download.IndexHandler),
+                       (r"/download/([0-9a-z\-\.]+)", download.ReleaseHandler),
 
                        # Donate
                        (r"/donate", DonateHandler),
diff --git a/src/web/download.py b/src/web/download.py
new file mode 100644 (file)
index 0000000..689d2eb
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import tornado.web
+
+from . import handlers_base as base
+
+from . import ui_modules
+
+class IndexHandler(base.BaseHandler):
+       def get(self):
+               release = self.backend.releases.get_latest()
+               if not release:
+                       raise tornado.web.HTTPError(404)
+
+               self.render("download/index.html", release=release)
+
+
+class ReleaseHandler(base.BaseHandler):
+       def get(self, slug):
+               release = self.backend.releases.get_by_sname(slug)
+               if not release:
+                       raise tornado.web.HTTPError(404)
+
+               self.render("download/release.html", release=release)
+
+
+class ButtonModule(ui_modules.UIModule):
+       def render(self, release):
+               for arch in release.arches:
+                       for file in release.get_files_by_arch(arch):
+                               return self.render_string("download/modules/button.html", release=release, file=file)
+
+               # return nothing
+               return ""