Get the list of documentation versions out of the database
authorMagnus Hagander <magnus@hagander.net>
Sat, 17 Aug 2013 15:28:36 +0000 (17:28 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 17 Aug 2013 15:28:36 +0000 (17:28 +0200)
Instead of having to update this list manually in multiple places when
releasing new versions, just take the information out of the database
where it has to be anyway.

Fixes #90
Closes #93

Also make the code automatically pick up wich PDF files exist in the
static checkout, and auto-detect their size, both A4 and US sizes. This
removes yet one more manual step, yay!

Fixes #163

pgweb/core/models.py
pgweb/docs/views.py
pgweb/settings.py
pgweb/urls.py
templates/pages/docs.html
templates/pages/docs/manuals.html
templates/pages/docs/manuals/archive.html

index 13b747abf4eb293b0e239eddb0cf30b16ac740fa..7dbcb18304ee268ea04e23c0ef7b5dea5b6d3cf7 100644 (file)
@@ -27,6 +27,13 @@ class Version(PgModel, models.Model):
                else:
                        return "%sbeta%s" % (self.tree, self.latestminor)
 
+       @property
+       def treestring(self):
+               if not self.beta:
+                       return self.tree
+               else:
+                       return "%s beta" % self.tree
+
        def save(self):
                # Make sure only one version at a time can be the current one.
                # (there may be some small race conditions here, but the likelyhood
index c0bb86a480a368f863a85680f94da2bbe0a5a2d8..07c812cf3b5204a5d947930f8069adda79cdb9c5 100644 (file)
@@ -2,8 +2,11 @@ from django.shortcuts import render_to_response, get_object_or_404
 from django.http import HttpResponse, Http404, HttpResponseRedirect
 from django.template import TemplateDoesNotExist, loader, Context
 from django.contrib.auth.decorators import login_required
+from django.db.models import Q
+from django.conf import settings
 
 from decimal import Decimal
+import os
 
 from pgweb.util.decorators import ssl_required
 from pgweb.util.contexts import NavContext
@@ -72,6 +75,42 @@ def docsrootpage(request, version, typ):
 def redirect_root(request, version):
        return HttpResponseRedirect("/docs/%s/static/" % version)
 
+def root(request):
+       versions = Version.objects.filter(Q(supported=True) | Q(beta=True,tree__gt=0)).order_by('-tree')
+       return render_to_response('pages/docs.html', {
+               'versions': versions,
+       }, NavContext(request, 'docs'))
+
+class _VersionPdfWrapper(Version):
+       """
+       A wrapper around a version that knows to look for PDF files, and
+       return their sizes.
+       """
+       def __init__(self, version):
+               self.__version = version
+               self.a4pdf = self._find_pdf('A4')
+               self.uspdf = self._find_pdf('US')
+       def __getattr__(self, name):
+               return getattr(self.__version, name)
+       def _find_pdf(self, pagetype):
+               try:
+                       return os.stat('%s/documentation/pdf/%s/postgresql-%s-%s.pdf' % (settings.STATIC_CHECKOUT, self.__version.tree, self.__version.tree, pagetype)).st_size
+               except:
+                       return 0
+
+def manuals(request):
+       # We don't include beta's here. Why?
+       versions = Version.objects.filter(supported=True).order_by('-tree')
+       return render_to_response('pages/docs/manuals.html', {
+               'versions': [_VersionPdfWrapper(v) for v in versions],
+       }, NavContext(request, 'docs'))
+
+def manualarchive(request):
+       versions = Version.objects.filter(beta=False,tree__gt=0).order_by('-tree')
+       return render_to_response('pages/docs/manuals/archive.html', {
+               'versions': [_VersionPdfWrapper(v) for v in versions],
+       }, NavContext(request, 'docs'))
+
 @ssl_required
 @login_required
 def commentform(request, itemid, version, filename):
index 61ce975afc5a67922e05dba4a879503f09affbc8..b4164d6ef9496df123c6f46bb2ee02382e49bf86 100644 (file)
@@ -143,6 +143,7 @@ SESSION_COOKIE_SECURE=True                             # Allow our session only
 SESSION_COOKIE_DOMAIN="www.postgresql.org"             # Don't allow access by other postgresql.org sites
 SITE_ROOT="http://www.postgresql.org"                  # Root of working URLs
 FTP_PICKLE="/usr/local/pgweb/ftpsite.pickle"           # Location of file with current contents from ftp site
+STATIC_CHECKOUT="/usr/local/pgweb-static"              # Location of a checked out pgweb-static project
 NOTIFICATION_EMAIL="someone@example.com"               # Address to send notifications *to*
 NOTIFICATION_FROM="someone@example.com"                # Address to send notifications *from*
 LISTSERVER_EMAIL="someone@example.com"                 # Address to majordomo
index 7773849dd2746cb3a7fde5c69dc8745e54335457..f90b61696c8ddf6c42394794237c758d947192a6 100644 (file)
@@ -39,6 +39,9 @@ urlpatterns = patterns('',
     (r'^applications-v2.xml$', 'downloads.views.applications_v2_xml'),
     (r'^download/uploadftp/', 'downloads.views.uploadftp'),
 
+    (r'^docs/$', 'docs.views.root'),
+    (r'^docs/manuals/$', 'docs.views.manuals'),
+    (r'^docs/manuals/archive/$', 'docs.views.manualarchive'),
     (r'^docs/(current|devel|\d\.\d)/(static|interactive)/(.*).html?$', 'docs.views.docpage'),
     (r'^docs/(current|devel|\d\.\d)/(static|interactive)/$', 'docs.views.docsrootpage'),
     (r'^docs/(current|devel|\d\.\d)/$', 'docs.views.redirect_root'),
index 52a3629465be019c01692097d939452de39f2ad1..acb14d2032f45c4c9852dec202dcb4abd1d95c20 100644 (file)
@@ -21,11 +21,9 @@ written about PostgreSQL (some of which are available in their entirety online).
   <dl>
     <dt>Online Manuals</dt>
     <dd>
-        <p><b>9.3 beta</b> (<a href="/docs/9.3/static/index.html">without</a> comments)</p>
-        <p><b>9.2</b> (<a href="/docs/9.2/interactive/index.html">with</a>/<a href="/docs/9.2/static/index.html">without</a> comments)</p>
-        <p><b>9.1</b> (<a href="/docs/9.1/interactive/index.html">with</a>/<a href="/docs/9.1/static/index.html">without</a> comments)</p>
-        <p><b>9.0</b> (<a href="/docs/9.0/interactive/index.html">with</a>/<a href="/docs/9.0/static/index.html">without</a> comments)</p>
-        <p><b>8.4</b> (<a href="/docs/8.4/interactive/index.html">with</a>/<a href="/docs/8.4/static/index.html">without</a> comments)</p>
+{%for v in versions%}
+        <p><b>{{v.treestring}}</b> ({%if not v.beta%}<a href="/docs/{{v.tree}}/interactive/index.html">with</a>/{%endif%}<a href="/docs/{{v.tree}}/static/index.html">without</a> comments)</p>
+{%endfor%}
     </dd>
     <dt>Translated Manuals</dt>
     <dd>
index d9f908dd28380b050c386e4e78fe96838fa41225..13aed1290e91792ffcec20b7ba3b14eae431f9d9 100644 (file)
        <th class="colMid">Online Version</th>
        <th class="colLast">Downloadable Version</th>
 </tr>
-<tr>
-    <td class="colFirst">9.2</td>
+{%for v in versions%}
+<tr{%if forloop.last%} class="lastrow"{%endif%}>
+    <td class="colFirst">{{v.tree}}</td>
     <td class="colMid">
           <ul>
-              <li><a href="/docs/9.2/interactive/index.html">With user comments</a></li>
-             <li><a href="/docs/9.2/static/index.html">Without user comments</a></li>
+              <li><a href="/docs/{{v.tree}}/interactive/index.html">With user comments</a></li>
+             <li><a href="/docs/{{v.tree}}/static/index.html">Without user comments</a></li>
          </ul>
     </td>
     <td class="colLast">
        <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/9.2/postgresql-9.2-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(6.1 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/9.2/postgresql-9.2-US.pdf">US PDF</a> <span class="txtMediumGrey">(6.2 MB)</span></li>
+         {%if v.a4pdf%}<li>Comprehensive Manual: <a href="/files/documentation/pdf/{{v.tree}}/postgresql-{{v.tree}}-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">({{v.a4pdf|filesizeformat}})</span></li>{%endif%}
+         {%if v.uspdf%}<li>Comprehensive Manual: <a href="/files/documentation/pdf/{{v.tree}}/postgresql-{{v.tree}}-US.pdf">US PDF</a> <span class="txtMediumGrey">({{v.uspdf|filesizeformat}})</span></li>{%endif%}
        </ul>
     </td>
 </tr>
-<tr>
-    <td class="colFirst">9.1</td>
-    <td class="colMid">
-          <ul>
-              <li><a href="/docs/9.1/interactive/index.html">With user comments</a></li>
-             <li><a href="/docs/9.1/static/index.html">Without user comments</a></li>
-         </ul>
-    </td>
-    <td class="colLast">
-       <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/9.1/postgresql-9.1-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(5.9 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/9.1/postgresql-9.1-US.pdf">US PDF</a> <span class="txtMediumGrey">(5.9 MB)</span></li>
-       </ul>
-    </td>
-</tr>
-<tr>
-    <td class="colFirst">9.0</td>
-    <td class="colMid">
-          <ul>
-              <li><a href="/docs/9.0/interactive/index.html">With user comments</a></li>
-             <li><a href="/docs/9.0/static/index.html">Without user comments</a></li>
-         </ul>
-    </td>
-    <td class="colLast">
-       <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/9.0/postgresql-9.0-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(5.4 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/9.0/postgresql-9.0-US.pdf">US PDF</a> <span class="txtMediumGrey">(5.5 MB)</span></li>
-       </ul>
-    </td>
-</tr>
-<tr>
-    <td class="colFirst">8.4</td>
-    <td class="colMid">
-          <ul>
-              <li><a href="/docs/8.4/interactive/index.html">With user comments</a></li>
-              <li><a href="/docs/8.4/static/index.html">Without user comments</a></li>
-          </ul>
-      </td>
-      <td class="colLast">
-        <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.4/postgresql-8.4-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(5.0 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.4/postgresql-8.4-US.pdf">US PDF</a> <span class="txtMediumGrey">(5.1 MB)</span></li>
-        </ul>
-      </td>
-</tr>
+{%endfor%}
 </table>
 </div>
 
index 8393054f558f5fe0d0e8f9b55cedd14cdda96a44..45208b13fd21490c89164c25c2fc22518fd93ffc 100644 (file)
@@ -15,188 +15,23 @@ If you are still using any of these releases, you are strongly advised to upgrad
        <th class="colLast">PDF Version</th>
 </tr>
 
-<tr>
-    <td class="colFirst">8.3</td>
+{%for v in versions%}
+<tr{%if forloop.last%} class="lastrow"{%endif%}>
+    <td class="colFirst">{{v.tree}}</td>
     <td class="colMid">
           <ul>
-              <li><a href="/docs/8.3/static/index.html">Without user comments</a></li>
+              <li><a href="/docs/{{v.tree}}/static/index.html">Without user comments</a></li>
           </ul>
       </td>
       <td class="colLast">
        <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.3/postgresql-8.3-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(4.6 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.3/postgresql-8.3-US.pdf">US PDF</a> <span class="txtMediumGrey">(4.6 MB)</span></li> 
+         {%if v.a4pdf%}<li>Comprehensive Manual: <a href="/files/documentation/pdf/{{v.tree}}/postgresql-{{v.tree}}-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">({{v.a4pdf|filesizeformat}})</span></li>{%endif%}
+         {%if v.uspdf%}<li>Comprehensive Manual: <a href="/files/documentation/pdf/{{v.tree}}/postgresql-{{v.tree}}-US.pdf">US PDF</a> <span class="txtMediumGrey">({{v.uspdf|filesizeformat}})</span></li>{%endif%}
+         {%if not v.a4pdf and not v4.uspdf%}<li>PDF version noot available</li>{%endif%}
        </ul>
       </td>
 </tr>
-<tr>
-       <td class="colFirst">8.2</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/8.2/static/index.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.2/postgresql-8.2-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(5.5 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.2/postgresql-8.2-US.pdf">US PDF</a> <span class="txtMediumGrey">(14 MB)</span></li>
-    </ul>
-       </td>
-</tr>
-
-<tr>
-       <td class="colFirst">8.1</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/8.1/static/index.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.1/postgresql-8.1-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(12.1 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.1/postgresql-8.1-US.pdf">US PDF</a> <span class="txtMediumGrey">(12.1 MB)</span></li>
-    </ul>
-       </td>
-</tr>
-
-<tr>
-       <td class="colFirst">8.0</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/8.0/static/index.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.0/postgresql-8.0-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(9.8 MB)</span></li>
-            <li>Comprehensive Manual: <a href="/files/documentation/pdf/8.0/postgresql-8.0-US.pdf">US PDF</a> <span class="txtMediumGrey">(9.9 MB)</span></li>
-    </ul>
-       </td>
-</tr>
-
-<tr>
-       <td class="colFirst">7.4</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/7.4/static/index.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-       <li>Comprehensive Manual: <a href="/files/documentation/pdf/7.4/postgresql-7.4.2-A4.pdf">A4 PDF</a> <span class="txtMediumGrey">(9.0 MB)</span></li>
-        <li>Comprehensive Manual: <a href="/files/documentation/pdf/7.4/postgresql-7.4.2-US.pdf">US PDF</a> <span class="txtMediumGrey">(9.1 MB)</span></li>
-    </ul>
-       </td>
-</tr>
-
-<tr>
-       <td class="colFirst">7.3</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/7.3/static/index.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-        <li>Administrators Guide: <a href="/files/documentation/pdf/7.3/admin-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/admin-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>System Catalog Diagram: <a href="/files/documentation/pdf/7.3/catalogs-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/catalogs-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>Connection Diagram: <a href="/files/documentation/pdf/7.3/connections-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/connections-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>Developers Guide: <a href="/files/documentation/pdf/7.3/developer-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/developer-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>Programmers Guide: <a href="/files/documentation/pdf/7.3/programmer-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/programmer-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>Reference Guide: <a href="/files/documentation/pdf/7.3/reference-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/reference-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>Tutorial: <a href="/files/documentation/pdf/7.3/tutorial-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/tutorial-7.3.2-A4.pdf">A4 PDF</a></li>
-        <li>Users Guide: <a href="/files/documentation/pdf/7.3/user-7.3.2-US.pdf">US PDF</a> | <a href="/files/documentation/pdf/7.3/user-7.3.2-A4.pdf">A4 PDF</a></li>
-    </ul>
-       </td>
-</tr>
-<tr class="lastrow">
-       <td class="colFirst">7.2</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/7.2/static/index.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-        <li>Administrators Guide: <a href="/files/documentation/pdf/7.2/admin-7.2-US.pdf">US</a> <a href="/files/documentation/pdf/7.2/admin-7.2-A4.pdf">A4</a></li>
-        <li>Developers Guide: <a href="/files/documentation/pdf/7.2/developer-7.2-US.pdf">US</a> <a href="/files/documentation/pdf/7.2/developer-7.2-A4.pdf">A4</a></li>
-        <li>Programmers Guide: <a href="/files/documentation/pdf/7.2/programmer-7.2-US.pdf">US</a> <a href="/files/documentation/pdf/7.2/programmer-7.2-A4.pdf">A4</a></li>
-        <li>Reference Guide: <a href="/files/documentation/pdf/7.2/reference-7.2-US.pdf">US</a> <a href="/files/documentation/pdf/7.2/reference-7.2-A4.pdf">A4</a></li>
-        <li>Tutorial: <a href="/files/documentation/pdf/7.2/tutorial-7.2-US.pdf">US</a> <a href="/files/documentation/pdf/7.2/tutorial-7.2-A4.pdf">A4</a></li>
-        <li>Users Guide: <a href="/files/documentation/pdf/7.2/user-7.2-US.pdf">US</a> <a href="/files/documentation/pdf/7.2/user-7.2-A4.pdf">A4</a></li>
-    </ul>
-       </td>
-</tr>
-<tr>
-       <td class="colFirst">7.1</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/7.1/static/postgres.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-        <li><a href="/files/documentation/pdf/7.1/admin.pdf">Administrators Guide</a></li>
-        <li><a href="/files/documentation/pdf/7.1/developer.pdf">Developers Guide</a></li>
-        <li><a href="/files/documentation/pdf/7.1/programmer.pdf">Programmers Guide</a></li>
-        <li><a href="/files/documentation/pdf/7.1/reference.pdf">Reference Guide</a></li>
-        <li><a href="/files/documentation/pdf/7.1/tutorial.pdf">Tutorial</a></li>
-        <li><a href="/files/documentation/pdf/7.1/user.pdf">Users Guide</a></li>
-    </ul>
-       </td>
-</tr>
-<tr>
-       <td class="colFirst">7.0</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/7.0/static/postgres.html">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-               <li><span class="txtMediumGrey">PDF version not available</span></li>
-       </ul>
-       </td>
-</tr>
-<tr>
-       <td class="colFirst">6.5</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/6.5/static/postgres.htm">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-               <li><span class="txtMediumGrey">PDF version not available</span></li>
-       </ul>
-       </td>
-</tr>
-<tr>
-       <td class="colFirst">6.4</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/6.4/static/postgres.htm">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-               <li><span class="txtMediumGrey">PDF version not available</span></li>
-       </ul>
-       </td>
-</tr>
-<tr class="lastrow">
-       <td class="colFirst">6.3</td>
-       <td class="colMid">
-       <ul>
-        <li><a href="/docs/6.3/static/book01.htm">Without user comments</a></li>
-    </ul>
-       </td>
-       <td class="colLast">
-       <ul>
-               <li><span class="txtMediumGrey">PDF version not available</span></li>
-       </ul>
-       </td>
-</tr>
+{%endfor%}
 </table>
 </div>
 {%endblock%}