From b9693682ac430602e87b7373471a759f17092f7f Mon Sep 17 00:00:00 2001 From: sndt2012 Date: Thu, 12 Apr 2012 16:51:24 +0530 Subject: xmlrpc module created in gstudio/xmlrpc.xmlrpc queries routed to this module. --- demo/urls.py | 2 +- gstudio/xmlrpc/__init__.py | 8 +- gstudio/xmlrpc/django_xmlrpc/__init__.py | 44 +++++ gstudio/xmlrpc/django_xmlrpc/decorators.py | 179 +++++++++++++++++++++ gstudio/xmlrpc/django_xmlrpc/dispatcher.py | 76 +++++++++ .../django_xmlrpc/locale/fr/LC_MESSAGES/django.mo | Bin 0 -> 1030 bytes .../django_xmlrpc/locale/fr/LC_MESSAGES/django.po | 49 ++++++ .../xmlrpc/django_xmlrpc/templates/xmlrpc_get.html | 26 +++ gstudio/xmlrpc/django_xmlrpc/views.py | 160 ++++++++++++++++++ gstudio/xmlrpc/django_xmlrpc/views.py~ | 160 ++++++++++++++++++ gstudio/xmlrpc/metaweblog.py | 80 +++++++++ 11 files changed, 782 insertions(+), 2 deletions(-) create mode 100644 gstudio/xmlrpc/django_xmlrpc/__init__.py create mode 100644 gstudio/xmlrpc/django_xmlrpc/decorators.py create mode 100644 gstudio/xmlrpc/django_xmlrpc/dispatcher.py create mode 100644 gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.mo create mode 100644 gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.po create mode 100644 gstudio/xmlrpc/django_xmlrpc/templates/xmlrpc_get.html create mode 100644 gstudio/xmlrpc/django_xmlrpc/views.py create mode 100644 gstudio/xmlrpc/django_xmlrpc/views.py~ diff --git a/demo/urls.py b/demo/urls.py index ce2e623..c2f6fab 100644 --- a/demo/urls.py +++ b/demo/urls.py @@ -88,7 +88,7 @@ urlpatterns = patterns( url(r'^nodetypes/', include('gstudio.urls')), url(r'^objects/', include('objectapp.urls')), url(r'^comments/', include('django.contrib.comments.urls')), - url(r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc'), + url(r'^xmlrpc/$', 'gstudio.xmlrpc.django_xmlrpc1.views.handle_xmlrpc'), url(r'^i18n/', include('django.conf.urls.i18n')), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), diff --git a/gstudio/xmlrpc/__init__.py b/gstudio/xmlrpc/__init__.py index 9bec595..8bdb1ce 100644 --- a/gstudio/xmlrpc/__init__.py +++ b/gstudio/xmlrpc/__init__.py @@ -80,6 +80,12 @@ 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.nodeExists', + 'metaWeblog.nodeExists'), + ('gstudio.xmlrpc.metaweblog.getinfoFromSSID', + 'metaWeblog.getinfoFromSSID')] GSTUDIO_XMLRPC_METHODS = GSTUDIO_XMLRPC_PINGBACK + GSTUDIO_XMLRPC_METAWEBLOG diff --git a/gstudio/xmlrpc/django_xmlrpc/__init__.py b/gstudio/xmlrpc/django_xmlrpc/__init__.py new file mode 100644 index 0000000..1d58f71 --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/__init__.py @@ -0,0 +1,44 @@ +"""__init__ module for the django_xmlrpc package + +Authors:: + Graham Binns + Julien Fache + +Credit must go to Brendan W. McAdams , 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 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. +""" +VERSION = (0, 1, 1) +__version__ = '.'.join(map(str, VERSION)) + +from views import xmlrpcdispatcher diff --git a/gstudio/xmlrpc/django_xmlrpc/decorators.py b/gstudio/xmlrpc/django_xmlrpc/decorators.py new file mode 100644 index 0000000..fc1ca83 --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/decorators.py @@ -0,0 +1,179 @@ +"""Offers decorators to make the use of django_xmlrpc a great deal simpler + +Authors:: + Graham Binns, + Reza Mohammadi + +Credit must go to Brendan W. McAdams , 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 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. +""" +from xmlrpclib import Fault +from django.contrib.auth import authenticate +from django.utils.translation import gettext as _ + + +# Some constants for your pleasure +#XXX: Any standardization? +AUTHENTICATION_FAILED_CODE = 81 +PERMISSION_DENIED_CODE = 82 + + +class AuthenticationFailedException(Fault): + """An XML-RPC fault to be raised when a permission_required authentication + check fails + + Author + """ + def __init__(self): + Fault.__init__(self, AUTHENTICATION_FAILED_CODE, + _('Username and/or password is incorrect')) + + +class PermissionDeniedException(Fault): + """An XML-RPC fault to be raised when a permission_required permission + check fails + """ + def __init__(self): + Fault.__init__(self, PERMISSION_DENIED_CODE, _('Permission denied')) + + +def xmlrpc_method(returns='string', args=None, name=None): + """Adds a signature to an XML-RPC function and register it with the dispatcher. + + returns + The return type of the function. This can either be a string + description (e.g. 'string') or a type (e.g. str, bool) etc. + + args + A list of the types of the arguments that the function accepts. These + can be strings or types or a mixture of the two e.g. + [str, bool, 'string'] + """ + # Args should be a list + if args is None: + args = [] + + + def _xmlrpc_func(func): + """Inner function for XML-RPC method decoration. Adds a signature to + the method passed to it. + + func + The function to add the signature to + """ + # If name is not None, register the method with the dispatcher. + from django_xmlrpc.views import xmlrpcdispatcher + if name is not None: + xmlrpcdispatcher.register_function(func, name) + + # Add a signature to the function + func._xmlrpc_signature = { + 'returns': returns, + 'args': args + } + return func + + return _xmlrpc_func + +xmlrpc_func = xmlrpc_method + + +# Don't use this decorator when your service is going to be +# available in an unencrpted/untrusted network. +# Configure HTTPS transport for your web server. +def permission_required(perm=None): + """Decorator for authentication. Uses Django's built in authentication + framework to provide authenticated-only and permission-related access + to XML-RPC methods + + perm + The permission (as a string) that the user must hold to be able to + call the function that is decorated with permission_required. + """ + def _dec(func): + """An inner decorator. Adds the lookup code for the permission passed + in the outer method to the function passed to it. + + func + The function to add the permission check to + """ + def __authenticated_call(username, password, *args): + """Inner inner decorator. Adds username and password parameters to + a given XML-RPC function for authentication and permission + checking purposes and modifies the method signature appropriately + + username + The username used for authentication + + password + The password used for authentication + """ + try: + user = authenticate(username=username, password=password) + if not user: + raise AuthenticationFailedException + if perm and not user.has_perm(perm): + raise PermissionDeniedException + except AuthenticationFailedException: +# log.error("Authentication Failed for username '%s'" % username) + raise + except PermissionDeniedException: +# log.error(("Permission Denied. Username: '%s', " + \ +# "Required permission: %s") % (username, perm)) + raise + except: +# log.error(traceback.format_exc()) + raise AuthenticationFailedException + return func(user, *args) + + # Update the function's XML-RPC signature, if the method has one + if hasattr(func, '_xmlrpc_signature'): + sig = func._xmlrpc_signature + + # We just stick two string args on the front of sign['args'] to + # represent username and password + sig['args'] = (['string'] * 2) + sig['args'] + __authenticated_call._xmlrpc_signature = sig + + # Update the function's docstring + if func.__doc__: + __authenticated_call.__doc__ = func.__doc__ + \ + "\nNote: Authentication is required.""" + if perm: + __authenticated_call.__doc__ += ' this function requires ' \ + + '"%s" permission.' % perm + + return __authenticated_call + + return _dec diff --git a/gstudio/xmlrpc/django_xmlrpc/dispatcher.py b/gstudio/xmlrpc/django_xmlrpc/dispatcher.py new file mode 100644 index 0000000..f401457 --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/dispatcher.py @@ -0,0 +1,76 @@ +"""Offers a simple XML-RPC dispatcher for django_xmlrpc + +Author:: + Graham Binns + +Credit must go to Brendan W. McAdams , 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 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. +""" +from inspect import getargspec +from SimpleXMLRPCServer import SimpleXMLRPCDispatcher +from django.conf import settings + + +# If we need to debug, now we know +DEBUG = hasattr(settings, 'XMLRPC_DEBUG') and settings.XMLRPC_DEBUG + + +class DjangoXMLRPCDispatcher(SimpleXMLRPCDispatcher): + """A simple XML-RPC dispatcher for Django. + + Subclassess SimpleXMLRPCServer.SimpleXMLRPCDispatcher for the purpose of + overriding certain built-in methods (it's nicer than monkey-patching them, + that's for sure). + """ + + def system_methodSignature(self, method): + """Returns the signature details for a specified method + + method + The name of the XML-RPC method to get the details for + """ + # See if we can find the method in our funcs dict + # TODO: Handle this better: We really should return something more + # formal than an AttributeError + func = self.funcs[method] + + try: + sig = func._xmlrpc_signature + except: + sig = { + 'returns': 'string', + 'args': ['string' for arg in getargspec(func)[0]], + } + + return [sig['returns']] + sig['args'] diff --git a/gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.mo b/gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.mo new file mode 100644 index 0000000..06035ed Binary files /dev/null and b/gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.mo differ diff --git a/gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.po b/gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..091e086 --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,49 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: django-xmlrpc\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-07-31 15:33+0200\n" +"PO-Revision-Date: 2010-07-31 15:50+0100\n" +"Last-Translator: Fantomas \n" +"Language-Team: Fantomas42 \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Language: French\n" +"X-Poedit-Country: FRANCE\n" +"X-Poedit-SourceCharset: utf-8\n" + +#: decorators.py:60 +msgid "Username and/or password is incorrect" +msgstr "Nom d'utilisateur et/ou mot de passe incorrect" + +#: decorators.py:68 +msgid "Permission denied" +msgstr "Permission refusée" + +#: templates/xmlrpc_get.html:4 +#: templates/xmlrpc_get.html.py:7 +msgid "XML-RPC Service" +msgstr "Service XML-RPC" + +#: templates/xmlrpc_get.html:9 +msgid "You need to invoke this service using an XML-RPC Client." +msgstr "Vous devez invoquer ce service en utilisant un client XML-RPC." + +#: templates/xmlrpc_get.html:11 +msgid "The following methods are available :" +msgstr "Les méthodes suivantes sont disponibles :" + +#: templates/xmlrpc_get.html:17 +msgid "Types of argument" +msgstr "Types d'argument" + +#: templates/xmlrpc_get.html:19 +msgid "Type of return" +msgstr "Type de retour" + diff --git a/gstudio/xmlrpc/django_xmlrpc/templates/xmlrpc_get.html b/gstudio/xmlrpc/django_xmlrpc/templates/xmlrpc_get.html new file mode 100644 index 0000000..4c9fdfc --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/templates/xmlrpc_get.html @@ -0,0 +1,26 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block title %}{% trans "XML-RPC Service" %}{% endblock %} + +{% block content %} +

{% trans "XML-RPC Service" %}

+ +

{% trans "You need to invoke this service using an XML-RPC Client." %}

+ +

{% trans "The following methods are available :" %}

+ +{% for m in methods %} +
+

{{ m.0 }}

+
+ {% trans "Types of argument" %}{{ m.1.args|length|pluralize }} : {{ m.1.args }} +
+ {% trans "Type of return" %} : {{ m.1.returns }} +
+
{{ m.2 }}
+
+
+{% endfor %} +{% endblock %} + diff --git a/gstudio/xmlrpc/django_xmlrpc/views.py b/gstudio/xmlrpc/django_xmlrpc/views.py new file mode 100644 index 0000000..81b2049 --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/views.py @@ -0,0 +1,160 @@ +"""Uses SimpleXMLRPCServer's SimpleXMLRPCDispatcher to serve XML-RPC requests + +Authors:: + Graham Binns + Reza Mohammadi + Julien Fache + +Credit must go to Brendan W. McAdams , 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 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 + +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.models import * +from gstudio.xmlrpc.metaweblog import * +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, permission_required + + +# 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() + + +@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.raw_post_data + try: + response = HttpResponse(content_type='text/xml') + response.write( + xmlrpcdispatcher._marshaled_dispatch(request.raw_post_data)) + 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(nodeExists,'nodeExists') + xmlrpcdispatcher.register_function(getinfoFromSSID,'getinfoFromSSID') + + +# Finally, register the introspection and multicall methods with the XML-RPC +# namespace +xmlrpcdispatcher.register_introspection_functions() +xmlrpcdispatcher.register_multicall_functions() diff --git a/gstudio/xmlrpc/django_xmlrpc/views.py~ b/gstudio/xmlrpc/django_xmlrpc/views.py~ new file mode 100644 index 0000000..82eabc1 --- /dev/null +++ b/gstudio/xmlrpc/django_xmlrpc/views.py~ @@ -0,0 +1,160 @@ +"""Uses SimpleXMLRPCServer's SimpleXMLRPCDispatcher to serve XML-RPC requests + +Authors:: + Graham Binns + Reza Mohammadi + Julien Fache + +Credit must go to Brendan W. McAdams , 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 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 + +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.models import * +from gstudio.xmlrpc.metaweblog import * +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, permission_required + + +# 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=False, encoding=None) +else: + xmlrpcdispatcher = DjangoXMLRPCDispatcher() + + +@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.raw_post_data + try: + response = HttpResponse(content_type='text/xml') + response.write( + xmlrpcdispatcher._marshaled_dispatch(request.raw_post_data)) + 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(nodeExists,'nodeExists') + xmlrpcdispatcher.register_function(getinfoFromSSID,'getinfoFromSSID') + + +# Finally, register the introspection and multicall methods with the XML-RPC +# namespace +xmlrpcdispatcher.register_introspection_functions() +xmlrpcdispatcher.register_multicall_functions() diff --git a/gstudio/xmlrpc/metaweblog.py b/gstudio/xmlrpc/metaweblog.py index 6c89c21..7422323 100644 --- a/gstudio/xmlrpc/metaweblog.py +++ b/gstudio/xmlrpc/metaweblog.py @@ -71,6 +71,8 @@ from gstudio.settings import UPLOAD_TO from gstudio.managers import DRAFT, PUBLISHED from django_xmlrpc.decorators import xmlrpc_func + + # http://docs.nucleuscms.org/blog/12#errorcodes LOGIN_ERROR = 801 PERMISSION_DENIED = 803 @@ -374,3 +376,81 @@ def new_media_object(blog_id, username, password, media): path = default_storage.save(os.path.join(UPLOAD_TO, media['name']), ContentFile(media['bits'].data)) return {'url': default_storage.url(path)} + + +@xmlrpc_func(returns='string', args=['int']) +def getNodetype(ssid): + g = NID.objects.get(id=ssid) + return (g.ref._meta.module_name) + + +@xmlrpc_func(returns='int', args=['string']) +def nodeExists(name): + try: + p = NID.objects.get(title = name) + return 1 + except NID.DoesNotExist: + return 0 + + +@xmlrpc_func(returns=['struct'], args=['string']) +def getinfoFromSSID(ssid_list): + return [{"a":"b","c":None},{"a":"0","c":"1"},{"a":"b","c":"2"}] + +""" + lst = [] + for ssid in ssid_list: + try: + p = NID.objects.get(id=ssid) + nbh = p.ref.get_nbh + lst.append(nbh) + except NID.DoesNotExist: + print "ssid: ", ssid, " does not exist!" + + if () + return lst +""" + + +@xmlrpc_func(returns='int', args=['struct']) +def getNeighbourhood(ssid_list, get_what): + lst = [] + for ssid in ssid_list: + try: + p = NID.objects.get(id=ssid) + if get_what=='rendered_nbh': + nbh = p.ref.get_rendered_nbh + elif get_what=='nbh': + nbh = p.ref.get_nbh + lst.append(nbh) + except NID.DoesNotExist: + print "ssid: ", ssid, " does not exist!" + + return lst + + + +@xmlrpc_func(returns='int', args=['struct']) +def getDataType(ssid_list): + lst = [] + for ssid in ssid_list: + try: + p = NID.objects.get(id=ssid) + if get_what=='rendered_nbh': + nbh = p.ref.get_rendered_nbh + elif get_what=='nbh': + nbh = p.ref.get_nbh + lst.append(nbh) + except NID.DoesNotExist: + print "ssid: ", ssid, " does not exist!" + + return lst + + + + + + + + + -- cgit v1.1 From c2c5b803702f3c710e009e6550d0f3ca05caa87d Mon Sep 17 00:00:00 2001 From: sndt2012 Date: Thu, 12 Apr 2012 16:52:51 +0530 Subject: xmlrpc module created in gstudio/xmlrpc.xmlrpc queries routed to this module. --- gstudio/xmlrpc/django_xmlrpc/views.py~ | 160 --------------------------------- 1 file changed, 160 deletions(-) delete mode 100644 gstudio/xmlrpc/django_xmlrpc/views.py~ diff --git a/gstudio/xmlrpc/django_xmlrpc/views.py~ b/gstudio/xmlrpc/django_xmlrpc/views.py~ deleted file mode 100644 index 82eabc1..0000000 --- a/gstudio/xmlrpc/django_xmlrpc/views.py~ +++ /dev/null @@ -1,160 +0,0 @@ -"""Uses SimpleXMLRPCServer's SimpleXMLRPCDispatcher to serve XML-RPC requests - -Authors:: - Graham Binns - Reza Mohammadi - Julien Fache - -Credit must go to Brendan W. McAdams , 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 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 - -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.models import * -from gstudio.xmlrpc.metaweblog import * -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, permission_required - - -# 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=False, encoding=None) -else: - xmlrpcdispatcher = DjangoXMLRPCDispatcher() - - -@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.raw_post_data - try: - response = HttpResponse(content_type='text/xml') - response.write( - xmlrpcdispatcher._marshaled_dispatch(request.raw_post_data)) - 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(nodeExists,'nodeExists') - xmlrpcdispatcher.register_function(getinfoFromSSID,'getinfoFromSSID') - - -# Finally, register the introspection and multicall methods with the XML-RPC -# namespace -xmlrpcdispatcher.register_introspection_functions() -xmlrpcdispatcher.register_multicall_functions() -- cgit v1.1 From be7765e07e626c8be1e3d433ddb2e4f84259cf59 Mon Sep 17 00:00:00 2001 From: shefali shetty Date: Wed, 9 May 2012 11:24:16 +0530 Subject: bug related to 'relation' is rectified --- gstudio/models.py | 32 +++++++++++++++++++++-------- gstudio/static/gstudio/css/screen.css | 6 +++--- gstudio/templates/gstudio/skeleton.html | 19 +++++++++-------- objectapp/models.py | 24 +++++++++++++++++----- objectapp/static/objectapp/css/screen.css | 6 +++--- objectapp/templates/objectapp/skeleton.html | 2 +- 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/gstudio/models.py b/gstudio/models.py index 65262cc..0b6886d 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -729,7 +729,7 @@ class Nodetype(Node): predicate_id = {} for key in nbh.keys(): - val = str(counter)+"a" + val = str(counter) + "a" predicate_id[key] = val counter = counter + 1 #print predicate_id @@ -750,14 +750,30 @@ class Nodetype(Node): #g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] }) + if not isinstance(nbh[key],basestring): for item in nbh[key]: - #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[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) - #create links - g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) + if item.reftype!="Relation": + # 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[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) + + else: + + if item.left_subject.id==self.id: + item1=item.right_subject + elif item.right_subject.id==self.id: + item1=item.left_subject + + g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"expanded":"false"}) + + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item1.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} @@ -765,7 +781,7 @@ class Nodetype(Node): #for item in value.keys(): g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":nbh[key]}) #g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) - g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a") }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")}) attr_counter-=1 except: diff --git a/gstudio/static/gstudio/css/screen.css b/gstudio/static/gstudio/css/screen.css index f786de6..a5e3ba3 100644 --- a/gstudio/static/gstudio/css/screen.css +++ b/gstudio/static/gstudio/css/screen.css @@ -475,9 +475,9 @@ a:hover { text-decoration: underline; } font-weight: bold; } #graphcss { - margin-left: 224px; - margin-right: 150px; - margin-top: 1px; + margin-left: 180px; + margin-right: 200px; + margin-top: -150px; position: absolute; width: 300px; height: 900px diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index 41df756..c5a15c3 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -192,10 +192,10 @@ function init(a,b) all_edges =_(b).chain().map(function(e) { e.source = nodes_by_id[e.from]; e.target = nodes_by_id[e.to]; - + //`e.type = nodes_by_id[e.type] return e; }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" + return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" }).value(); @@ -253,7 +253,7 @@ var a = 25 * s; .charge(-5000) .friction(0.7) .gravity(0.7) - .linkDistance(75) + .linkDistance(50) .nodes([]) .links([]) .size([w, h]) @@ -304,12 +304,13 @@ var a = 25 * s; }) .attr("text", function(d) { return d.type; - }) + }); + + + + - .append("a") - .text(function(d) { return d.type; }); - var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); @@ -383,7 +384,8 @@ $(window).bind('keydown',function(event){ new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect") - .attr("x",bbox.x-22) + .attr("x",bbox.x-22 + ) .attr("y", bbox.y) .attr("width", function(d) {var ttx=d.screen_name ; return (ttx.length+bbox.width+40)}) .attr("height", bbox.height) @@ -411,6 +413,7 @@ $(window).bind('keydown',function(event){ + node.exit().remove(); diff --git a/objectapp/models.py b/objectapp/models.py index a27832a..97501c8 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -391,13 +391,27 @@ class Gbobject(Node): g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] }) if not isinstance(nbh[key],basestring): for item in nbh[key]: + if item.reftype!="Relation": # 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[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) - #create links - g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) - + 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[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) + + else: + + if item.left_subject.id==self.id: + item1=item.right_subject + elif item.right_subject.id==self.id: + item1=item.left_subject + + g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"expanded":"false"}) + + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item1.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} #this_node[str(key)]=nbh[key] key, nbh[key] diff --git a/objectapp/static/objectapp/css/screen.css b/objectapp/static/objectapp/css/screen.css index c69ca99..fd913f7 100644 --- a/objectapp/static/objectapp/css/screen.css +++ b/objectapp/static/objectapp/css/screen.css @@ -479,9 +479,9 @@ a:hover { text-decoration: underline; } font-weight: bold; } #graphcss{ - margin-left: 230px; - margin-right: 150px; - margin-top: 1px; + margin-left: 180px; + margin-right: 200px; + margin-top: -150px; position: absolute; width: 300px; height: 900px diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index 2990d9a..f3325b8 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -264,7 +264,7 @@ var a = 800 * s; .charge(-5000) .friction(0.7) .gravity(0.7) - .linkDistance(75) + .linkDistance(50) .nodes([]) .links([]) .size([w, h]) -- cgit v1.1 From 06db97bafe284e9d974a869db4cb2b6bd86f39de Mon Sep 17 00:00:00 2001 From: shefali shetty Date: Wed, 9 May 2012 14:16:09 +0530 Subject: Arrow marker added to the links --- gstudio/models.py | 8 ++++++-- gstudio/templates/gstudio/skeleton.html | 26 ++++++++++++++++++++----- objectapp/models.py | 4 +++- objectapp/templates/objectapp/skeleton.html | 30 ++++++++++++++++++++++------- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/gstudio/models.py b/gstudio/models.py index 0b6886d..f4715a5 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -722,7 +722,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 @@ -737,7 +738,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]: @@ -757,6 +759,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/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/objectapp/models.py b/objectapp/models.py index 97501c8..2c56dbf 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -364,6 +364,7 @@ class Gbobject(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] + g_json["relset"]=[] global counter global attr_counter @@ -380,6 +381,7 @@ class Gbobject(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["relset"].append(self.id) for key in predicate_id.keys(): if nbh[key]: @@ -395,7 +397,7 @@ class Gbobject(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 g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index f3325b8..2e08471 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -290,12 +290,12 @@ var a = 800 * s; force.links(edges); force.start(); - 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") .attr("class", "link") - .style("stroke-width", 2 /* function(d) { + .style("stroke-width", 2/* function(d) { return Math.sqrt(d.value); } */ ) .attr("x1", function(d) { @@ -313,9 +313,8 @@ var a = 800 * s; .attr("text", function(d) { return d.type; }) - - .append("a") - .text(function(d) { return d.type; }); + + .attr("marker-end", "url(#arrowhead)"); @@ -332,6 +331,23 @@ var a = 800 * s; .call(force.drag); + 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){ @@ -408,8 +424,8 @@ $(window).bind('keydown',function(event){ .attr("cx", bbox.x+25) .attr("cy", bbox.y+13) .call(force.drag) - .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 40)}) - .attr("ry",13) + .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 55)}) + .attr("ry",14) .style("fill-opacity", ".2") .style("stroke", "#666") .style("stroke-width", "1.5px") -- cgit v1.1 From 4c0a08ce6ef98e9b3e5020471e364e8b81d13eb0 Mon Sep 17 00:00:00 2001 From: Neha shah Date: Wed, 9 May 2012 14:27:09 +0530 Subject: rss feed for nodetype --- gstudio/templates/gstudio/base.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gstudio/templates/gstudio/base.html b/gstudio/templates/gstudio/base.html index 94a72eb..0b70311 100644 --- a/gstudio/templates/gstudio/base.html +++ b/gstudio/templates/gstudio/base.html @@ -20,8 +20,8 @@ {% endblock %} {% block sidebar %} - ? -

Rssfeed

+ ? +

Rssfeed

- diff --git a/objectapp/settings.py b/objectapp/settings.py index 885a870..2b215f0 100644 --- a/objectapp/settings.py +++ b/objectapp/settings.py @@ -56,7 +56,7 @@ SAVE_PING_EXTERNAL_URLS = getattr(settings, 'OBJECTAPP_PING_EXTERNAL_URLS', True COPYRIGHT = getattr(settings, 'OBJECTAPP_COPYRIGHT', 'Objectapp') -PAGINATION = getattr(settings, 'OBJECTAPP_PAGINATION', 10) +PAGINATION = getattr(settings, 'OBJECTAPP_PAGINATION', 4) ALLOW_EMPTY = getattr(settings, 'OBJECTAPP_ALLOW_EMPTY', True) ALLOW_FUTURE = getattr(settings, 'OBJECTAPP_ALLOW_FUTURE', True) diff --git a/objectapp/static/objectapp/css/screen.css b/objectapp/static/objectapp/css/screen.css index fd913f7..408dd84 100644 --- a/objectapp/static/objectapp/css/screen.css +++ b/objectapp/static/objectapp/css/screen.css @@ -1,4 +1,4 @@ -body { line-height: 1.5; font-family: Arial, Helvetica, sans-serif; color: #333333; font-size: 75%; height:1500px;width:1500px} +body { line-height: 1.5; font-family: Arial, Helvetica, sans-serif; color: #333333; font-size: 75%; height:1500px; width: 85%; } h1, h2, h3, h4, h5, h6 { font-weight: normal; color: #000000; border-radius:15px; } h1 img, h2 img, h3 img, h4 img, h5 img, h6 img { margin: 0; } @@ -424,7 +424,7 @@ ul, ol { margin: 0 1.5em 1.5em 0; padding-left: 3.333em; } a { text-decoration: none; } a:hover { text-decoration: underline; } -#header { margin-bottom: 1em; border-bottom: 1px solid #e9e9f3; } +#header { margin-bottom: 1em; border-bottom: 1px solid #e9e9f3; background: #2b3959; color: white;} #header h1 { font-size: 2em; font-weight: bold; margin-bottom: 0; } #header .top-navigation { float: right; } #header .top-navigation img { border: 0; } @@ -440,7 +440,7 @@ a:hover { text-decoration: underline; } #b1 {position:relative; center:5%; background-color:#43AEE7; color: white; border: 1px solid #000000; font-size:1em;} #b2 {position:relative; center:6%; background-color:#43AEE7; color: white; border: 1px solid #000000; font-size:1em;} -#body { margin-bottom: 1em; border-bottom: 1px solid #e9e9f3; } +#body { margin-bottom: 1em; border-bottom: 0px solid #e9e9f3; width: 100%;} #content h1, #content h2, #content h3 { margin-top: 10px; } @@ -450,10 +450,10 @@ a:hover { text-decoration: underline; } float: left; clear: both; margin-bottom: 10px; - margin-left: 0; - margin-right: 60px; + margin-left: 0%; + margin-right: 0%; margin-top: 10px; - padding-right: 30px; + padding-right: 0%; width:250px; } @@ -479,14 +479,14 @@ a:hover { text-decoration: underline; } font-weight: bold; } #graphcss{ - margin-left: 180px; - margin-right: 200px; - margin-top: -150px; + margin-left: 237px; + margin-right: 0px; + margin-top: 1px; position: absolute; - width: 300px; + width: 46%; height: 900px } -#sidebar{position:absolute; margin-left:600px; margin-right:150px; margin-top:10px; width:300px;} +#sidebar{position:relative; margin-left:92%; margin-right:0px; margin-top:10px; width:23%;} #sidebar div:first-child h3 { margin-top:0px; } #sidebar h3 { background-color: #FFE9E8; padding: 0.5em; } #sidebar p { padding-left: 1em; } @@ -508,7 +508,7 @@ a:hover { text-decoration: underline; } #sidebar .tags div ul .tag_4 { font-size: 2em; color: #0070a8; } #sidebar .tags div ul .tag_5 { font-size: 2.25em; color: #0099e5; } #sidebar .tags div ul .tag_6 { font-size: 3em; color: #00adff; } - +#footer{ position:static; border-bottom: 1px solid #E9E9F3; margin-top: 85px; } th.month{padding:0cm 2.5cm;} table.month { margin-bottom: 0; } table.month th.month { text-transform: uppercase; color: #555555; background: none; } @@ -516,7 +516,7 @@ table.month th { text-transform: capitalize; color: #555555; background-color: # table.month td { text-align: center; font-weight: bold; } table.month td.objecttype { background-color: #C4EBF4; } -div.paginator { margin-bottom: 1em; } +div.paginator { margin-bottom: 2em; } div.paginator span { font-size: 1.2em; margin-left: 0.3em; padding: 0 0.5em 0 0.5em; float: left; border: 1px solid #e9e9f3; } div.paginator span.index { margin-left: 0; } div.paginator span.page:hover, div.paginator span.next:hover, div.paginator span.previous:hover { background-color: #006699; } diff --git a/objectapp/templates/objectapp/_gbobject_detail.html b/objectapp/templates/objectapp/_gbobject_detail.html index 6b21356..ee43aba 100644 --- a/objectapp/templates/objectapp/_gbobject_detail.html +++ b/objectapp/templates/objectapp/_gbobject_detail.html @@ -28,7 +28,7 @@ - +

Name: {{ object.title }}
@@ -76,7 +76,7 @@

- +
diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index 2e08471..928c0e6 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -47,8 +47,8 @@ display: block; } svg { - margin-left: 10%; - margin-right: 10%; + margin-left: 0%; + margin-right: 0%; display: block; position: absolute; } @@ -224,27 +224,26 @@ $.getJSON('/nodetypes/graphs/graph_json/' + {{object.id}}, function (json1) { function load(key) { - -var a = 800 * s; - - if ( a > 700 ) - { - var w = 700; - } - else - { - var w = a; - } - - var h = 232 * s, + +if ( s > 0) { +var w = 700; +var p = 122 + "%"; +var h = 800; +var q = 3 * s + 60 + "%"; +}else{ +var w = 700; +var p = 122 + "%"; +var h = 800; +var q = 110 + "%"; +} fill = d3.scale.category20(); var vis = d3.select("#chart") .append("svg:svg") .attr("id", "amazingViz") - .attr("width", w) - .attr("height", h); + .attr("width", p) + .attr("height", q); vis.append("svg:g").attr("class", "edges"); vis.append("svg:g").attr("class", "nodes"); @@ -474,16 +473,24 @@ $(window).bind('keydown',function(event){ {% block graph %} {% endblock %}
- -
- -- cgit v1.1