moksha/apps/knowledge/moksha/apps/knowledge/model/model.py | 222 ++++++-------
moksha/apps/knowledge/pavement.py | 32 +
moksha/apps/knowledge/pavement.py.hide | 32 -
moksha/public/javascript/jquery.json.js | 156 ---------
moksha/widgets/json.py | 6
moksha/widgets/moksha_js.py | 4
moksha/widgets/static/jquery.json.js | 156 +++++++++
moksha/widgets/static/moksha.js | 1
8 files changed, 307 insertions(+), 302 deletions(-)
New commits:
commit 061449fb0caa477a3edd8a9da20f7ac19518e412
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon Jul 12 13:57:22 2010 -0400
Move some of our javascript files around so we can pull them in from other apps
diff --git a/moksha/public/javascript/jquery.json.js
b/moksha/public/javascript/jquery.json.js
deleted file mode 100644
index 225ca82..0000000
--- a/moksha/public/javascript/jquery.json.js
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * jQuery JSON Plugin
- * version: 1.0 (2008-04-17)
- *
- * This document is licensed as free software under the terms of the
- * MIT License:
http://www.opensource.org/licenses/mit-license.php
- *
- * Brantley Harris technically wrote this plugin, but it is based somewhat
- * on the
JSON.org website's
http://www.json.org/json2.js, which proclaims:
- * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
- * I uphold. I really just cleaned it up.
- *
- * It is also based heavily on MochiKit's serializeJSON, which is
- * copywrited 2005 by Bob Ippolito.
- */
-
-(function($) {
- function toIntegersAtLease(n)
- // Format integers to have at least two digits.
- {
- return n < 10 ? '0' + n : n;
- }
-
- Date.prototype.toJSON = function(date)
- // Yes, it polutes the Date namespace, but we'll allow it here, as
- // it's damned usefull.
- {
- return this.getUTCFullYear() + '-' +
- toIntegersAtLease(this.getUTCMonth()) + '-' +
- toIntegersAtLease(this.getUTCDate());
- };
-
- var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
- var meta = { // table of character substitutions
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '\\': '\\\\'
- };
-
- $.quoteString = function(string)
- // Places quotes around a string, inteligently.
- // If the string contains no control characters, no quote characters, and no
- // backslash characters, then we can safely slap some quotes around it.
- // Otherwise we must also replace the offending characters with safe escape
- // sequences.
- {
- if (escapeable.test(string))
- {
- return '"' + string.replace(escapeable, function (a)
- {
- var c = meta[a];
- if (typeof c === 'string') {
- return c;
- }
- c = a.charCodeAt();
- return '\\u00' + Math.floor(c / 16).toString(16) + (c %
16).toString(16);
- }) + '"';
- }
- return '"' + string + '"';
- };
-
- $.toJSON = function(o, compact)
- {
- var type = typeof(o);
-
- if (type == "undefined")
- return "undefined";
- else if (type == "number" || type == "boolean")
- return o + "";
- else if (o === null)
- return "null";
-
- // Is it a string?
- if (type == "string")
- {
- return $.quoteString(o);
- }
-
- // Does it have a .toJSON function?
- if (type == "object" && typeof o.toJSON ==
"function")
- return o.toJSON(compact);
-
- // Is it an array?
- if (type != "function" && typeof(o.length) ==
"number")
- {
- var ret = [];
- for (var i = 0; i < o.length; i++) {
- ret.push( $.toJSON(o[i], compact) );
- }
- if (compact)
- return "[" + ret.join(",") + "]";
- else
- return "[" + ret.join(", ") + "]";
- }
-
- // If it's a function, we have to warn somebody!
- if (type == "function") {
- throw new TypeError("Unable to convert object of type 'function'
to json.");
- }
-
- // It's probably an object, then.
- var ret = [];
- for (var k in o) {
- var name;
- type = typeof(k);
-
- if (type == "number")
- name = '"' + k + '"';
- else if (type == "string")
- name = $.quoteString(k);
- else
- continue; //skip non-string or number keys
-
- var val = $.toJSON(o[k], compact);
- if (typeof(val) != "string") {
- // skip non-serializable values
- continue;
- }
-
- if (compact)
- ret.push(name + ":" + val);
- else
- ret.push(name + ": " + val);
- }
- return "{" + ret.join(", ") + "}";
- };
-
- $.compactJSON = function(o)
- {
- return $.toJSON(o, true);
- };
-
- $.evalJSON = function(src)
- // Evals JSON that we know to be safe.
- {
- return eval("(" + src + ")");
- };
-
- $.secureEvalJSON = function(src)
- // Evals JSON in a way that is *more* secure.
- {
- var filtered = src;
- filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
- filtered =
filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
']');
- filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
-
- if (/^[\],:{}\s]*$/.test(filtered))
- return eval("(" + src + ")");
- else
- throw new SyntaxError("Error parsing JSON, source is not valid.");
- };
-})(jQuery);
diff --git a/moksha/widgets/json.py b/moksha/widgets/json.py
index ae790fe..5ffe086 100644
--- a/moksha/widgets/json.py
+++ b/moksha/widgets/json.py
@@ -1,2 +1,6 @@
from tw.api import JSLink
-jquery_json_js = JSLink(link='/javascript/jquery.json.js')
+from tw.jquery import jquery_js
+
+jquery_json_js = JSLink(modname=__name__,
+ filename='static/jquery.json.js',
+ javascript=[jquery_js])
diff --git a/moksha/widgets/moksha_js.py b/moksha/widgets/moksha_js.py
index 733be89..d11a88b 100644
--- a/moksha/widgets/moksha_js.py
+++ b/moksha/widgets/moksha_js.py
@@ -17,8 +17,8 @@
from tw.api import JSLink
from tw.jquery import jquery_js
-moksha_js = JSLink(modname="moksha",
- filename='public/javascript/moksha.js',
+moksha_js = JSLink(modname=__name__,
+ filename='static/moksha.js',
javascript=[jquery_js])
moksha_extension_points_js = JSLink(modname="moksha",
diff --git a/moksha/widgets/static/__init__.py b/moksha/widgets/static/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/moksha/widgets/static/jquery.json.js b/moksha/widgets/static/jquery.json.js
new file mode 100644
index 0000000..225ca82
--- /dev/null
+++ b/moksha/widgets/static/jquery.json.js
@@ -0,0 +1,156 @@
+/*
+ * jQuery JSON Plugin
+ * version: 1.0 (2008-04-17)
+ *
+ * This document is licensed as free software under the terms of the
+ * MIT License:
http://www.opensource.org/licenses/mit-license.php
+ *
+ * Brantley Harris technically wrote this plugin, but it is based somewhat
+ * on the
JSON.org website's
http://www.json.org/json2.js, which proclaims:
+ * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
+ * I uphold. I really just cleaned it up.
+ *
+ * It is also based heavily on MochiKit's serializeJSON, which is
+ * copywrited 2005 by Bob Ippolito.
+ */
+
+(function($) {
+ function toIntegersAtLease(n)
+ // Format integers to have at least two digits.
+ {
+ return n < 10 ? '0' + n : n;
+ }
+
+ Date.prototype.toJSON = function(date)
+ // Yes, it polutes the Date namespace, but we'll allow it here, as
+ // it's damned usefull.
+ {
+ return this.getUTCFullYear() + '-' +
+ toIntegersAtLease(this.getUTCMonth()) + '-' +
+ toIntegersAtLease(this.getUTCDate());
+ };
+
+ var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
+ var meta = { // table of character substitutions
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '"' : '\\"',
+ '\\': '\\\\'
+ };
+
+ $.quoteString = function(string)
+ // Places quotes around a string, inteligently.
+ // If the string contains no control characters, no quote characters, and no
+ // backslash characters, then we can safely slap some quotes around it.
+ // Otherwise we must also replace the offending characters with safe escape
+ // sequences.
+ {
+ if (escapeable.test(string))
+ {
+ return '"' + string.replace(escapeable, function (a)
+ {
+ var c = meta[a];
+ if (typeof c === 'string') {
+ return c;
+ }
+ c = a.charCodeAt();
+ return '\\u00' + Math.floor(c / 16).toString(16) + (c %
16).toString(16);
+ }) + '"';
+ }
+ return '"' + string + '"';
+ };
+
+ $.toJSON = function(o, compact)
+ {
+ var type = typeof(o);
+
+ if (type == "undefined")
+ return "undefined";
+ else if (type == "number" || type == "boolean")
+ return o + "";
+ else if (o === null)
+ return "null";
+
+ // Is it a string?
+ if (type == "string")
+ {
+ return $.quoteString(o);
+ }
+
+ // Does it have a .toJSON function?
+ if (type == "object" && typeof o.toJSON ==
"function")
+ return o.toJSON(compact);
+
+ // Is it an array?
+ if (type != "function" && typeof(o.length) ==
"number")
+ {
+ var ret = [];
+ for (var i = 0; i < o.length; i++) {
+ ret.push( $.toJSON(o[i], compact) );
+ }
+ if (compact)
+ return "[" + ret.join(",") + "]";
+ else
+ return "[" + ret.join(", ") + "]";
+ }
+
+ // If it's a function, we have to warn somebody!
+ if (type == "function") {
+ throw new TypeError("Unable to convert object of type 'function'
to json.");
+ }
+
+ // It's probably an object, then.
+ var ret = [];
+ for (var k in o) {
+ var name;
+ type = typeof(k);
+
+ if (type == "number")
+ name = '"' + k + '"';
+ else if (type == "string")
+ name = $.quoteString(k);
+ else
+ continue; //skip non-string or number keys
+
+ var val = $.toJSON(o[k], compact);
+ if (typeof(val) != "string") {
+ // skip non-serializable values
+ continue;
+ }
+
+ if (compact)
+ ret.push(name + ":" + val);
+ else
+ ret.push(name + ": " + val);
+ }
+ return "{" + ret.join(", ") + "}";
+ };
+
+ $.compactJSON = function(o)
+ {
+ return $.toJSON(o, true);
+ };
+
+ $.evalJSON = function(src)
+ // Evals JSON that we know to be safe.
+ {
+ return eval("(" + src + ")");
+ };
+
+ $.secureEvalJSON = function(src)
+ // Evals JSON in a way that is *more* secure.
+ {
+ var filtered = src;
+ filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
+ filtered =
filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
']');
+ filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
+
+ if (/^[\],:{}\s]*$/.test(filtered))
+ return eval("(" + src + ")");
+ else
+ throw new SyntaxError("Error parsing JSON, source is not valid.");
+ };
+})(jQuery);
diff --git a/moksha/widgets/static/moksha.js b/moksha/widgets/static/moksha.js
new file mode 120000
index 0000000..acb0769
--- /dev/null
+++ b/moksha/widgets/static/moksha.js
@@ -0,0 +1 @@
+../../public/javascript/moksha.js
\ No newline at end of file
commit d1f3be55c353bbdd2626e6b67870458f420c289f
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon Jul 12 13:56:51 2010 -0400
Re-enable the knowledge app
diff --git a/moksha/apps/knowledge/moksha/apps/knowledge/model/model.py
b/moksha/apps/knowledge/moksha/apps/knowledge/model/model.py
index 54b76ef..ee67f33 100644
--- a/moksha/apps/knowledge/moksha/apps/knowledge/model/model.py
+++ b/moksha/apps/knowledge/moksha/apps/knowledge/model/model.py
@@ -22,114 +22,114 @@
.. moduleauthor:: Luke Macken <lmacken(a)redhat.com>
"""
-#from sqlalchemy import *
-#from sqlalchemy.orm import *
-#from sqlalchemy.orm.collections import attribute_mapped_collection
-#
-#from datetime import datetime
-#from sqlalchemy import *
-#from sqlalchemy.orm import relation, comparable_property
-#from sqlalchemy.orm.collections import attribute_mapped_collection
-#from vertical import PolymorphicVerticalProperty, VerticalPropertyDictMixin
-#
-##from moksha.model import metadata, DeclarativeBase, DBSession
-#from moksha.apps.knowledge.model import metadata, DeclarativeBase, DBSession
-#
-#
-#class Fact(PolymorphicVerticalProperty, DeclarativeBase):
-# """ A polymorphic-valued vertical table property """
-# __tablename__ = 'moksha_facts'
-#
-# id = Column(Integer, ForeignKey('moksha_entities.id'), primary_key=True)
-# key = Column(Unicode(64), primary_key=True)
-# type_ = Column(Unicode(16), default=None)
-# int_value = Column(Integer, default=None)
-# char_value = Column(UnicodeText, default=None)
-# boolean_value = Column(Boolean, default=None)
-# datetime_value = Column(DateTime, default=None)
-# list_value = Column(PickleType, default=None)
-# dict_value = Column(PickleType, default=None)
-#
-# value = comparable_property(PolymorphicVerticalProperty.Comparator,
-# PolymorphicVerticalProperty.value)
-#
-# type_map = {
-# int: (u'integer', 'int_value'),
-# str: (u'char', 'char_value'),
-# unicode: (u'char', 'char_value'),
-# bool: (u'boolean', 'boolean_value'),
-# datetime: (u'datetime', 'datetime_value'),
-# list: (u'list', 'list_value'),
-# dict: (u'dict', 'dict_value'),
-# type(None): (None, None),
-# }
-#
-#with_characteristic = lambda key, value: and_(Fact.key==key, Fact.value==value)
-#
-#
-#class Entity(VerticalPropertyDictMixin, DeclarativeBase):
-# """ An polymorphic entity.
-#
-# Entity facts are available via the 'facts' property or by using
-# dict-like accessors on an Entity instance::
-#
-# apple = Entity('apple')
-# apple['color'] = 'red'
-# # or, equivalently:
-# apple.facts['color'] = Fact('color', 'red')
-#
-# This Entity is also an adjacency tree. Meaning, every entity
-# can have a `parent` and zero or more `children`.
-# """
-# __tablename__ = 'moksha_entities'
-# _property_type = Fact
-# _property_mapping = 'facts'
-#
-# id = Column(Integer, autoincrement=True, primary_key=True)
-# name = Column(UnicodeText, nullable=False)
-#
-# facts = relation(Fact, backref='entity',
-# collection_class=attribute_mapped_collection('key'))
-#
-# # Adjacency tree properties
-# #id = Column(Integer, Sequence('moksha_tree_id_seq', optional=True),
primary_key=True)
-# parent_id = Column(Integer, ForeignKey('moksha_entities.id'),
nullable=True)
-#
-# children = relation('Entity', cascade="all",
-# backref=backref("parent",
remote_side="Entity.id"),
-# collection_class=attribute_mapped_collection('name'),
-# lazy=False, join_depth=3)
-#
-# def __init__(self, name=None):
-# self.name = name
-#
-# @classmethod
-# def by_name(cls, name):
-# """A class method that permits to search entities
-# based on their name attribute.
-# """
-# return DBSession.query(cls).filter(cls.name==name).first()
-#
-# # Adjacency-tree methods
-# def append(self, node):
-# if isinstance(node, basestring):
-# node = Entity(node)
-# node.parent = self
-# self.children[node.name] = node
-#
-# def __repr__(self):
-# return self._getstring(0, False)
-#
-# def __str__(self):
-# return self._getstring(0, False)
-#
-# def _getstring(self, level, expand = False):
-# s = (' ' * level) + "%s (%s,%s, %d)" % (
-# self.name, self.id,self.parent_id,id(self)) + '\n'
-# if expand:
-# s += ''.join([n._getstring(level+1, True)
-# for n in self.children.values()])
-# return s
-#
-# def print_nodes(self):
-# return self._getstring(0, True)
+from sqlalchemy import *
+from sqlalchemy.orm import *
+from sqlalchemy.orm.collections import attribute_mapped_collection
+
+from datetime import datetime
+from sqlalchemy import *
+from sqlalchemy.orm import relation, comparable_property
+from sqlalchemy.orm.collections import attribute_mapped_collection
+from vertical import PolymorphicVerticalProperty, VerticalPropertyDictMixin
+
+#from moksha.model import metadata, DeclarativeBase, DBSession
+from moksha.apps.knowledge.model import metadata, DeclarativeBase, DBSession
+
+
+class Fact(PolymorphicVerticalProperty, DeclarativeBase):
+ """ A polymorphic-valued vertical table property """
+ __tablename__ = 'moksha_facts'
+
+ id = Column(Integer, ForeignKey('moksha_entities.id'), primary_key=True)
+ key = Column(Unicode(64), primary_key=True)
+ type_ = Column(Unicode(16), default=None)
+ int_value = Column(Integer, default=None)
+ char_value = Column(UnicodeText, default=None)
+ boolean_value = Column(Boolean, default=None)
+ datetime_value = Column(DateTime, default=None)
+ list_value = Column(PickleType, default=None)
+ dict_value = Column(PickleType, default=None)
+
+ value = comparable_property(PolymorphicVerticalProperty.Comparator,
+ PolymorphicVerticalProperty.value)
+
+ type_map = {
+ int: (u'integer', 'int_value'),
+ str: (u'char', 'char_value'),
+ unicode: (u'char', 'char_value'),
+ bool: (u'boolean', 'boolean_value'),
+ datetime: (u'datetime', 'datetime_value'),
+ list: (u'list', 'list_value'),
+ dict: (u'dict', 'dict_value'),
+ type(None): (None, None),
+ }
+
+with_characteristic = lambda key, value: and_(Fact.key==key, Fact.value==value)
+
+
+class Entity(VerticalPropertyDictMixin, DeclarativeBase):
+ """ An polymorphic entity.
+
+ Entity facts are available via the 'facts' property or by using
+ dict-like accessors on an Entity instance::
+
+ apple = Entity('apple')
+ apple['color'] = 'red'
+ # or, equivalently:
+ apple.facts['color'] = Fact('color', 'red')
+
+ This Entity is also an adjacency tree. Meaning, every entity
+ can have a `parent` and zero or more `children`.
+ """
+ __tablename__ = 'moksha_entities'
+ _property_type = Fact
+ _property_mapping = 'facts'
+
+ id = Column(Integer, autoincrement=True, primary_key=True)
+ name = Column(UnicodeText, nullable=False)
+
+ facts = relation(Fact, backref='entity',
+ collection_class=attribute_mapped_collection('key'))
+
+ # Adjacency tree properties
+ #id = Column(Integer, Sequence('moksha_tree_id_seq', optional=True),
primary_key=True)
+ parent_id = Column(Integer, ForeignKey('moksha_entities.id'), nullable=True)
+
+ children = relation('Entity', cascade="all",
+ backref=backref("parent",
remote_side="Entity.id"),
+ collection_class=attribute_mapped_collection('name'),
+ lazy=False, join_depth=3)
+
+ def __init__(self, name=None):
+ self.name = name
+
+ @classmethod
+ def by_name(cls, name):
+ """A class method that permits to search entities
+ based on their name attribute.
+ """
+ return DBSession.query(cls).filter(cls.name==name).first()
+
+ # Adjacency-tree methods
+ def append(self, node):
+ if isinstance(node, basestring):
+ node = Entity(node)
+ node.parent = self
+ self.children[node.name] = node
+
+ def __repr__(self):
+ return self._getstring(0, False)
+
+ def __str__(self):
+ return self._getstring(0, False)
+
+ def _getstring(self, level, expand = False):
+ s = (' ' * level) + "%s (%s,%s, %d)" % (
+ self.name, self.id,self.parent_id,id(self)) + '\n'
+ if expand:
+ s += ''.join([n._getstring(level+1, True)
+ for n in self.children.values()])
+ return s
+
+ def print_nodes(self):
+ return self._getstring(0, True)
diff --git a/moksha/apps/knowledge/pavement.py b/moksha/apps/knowledge/pavement.py
new file mode 100644
index 0000000..8bb2d45
--- /dev/null
+++ b/moksha/apps/knowledge/pavement.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+from paver.easy import *
+from paver.setuputils import (setup, find_package_data, find_packages,
+ install_distutils_tasks)
+install_distutils_tasks()
+from moksha.lib.paver_tasks import *
+
+options(
+ setup=Bunch(
+ name="moksha.knowledge",
+ version="0.1",
+ release="1",
+ url="http://moksha.fedorahosted.org",
+ description="Describe your package here",
+ license="AGPLv3",
+ long_description="",
+ author="",
+ author_email="",
+ rpm_name='moksha-apps-knowledge',
+ packages=find_packages(),
+ package_data=find_package_data(),
+ namespace_packages=[
+ 'moksha',
+ 'moksha.apps',
+ ],
+ install_requires=["Moksha"],
+ entry_points="""
+ [moksha.application]
+ moksha.apps.knowledge =
moksha.apps.knowledge.controllers.root:RootController
+ """,
+ ),
+)
diff --git a/moksha/apps/knowledge/pavement.py.hide
b/moksha/apps/knowledge/pavement.py.hide
deleted file mode 100644
index 8bb2d45..0000000
--- a/moksha/apps/knowledge/pavement.py.hide
+++ /dev/null
@@ -1,32 +0,0 @@
-# -*- coding: utf-8 -*-
-from paver.easy import *
-from paver.setuputils import (setup, find_package_data, find_packages,
- install_distutils_tasks)
-install_distutils_tasks()
-from moksha.lib.paver_tasks import *
-
-options(
- setup=Bunch(
- name="moksha.knowledge",
- version="0.1",
- release="1",
- url="http://moksha.fedorahosted.org",
- description="Describe your package here",
- license="AGPLv3",
- long_description="",
- author="",
- author_email="",
- rpm_name='moksha-apps-knowledge',
- packages=find_packages(),
- package_data=find_package_data(),
- namespace_packages=[
- 'moksha',
- 'moksha.apps',
- ],
- install_requires=["Moksha"],
- entry_points="""
- [moksha.application]
- moksha.apps.knowledge =
moksha.apps.knowledge.controllers.root:RootController
- """,
- ),
-)