[ckan-changes] [okfn/ckan] d9d991: [2306][model, schema, migration] Add 'created' fie...
GitHub
noreply at github.com
Tue Apr 24 14:56:23 UTC 2012
Branch: refs/heads/master
Home: https://github.com/okfn/ckan
Commit: d9d9915b6853cfc0cd113f0a275cd523c8e9fcd8
https://github.com/okfn/ckan/commit/d9d9915b6853cfc0cd113f0a275cd523c8e9fcd8
Author: John Glover <j at johnglover.net>
Date: 2012-04-24 (Tue, 24 Apr 2012)
Changed paths:
M ckan/lib/dictization/model_save.py
M ckan/logic/schema.py
A ckan/migration/versions/054_add_resource_created_date.py
M ckan/model/package.py
M ckan/model/resource.py
M ckan/tests/lib/test_dictization.py
Log Message:
-----------
[2306][model, schema, migration] Add 'created' field to resource objects
diff --git a/ckan/lib/dictization/model_save.py b/ckan/lib/dictization/model_save.py
index aa9f1a5..0d45b57 100644
--- a/ckan/lib/dictization/model_save.py
+++ b/ckan/lib/dictization/model_save.py
@@ -1,3 +1,4 @@
+import datetime
import uuid
from sqlalchemy.orm import class_mapper
import ckan.lib.dictization as d
@@ -8,7 +9,6 @@
def resource_dict_save(res_dict, context):
model = context["model"]
session = context["session"]
- trigger_url_change = False
id = res_dict.get("id")
obj = None
@@ -29,6 +29,9 @@ def resource_dict_save(res_dict, context):
if key in ('extras', 'revision_timestamp'):
continue
if key in fields:
+ if isinstance(getattr(obj, key), datetime.datetime):
+ if getattr(obj, key).isoformat() == value:
+ continue
if key == 'url' and not new and obj.url <> value:
obj.url_changed = True
setattr(obj, key, value)
diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py
index 0d41722..d756657 100644
--- a/ckan/logic/schema.py
+++ b/ckan/logic/schema.py
@@ -62,6 +62,7 @@ def default_resource_schema():
'webstore_url': [ignore_missing, unicode],
'cache_url': [ignore_missing, unicode],
'size': [ignore_missing, int_validator],
+ 'created': [ignore_missing, isodate],
'last_modified': [ignore_missing, isodate],
'cache_last_updated': [ignore_missing, isodate],
'webstore_last_updated': [ignore_missing, isodate],
diff --git a/ckan/migration/versions/054_add_resource_created_date.py b/ckan/migration/versions/054_add_resource_created_date.py
new file mode 100644
index 0000000..0364150
--- /dev/null
+++ b/ckan/migration/versions/054_add_resource_created_date.py
@@ -0,0 +1,9 @@
+def upgrade(migrate_engine):
+ migrate_engine.execute('''
+ ALTER TABLE resource
+ ADD COLUMN created timestamp without time zone;
+
+ ALTER TABLE resource_revision
+ ADD COLUMN created timestamp without time zone;
+ '''
+ )
diff --git a/ckan/model/package.py b/ckan/model/package.py
index 4365963..dd1e0d3 100644
--- a/ckan/model/package.py
+++ b/ckan/model/package.py
@@ -114,6 +114,7 @@ def get_resource_identity(resource_obj_or_dict):
else:
resource = resource_obj_or_dict
res_dict = resource.as_dict(core_columns_only=True)
+ del res_dict['created']
return res_dict
existing_res_identites = [get_resource_identity(res) \
for res in self.resources]
diff --git a/ckan/model/resource.py b/ckan/model/resource.py
index 3d08575..f370e02 100644
--- a/ckan/model/resource.py
+++ b/ckan/model/resource.py
@@ -3,6 +3,7 @@
from sqlalchemy import orm
from pylons import config
import vdm.sqlalchemy
+import datetime
from meta import *
from types import make_uuid, JsonDictType
@@ -11,7 +12,7 @@
from ckan.model import extension
from ckan.model.activity import ActivityDetail
-__all__ = ['Resource', 'resource_table',
+__all__ = ['Resource', 'resource_table',
'ResourceGroup', 'resource_group_table',
'ResourceRevision', 'resource_revision_table',
'ResourceGroupRevision', 'resource_group_revision_table',
@@ -19,9 +20,9 @@
CORE_RESOURCE_COLUMNS = ['url', 'format', 'description', 'hash', 'name',
'resource_type', 'mimetype', 'mimetype_inner',
- 'size', 'last_modified', 'cache_url', 'cache_last_updated',
- 'webstore_url', 'webstore_last_updated']
-
+ 'size', 'created', 'last_modified', 'cache_url',
+ 'cache_last_updated', 'webstore_url',
+ 'webstore_last_updated']
##formally package_resource
@@ -40,6 +41,7 @@
Column('mimetype', types.UnicodeText),
Column('mimetype_inner', types.UnicodeText),
Column('size', types.BigInteger),
+ Column('created', types.DateTime, default=datetime.datetime.now),
Column('last_modified', types.DateTime),
Column('cache_url', types.UnicodeText),
Column('cache_last_updated', types.DateTime),
diff --git a/ckan/tests/lib/test_dictization.py b/ckan/tests/lib/test_dictization.py
index 09342d2..d32fd89 100644
--- a/ckan/tests/lib/test_dictization.py
+++ b/ckan/tests/lib/test_dictization.py
@@ -353,7 +353,7 @@ def test_08_package_save(self):
def test_09_package_alter(self):
context = {"model": model,
- "session": model.Session}
+ "session": model.Session}
anna1 = model.Session.query(model.Package).filter_by(name='annakarenina').one()
================================================================
Commit: 3b33b0492e7cdbe90e60a3d5c261ed929b17f1fd
https://github.com/okfn/ckan/commit/3b33b0492e7cdbe90e60a3d5c261ed929b17f1fd
Author: John Glover <j at johnglover.net>
Date: 2012-04-24 (Tue, 24 Apr 2012)
Changed paths:
M ckan/lib/helpers.py
M ckan/templates/user/layout.html
M doc/_themes/sphinx-theme-okfn
Log Message:
-----------
Merge remote-tracking branch 'origin/master' into feature-2306-resource-created
diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py
index dfdc0a8..78924b4 100644
--- a/ckan/lib/helpers.py
+++ b/ckan/lib/helpers.py
@@ -112,6 +112,9 @@ def _add_i18n_to_url(url_to_amend, **kw):
root = request.environ.get('SCRIPT_NAME', '')
except TypeError:
root = ''
+ if kw.get('qualified', False):
+ # if qualified is given we want the full url ie http://...
+ root = _routes_default_url_for('/', qualified=True)[:-1] + root
# ckan.root_path is defined when we have none standard language
# position in the url
root_path = config.get('ckan.root_path', None)
diff --git a/ckan/templates/user/layout.html b/ckan/templates/user/layout.html
index cf4d02c..2de8d35 100644
--- a/ckan/templates/user/layout.html
+++ b/ckan/templates/user/layout.html
@@ -14,7 +14,7 @@
</py:when>
<py:otherwise>
<py:if test="c.id">
- <li class="${'active' if c.action=='read' else ''}"><a href="${h.url_for(controller='user', action='me')}">View Profile</a></li>
+ <li class="${'active' if c.action=='read' else ''}"><a href="${h.url_for(controller='user', action='read', id=c.user_dict.name)}">View Profile</a></li>
</py:if>
<py:if test="not c.id">
<li class="${'active' if c.action=='login' else ''}"><a href="${h.url_for(controller='user', action='login')}">Login</a></li>
diff --git a/doc/_themes/sphinx-theme-okfn b/doc/_themes/sphinx-theme-okfn
index ef101a1..fd96c62 160000
--- a/doc/_themes/sphinx-theme-okfn
+++ b/doc/_themes/sphinx-theme-okfn
@@ -1 +1 @@
-Subproject commit ef101a18d6de959207361e233b89efd3be24e66f
+Subproject commit fd96c62b6426a3cc72b3c70314bc4af25e265cb3
================================================================
Commit: 13805f2a2cd0f217ea2e28ce035356bb9c626332
https://github.com/okfn/ckan/commit/13805f2a2cd0f217ea2e28ce035356bb9c626332
Author: John Glover <j at johnglover.net>
Date: 2012-04-24 (Tue, 24 Apr 2012)
Changed paths:
M ckan/public/scripts/application.js
M ckan/public/scripts/templates.js
M ckan/templates/js_strings.html
Log Message:
-----------
[2306][scripts, templates] Add resource 'created' field to edit form (read-only for now)
diff --git a/ckan/public/scripts/application.js b/ckan/public/scripts/application.js
index d94bbd4..3c9b62d 100644
--- a/ckan/public/scripts/application.js
+++ b/ckan/public/scripts/application.js
@@ -638,6 +638,7 @@ CKAN.View.Resource = Backbone.View.extend({
word=='format' ||
word=='hash' ||
word=='id' ||
+ word=='created' ||
word=='last_modified' ||
word=='mimetype' ||
word=='mimetype_inner' ||
diff --git a/ckan/public/scripts/templates.js b/ckan/public/scripts/templates.js
index 66b06cb..6ecad11 100644
--- a/ckan/public/scripts/templates.js
+++ b/ckan/public/scripts/templates.js
@@ -143,6 +143,12 @@ CKAN.Templates.resourceDetails = ' \
</div> \
</div> \
<div class="control-group"> \
+ <label for="" class="control-label" property="rdfs:label">'+CKAN.Strings.created+'</label> \
+ <div class="controls"> \
+ <input type="text" disabled="disabled" value="${resource.created}" class="disabled" /> \
+ </div> \
+ </div> \
+ <div class="control-group"> \
<label class="control-label">'+CKAN.Strings.extraFields+' \
<button class="btn btn-small add-resource-extra">'+CKAN.Strings.addExtraField+'</button>\
</label>\
diff --git a/ckan/templates/js_strings.html b/ckan/templates/js_strings.html
index 5ba337c..76a0d7e 100644
--- a/ckan/templates/js_strings.html
+++ b/ckan/templates/js_strings.html
@@ -51,6 +51,7 @@
CKAN.Strings.datastoreEnabled = "${_('DataStore enabled')}";
CKAN.Strings.sizeBracketsBytes = "${_('Size (Bytes)')}";
CKAN.Strings.mimetype = "${_('Mimetype')}";
+ CKAN.Strings.created = "${_('Created')}";
CKAN.Strings.lastModified = "${_('Last Modified')}";
CKAN.Strings.mimetypeInner = "${_('Mimetype (Inner)')}";
CKAN.Strings.hash = "${_('Hash')}";
================================================================
Commit: 8c360e49df53e0531f560392d5188d9ca9326917
https://github.com/okfn/ckan/commit/8c360e49df53e0531f560392d5188d9ca9326917
Author: John Glover <j at johnglover.net>
Date: 2012-04-24 (Tue, 24 Apr 2012)
Changed paths:
M ckan/lib/base.py
Log Message:
-----------
Merge remote-tracking branch 'origin/master' into feature-2306-resource-created
diff --git a/ckan/lib/base.py b/ckan/lib/base.py
index dd1f03b..ffb79a7 100644
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -53,16 +53,19 @@ def render_snippet(template_name, **kw):
comment tags added to show the template used. NOTE: unlike other
render functions this takes a list of keywords instead of a dict for
the extra template variables. '''
- output = render(template_name, extra_vars=kw)
+ # allow cache_force to be set in render function
+ cache_force = kw.pop('cache_force', None)
+ output = render(template_name, extra_vars=kw, cache_force=cache_force)
output = '\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->\n' % (
template_name, output, template_name)
return literal(output)
-def render_text(template_name, extra_vars=None):
+def render_text(template_name, extra_vars=None, cache_force=None):
''' Helper function to render a genshi NewTextTemplate without
having to pass the loader_class or method. '''
return render(template_name,
extra_vars=extra_vars,
+ cache_force=cache_force,
method='text',
loader_class=NewTextTemplate)
================================================================
Commit: 0dd4efaa71cd264c533688640ea42e8f819d9aaa
https://github.com/okfn/ckan/commit/0dd4efaa71cd264c533688640ea42e8f819d9aaa
Author: John Glover <j at johnglover.net>
Date: 2012-04-24 (Tue, 24 Apr 2012)
Changed paths:
A ckan/migration/versions/055_update_user_and_activity_detail.py
Log Message:
-----------
[xs][migrations] clean up: add missing migration for changes to user table (set name not null) and activiy_detail table
diff --git a/ckan/migration/versions/055_update_user_and_activity_detail.py b/ckan/migration/versions/055_update_user_and_activity_detail.py
new file mode 100644
index 0000000..5d34900
--- /dev/null
+++ b/ckan/migration/versions/055_update_user_and_activity_detail.py
@@ -0,0 +1,9 @@
+def upgrade(migrate_engine):
+ migrate_engine.execute('''
+ ALTER TABLE activity_detail
+ ALTER COLUMN activity_id DROP NOT NULL;
+
+ ALTER TABLE "user"
+ ALTER COLUMN name SET NOT NULL;
+ '''
+ )
================================================================
Commit: ffec1e674707ccea4a4d9448e42f8aaabcb9a977
https://github.com/okfn/ckan/commit/ffec1e674707ccea4a4d9448e42f8aaabcb9a977
Author: John Glover <j at johnglover.net>
Date: 2012-04-24 (Tue, 24 Apr 2012)
Changed paths:
M ckan/lib/base.py
M ckan/lib/dictization/model_save.py
M ckan/lib/helpers.py
M ckan/logic/schema.py
A ckan/migration/versions/054_add_resource_created_date.py
A ckan/migration/versions/055_update_user_and_activity_detail.py
M ckan/model/package.py
M ckan/model/resource.py
M ckan/public/scripts/application.js
M ckan/public/scripts/templates.js
M ckan/templates/js_strings.html
M ckan/templates/user/layout.html
M ckan/tests/lib/test_dictization.py
M doc/_themes/sphinx-theme-okfn
Log Message:
-----------
Merge branch 'feature-2306-resource-created'
diff --git a/ckan/lib/base.py b/ckan/lib/base.py
index dd1f03b..ffb79a7 100644
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -53,16 +53,19 @@ def render_snippet(template_name, **kw):
comment tags added to show the template used. NOTE: unlike other
render functions this takes a list of keywords instead of a dict for
the extra template variables. '''
- output = render(template_name, extra_vars=kw)
+ # allow cache_force to be set in render function
+ cache_force = kw.pop('cache_force', None)
+ output = render(template_name, extra_vars=kw, cache_force=cache_force)
output = '\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->\n' % (
template_name, output, template_name)
return literal(output)
-def render_text(template_name, extra_vars=None):
+def render_text(template_name, extra_vars=None, cache_force=None):
''' Helper function to render a genshi NewTextTemplate without
having to pass the loader_class or method. '''
return render(template_name,
extra_vars=extra_vars,
+ cache_force=cache_force,
method='text',
loader_class=NewTextTemplate)
diff --git a/ckan/lib/dictization/model_save.py b/ckan/lib/dictization/model_save.py
index aa9f1a5..0d45b57 100644
--- a/ckan/lib/dictization/model_save.py
+++ b/ckan/lib/dictization/model_save.py
@@ -1,3 +1,4 @@
+import datetime
import uuid
from sqlalchemy.orm import class_mapper
import ckan.lib.dictization as d
@@ -8,7 +9,6 @@
def resource_dict_save(res_dict, context):
model = context["model"]
session = context["session"]
- trigger_url_change = False
id = res_dict.get("id")
obj = None
@@ -29,6 +29,9 @@ def resource_dict_save(res_dict, context):
if key in ('extras', 'revision_timestamp'):
continue
if key in fields:
+ if isinstance(getattr(obj, key), datetime.datetime):
+ if getattr(obj, key).isoformat() == value:
+ continue
if key == 'url' and not new and obj.url <> value:
obj.url_changed = True
setattr(obj, key, value)
diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py
index dfdc0a8..78924b4 100644
--- a/ckan/lib/helpers.py
+++ b/ckan/lib/helpers.py
@@ -112,6 +112,9 @@ def _add_i18n_to_url(url_to_amend, **kw):
root = request.environ.get('SCRIPT_NAME', '')
except TypeError:
root = ''
+ if kw.get('qualified', False):
+ # if qualified is given we want the full url ie http://...
+ root = _routes_default_url_for('/', qualified=True)[:-1] + root
# ckan.root_path is defined when we have none standard language
# position in the url
root_path = config.get('ckan.root_path', None)
diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py
index 0d41722..d756657 100644
--- a/ckan/logic/schema.py
+++ b/ckan/logic/schema.py
@@ -62,6 +62,7 @@ def default_resource_schema():
'webstore_url': [ignore_missing, unicode],
'cache_url': [ignore_missing, unicode],
'size': [ignore_missing, int_validator],
+ 'created': [ignore_missing, isodate],
'last_modified': [ignore_missing, isodate],
'cache_last_updated': [ignore_missing, isodate],
'webstore_last_updated': [ignore_missing, isodate],
diff --git a/ckan/migration/versions/054_add_resource_created_date.py b/ckan/migration/versions/054_add_resource_created_date.py
new file mode 100644
index 0000000..0364150
--- /dev/null
+++ b/ckan/migration/versions/054_add_resource_created_date.py
@@ -0,0 +1,9 @@
+def upgrade(migrate_engine):
+ migrate_engine.execute('''
+ ALTER TABLE resource
+ ADD COLUMN created timestamp without time zone;
+
+ ALTER TABLE resource_revision
+ ADD COLUMN created timestamp without time zone;
+ '''
+ )
diff --git a/ckan/migration/versions/055_update_user_and_activity_detail.py b/ckan/migration/versions/055_update_user_and_activity_detail.py
new file mode 100644
index 0000000..5d34900
--- /dev/null
+++ b/ckan/migration/versions/055_update_user_and_activity_detail.py
@@ -0,0 +1,9 @@
+def upgrade(migrate_engine):
+ migrate_engine.execute('''
+ ALTER TABLE activity_detail
+ ALTER COLUMN activity_id DROP NOT NULL;
+
+ ALTER TABLE "user"
+ ALTER COLUMN name SET NOT NULL;
+ '''
+ )
diff --git a/ckan/model/package.py b/ckan/model/package.py
index 4365963..dd1e0d3 100644
--- a/ckan/model/package.py
+++ b/ckan/model/package.py
@@ -114,6 +114,7 @@ def get_resource_identity(resource_obj_or_dict):
else:
resource = resource_obj_or_dict
res_dict = resource.as_dict(core_columns_only=True)
+ del res_dict['created']
return res_dict
existing_res_identites = [get_resource_identity(res) \
for res in self.resources]
diff --git a/ckan/model/resource.py b/ckan/model/resource.py
index 3d08575..f370e02 100644
--- a/ckan/model/resource.py
+++ b/ckan/model/resource.py
@@ -3,6 +3,7 @@
from sqlalchemy import orm
from pylons import config
import vdm.sqlalchemy
+import datetime
from meta import *
from types import make_uuid, JsonDictType
@@ -11,7 +12,7 @@
from ckan.model import extension
from ckan.model.activity import ActivityDetail
-__all__ = ['Resource', 'resource_table',
+__all__ = ['Resource', 'resource_table',
'ResourceGroup', 'resource_group_table',
'ResourceRevision', 'resource_revision_table',
'ResourceGroupRevision', 'resource_group_revision_table',
@@ -19,9 +20,9 @@
CORE_RESOURCE_COLUMNS = ['url', 'format', 'description', 'hash', 'name',
'resource_type', 'mimetype', 'mimetype_inner',
- 'size', 'last_modified', 'cache_url', 'cache_last_updated',
- 'webstore_url', 'webstore_last_updated']
-
+ 'size', 'created', 'last_modified', 'cache_url',
+ 'cache_last_updated', 'webstore_url',
+ 'webstore_last_updated']
##formally package_resource
@@ -40,6 +41,7 @@
Column('mimetype', types.UnicodeText),
Column('mimetype_inner', types.UnicodeText),
Column('size', types.BigInteger),
+ Column('created', types.DateTime, default=datetime.datetime.now),
Column('last_modified', types.DateTime),
Column('cache_url', types.UnicodeText),
Column('cache_last_updated', types.DateTime),
diff --git a/ckan/public/scripts/application.js b/ckan/public/scripts/application.js
index d94bbd4..3c9b62d 100644
--- a/ckan/public/scripts/application.js
+++ b/ckan/public/scripts/application.js
@@ -638,6 +638,7 @@ CKAN.View.Resource = Backbone.View.extend({
word=='format' ||
word=='hash' ||
word=='id' ||
+ word=='created' ||
word=='last_modified' ||
word=='mimetype' ||
word=='mimetype_inner' ||
diff --git a/ckan/public/scripts/templates.js b/ckan/public/scripts/templates.js
index 66b06cb..6ecad11 100644
--- a/ckan/public/scripts/templates.js
+++ b/ckan/public/scripts/templates.js
@@ -143,6 +143,12 @@ CKAN.Templates.resourceDetails = ' \
</div> \
</div> \
<div class="control-group"> \
+ <label for="" class="control-label" property="rdfs:label">'+CKAN.Strings.created+'</label> \
+ <div class="controls"> \
+ <input type="text" disabled="disabled" value="${resource.created}" class="disabled" /> \
+ </div> \
+ </div> \
+ <div class="control-group"> \
<label class="control-label">'+CKAN.Strings.extraFields+' \
<button class="btn btn-small add-resource-extra">'+CKAN.Strings.addExtraField+'</button>\
</label>\
diff --git a/ckan/templates/js_strings.html b/ckan/templates/js_strings.html
index 5ba337c..76a0d7e 100644
--- a/ckan/templates/js_strings.html
+++ b/ckan/templates/js_strings.html
@@ -51,6 +51,7 @@
CKAN.Strings.datastoreEnabled = "${_('DataStore enabled')}";
CKAN.Strings.sizeBracketsBytes = "${_('Size (Bytes)')}";
CKAN.Strings.mimetype = "${_('Mimetype')}";
+ CKAN.Strings.created = "${_('Created')}";
CKAN.Strings.lastModified = "${_('Last Modified')}";
CKAN.Strings.mimetypeInner = "${_('Mimetype (Inner)')}";
CKAN.Strings.hash = "${_('Hash')}";
diff --git a/ckan/templates/user/layout.html b/ckan/templates/user/layout.html
index cf4d02c..2de8d35 100644
--- a/ckan/templates/user/layout.html
+++ b/ckan/templates/user/layout.html
@@ -14,7 +14,7 @@
</py:when>
<py:otherwise>
<py:if test="c.id">
- <li class="${'active' if c.action=='read' else ''}"><a href="${h.url_for(controller='user', action='me')}">View Profile</a></li>
+ <li class="${'active' if c.action=='read' else ''}"><a href="${h.url_for(controller='user', action='read', id=c.user_dict.name)}">View Profile</a></li>
</py:if>
<py:if test="not c.id">
<li class="${'active' if c.action=='login' else ''}"><a href="${h.url_for(controller='user', action='login')}">Login</a></li>
diff --git a/ckan/tests/lib/test_dictization.py b/ckan/tests/lib/test_dictization.py
index 09342d2..d32fd89 100644
--- a/ckan/tests/lib/test_dictization.py
+++ b/ckan/tests/lib/test_dictization.py
@@ -353,7 +353,7 @@ def test_08_package_save(self):
def test_09_package_alter(self):
context = {"model": model,
- "session": model.Session}
+ "session": model.Session}
anna1 = model.Session.query(model.Package).filter_by(name='annakarenina').one()
diff --git a/doc/_themes/sphinx-theme-okfn b/doc/_themes/sphinx-theme-okfn
index ef101a1..fd96c62 160000
--- a/doc/_themes/sphinx-theme-okfn
+++ b/doc/_themes/sphinx-theme-okfn
@@ -1 +1 @@
-Subproject commit ef101a18d6de959207361e233b89efd3be24e66f
+Subproject commit fd96c62b6426a3cc72b3c70314bc4af25e265cb3
================================================================
Compare: https://github.com/okfn/ckan/compare/d3eb51a...ffec1e6
More information about the ckan-changes
mailing list