[ckan-changes] [okfn/ckan] cbb1d6: [2302] Fixed model and imports in setting model

GitHub noreply at github.com
Fri Apr 20 15:08:51 UTC 2012


  Branch: refs/heads/feature-2302-simple-theming
  Home:   https://github.com/okfn/ckan
  Commit: cbb1d6be881419a069e66d1100eac65ab2eefd8e
      https://github.com/okfn/ckan/commit/cbb1d6be881419a069e66d1100eac65ab2eefd8e
  Author: Ross Jones <rossdjones at gmail.com>
  Date:   2012-04-20 (Fri, 20 Apr 2012)

  Changed paths:
    M ckan/controllers/settings.py
    M ckan/model/__init__.py
    A ckan/model/setting.py
    R ckan/model/settings.py

  Log Message:
  -----------
  [2302] Fixed model and imports in setting model


diff --git a/ckan/controllers/settings.py b/ckan/controllers/settings.py
index 7ddaf07..1f99cf6 100644
--- a/ckan/controllers/settings.py
+++ b/ckan/controllers/settings.py
@@ -5,6 +5,7 @@
 import ckan.lib.navl.dictization_functions as dictfunc
 import ckan.logic as logic
 import ckan.logic.action as action
+import ckan.model as model
 
 from ckan.lib.base import *
 from ckan.lib.helpers import url_for
diff --git a/ckan/model/__init__.py b/ckan/model/__init__.py
index df0d2f5..e12bb24 100644
--- a/ckan/model/__init__.py
+++ b/ckan/model/__init__.py
@@ -16,7 +16,7 @@
 from tag import *
 from package_mapping import *
 from user import user_table, User
-from authorization_group import * 
+from authorization_group import *
 from group import *
 from group_extra import *
 from authz import *
@@ -27,6 +27,7 @@
 from task_status import *
 from vocabulary import *
 from activity import *
+from setting import *
 from term_translation import *
 import ckan.migration
 from ckan.lib.helpers import OrderedDict, datetime_to_date_str
@@ -51,14 +52,14 @@ def init_model(engine):
     except sqlalchemy.exc.NoSuchTableError:
         pass
 
-    
+
 
 class Repository(vdm.sqlalchemy.Repository):
     migrate_repository = ckan.migration.__path__[0]
 
     # note: tables_created value is not sustained between instantiations so
     #       only useful for tests. The alternative is to use are_tables_created().
-    tables_created_and_initialised = False 
+    tables_created_and_initialised = False
 
     def init_db(self):
         '''Ensures tables, const data and some default config is created.
@@ -112,14 +113,14 @@ def init_configuration_data(self):
             rev.author = 'system'
             rev.message = u'Initialising the Repository'
             Session.add(rev)
-        self.commit_and_remove()   
+        self.commit_and_remove()
 
     def create_db(self):
         '''Ensures tables, const data and some default config is created.
         i.e. the same as init_db APART from when running tests, when init_db
         has shortcuts.
         '''
-        self.metadata.create_all(bind=self.metadata.bind)    
+        self.metadata.create_all(bind=self.metadata.bind)
         self.init_const_data()
         self.init_configuration_data()
 
@@ -143,7 +144,7 @@ def rebuild_db(self):
         self.session.remove()
         self.init_db()
         self.session.flush()
-        
+
     def delete_all(self):
         '''Delete all data from all tables.'''
         self.session.remove()
@@ -180,7 +181,7 @@ def upgrade_db(self, version=None):
         self.setup_migration_version_control()
         mig.upgrade(self.metadata.bind, self.migrate_repository, version=version)
         self.init_const_data()
-        
+
         ##this prints the diffs in a readable format
         ##import pprint
         ##from migrate.versioning.schemadiff import getDiffOfModelAgainstDatabase
@@ -307,7 +308,7 @@ def revision_as_dict(revision, include_packages=True, include_groups=True,ref_pa
     if include_groups:
         revision_dict['groups'] = [getattr(grp, ref_package_by) \
                                      for grp in revision.groups if grp]
-       
+
     return revision_dict
 
 def is_id(id_string):
diff --git a/ckan/model/setting.py b/ckan/model/setting.py
new file mode 100644
index 0000000..c529e9e
--- /dev/null
+++ b/ckan/model/setting.py
@@ -0,0 +1,26 @@
+import datetime
+
+
+import core
+import meta
+import types
+import sqlalchemy as sa
+
+__all__ = ['Setting']
+
+setting_table = meta.Table('setting', meta.metadata,
+                     meta.Column('id', sa.types.UnicodeText,
+                                  primary_key=True,
+                                  default=types.make_uuid),
+                     meta.Column('key', sa.types.UnicodeText),
+                     meta.Column('value', sa.types.UnicodeText),
+                     )
+
+class Setting(core.DomainObject):
+
+    @classmethod
+    def get_values(cls, keys):
+        pass
+
+
+meta.mapper(Setting, setting_table)
diff --git a/ckan/model/settings.py b/ckan/model/settings.py
deleted file mode 100644
index 2e71bad..0000000
--- a/ckan/model/settings.py
+++ /dev/null
@@ -1,20 +0,0 @@
-import datetime
-
-from meta import *
-from core import *
-from package import *
-from types import make_uuid
-from user import User
-
-__all__ = ['Setting']
-
-setting_table = Table('setting', metadata,
-                     Column('id', UnicodeText, primary_key=True, default=make_uuid),
-                     Column('key', UnicodeText),
-                     Column('value', UnicodeText),
-                     )
-
-class Setting(DomainObject):
-    pass
-
-mapper(Setting, setting_table)


================================================================
  Commit: 1d5a46263aa298192cdb10b1a058df2e2a15c074
      https://github.com/okfn/ckan/commit/1d5a46263aa298192cdb10b1a058df2e2a15c074
  Author: Ross Jones <rossdjones at gmail.com>
  Date:   2012-04-20 (Fri, 20 Apr 2012)

  Changed paths:
    M ckan/model/setting.py
    M ckan/templates/settings/index.html

  Log Message:
  -----------
  [2302] Added simple setting lookup


diff --git a/ckan/model/setting.py b/ckan/model/setting.py
index c529e9e..ab4fd27 100644
--- a/ckan/model/setting.py
+++ b/ckan/model/setting.py
@@ -20,7 +20,9 @@ class Setting(core.DomainObject):
 
     @classmethod
     def get_values(cls, keys):
-        pass
-
+        query = Session.query(cls)
+        for k in keys:
+            query = query.filter(cls.key == k)
+        return [ (s.key, s.value,) for s in query.all() ]
 
 meta.mapper(Setting, setting_table)
diff --git a/ckan/templates/settings/index.html b/ckan/templates/settings/index.html
index 225b8d1..8480e27 100644
--- a/ckan/templates/settings/index.html
+++ b/ckan/templates/settings/index.html
@@ -39,14 +39,14 @@
               <div class="control-group ${ 'error' if errors.get('name', '') else '' }">
                   <label class="control-label" for="input01">Site name</label>
                   <div class="controls">
-                      <input type="text" class="input-xlarge" id="name" name="name"  value="${data.get('name','')}"/>
+                      <input type="text" class="input-xlarge" id="name" name="name"  value="${data.get('name','CKAN')}"/>
                       <span class="help-inline" py:if="errors.get('name')">${errors['name']}</span>
                   </div>
               </div>
               <div class="control-group ${ 'error' if errors.get('tagline', '') else '' }">
                   <label class="control-label" for="input01">Tag line</label>
                   <div class="controls">
-                      <input type="text" class="input-xlarge" id="tagline" name="tagline"  value="${data.get('tagline','')}"/>
+                      <input type="text" class="input-xlarge" id="tagline" name="tagline"  value="${data.get('tagline','The easy way to get, use and share data')}"/>
                       <span class="help-inline" py:if="errors.get('tagline')">${errors['tagline']}</span>
                   </div>
               </div>
@@ -58,7 +58,7 @@
                   <label class="control-label" for="input01">Header background</label>
                   <div class="controls">
                       <div class="input-prepend">
-                      <span class='add-on'>#</span><input type="text" class="input-xlarge" id="css_header" name="css_header"  value="${data.get('css_header','')}"/>
+                      <span class='add-on'>#</span><input type="text" class="input-xlarge" id="css_header" name="css_header"  value="${data.get('css_header','dbdbdb')}"/>
                       </div>
                       <span class="help-inline" py:if="not errors.get('css_header')">Hexadecimal value for the header</span>
                       <span class="help-inline" py:if="errors.get('css_header')">${errors['css_header']}</span>
@@ -69,7 +69,7 @@
                   <label class="control-label" for="input01">Background</label>
                   <div class="controls">
                       <div class="input-prepend">
-                      <span class='add-on'>#</span><input type="text" class="input-xlarge" id="css_background" name="css_background"  value="${data.get('css_background','')}"/>
+                      <span class='add-on'>#</span><input type="text" class="input-xlarge" id="css_background" name="css_background"  value="${data.get('css_background','ffffff')}"/>
                       </div>
                       <span class="help-inline" py:if="not errors.get('css_background')">Hexadecimal value for the main background</span>
                       <span class="help-inline" py:if="errors.get('css_background')">${errors['css_background']}</span>
@@ -80,7 +80,7 @@
                   <label class="control-label" for="input01">Footer background</label>
                   <div class="controls">
                       <div class="input-prepend">
-                          <span class='add-on'>#</span><input type="text" class="input-xlarge" id="css_footer" name="css_footer"  value="${data.get('css_footer','')}"/>
+                          <span class='add-on'>#</span><input type="text" class="input-xlarge" id="css_footer" name="css_footer"  value="${data.get('css_footer','dbdbdb')}"/>
                       </div>
                       <span class="help-inline" py:if="not errors.get('css_footer')">Hexadecimal value for the footer</span>
                       <span class="help-inline" py:if="errors.get('css_footer')">${errors['css_footer']}</span>


================================================================
Compare: https://github.com/okfn/ckan/compare/e1c747a...1d5a462


More information about the ckan-changes mailing list