[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Mon Aug 8 09:50:16 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/cf9e47134954/
changeset:   cf9e47134954
branch:      release-v1.4.3
user:        dread
date:        2011-08-08 11:48:10
summary:     [doc]: Add info about paster db clean.
affected #:  1 file (536 bytes)

--- a/doc/paster.rst	Mon Aug 08 10:12:41 2011 +0100
+++ b/doc/paster.rst	Mon Aug 08 10:48:10 2011 +0100
@@ -99,16 +99,38 @@
 db: Manage databases
 --------------------
 
-Lets you initialise, upgrade, and dump database files in various formats. 
+Lets you initialise, upgrade, and dump the CKAN database. 
 
-For example, to initialise the CKAN database, creating the tables that CKAN uses (note that you don't need to do this during setup if you have run ``create-test-data``)::
+Initialisation
+~~~~~~~~~~~~~~
+
+Before you can run CKAN for the first time, you need to run "db init" to create the tables in the database and the default authorization settings::
 
  paster --plugin=ckan db init --config=/etc/ckan/std/std.ini
 
-When you upgrade CKAN software by any method *other* than the package update described in :doc:`upgrade`, before you restart it, you should run 'db upgrade', to migrate the database tables if necessary::
+If you forget to do this then CKAN won't serve requests and you will see errors such as this in the logs::
+
+ ProgrammingError: (ProgrammingError) relation "user" does not exist
+
+Cleaning
+~~~~~~~~
+
+You can delete everything in the CKAN database, including the tables, to start from scratch::
+
+ paster --plugin=ckan db clean --config=/etc/ckan/std/std.ini
+
+The next logical step from this point is to do a "db init" step before starting CKAN again.
+
+Upgrade migration
+~~~~~~~~~~~~~~~~~
+
+When you upgrade CKAN software by any method *other* than the package update described in :doc:`upgrade`, before you restart it, you should run 'db upgrade', which will do any necessary migrations to the database tables::
 
  paster --plugin=ckan db upgrade --config=/etc/ckan/std/std.ini
 
+Creating dump files
+~~~~~~~~~~~~~~~~~~~
+
 For information on using ``db`` to create dumpfiles, see :doc:`database_dumps`.
 
 


http://bitbucket.org/okfn/ckan/changeset/ed847ce8ce2f/
changeset:   ed847ce8ce2f
user:        dread
date:        2011-08-08 11:49:14
summary:     [merge] from release-v1.4.3.
affected #:  4 files (2.4 KB)

--- a/ckan/lib/helpers.py	Fri Aug 05 18:36:08 2011 +0100
+++ b/ckan/lib/helpers.py	Mon Aug 08 10:49:14 2011 +0100
@@ -5,7 +5,9 @@
 Consists of functions to typically be used within templates, but also
 available to Controllers. This module is available to templates as 'h'.
 """
-from datetime import datetime
+import datetime
+import re
+
 from webhelpers.html import escape, HTML, literal, url_escape
 from webhelpers.html.tools import mail_to
 from webhelpers.html.tags import *
@@ -28,8 +30,7 @@
     import json
 except ImportError:
     import simplejson as json
-
-ISO_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%f'
+    
 
 class Message(object):
     """A message returned by ``Flash.pop_messages()``.
@@ -210,11 +211,11 @@
     '''
     from ckan import model
     date_format = '%Y-%m-%d %H:%M'
-    if isinstance(datetime_, datetime):
+    if isinstance(datetime_, datetime.datetime):
         return datetime_.strftime(date_format)
     elif isinstance(datetime_, basestring):
         try:
-            datetime_ = model.strptimestamp(datetime_)
+            datetime_ = date_str_to_datetime(datetime_)
         except TypeError:
             return ''
         except ValueError:
@@ -223,8 +224,20 @@
     else:
         return ''
 
-def date_str_to_datetime(date_str, format=ISO_DATE_FORMAT):
-    return datetime.strptime(date_str, format)
+def datetime_to_date_str(datetime_):
+    '''Takes a datetime.datetime object and returns a string of it
+    in ISO format.
+    '''
+    return datetime_.isoformat()
 
-def time_ago_in_words_from_str(date_str, format=ISO_DATE_FORMAT, granularity='month'):
-    return date.time_ago_in_words(datetime.strptime(date_str, format), granularity=granularity)
+def date_str_to_datetime(date_str):
+    '''Takes an ISO format timestamp and returns the equivalent
+    datetime.datetime object.
+    '''
+    # Doing this split is more accepting of input variations than doing
+    # a strptime. Also avoids problem with Python 2.5 not having %f.
+    return datetime.datetime(*map(int, re.split('[^\d]', date_str)))
+
+def time_ago_in_words_from_str(date_str, granularity='month'):
+    return date.time_ago_in_words(date_str_to_datetime(date_str), granularity=granularity)
+


--- a/ckan/model/__init__.py	Fri Aug 05 18:36:08 2011 +0100
+++ b/ckan/model/__init__.py	Mon Aug 08 10:49:14 2011 +0100
@@ -284,7 +284,7 @@
                      and 7 (see datetime constructor).
     raises ValueError if any of the numbers are out of range.
     '''
-    
+    # TODO: METHOD DEPRECATED - use ckan.lib.helpers.date_str_to_datetime
     import datetime, re
     return datetime.datetime(*map(int, re.split('[^\d]', s)))
 
@@ -292,6 +292,7 @@
     '''Takes a datetime.datetime and returns it as an ISO string. For
     a pretty printed string, use ckan.lib.helpers.render_datetime.
     '''
+    # TODO: METHOD DEPRECATED - use ckan.lib.helpers.datetime_to_date_str
     return t.isoformat()
 
 def revision_as_dict(revision, include_packages=True, include_groups=True,ref_package_by='name'):


--- a/ckan/tests/lib/test_helpers.py	Fri Aug 05 18:36:08 2011 +0100
+++ b/ckan/tests/lib/test_helpers.py	Mon Aug 08 10:49:14 2011 +0100
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 import time
+import datetime
+from nose.tools import assert_equal
 
 from ckan.tests import *
 from ckan.lib import helpers as h
@@ -16,4 +18,35 @@
         
     def test_extract_markdown(self):
         assert "Data exposed" in h.markdown_extract(WITH_HTML)
-        assert "collects information" in h.markdown_extract(WITH_UNICODE)
\ No newline at end of file
+        assert "collects information" in h.markdown_extract(WITH_UNICODE)
+
+    def test_render_datetime(self):
+        res = h.render_datetime(datetime.datetime(2008, 4, 13, 20, 40, 20, 123456))
+        assert_equal(res, '2008-04-13 20:40')
+
+    def test_render_datetime_but_from_string(self):
+        res = h.render_datetime('2008-04-13T20:40:20.123456')
+        assert_equal(res, '2008-04-13 20:40')
+
+    def test_render_datetime_blank(self):
+        res = h.render_datetime(None)
+        assert_equal(res, '')
+
+    def test_datetime_to_date_str(self):
+        res = h.datetime_to_date_str(datetime.datetime(2008, 4, 13, 20, 40, 20, 123456))
+        assert_equal(res, '2008-04-13T20:40:20.123456')
+
+    def test_date_str_to_datetime(self):
+        res = h.date_str_to_datetime('2008-04-13T20:40:20.123456')
+        assert_equal(res, datetime.datetime(2008, 4, 13, 20, 40, 20, 123456))
+
+    def test_date_str_to_datetime_without_microseconds(self):
+        # This occurs in ckan.net timestamps - not sure how they appeared
+        res = h.date_str_to_datetime('2008-04-13T20:40:20')
+        assert_equal(res, datetime.datetime(2008, 4, 13, 20, 40, 20))
+
+    def test_time_ago_in_words_from_str(self):
+        two_months_ago = datetime.datetime.now() - datetime.timedelta(days=65)
+        two_months_ago_str = h.datetime_to_date_str(two_months_ago)
+        res = h.time_ago_in_words_from_str(two_months_ago_str)
+        assert_equal(res, '2 months')


--- a/doc/paster.rst	Fri Aug 05 18:36:08 2011 +0100
+++ b/doc/paster.rst	Mon Aug 08 10:49:14 2011 +0100
@@ -99,16 +99,38 @@
 db: Manage databases
 --------------------
 
-Lets you initialise, upgrade, and dump database files in various formats. 
+Lets you initialise, upgrade, and dump the CKAN database. 
 
-For example, to initialise the CKAN database, creating the tables that CKAN uses (note that you don't need to do this during setup if you have run ``create-test-data``)::
+Initialisation
+~~~~~~~~~~~~~~
+
+Before you can run CKAN for the first time, you need to run "db init" to create the tables in the database and the default authorization settings::
 
  paster --plugin=ckan db init --config=/etc/ckan/std/std.ini
 
-When you upgrade CKAN software by any method *other* than the package update described in :doc:`upgrade`, before you restart it, you should run 'db upgrade', to migrate the database tables if necessary::
+If you forget to do this then CKAN won't serve requests and you will see errors such as this in the logs::
+
+ ProgrammingError: (ProgrammingError) relation "user" does not exist
+
+Cleaning
+~~~~~~~~
+
+You can delete everything in the CKAN database, including the tables, to start from scratch::
+
+ paster --plugin=ckan db clean --config=/etc/ckan/std/std.ini
+
+The next logical step from this point is to do a "db init" step before starting CKAN again.
+
+Upgrade migration
+~~~~~~~~~~~~~~~~~
+
+When you upgrade CKAN software by any method *other* than the package update described in :doc:`upgrade`, before you restart it, you should run 'db upgrade', which will do any necessary migrations to the database tables::
 
  paster --plugin=ckan db upgrade --config=/etc/ckan/std/std.ini
 
+Creating dump files
+~~~~~~~~~~~~~~~~~~~
+
 For information on using ``db`` to create dumpfiles, see :doc:`database_dumps`.

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list