diff options
author | Nikita Karetnikov <nikita.karetnikov@gmail.com> | 2012-08-04 05:08:12 +0400 |
---|---|---|
committer | Nikita Karetnikov <nikita.karetnikov@gmail.com> | 2012-08-04 05:08:12 +0400 |
commit | aa603fe30758c821162a2201d70e079c7a59db07 (patch) | |
tree | b800925ee6b956998f5de707441113bf3d7400bf /gstudio/xmlrpc | |
parent | 2651f29410b212021544893d7e967c52fa6dae65 (diff) | |
download | gnowsys-aa603fe30758c821162a2201d70e079c7a59db07.tar.gz |
show_id() and show_instance() for sync-instances
Diffstat (limited to 'gstudio/xmlrpc')
-rw-r--r-- | gstudio/xmlrpc/__init__.py | 13 | ||||
-rw-r--r-- | gstudio/xmlrpc/metaweblog.py | 102 |
2 files changed, 99 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..b583b4a 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,91 @@ 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 == 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") |