diff options
author | Arun yadav <arunkumar5587@gmail.com> | 2012-05-10 14:25:23 +0530 |
---|---|---|
committer | Arun yadav <arunkumar5587@gmail.com> | 2012-05-10 14:25:23 +0530 |
commit | 4d4df37a9f858d5fc2dc342d06d30b87031000d8 (patch) | |
tree | 13cbe361fe5636596cb1dbce9c0206d463399383 /gstudio | |
parent | fe4a82b80954e4a4666afa71ab3161c8b824f9e9 (diff) | |
parent | b06db59efba106edb115598f822887143e729d33 (diff) | |
download | gnowsys-4d4df37a9f858d5fc2dc342d06d30b87031000d8.tar.gz |
Merge remote-tracking branch 'gn/master'
Diffstat (limited to 'gstudio')
-rw-r--r-- | gstudio/models.py | 8 | ||||
-rw-r--r-- | gstudio/templates/gstudio/base.html | 4 | ||||
-rw-r--r-- | gstudio/templates/gstudio/skeleton.html | 26 | ||||
-rw-r--r-- | gstudio/xmlrpc/__init__.py | 34 | ||||
-rw-r--r-- | gstudio/xmlrpc/metaweblog.py | 193 | ||||
-rw-r--r-- | gstudio/xmlrpc/rpc/views.py | 186 |
6 files changed, 439 insertions, 12 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index 5129716..8177cef 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -816,7 +816,8 @@ class Nodetype(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] - + g_json["relset"]=[] + global counter global attr_counter nbh = self.get_nbh @@ -831,7 +832,8 @@ class Nodetype(Node): this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"expanded":"true"} - g_json["node_metadata"].append(this_node) + g_json["node_metadata"].append(this_node) + g_json["relset"].append(self.id) for key in predicate_id.keys(): if nbh[key]: @@ -851,6 +853,8 @@ class Nodetype(Node): # create nodes g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"expanded":"false"}) + g_json["relset"].append(item.id) + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) #create links diff --git a/gstudio/templates/gstudio/base.html b/gstudio/templates/gstudio/base.html index 20b010d..d0363f3 100644 --- a/gstudio/templates/gstudio/base.html +++ b/gstudio/templates/gstudio/base.html @@ -20,8 +20,8 @@ {% endblock %} {% block sidebar %} - <img src="{{ STATIC_URL }}objectapp/img/rss.png" alt="?" width="20" height="" /> - <a href="{% url objectapp_gbobject_latest_feed %}" class="feeds"><h4>Rssfeed</h4></a> + <img src="{{ STATIC_URL }}gstudio/img/rss.png" alt="?" width="20" height="" /> + <a href="{% url gstudio_nodetype_latest_feed %}" class="feeds"><h4>Rssfeed</h4></a> <div class="search"> <h3>{% trans "Search" %}</h3> diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index c5a15c3..d179220 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -207,6 +207,7 @@ $(function fgraph() { $.getJSON('/nodetypes/graphs/graph_json/' + {{object.id}}, function (json1) { metadata=json1.node_metadata; relations=json1.relations; + relnset=json1.relset init(metadata,relations); load({{object.id}}) }); @@ -282,7 +283,7 @@ var a = 25 * s; - link = d3.select("#chart g.edges").selectAll("line.link") + link = d3.select("#chart g.edges").selectAll("line.link").select(this.arrowhead) .data(edges, function(e){return e.from + "-" + e.to + "-" + e.type}); link.enter().append("svg:line") @@ -304,13 +305,12 @@ var a = 25 * s; }) .attr("text", function(d) { return d.type; - }); + }) + .attr("marker-end", "url(#arrowhead)"); - - var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); @@ -325,6 +325,21 @@ var a = 25 * s; + new_g.append("svg:marker") + .attr("id", "arrowhead") + .attr("viewBox","0 0 10 10") + .attr("refX","20") + .attr("refY","5") + .attr("markerUnits","strokeWidth") + .attr("markerWidth","9") + .attr("markerHeight","5") + .attr("orient","auto") + .append("svg:path") + .attr("d","M 0 0 L 10 5 L 0 10 z") + .attr("fill", "#6D6666"); + + + $(window).bind('keydown',function(event){ if(17==event.keyCode){ new_g.on("click",function(d){ @@ -334,7 +349,8 @@ $(window).bind('keydown',function(event){ d.expanded="true"; $.getJSON('/nodetypes/graphs/graph_json/' + d._id , function (json2) { new_metadata=json2.node_metadata; - new_relations=json2.relations; + new_relations=json2.relations; + new_relnset=json2.relset metadata=_.union(new_metadata,metadata); relations=_.union(new_relations,relations); init(metadata,relations); diff --git a/gstudio/xmlrpc/__init__.py b/gstudio/xmlrpc/__init__.py index 9bec595..afb41e6 100644 --- a/gstudio/xmlrpc/__init__.py +++ b/gstudio/xmlrpc/__init__.py @@ -80,6 +80,38 @@ GSTUDIO_XMLRPC_METAWEBLOG = [ ('gstudio.xmlrpc.metaweblog.get_nbh', 'metaWeblog.get_nbh'), ('gstudio.xmlrpc.metaweblog.new_media_object', - 'metaWeblog.newMediaObject')] + 'metaWeblog.newMediaObject'), + ('gstudio.xmlrpc.metaweblog.getNodetype', + 'metaweblog.getNodetype'), + ('gstudio.xmlrpc.metaweblog.nidExists', + 'metaweblog.nidExists'), + ('gstudio.xmlrpc.metaweblog.getinfoFromSSID', + 'metaweblog.getinfoFromSSID'), + #('gstudio.xmlrpc.metaweblog.getNeighbourhood', + #'metaweblog.getNeighbourhood'), + # ('gstudio.xmlrpc.metaweblog.getallNodes', + # 'metaweblog.getallNodes'), + ('gstudio.xmlrpc.metaweblog.getDatatype', + 'metaweblog.getDatatype'), + ('gstudio.xmlrpc.metaweblog.getAttributevalues', + 'metaweblog.getAttributevalues'), + ('gstudio.xmlrpc.metaweblog.getSubjecttypes', + 'metaweblog.getSubjecttypes'), + #('gstudio.xmlrpc.metaweblog.getAttributeType', + #'metaweblog.getAttributeType'), + ('gstudio.xmlrpc.metaweblog.getRoles', + 'metaweblog.getRoles'), + ('gstudio.xmlrpc.metaweblog.getSubtypes', + 'metaweblog.getSubtypes'), + #('gstudio.xmlrpc.metaweblog.Suballtypes', + #'metaweblog.Suballtypes'), + ('gstudio.xmlrpc.metaweblog.getRestrictions', + 'metaweblog.getRestrictions'), + ('gstudio.xmlrpc.metaweblog.getlatestSSID', + 'metaweblog.getlatestSSID'), + ('gstudio.xmlrpc.metaweblog.getAllSnapshots', + 'metaweblog.getAllSnapshots') +] + GSTUDIO_XMLRPC_METHODS = GSTUDIO_XMLRPC_PINGBACK + GSTUDIO_XMLRPC_METAWEBLOG diff --git a/gstudio/xmlrpc/metaweblog.py b/gstudio/xmlrpc/metaweblog.py index 6c89c21..5b273ea 100644 --- a/gstudio/xmlrpc/metaweblog.py +++ b/gstudio/xmlrpc/metaweblog.py @@ -1,4 +1,4 @@ -# Copyright (c) 2011, 2012 Free Software Foundation + # 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 @@ -70,6 +70,8 @@ from gstudio.settings import PROTOCOL from gstudio.settings import UPLOAD_TO from gstudio.managers import DRAFT, PUBLISHED from django_xmlrpc.decorators import xmlrpc_func +from django.utils.datastructures import SortedDict +from gstudio.models import * # http://docs.nucleuscms.org/blog/12#errorcodes LOGIN_ERROR = 801 @@ -373,4 +375,191 @@ def new_media_object(blog_id, username, password, media): authenticate(username, password) path = default_storage.save(os.path.join(UPLOAD_TO, media['name']), ContentFile(media['bits'].data)) - return {'url': default_storage.url(path)} + return {'url': default_storage.url(path)} + + +@xmlrpc_func(returns='string', args='int') +def getNodetype(ssid): + """Returns the nodetype of given ssid """ + try : + g = Nodetype.objects.get(id=ssid) + return (g.ref._meta.module_name) + except Nodetype.DoesNotExist : + return "Node with the given ssid does not exist" + +@xmlrpc_func(returns='int', args='string') +def nidExists(nid): + """Returns 1 if a node with given id exists, else returns a 0 """ + try: + p = Nodetype.objects.get(title = nid) + return 1 + except Nodetype.DoesNotExist: + return 0 + + +@xmlrpc_func(returns=['struct'],args=['string']) +def getinfoFromSSID(ssid_list) : + """Given a list of ssids, it returns entire information of each ssid inside a dictionary with all the dictionaries contained within a list """ + lst = [] + for ssid in ssid_list : + try : + p = Objecttype.objects.get(id = ssid) + nbh = p.ref.get_nbh + lst.append(str(nbh)) + except Objecttype.DoesNotExist : + return "ssid",ssid,"Does not exist" + + + return lst + + + +@xmlrpc_func(returns=['struct'], args=['string']) + +def getDatatype(attrtype_ssid_list) : + """Given a list of attributessids, it returns its datatypes """ + + d = {} + g = {} + for l in attrtype_ssid_list : + p = NID.objects.get(id = l) + n = p.ref._meta.module_name + if n == 'attributetype' : + ft = FIELD_TYPE_CHOICES[int(p.ref.dataType) - 1] + d[str(p.id)] = ft[1] + else : + return " Node does not exist " + + return d + + +@xmlrpc_func(returns=['struct'], args=['string']) + +def getAttributevalues(Attrssidlist) : + """Given a list of attributessid, it returns their values """ + + d = {} + for l in Attrssidlist : + try : + p = Attribute.objects.get(id = l) + d[str(p.id)] = p.svalue + except Attribute.DoesNotExist : + return " Node does not exist" + + return d + + +@xmlrpc_func(returns=['struct'], args=['string']) + + +def getSubjecttypes( AttributeTypeNid ) : + """Given an attributetypenid, it returns the subjecttype participating in the attributetype """ + d ={} + for l in AttributeTypeNid : + try : + p = Attributetype.objects.get(id = l) + n = p.ref.subjecttype_id + s = NID.objects.get(id = n) + d[str(s.title)]= n + d['applicable_nodetypes'] = p.applicable_nodetypes + except Attribute.DoesNotExist: + return " Node does not exist " + return d + + + + + + +@xmlrpc_func(returns=['struct'], args=['string']) + +def getRoles(relationtypenid) : + """given a relationtype nid this method returns the roles participating in the relationtype """ + + d = {} + p = Relationtype.objects.get(nodetype_ptr_id = relationtypenid) + + d['cardinality1 '] = p.left_cardinality + d['cardinality2'] = p.right_cardinality + d['rtid'] = p.nodetype_ptr_id + d['applicablenodetype1'] = p.left_applicable_nodetypes + d['applicablenodetype2'] = p.right_applicable_nodetypes + d['subjecttype1'] = p.left_subjecttype_id + d['subjecttype2'] = p.right_subjecttype_id + return d + + +@xmlrpc_func(returns=['struct'], args=['string']) + + +def getSubtypes(nodeid) : + """Returns only the immediate subtype of the node specified""" + i = 0 + l = [] + p = Objecttype.objects.get(id = nodeid) + n = p.get_children() + u = len(n) + while u>0 : + t = n[i].id + l.append(str(t)) + i = i+1 + u = u-1 + return l + + + + +@xmlrpc_func(returns=['struct'], args=['string']) + +def getRestrictions(ATlist) : + """Given a list of attributetype ssids, this method returns all the restrictions that the attributetypes have """ + u = {} + d = {} + ft = [] + for a in ATlist : + p = Attributetype.objects.get(id = a) + ft = FIELD_TYPE_CHOICES[int(p.dataType)-1] + u['datatype'] = ft[1] + u['length'] = p.max_digits + u['precision'] = p.decimal_places + d[str(p.id)] = u + + return d + +@xmlrpc_func(returns='int', args='int') + +def getlatestSSID(nid) : + """Given the id, this method will return the latest ssid of the given id """ + + p = NID.objects.get(id = nid) + n = p.get_ssid + u = len(n) + r = n[u-1] + return r + + +@xmlrpc_func(returns=['struct'], args='int') + +def getAllSnapshots(nid) : + """Given the id, this method will return all the ssids of the given id """ + + p = NID.objects.get(id = nid) + n = p.get_ssid + return n + + + + + + + + + + + + + + + + + diff --git a/gstudio/xmlrpc/rpc/views.py b/gstudio/xmlrpc/rpc/views.py new file mode 100644 index 0000000..8c66b38 --- /dev/null +++ b/gstudio/xmlrpc/rpc/views.py @@ -0,0 +1,186 @@ +"""Uses SimpleXMLRPCServer's SimpleXMLRPCDispatcher to serve XML-RPC requests + +Authors:: + Graham Binns + Reza Mohammadi + Julien Fache + +Credit must go to Brendan W. McAdams <brendan.mcadams@thewintergrp.com>, who +posted the original SimpleXMLRPCDispatcher to the Django wiki: +http://code.djangoproject.com/wiki/XML-RPC + +New BSD License +=============== +Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the <ORGANIZATION> nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +""" +import sys + +import django +from django.conf import settings +from django.template import RequestContext +from django.shortcuts import render_to_response +from django.core.exceptions import ImproperlyConfigured +from django.http import HttpResponse, HttpResponseServerError +from gstudio.xmlrpc.metaweblog import * +from django.utils.datastructures import SortedDict +try: + from django.views.decorators.csrf import csrf_exempt +except ImportError: + from django.contrib.csrf.middleware import csrf_exempt + +from dispatcher import DjangoXMLRPCDispatcher +from decorators import xmlrpc_func + + +# We create a local DEBUG variable from the data in settings. +DEBUG = hasattr(settings, 'XMLRPC_DEBUG') and settings.XMLRPC_DEBUG + +# Declare xmlrpcdispatcher correctly depending on our python version +if sys.version_info[:3] >= (2, 5,): + xmlrpcdispatcher = DjangoXMLRPCDispatcher(allow_none=True, encoding=None) +else: + xmlrpcdispatcher = DjangoXMLRPCDispatcher() + + +def request_datas(request): + if django.VERSION[1] > 3: + return request.body + return request.raw_post_data + + +@xmlrpc_func(returns='string', args=['string']) +def test_xmlrpc(text): + """Simply returns the args passed to it as a string""" + return "Here's a response! %s" % str(text) + + +@csrf_exempt +def handle_xmlrpc(request): + """Handles XML-RPC requests. All XML-RPC calls should be forwarded here + + request + The HttpRequest object that carries the XML-RPC call. If this is a + GET request, nothing will happen (we only accept POST requests) + """ + if request.method == "POST": + if DEBUG: + print request_datas(request) + try: + response = HttpResponse(content_type='text/xml') + response.write( + xmlrpcdispatcher._marshaled_dispatch(request_datas(request))) + if DEBUG: + print response + return response + except: + return HttpResponseServerError() + else: + methods = xmlrpcdispatcher.system_listMethods() + method_list = [] + + for method in methods: + sig_ = xmlrpcdispatcher.system_methodSignature(method) + sig = { + 'returns': sig_[0], + 'args': ", ".join(sig_[1:]), + } + + # this just reads your docblock, so fill it in! + method_help = xmlrpcdispatcher.system_methodHelp(method) + + method_list.append((method, sig, method_help)) + + if hasattr(settings, 'XMLRPC_GET_TEMPLATE'): + # This behaviour is deprecated + if settings.DEBUG: + print "Use of settings.XMLRPC_GET_TEMPLATE is deprecated " \ + + "Please update your code to use django_xmlrpc/templates" + template = settings.XMLRPC_GET_TEMPLATE + else: + template = 'xmlrpc_get.html' + return render_to_response(template, {'methods': method_list}, + context_instance=RequestContext(request)) + + +# Load up any methods that have been registered with the server in settings +if hasattr(settings, 'XMLRPC_METHODS'): + for path, name in settings.XMLRPC_METHODS: + # if "path" is actually a function, just add it without fuss + if callable(path): + xmlrpcdispatcher.register_function(path, name) + continue + + # Otherwise we try and find something that we can call + i = path.rfind('.') + module, attr = path[:i], path[i + 1:] + + try: + mod = __import__(module, globals(), locals(), [attr]) + except ImportError, ex: + raise ImproperlyConfigured("Error registering XML-RPC method: " \ + + "module %s can't be imported" % module) + + try: + func = getattr(mod, attr) + except AttributeError: + raise ImproperlyConfigured('Error registering XML-RPC method: ' \ + + 'module %s doesn\'t define a method "%s"' % (module, attr)) + + if not callable(func): + raise ImproperlyConfigured('Error registering XML-RPC method: ' \ + + '"%s" is not callable in module %s' % (attr, module)) + + xmlrpcdispatcher.register_function(func, name) + xmlrpcdispatcher.register_function(getNodetype,'getNodetype') + xmlrpcdispatcher.register_function(nidExists,'nidExists') + xmlrpcdispatcher.register_function(getinfoFromSSID,'getinfoFromSSID') + #xmlrpcdispatcher.register_function(getNeighbourhood,'getNeighbourhood') + xmlrpcdispatcher.register_function(get_nbh,'get_nbh') + #xmlrpcdispatcher.register_function(getallNodes,'getallNodes') + xmlrpcdispatcher.register_function(getDatatype,'getDatatype') + xmlrpcdispatcher.register_function(getAttributevalues,'getAttributevalues') + xmlrpcdispatcher.register_function(getSubjecttypes,'getSubjecttypes') + #xmlrpcdispatcher.register_function(getAttributeType,'getAttributeType') + xmlrpcdispatcher.register_function(getRoles,'getRoles') + xmlrpcdispatcher.register_function(getSubtypes,'getSubtypes') + #xmlrpcdispatcher.register_function(Suballtypes,'Suballtypes') + xmlrpcdispatcher.register_function(getRestrictions,'getRestrictions') + xmlrpcdispatcher.register_function(getlatestSSID,'getlatestSSID') + xmlrpcdispatcher.register_function(getAllSnapshots,'getAllSnapshots') + + + + + + + +# Finally, register the introspection and multicall methods with the XML-RPC +# namespace +xmlrpcdispatcher.register_introspection_functions() +xmlrpcdispatcher.register_multicall_functions() |