diff options
author | gnowgi <nagarjun@gnowledge.org> | 2012-08-12 21:25:59 +0530 |
---|---|---|
committer | gnowgi <nagarjun@gnowledge.org> | 2012-08-12 21:25:59 +0530 |
commit | 3180e360c3eff8f6bf02d3c5fffeb22644a98704 (patch) | |
tree | d1c149de78879ca7b4a250c30269224858f0a130 /gstudio/xmlrpc | |
parent | 968ac9c7f31e8096e614dcd125e37bf0acf80368 (diff) | |
parent | 00659738cb8fe8d6418d8ef5f945a14ce5acd044 (diff) | |
download | gnowsys-3180e360c3eff8f6bf02d3c5fffeb22644a98704.tar.gz |
Merge branch 'master' of git.sv.gnu.org:/srv/git/gnowsys
Diffstat (limited to 'gstudio/xmlrpc')
-rw-r--r-- | gstudio/xmlrpc/__init__.py | 13 | ||||
-rw-r--r-- | gstudio/xmlrpc/metaweblog.py | 116 |
2 files changed, 113 insertions, 16 deletions
diff --git a/gstudio/xmlrpc/__init__.py b/gstudio/xmlrpc/__init__.py index 9b91635..351ca47 100644 --- a/gstudio/xmlrpc/__init__.py +++ b/gstudio/xmlrpc/__init__.py @@ -126,10 +126,13 @@ GSTUDIO_XMLRPC_METAWEBLOG = [ 'metaWeblog.setRelation'), ('gstudio.xmlrpc.metaweblog.get_gbobject_neighbourhood', 'metaWeblog.getGbobjectNeighbourhood'), - ('gstudio.xmlrpc.metaweblog.list_id', - 'metaWeblog.list_id'), - ('gstudio.xmlrpc.metaweblog.dict_id', - 'metaWeblog.dict_id')] - + # ('gstudio.xmlrpc.metaweblog.list_id', + # 'metaWeblog.list_id'), + # ('gstudio.xmlrpc.metaweblog.dict_id', + # 'metaWeblog.dict_id'), + ('gstudio.xmlrpc.metaweblog.show_id', + 'metaWeblog.show_id'), + ('gstudio.xmlrpc.metaweblog.show_instance', + 'metaWeblog.show_instance')] GSTUDIO_XMLRPC_METHODS = GSTUDIO_XMLRPC_PINGBACK + GSTUDIO_XMLRPC_METAWEBLOG diff --git a/gstudio/xmlrpc/metaweblog.py b/gstudio/xmlrpc/metaweblog.py index a77ab82..91d9eda 100644 --- a/gstudio/xmlrpc/metaweblog.py +++ b/gstudio/xmlrpc/metaweblog.py @@ -47,6 +47,7 @@ # OF THE POSSIBILITY OF SUCH DAMAGE. """XML-RPC methods of Gstudio metaWeblog API""" import os +import sys from datetime import datetime from xmlrpclib import Fault from xmlrpclib import DateTime @@ -74,7 +75,10 @@ from django.utils.datastructures import SortedDict from gstudio.models import * from django.contrib.auth.models import User - +import inspect +from gstudio import models as gstmodels +from objectapp import models as objmodels +from objectapp.models import ObjectDoesNotExist # http://docs.nucleuscms.org/blog/12#errorcodes LOGIN_ERROR = 801 @@ -833,15 +837,105 @@ def set_relation(d,obj1,obj2) : except Relationtype.DoesNotExist : return "Relationtype Does Not Exist" -@xmlrpc_func(returns='list') -def list_id(): - """Get a list of Gbobjects' ids""" - return [id.id for id in Gbobject.objects.all()] +# Previous version of the following methods + +# @xmlrpc_func(returns='list') +# def list_id(): +# """Get a list of Gbobjects' ids""" +# return [id.id for id in Gbobject.objects.all()] + +# @xmlrpc_func(returns='struct', args=['string']) +# def dict_id(id=None): +# """Get a Gbobject as a dict or as a list of dicts""" +# if id: +# return Gbobject.objects.get(id="{0}".format(id)) +# else: +# return [dict_id(id) for id in list_id()] + +def class_checker(m): + """Returns a dict which contains all classes of the m module""" + res = {} + for name, obj in inspect.getmembers(m): + if inspect.isclass(obj) and obj.__module__ == m.__name__: + res[name] = obj + return res + +def instance_checker(m, instance, option, id=None): + cc = class_checker(m) + for i in cc.keys(): + if i == instance: + if option == "get": + return cc[i].objects.get(id="{0}".format(id)) + + if option == "all": + return [id.id for id in cc[i].objects.all()] + else: + # http://www.gnu.org/prep/standards/html_node/Errors.html#Errors + sys.stderr.write("metaweblog.py:line872: Wrong arguments\n") + +@xmlrpc_func(returns="struct", args=["string", "string"]) +def show_id(module=None, instance=None): + if (module == "objectapp.models" or module == objmodels) and instance: + return instance_checker(objmodels, instance, "all") + + if (module == "gstudio.models" or module == gstmodels) and instance: + return instance_checker(gstmodels, instance, "all") + + if module == None and instance == None: + def show_all(m): + res = {} + for i in class_checker(m).keys(): + res[i] = show_id(m, i) + return res + + gstres = show_all(gstmodels) + objres = show_all(objmodels) + return gstres, objres -@xmlrpc_func(returns='struct', args=['string']) -def dict_id(id=None): - """Get a Gbobject as a dict or as a list of dicts""" - if id: - return Gbobject.objects.get(id="{0}".format(id)) else: - return [dict_id(id) for id in list_id()] + sys.stderr.write("metaweblog.py:line870: Wrong arguments\n") + +@xmlrpc_func(returns="struct", args=["string", "string", "string"]) +def show_instance(module=None, instance=None, id=None): + try: + if ((module == "objectapp.models" or module == objmodels) and + instance and id): + return instance_checker(objmodels, instance, "get", id) + + if ((module == "gstudio.models" or module == gstmodels) and + instance and id): + return instance_checker(gstmodels, instance, "get", id) + + if ((module == "objectapp.models" or module == objmodels) and + instance): + res = [] + for i in show_id(objmodels, instance): + res.append(instance_checker(objmodels, instance, "get", i)) + return res + + if ((module == "gstudio.models" or module == gstmodels) and + instance): + res = [] + for i in show_id(gstmodels, instance): + res.append(instance_checker(gstmodels, instance, "get", i)) + return res + + if module == None and instance == None and id == None: + def show_all(m, index): + res = [] + for k in show_id()[index].keys(): + for v in show_id()[index][k]: + res.append(show_instance(m, k, v)) + return res + + res = [] + res.append(show_all(gstmodels, 0)) + res.append(show_all(objmodels, 1)) + return res + + else: + sys.stderr.write("metaweblog.py:line898: Wrong arguments\n") + + except ObjectDoesNotExist: + sys.stderr.write("metaweblog.py:line901: " + + "Object matching query does not exist\n") |