From 1cb48d5e6346e9a319af1942bc5a09add3bf4ed9 Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Thu, 22 Mar 2012 08:19:12 +0000 Subject: xmlrpc get_nbh for OT, O, MT .. rudimendtary work --- gstudio/xmlrpc/__init__.py | 4 ++++ gstudio/xmlrpc/metaweblog.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gstudio/xmlrpc/__init__.py b/gstudio/xmlrpc/__init__.py index 88ced6b4..9bec5952 100644 --- a/gstudio/xmlrpc/__init__.py +++ b/gstudio/xmlrpc/__init__.py @@ -75,6 +75,10 @@ GSTUDIO_XMLRPC_METAWEBLOG = [ 'metaWeblog.newPost'), ('gstudio.xmlrpc.metaweblog.edit_post', 'metaWeblog.editPost'), + ('gstudio.xmlrpc.metaweblog.add_nums', + 'metaWeblog.add_nums'), + ('gstudio.xmlrpc.metaweblog.get_nbh', + 'metaWeblog.get_nbh'), ('gstudio.xmlrpc.metaweblog.new_media_object', 'metaWeblog.newMediaObject')] diff --git a/gstudio/xmlrpc/metaweblog.py b/gstudio/xmlrpc/metaweblog.py index 56ee26cb..6c89c21c 100644 --- a/gstudio/xmlrpc/metaweblog.py +++ b/gstudio/xmlrpc/metaweblog.py @@ -64,6 +64,8 @@ from django.template.defaultfilters import slugify from gstudio.models import Nodetype from gstudio.models import Metatype +from gstudio.models import NID +from objectapp.models import Gbobject from gstudio.settings import PROTOCOL from gstudio.settings import UPLOAD_TO from gstudio.managers import DRAFT, PUBLISHED @@ -246,6 +248,36 @@ def new_metatype(blog_id, username, password, metatype_struct): return metatype.pk +@xmlrpc_func(returns='struct', args=['string', 'string']) +def add_nums(num1, num2): + """metaWeblog.add("num1","num2") + => sum""" + num1= int(num1) + num2= int(num2) + return dict({'sum':[num1 + num2]}) + +@xmlrpc_func(returns='string', args=['string', 'string']) +def get_nbh(name, of_type=""): + """metaWeblog.get_nbh("object_name", "type of: [OT, O, MT]") + => nbh""" + # this should be extended to identifying an object with other criteria instead of title as it can be ambiguous + try: + # retrieve the first matching object, (this should be changed to id or an additional specifiers like of_type="OT") + n = NID.objects.filter(title=name)[0] + if not n: + return str({'error':'NOT FOUND'}) + + if n.ref._meta.module_name == 'objecttype' or 'gbobject' or 'metatype': + nbh = n.ref.get_nbh + if nbh: + return str(nbh) + else: + return str({'error':'Error!'}) + else: + return str({'error':'Not applicable as node is not OT, O or MT'}) + except: + return str({'error':'Error!'}) + @xmlrpc_func(returns='string', args=['string', 'string', 'string', 'struct', 'boolean']) def new_post(blog_id, username, password, post, publish): -- cgit v1.2.3-70-g09d2