diff options
author | gnowgi <nagarjun@gnowledge.org> | 2012-03-15 16:19:20 +0530 |
---|---|---|
committer | gnowgi <nagarjun@gnowledge.org> | 2012-03-15 16:19:20 +0530 |
commit | 7a4f561e851fdc7246d804c3abb6748b8a4199a6 (patch) | |
tree | d2afc3463fd49625a9be482012f5c3bfcf7c42b9 /gstudio/gnowql.py | |
download | gnowsys-7a4f561e851fdc7246d804c3abb6748b8a4199a6.tar.gz |
master trunk of gnowsys-studio
Diffstat (limited to 'gstudio/gnowql.py')
-rw-r--r-- | gstudio/gnowql.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/gstudio/gnowql.py b/gstudio/gnowql.py new file mode 100644 index 0000000..92edd82 --- /dev/null +++ b/gstudio/gnowql.py @@ -0,0 +1,85 @@ +# Copyright (c) 2011, 2012 Free Software Foundation + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + + +from gstudio.models import * +from objectapp.models import * +from reversion.models import Version + +MAP = ( + ('objecttype','Objecttype'), + ('gbobject', 'Gbobject') + ) + + +def get_slug(name): + """ + returns the uri of the node. + """ + try: + """ + note: its very good to use only the meta information given for Version data, + individual object information is best retrieved from the main table. + # Also Version.object.meta contains a lot of valuable information about the model. + """ + node = NID.objects.get(title=str(name)) + # Retrieving only the relevant tupleset for the versioned objects + vrs = Version.objects.filter(type=0 , object_id=node.id) + vrs = vrs[0] + + except: + return "The item was not found." + + return vrs.object.get_absolute_url() + +def get_nodetype(name): + """ + returns the model the id belongs to. + """ + try: + """ + ALGO: get object id, go to version model, return for the given id. + """ + node = NID.objects.get(title=str(name)) + # Retrieving only the relevant tupleset for the versioned objects + vrs = Version.objects.filter(type=0 , object_id=node.id) + # Returned value is a list, so splice it . + vrs = vrs[0] + + except: + return "The item was not found." + + return vrs.object._meta.module_name + + + +def get_node(name): + """ + returns a reference to the model object + """ + nt = get_nodetype(name) + node = NID.objects.get(title=str(name)) + this_id = node.id + if (nt == 'gbobject'): + return Gbobject.objects.get(id=this_id) + + if (nt == 'objecttype'): + return Objecttype.objects.get(id=this_id) + + if (nt == 'metatype'): + return Metatype.objects.get(id=this_id) + + |