diff options
60 files changed, 1643 insertions, 695 deletions
@@ -1,2 +1,11 @@ build/ demo/demo.db + +### tilde, pyc and hash files + +*.pyc +*~ +\#*\# + + + diff --git a/demo/__init__.pyc b/demo/__init__.pyc Binary files differdeleted file mode 100644 index 3aa8423..0000000 --- a/demo/__init__.pyc +++ /dev/null diff --git a/demo/dashboard.py b/demo/dashboard.py index 93b0805..3e4c726 100644 --- a/demo/dashboard.py +++ b/demo/dashboard.py @@ -92,17 +92,29 @@ class CustomIndexDashboard(Dashboard): collapsible=False, children = [ modules.AppList( - #Gstudio models here ( other than attribute datatype) - _('Gstudio'), + _('Gstudio (Basic)'), column=1, collapsible=False, models=( - 'gstudio.models.Objecttype', + 'gstudio.models.Objecttype', + 'gstudio.models.Attributetype', + 'gstudio.models.Relationtype', + 'objectapp.models.Gbobject', + ), + ), + + modules.AppList( + + + #Gstudio models here ( other than attribute datatype and collapsible ones) + _('Gstudio (Advanced)'), + column=1, + collapsible=True, + models=( + 'gstudio.models.Metatype', 'gstudio.models.Relation', - 'gstudio.models.Relationtype', 'gstudio.models.Attribute', - 'gstudio.models.Attributetype', 'gstudio.models.Systemtype', 'gstudio.models.Processtype', 'gstudio.models.AttributeSpecification', @@ -112,22 +124,27 @@ class CustomIndexDashboard(Dashboard): 'gstudio.models.Complement', 'gstudio.models.Intersection', 'gstudio.models.Expression', + 'gstudio.models.Peer', ), ), #Object App models here - modules.AppList( - _('Object App'), + _('Object App (Advanced)'), column=1, - collapsible=False, + collapsible=True, models=( - 'objectapp.models.*', + 'objectapp.models.Process', + 'objectapp.models.System', ), ), + + + + # Gstudio Attribute datatype models here modules.AppList( diff --git a/demo/dashboard.pyc b/demo/dashboard.pyc Binary files differdeleted file mode 100644 index d0e061e..0000000 --- a/demo/dashboard.pyc +++ /dev/null diff --git a/demo/graphviz/__init__.pyc b/demo/graphviz/__init__.pyc Binary files differdeleted file mode 100644 index 02e3f24..0000000 --- a/demo/graphviz/__init__.pyc +++ /dev/null diff --git a/demo/graphviz/admin.pyc b/demo/graphviz/admin.pyc Binary files differdeleted file mode 100644 index d712f1c..0000000 --- a/demo/graphviz/admin.pyc +++ /dev/null diff --git a/demo/graphviz/management/__init__.pyc b/demo/graphviz/management/__init__.pyc Binary files differdeleted file mode 100644 index 4fb5495..0000000 --- a/demo/graphviz/management/__init__.pyc +++ /dev/null diff --git a/demo/graphviz/models.pyc b/demo/graphviz/models.pyc Binary files differdeleted file mode 100644 index 00d027e..0000000 --- a/demo/graphviz/models.pyc +++ /dev/null diff --git a/demo/grappelli/__init__.pyc b/demo/grappelli/__init__.pyc Binary files differdeleted file mode 100644 index ad6c9f3..0000000 --- a/demo/grappelli/__init__.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/__init__.pyc b/demo/grappelli/dashboard/__init__.pyc Binary files differdeleted file mode 100644 index db1644a..0000000 --- a/demo/grappelli/dashboard/__init__.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/dashboards.pyc b/demo/grappelli/dashboard/dashboards.pyc Binary files differdeleted file mode 100644 index 8359b87..0000000 --- a/demo/grappelli/dashboard/dashboards.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/management/__init__.pyc b/demo/grappelli/dashboard/management/__init__.pyc Binary files differdeleted file mode 100644 index 8296cb8..0000000 --- a/demo/grappelli/dashboard/management/__init__.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/modules.pyc b/demo/grappelli/dashboard/modules.pyc Binary files differdeleted file mode 100644 index 02cc73c..0000000 --- a/demo/grappelli/dashboard/modules.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/registry.pyc b/demo/grappelli/dashboard/registry.pyc Binary files differdeleted file mode 100644 index fca1a27..0000000 --- a/demo/grappelli/dashboard/registry.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/templatetags/__init__.pyc b/demo/grappelli/dashboard/templatetags/__init__.pyc Binary files differdeleted file mode 100644 index 892c983..0000000 --- a/demo/grappelli/dashboard/templatetags/__init__.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/templatetags/grp_dashboard_tags.pyc b/demo/grappelli/dashboard/templatetags/grp_dashboard_tags.pyc Binary files differdeleted file mode 100644 index 392f329..0000000 --- a/demo/grappelli/dashboard/templatetags/grp_dashboard_tags.pyc +++ /dev/null diff --git a/demo/grappelli/dashboard/utils.pyc b/demo/grappelli/dashboard/utils.pyc Binary files differdeleted file mode 100644 index cecc4b0..0000000 --- a/demo/grappelli/dashboard/utils.pyc +++ /dev/null diff --git a/demo/grappelli/models.pyc b/demo/grappelli/models.pyc Binary files differdeleted file mode 100644 index 2635511..0000000 --- a/demo/grappelli/models.pyc +++ /dev/null diff --git a/demo/grappelli/settings.pyc b/demo/grappelli/settings.pyc Binary files differdeleted file mode 100644 index f8f4c5a..0000000 --- a/demo/grappelli/settings.pyc +++ /dev/null diff --git a/demo/grappelli/static/grappelli/css/forms.css b/demo/grappelli/static/grappelli/css/forms.css index 84e21f6..277334e 100644 --- a/demo/grappelli/static/grappelli/css/forms.css +++ b/demo/grappelli/static/grappelli/css/forms.css @@ -2,7 +2,7 @@ /* Basic Settings, Fieldsets, Form-Rows ------------------------------------------------------------------------------------------------------- */ +----------------------------------------------------------------------------------------------------- */ form { margin: 0; @@ -657,7 +657,7 @@ select.span-16, textarea.span-16, div.autocomplete-wrapper-m2m.span-16, .span-20 label + input[type=text], .span-20 label + input[type=password], .span-20 label + select, .span-20 label + textarea { - width: 598px; + width: 230px; } .span-16 div.autocomplete-wrapper-m2m ul.repr, .span-16 div.autocomplete-wrapper-m2m ul.repr li, @@ -1240,4 +1240,4 @@ div.autocomplete-wrapper-m2m input.vManyToManyRawIdAdminField, div.autocomplete- background: transparent !important; box-shadow: none !important; -moz-box-shadow: none !important; -webkit-box-shadow: none !important; cursor: default !important; -}
\ No newline at end of file +} diff --git a/demo/grappelli/static/grappelli/css/grappelli-skin-default.css b/demo/grappelli/static/grappelli/css/grappelli-skin-default.css index 6f5e721..fe718a3 100644 --- a/demo/grappelli/static/grappelli/css/grappelli-skin-default.css +++ b/demo/grappelli/static/grappelli/css/grappelli-skin-default.css @@ -7,7 +7,7 @@ /* Paragraphs ------------------------------------------------------------------------------------------------------- */ +----------------------------------------------------------------------------------------------------- */ .module p.help, p.help { @@ -166,6 +166,7 @@ body { background: -moz-linear-gradient(top, white, white); background: -webkit-gradient(linear, left top, left bottom, from(white), to(white)); background: -o-linear-gradient(top, white, white); + background: #2B3959; } #header a:hover, #header a:active { color: red; @@ -1907,7 +1908,7 @@ a:hover, a:active, a.selected { } #header a:link, #header a:visited { - color: #0872B4; + color: white; } #header a:hover, #header a:active { color: red; @@ -2016,11 +2017,11 @@ hr { /* User Tools ................................................... */ #user-tools { - border-left: 1px solid #303030; + border-left: 0px solid #303030; } #user-tools>li { - border-left: 1px solid #404040; - border-right: 1px solid #303030; + border-left: 0px solid #404040; + border-right: 0px solid #303030; } li.user-options-container.open a.user-options-handler { color: #eee !important; @@ -2946,7 +2947,7 @@ ul.pagination li.separator span { /* Tooltips ------------------------------------------------------------------------------------------------------- */ +----------------------------------------------------------------------------------------------------- */ .module.search .tooltip .tooltip-content { border: 1px solid #ccc; diff --git a/demo/grappelli/templates/admin/change_form.html b/demo/grappelli/templates/admin/change_form.html index c5a2654..7228290 100644 --- a/demo/grappelli/templates/admin/change_form.html +++ b/demo/grappelli/templates/admin/change_form.html @@ -17,6 +17,7 @@ <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_inline.js" type="text/javascript"></script> {% if change %} <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/URI.js"></script> + <script type="text/javascript" charset="utf-8"> (function($){ $(document).ready(function() { diff --git a/demo/grappelli/templatetags/__init__.pyc b/demo/grappelli/templatetags/__init__.pyc Binary files differdeleted file mode 100644 index 6873fc5..0000000 --- a/demo/grappelli/templatetags/__init__.pyc +++ /dev/null diff --git a/demo/grappelli/templatetags/grp_tags.pyc b/demo/grappelli/templatetags/grp_tags.pyc Binary files differdeleted file mode 100644 index 1d9bfaa..0000000 --- a/demo/grappelli/templatetags/grp_tags.pyc +++ /dev/null diff --git a/demo/grappelli/urls.pyc b/demo/grappelli/urls.pyc Binary files differdeleted file mode 100644 index 24a0b72..0000000 --- a/demo/grappelli/urls.pyc +++ /dev/null diff --git a/demo/grappelli/views/__init__.pyc b/demo/grappelli/views/__init__.pyc Binary files differdeleted file mode 100644 index 1533e6e..0000000 --- a/demo/grappelli/views/__init__.pyc +++ /dev/null diff --git a/demo/grappelli/views/related.pyc b/demo/grappelli/views/related.pyc Binary files differdeleted file mode 100644 index 01e8189..0000000 --- a/demo/grappelli/views/related.pyc +++ /dev/null diff --git a/demo/settings.py b/demo/settings.py index a325258..77296fb 100644 --- a/demo/settings.py +++ b/demo/settings.py @@ -157,7 +157,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.sites', 'mptt', - 'reversion', + # 'reversion', 'tagging', 'django_xmlrpc', 'grappelli.dashboard', diff --git a/demo/settings.pyc b/demo/settings.pyc Binary files differdeleted file mode 100644 index 5cfa794..0000000 --- a/demo/settings.pyc +++ /dev/null diff --git a/demo/urls.pyc b/demo/urls.pyc Binary files differdeleted file mode 100644 index a2d9523..0000000 --- a/demo/urls.pyc +++ /dev/null diff --git a/demo/views.pyc b/demo/views.pyc Binary files differdeleted file mode 100644 index 046700a..0000000 --- a/demo/views.pyc +++ /dev/null diff --git a/gstudio/__init__.pyc b/gstudio/__init__.pyc Binary files differdeleted file mode 100644 index 9f1566a..0000000 --- a/gstudio/__init__.pyc +++ /dev/null diff --git a/gstudio/admin/__init__.py b/gstudio/admin/__init__.py index 030e056..159fcf2 100644 --- a/gstudio/admin/__init__.py +++ b/gstudio/admin/__init__.py @@ -36,6 +36,8 @@ from gstudio.models import AttributeFilePathField from gstudio.models import AttributeImageField from gstudio.models import AttributeURLField from gstudio.models import AttributeIPAddressField +from gstudio.models import Peer + #Admin imports @@ -79,6 +81,7 @@ from gstudio.admin.attribute_ipaddressfield import AttributeIPAddressFieldAdmin + admin.site.register(Objecttype, ObjecttypeAdmin) admin.site.register(Metatype, MetatypeAdmin) admin.site.register(Relationtype, RelationtypeAdmin) @@ -95,6 +98,8 @@ admin.site.register(Union, UnionAdmin) admin.site.register(Complement, ComplementAdmin) admin.site.register(Intersection, IntersectionAdmin) admin.site.register(Expression, ExpressionAdmin) +admin.site.register(Peer) + admin.site.register(AttributeCharField, AttributeCharFieldAdmin) admin.site.register(AttributeTextField, AttributeTextFieldAdmin) diff --git a/gstudio/admin/attribute.py b/gstudio/admin/attribute.py index 336509e..31266c4 100644 --- a/gstudio/admin/attribute.py +++ b/gstudio/admin/attribute.py @@ -1,4 +1,4 @@ -"""MetatypeAdmin for Gstudio""" +"""AttributeAdmin for Gstudio""" from django.contrib import admin from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ @@ -6,15 +6,24 @@ from django.utils.html import escape from gstudio.admin.forms import AttributeAdminForm from gstudio.models import * import reversion +from django.template.defaultfilters import slugify class AttributeAdmin(reversion.VersionAdmin): + fieldsets=((_('Attribute'),{'fields': ('attributetype','attributetype_scope','subject','subject_scope','svalue','value_scope')}), + +) + + + class Media: - js = ("gstudio/js/gstudiojs.js",) + js = ("gstudio/js/gstudio.js",) def save_model(self, request, attribute, form, change): - attribute.title = attribute.composed_attribution + attribute.title = attribute.composed_sentence + attribute.slug = slugify(attribute.title) attribute.save() + diff --git a/gstudio/admin/forms.py b/gstudio/admin/forms.py index 37b578c..a2415c1 100644 --- a/gstudio/admin/forms.py +++ b/gstudio/admin/forms.py @@ -154,7 +154,7 @@ class RelationtypeAdminForm(forms.ModelForm): super(RelationtypeAdminForm, self).__init__(*args, **kwargs) prior = ManyToManyRel(Nodetype, 'id') post = ManyToManyRel(Nodetype, 'id') - + self.fields['priornodes'].widget = RelatedFieldWidgetWrapper( @@ -207,18 +207,6 @@ class RelationAdminForm(forms.ModelForm): AppNodeList = AppNode.objects.all() return AppNodeList - - - - - - - - - - - - class Meta: @@ -289,7 +277,7 @@ class AttributetypeAdminForm(forms.ModelForm): super(AttributetypeAdminForm, self).__init__(*args, **kwargs) prior = ManyToManyRel(Nodetype, 'id') post = ManyToManyRel(Nodetype, 'id') - + self.fields['sites'].initial = [Site.objects.get_current()] self.fields['priornodes'].widget = RelatedFieldWidgetWrapper( self.fields['priornodes'].widget, prior, self.admin_site) diff --git a/gstudio/admin/relation.py b/gstudio/admin/relation.py index 688ad6e..8f112ef 100644 --- a/gstudio/admin/relation.py +++ b/gstudio/admin/relation.py @@ -5,12 +5,25 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import RelationAdminForm import reversion +from django.template.defaultfilters import slugify class RelationAdmin(reversion.VersionAdmin): - fieldsets=((_('Relation'),{'fields': ('title','last_update','creation_date','relationtype_scope','relationtype','left_subject_scope','left_subject' ,'right_subject_scope','right_subject')}), + fieldsets=((_('Relation'),{'fields': ('relationtype','relationtype_scope','left_subject' ,'left_subject_scope','right_subject','right_subject_scope')}), ) + + def get_title(self, edge): + """Return the title with word count and number of comments""" + title = _('%(title)s (%(word_count)i words)') % \ + {'title': nodetype.title, 'word_count': nodetype.word_count} + comments = nodetype.comments.count() + if comments: + return _('%(title)s (%(comments)i comments)') % \ + {'title': title, 'comments': comments} + return title + get_title.short_description = _('title') def save_model(self, request, relation, form, change): relation.title = relation.composed_sentence + relation.slug = slugify(relation.title) relation.save() diff --git a/gstudio/management/commands/peers.py b/gstudio/management/commands/peers.py new file mode 100644 index 0000000..cb79991 --- /dev/null +++ b/gstudio/management/commands/peers.py @@ -0,0 +1,23 @@ +# Copyright (c) 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 +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from django.core.management.base import NoArgsCommand +import sys +from gstudio.models import Peer + +class Command(NoArgsCommand): + """Custom manage.py command to show all peers""" + def handle_noargs(self, **options): + sys.stdout.write("{0}\n".format(Peer.objects.all())) diff --git a/gstudio/management/commands/register-peer.py b/gstudio/management/commands/register-peer.py new file mode 100644 index 0000000..afe2b50 --- /dev/null +++ b/gstudio/management/commands/register-peer.py @@ -0,0 +1,52 @@ +# Copyright (c) 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 +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# from django.core.management.base import BaseCommand +# from optparse import make_option +# import sys +# from gstudio.models import Peer + +# class Command(BaseCommand): +# """Custom manage.py command to register a peer""" +# option_list = BaseCommand.option_list + ( +# make_option("--ip", action="store", type="string", +# dest="ip", help="Specify an IP"), +# make_option("--pkey", action="store", type="string", +# dest="pkey", help="Specify a public-key")) + +# def handle(self, *args, **options): +# try: +# ip = options["ip"] +# pkey = options["pkey"] + +# if not ip: +# sys.stderr.write("Please specify an IP\n") +# sys.exit(2) + +# if not pkey: +# sys.stderr.write("Please specify a public-key\n") +# sys.exit(2) + +# pkey = open(options["pkey"]).readline().rstrip() + +# except (IOError, TypeError): +# sys.stderr.write("Please specify a correct public-key\n") +# sys.exit(2) + +# ip = Peer(ip="{0}".format(ip)) +# ip.save() + +# pkey = Peer(pkey="{0}".format(pkey)) +# pkey.save() diff --git a/gstudio/models.py b/gstudio/models.py index be39527..97b4888 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -93,6 +93,7 @@ from gstudio.settings import NODETYPE_TEMPLATES from gstudio.settings import NODETYPE_BASE_MODEL from gstudio.settings import MARKDOWN_EXTENSIONS from gstudio.settings import AUTO_CLOSE_COMMENTS_AFTER +from gstudio.settings import GSTUDIO_VERSIONING from gstudio.managers import nodetypes_published from gstudio.managers import NodetypePublishedManager from gstudio.managers import NodePublishedManager @@ -102,10 +103,14 @@ from gstudio.moderator import NodetypeCommentModerator from gstudio.url_shortener import get_url_shortener from gstudio.signals import ping_directories_handler from gstudio.signals import ping_external_urls_handler + import json -import reversion +if GSTUDIO_VERSIONING: + import reversion from reversion.models import Version from django.core import serializers +from reversion.models import * + NODETYPE_CHOICES = ( ('ND', 'Nodes'), @@ -168,6 +173,10 @@ STATUS_CHOICES = ((DRAFT, _('draft')), (HIDDEN, _('hidden')), (PUBLISHED, _('published'))) + +counter = 1 +attr_counter = -1 + class Author(User): """Proxy Model around User""" @@ -205,6 +214,9 @@ class NID(models.Model): slug = models.SlugField(help_text=_('used for publication'), unique_for_date='creation_date', max_length=255) + nodemodel = models.CharField(_('nodemodel'),max_length=255) + + def get_serialized_dict(self): @@ -236,22 +248,26 @@ class NID(models.Model): @property def ref(self): - """ - Returns the object reference the id belongs to. - """ - try: - """ - ALGO: get object id, go to version model, return for the given id. - """ - - # Retrieving only the relevant tupleset for the versioned objects - vrs = Version.objects.filter(type=0 , object_id=self.id) - # Returned value is a list, so splice it. - vrs = vrs[0] - except: - return None + from objectapp.models import * + return eval(self.nodemodel).objects.get(id=self.id) + + # """ + # Returns the object reference the id belongs to. + # """ + # try: + # """ + # ALGO: get object id, go to version model, return for the given id. + # """ + + # # Retrieving only the relevant tupleset for the versioned objects + # # vrs = Version.objects.filter(type=0 , object_id=self.id) + # # Returned value is a list, so splice it. + # vrs = vrs[0] + # except: + # return None - return vrs.object + # return vrs.object + @property def reftype(self): @@ -261,9 +277,11 @@ class NID(models.Model): try: """ ALGO: simple wrapper for the __class__.__name__ so that it can be used in templates + """ - obj = self.ref - return obj.__class__.__name__ + return self.__class__.__name__ + # obj = self.ref + # return obj.__class__.__name__ except: return None @@ -361,6 +379,8 @@ class Node(NID): sites = models.ManyToManyField(Site, verbose_name=_('sites publication'), related_name='nodetypes') + nbhood = models.TextField(help_text="The neighbourhood of the model.") + published = NodePublishedManager() def __unicode__(self): return self.title @@ -368,6 +388,16 @@ class Node(NID): class Meta: abstract=False + + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Node, self).save(*args, **kwargs) # Call the "real" save() method. + super(Node, self).save(*args, **kwargs) # Call the "real" save() method. + + + + class Edge(NID): @@ -376,6 +406,13 @@ class Edge(NID): class Meta: abstract=False + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Edge, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Edge, self).save(*args, **kwargs) # Call the "real" save() method. + class Metatype(Node): @@ -557,6 +594,16 @@ class Metatype(Node): verbose_name = _('metatype') verbose_name_plural = _('metatypes') + # Save for metatype + + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + + @@ -740,6 +787,9 @@ class Nodetype(Node): return attrs + + + def get_graph_json(self): @@ -747,21 +797,24 @@ class Nodetype(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] + g_json["relset"]=[] - + global counter + global attr_counter nbh = self.get_nbh predicate_id = {} - counter = 1 + for key in nbh.keys(): - val = "a" + str(counter) + val = str(counter) + "a" predicate_id[key] = val counter = counter + 1 #print predicate_id - attr_counter = -1 + - this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url()} - g_json["node_metadata"].append(this_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]: @@ -774,27 +827,46 @@ 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()}) + 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["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 }) + + # 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] #for item in value.keys(): - g_json["node_metadata"].append({"_id":attr_counter,"screen_name":nbh[key]}) + 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":attr_counter }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")}) attr_counter-=1 except: pass #print g_json + return json.dumps(g_json) @property @@ -1180,6 +1252,14 @@ class Nodetype(Node): verbose_name_plural = _('node types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + + # Save for nodetype + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. + class Objecttype(Nodetype): @@ -1190,7 +1270,7 @@ class Objecttype(Nodetype): def __unicode__(self): return self.title - #def get_graph_json(self): + @@ -1292,7 +1372,7 @@ class Objecttype(Nodetype): nbh['posterior_nodes'] = self.posterior_nodes.all() - nbh['authors'] = self.authors.all() + #nbh['authors'] = self.authors.all() return nbh @@ -1359,6 +1439,17 @@ class Objecttype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # Save for Objecttype + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + + @@ -1368,10 +1459,10 @@ class Relationtype(Nodetype): ''' inverse = models.CharField(_('inverse name'), help_text=_('when subjecttypes are interchanged, what should be the name of the relation type? This is mandatory field. If the relation is symmetric, same name will do.'), max_length=255,db_index=True ) left_subjecttype = models.ForeignKey(NID,related_name="left_subjecttype_of", verbose_name='left role') - left_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Node types for left role') + left_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Applicable node types for left role') left_cardinality = models.IntegerField(null=True, blank=True, verbose_name='cardinality for the left role') right_subjecttype = models.ForeignKey(NID,related_name="right_subjecttype_of", verbose_name='right role') - right_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Node types for right role') + right_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Applicable node types for right role') right_cardinality = models.IntegerField(null=True, blank=True, verbose_name='cardinality for the right role') is_symmetrical = models.NullBooleanField(verbose_name='Is symmetrical?') is_reflexive = models.NullBooleanField(verbose_name='Is reflexive?') @@ -1400,6 +1491,18 @@ class Relationtype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # Save for Relationtype + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + self.nodemodel = self.__class__.__name__ + + + super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method. + + class Attributetype(Nodetype): ''' @@ -1450,6 +1553,17 @@ class Attributetype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # Save for Attributetype + + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. + + class Relation(Edge): @@ -1540,6 +1654,17 @@ class Relation(Edge): function that composes the right_subject and relation name, as in "x as a friend", "y as a sibling" ''' return '%s as a %s' % (self.right_subject, self.relationtype) + + + # Save for Relation + + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. + super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. + class Attribute(Edge): @@ -1616,6 +1741,17 @@ class Attribute(Edge): for each in Objecttype.objects.all(): if attr.subjecttype.id == each.id: return each.get_members + + # Save for Attribute + + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. + @@ -1626,12 +1762,32 @@ class AttributeCharField(Attribute): def __unicode__(self): return self.title + + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeTextField(Attribute): value = models.TextField(verbose_name='text') def __unicode__(self): return self.title + + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeIntegerField(Attribute): value = models.IntegerField(max_length=100, verbose_name='Integer') @@ -1639,6 +1795,17 @@ class AttributeIntegerField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + + + class AttributeCommaSeparatedIntegerField(Attribute): value = models.CommaSeparatedIntegerField(max_length=100, verbose_name='integers separated by comma') @@ -1646,6 +1813,14 @@ class AttributeCommaSeparatedIntegerField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeBigIntegerField(Attribute): value = models.BigIntegerField(max_length=100, verbose_name='big integer') @@ -1660,12 +1835,29 @@ class AttributePositiveIntegerField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeDecimalField(Attribute): value = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='decimal') def __unicode__(self): return self.title + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. + + + super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeFloatField(Attribute): @@ -1674,12 +1866,30 @@ class AttributeFloatField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeBooleanField(Attribute): value = models.BooleanField(verbose_name='boolean') def __unicode__(self): return self.title + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeNullBooleanField(Attribute): @@ -1688,6 +1898,15 @@ class AttributeNullBooleanField(Attribute): def __unicode__(self): return self.title + + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeDateField(Attribute): value = models.DateField(max_length=100, verbose_name='date') @@ -1695,12 +1914,31 @@ class AttributeDateField(Attribute): def __unicode__(self): return self.title + + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeDateTimeField(Attribute): value = models.DateTimeField(max_length=100, verbose_name='date time') def __unicode__(self): return self.title + + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeTimeField(Attribute): @@ -1709,6 +1947,16 @@ class AttributeTimeField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeEmailField(Attribute): value = models.CharField(max_length=100,verbose_name='value') @@ -1716,6 +1964,15 @@ class AttributeEmailField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeFileField(Attribute): value = models.FileField(upload_to='/media', verbose_name='file') @@ -1723,6 +1980,16 @@ class AttributeFileField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeFilePathField(Attribute): value = models.FilePathField(verbose_name='path of file') @@ -1730,6 +1997,16 @@ class AttributeFilePathField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeImageField(Attribute): value = models.ImageField(upload_to='/media', verbose_name='image') @@ -1737,6 +2014,12 @@ class AttributeImageField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeURLField(Attribute): value = models.URLField(max_length=100, verbose_name='url') @@ -1744,6 +2027,16 @@ class AttributeURLField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeIPAddressField(Attribute): value = models.IPAddressField(max_length=100, verbose_name='ip address') @@ -1751,6 +2044,16 @@ class AttributeIPAddressField(Attribute): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. + + class Processtype(Nodetype): @@ -1774,6 +2077,15 @@ class Processtype(Nodetype): verbose_name_plural = _('process types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. + @@ -1805,6 +2117,16 @@ class Systemtype(Nodetype): verbose_name_plural = _('system types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeSpecification(Node): @@ -1830,6 +2152,7 @@ class AttributeSpecification(Node): def __unicode__(self): + self.nodemodel = self.__class__.__name__ return self.composed_subject @@ -1838,6 +2161,17 @@ class AttributeSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + + class RelationSpecification(Node): """ @@ -1861,11 +2195,22 @@ class RelationSpecification(Node): return self.composed_subject + class Meta: verbose_name = _('relation specification') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(RelationSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + super(RelationSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + class NodeSpecification(Node): """ @@ -1897,6 +2242,17 @@ class NodeSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(NodeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + super(NodeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + + class Expression(Node): """ @@ -1924,6 +2280,16 @@ class Expression(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Expression, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Expression, self).save(*args, **kwargs) # Call the "real" save() method. + + class Union(Node): @@ -1935,6 +2301,16 @@ class Union(Node): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Union, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Union, self).save(*args, **kwargs) # Call the "real" save() method. + + class Complement(Node): @@ -1946,6 +2322,16 @@ class Complement(Node): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Complement, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Complement, self).save(*args, **kwargs) # Call the "real" save() method. + + class Intersection(Node): """ Intersection of classes @@ -1954,44 +2340,54 @@ class Intersection(Node): def __unicode__(self): return self.title - -reversion.register(NID) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Intersection, self).save(*args, **kwargs) # Call the "real" save() method. -if not reversion.is_registered(Systemtype): - reversion.register(Systemtype) + super(Intersection, self).save(*args, **kwargs) # Call the "real" save() method. -if not reversion.is_registered(Objecttype): - reversion.register(Objecttype , follow=["nodetype_ptr"]) + +if GSTUDIO_VERSIONING == True: + reversion.register(NID) -if not reversion.is_registered(Node): - reversion.register(Node , follow=["nid_ptr"]) + if not reversion.is_registered(Systemtype): + reversion.register(Systemtype) -if not reversion.is_registered(Edge): - reversion.register(Edge , follow=["nid_ptr"]) + if not reversion.is_registered(Objecttype): + reversion.register(Objecttype , follow=["nodetype_ptr"]) + if not reversion.is_registered(Node): + reversion.register(Node , follow=["nid_ptr"]) -if not reversion.is_registered(Processtype): - reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"]) + if not reversion.is_registered(Edge): + reversion.register(Edge , follow=["nid_ptr"]) -if not reversion.is_registered(Nodetype): - reversion.register(Nodetype, follow=["node_ptr","parent", "metatypes","prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(Metatype): - reversion.register(Metatype, follow=["node_ptr","parent"]) + if not reversion.is_registered(Processtype): + reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"]) + if not reversion.is_registered(Nodetype): + reversion.register(Nodetype, follow=["node_ptr","parent", "metatypes","prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(Relationtype): - reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) + if not reversion.is_registered(Metatype): + reversion.register(Metatype, follow=["node_ptr","parent"]) -if not reversion.is_registered(Attributetype): - reversion.register(Attributetype, follow=["subjecttype"]) -if not reversion.is_registered(Attribute): - reversion.register(Attribute, follow=["subject", "attributetype"]) + if not reversion.is_registered(Relationtype): + reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) -if not reversion.is_registered(Relation): - reversion.register(Relation, follow=["left_subject", "right_subject", "relationtype"]) + if not reversion.is_registered(Attributetype): + reversion.register(Attributetype, follow=["subjecttype"]) + + if not reversion.is_registered(Attribute): + reversion.register(Attribute, follow=["subject", "attributetype"]) + + if not reversion.is_registered(Relation): + reversion.register(Relation, follow=["left_subject", "right_subject", "relationtype"]) moderator.register(Nodetype, NodetypeCommentModerator) mptt.register(Metatype, order_insertion_by=['title']) @@ -2006,5 +2402,10 @@ post_save.connect(ping_directories_handler, sender=Nodetype, post_save.connect(ping_external_urls_handler, sender=Nodetype, dispatch_uid='gstudio.nodetype.post_save.ping_external_urls') +class Peer(User): + """Subclass for non-human users""" + def __unicode__(self): + return self.ip - + ip = models.IPAddressField("Peer's IP address") + pkey = models.CharField(("Peer's public-key"), max_length=255) diff --git a/gstudio/settings.py b/gstudio/settings.py index dceb80f..7560667 100644 --- a/gstudio/settings.py +++ b/gstudio/settings.py @@ -152,3 +152,5 @@ TWITTER_ACCESS_SECRET = getattr(settings, 'TWITTER_ACCESS_SECRET', '') USE_TWITTER = getattr(settings, 'GSTUDIO_USE_TWITTER', bool(TWITTER_ACCESS_KEY and TWITTER_ACCESS_SECRET and \ TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET)) + +GSTUDIO_VERSIONING = False diff --git a/gstudio/static/gstudio/css/screen.css b/gstudio/static/gstudio/css/screen.css index f786de6..c107776 100644 --- a/gstudio/static/gstudio/css/screen.css +++ b/gstudio/static/gstudio/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: 90%; } h1, h2, h3, h4, h5, h6 { font-weight: normal; color: #176691; border-radius:15px; } h1 img, h2 img, h3 img, h4 img, h5 img, h6 img { margin: 0; } @@ -130,7 +130,7 @@ caption { background: #eeeeee; } .span-15 { width: 590px; } -.span-16 { width: 150px; } +.span-16 { width: 500px; } .span-17 { width: 670px; } @@ -406,7 +406,7 @@ textarea { margin: 0.5em 0; padding: 5px; } select { margin: 0.5em 0; } -fieldset { border: 1px solid #cccccc; } +fieldset { border: 1px solid #cccccc; width:150px;} input.text, input.title, input[type=email], input[type=text], input[type=password], textarea { background-color: #fff; border: 1px solid #bbbbbb; } input.text:focus, input.title:focus, input[type=email]:focus, input[type=text]:focus, input[type=password]:focus, textarea:focus { border: 1px solid #666666; } @@ -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; } @@ -436,7 +436,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: 1px solid #e9e9f3; width: 100%; } #content h1, #content h2, #content h3 { margin-top: 10px; } @@ -446,13 +446,12 @@ 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: 0px; width:250px; } - #graph { position: absolute; float: left; @@ -475,14 +474,14 @@ a:hover { text-decoration: underline; } font-weight: bold; } #graphcss { - margin-left: 224px; - margin-right: 150px; + margin-left: 231px; + margin-right: 0%; margin-top: 1px; position: absolute; - width: 300px; + width: 54%; height: 900px } -#sidebar{position:absolute; margin-left:1000px; margin-right:150px; margin-top:10px; width:300px;} +#sidebar{position:relative; margin-left:85%; margin-right:0%; margin-top:10px; width:24%;} #sidebar div:first-child h3 { margin-top:0px; } #sidebar h3 { background-color: #C4EBF4; padding: 0.5em; } #sidebar p { padding-left: 1em; } @@ -504,7 +503,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; top: 4px; left: -1px; margin-top: 18px;} th.month{padding:0cm 2.5cm;} table.month { margin-bottom: 0; } table.month th.month { text-transform: uppercase; color: #006699; background: none; } diff --git a/gstudio/static/gstudio/js/gstudio.js b/gstudio/static/gstudio/js/gstudio.js index d8d9d60..7ed67e2 100644 --- a/gstudio/static/gstudio/js/gstudio.js +++ b/gstudio/static/gstudio/js/gstudio.js @@ -47,23 +47,24 @@ $ = django.jQuery $("#id_attributetype").change(function() { test = $("#id_attributetype").val() - url = "/nodetypes/ajax/?id=" + test + url = "/nodetypes/ajax/ajaxattribute/?id=" + test + $.get(url, - function(data){ + function(data){ - $("#id_subject").empty() + $("#id_subject").empty() - for (var key in data) { - $('#id_subject').append( - $('<option></option>').val(key).html(data[key]) - ); - } + for (var key in data) { + $('#id_subject').append( + $('<option></option>').val(key).html(data[key]) + ); + } - }); + }); }); 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 %} - <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/graph1.html b/gstudio/templates/gstudio/graph1.html index 587b703..ab66e51 100644 --- a/gstudio/templates/gstudio/graph1.html +++ b/gstudio/templates/gstudio/graph1.html @@ -94,7 +94,7 @@ $(function() { success : function(json) { var force; - + // this contains all the nodes as a dict with _id as the key var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index 1fcf9cc..3b945f4 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -10,20 +10,20 @@ } .nodetext { #pointer-events: none; - font: 10px Serif; + font: 12px Serif; font-style:italic; } .mainnode{ font: 15px sans-serif; - fill:"red"; + fill:"black"; border-width: 1px; font-weight:bold; border-color: gray; } .relnode { - font: 10px sans-serif; + font: 12px sans-serif; font-weight:bold; fill:#000; } @@ -32,8 +32,9 @@ .node { border-width: 1px; border-color: gray; - fill:"green"; - font: 10px sans-serif; + font: 12px sans-serif; + fill:#25587E; + font-weight:bold; } body { background-color: white; @@ -45,7 +46,7 @@ display: block; } svg { - margin-left: 10%; + margin-left: 0%; margin-right: 10%; display: block; position: absolute; @@ -168,52 +169,18 @@ <script type="text/javascript" > //alert(s) //if ( parseInt(s) > 0 ){ - var a = 25 * s; - - if ( a > 700 ) - { - var w = 700; - } - else - { - var w = a; - } - var h = 24 * s, // } // else{ // var w = 700, // h = 300, // } - fill = d3.scale.category20(); - - var vis = d3.select("#chart") - .append("svg:svg") - .attr("width", w) - .attr("height", h); - - vis.append("svg:g").attr("class", "edges"); - vis.append("svg:g").attr("class", "nodes"); - - - - -var gid={{object.id}}; -$(function fgraph(gid) { +function init(a,b) +{ + - $.ajax({ - url: '/nodetypes/graphs/graph_json/{{object.id}}', - //crossDomain: true, - dataType: 'json', - success : function (json) { - - - var force; - - // this contains all the nodes as a dict with _id as the key - - var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { + nodes_by_id = _.reduce(a, function(acc, n) { acc[n._id] = n; return acc; }, {}); @@ -222,184 +189,71 @@ $(function fgraph(gid) { all_edges=new Array(); //this contains all the links between the nodes - all_edges =_(json.relations).chain().map(function(e) { + 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" + return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" }).value(); - nodes_by_id[{{object.id}}].x = w/2.0; - nodes_by_id[{{object.id}}].y = h/2.0; - - - - - /* var member_of = _(json.member_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'member_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); +} - - var contains_subtypes = _(json.contains_subtypes).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'contains_subtypes'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - var contains_members = _(json.contains_members).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'contains_members'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - +$(function fgraph() { + - var left_subjecttype_of = _(json.left_subjecttype_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'left_subjecttype_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - +$.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}}) }); - var subjecttype_of = _(json.subjecttype_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'subjecttype_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - var plural = _(json.plural).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'plural'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); +function load(key) +{ + + if (s > 0 ){ + var a = 50 * s; + var w = 700; + var p = 100 + "%"; + var h = 600; + var q = 3 * s + 35 + "%"; + }else{ + var w = 700; + var p = 100 + "%"; + var h = 600; + var q = 110 + "%"; + } + fill = d3.scale.category20(); + + var vis = d3.select("#chart") + .append("svg:svg") + .attr("id", "amazingViz") + .attr("width", p) + .attr("height", q); + vis.append("svg:g").attr("class", "edges"); + vis.append("svg:g").attr("class", "nodes"); + - var altnames = _(json.altnames).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'altnames'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); + - var contains_members = _(json.contains_members).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'contains_members'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - - var type_of = _(json.type_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'type_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - var right_subjecttype_of = _(json.right_subjecttype_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'right_subjecttype_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); + nodes_by_id[key].x = w/2.0; + nodes_by_id[key].y = h/2.0; + - var follows_edges = _(json.is_followed_by).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'follows_edges'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - - var prior_nodes = _(json.prior_nodes).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'prior_node'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - var posterior_nodes = _(json.posterior_nodes).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'posterior_node'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - var mentions_edges = _(json.is_mentioned_by).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'mentions_edges'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - */ - - - - //all_edges = new Array(); - - //all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of, type_of,plural,altnames,contains_members, prior_nodes, posterior_nodes); - /* all_edges.concat(follows_edges); - all_edges.concat(member_of_metatype); - all_edges.concat(contains_members); - all_edges.concat(contains_subtypes); - all_edges.concat(mentions_edges); - - - document.getElementById('debugbox1').value= follows_edges; //member_of_metatype - document.getElementById('debugbox2').value= mentions_edges; - //document.getElementById('debugbox2').value= member_of_metatype; - document.getElementById('debugbox3').value= all_edges; - */ - var force = d3.layout.force() + + var force = d3.layout.force() .linkStrength(0.5) - .charge(-2000) + .charge(-5000) .friction(0.7) .gravity(0.7) - .linkDistance(13) + .linkDistance(50) .nodes([]) .links([]) .size([w, h]) @@ -425,7 +279,10 @@ $(function fgraph(gid) { 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") @@ -448,41 +305,131 @@ $(function fgraph(gid) { .attr("text", function(d) { return d.type; }) + .attr("marker-end", "url(#arrowhead)"); + + + - .append("a") - .text(function(d) { return d.type; }); var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); - + + + + var new_g = node.enter().append("svg:a") - .attr("class", function(d) { if (d._id=={{ object.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) - - .attr("xlink:href",function(d){return d.url;}) + .attr("class", function(d) { var e=(d._id).charAt(0); if (d._id==key) return "mainnode"; else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode" ; else return "node"; }) + .call(force.drag); - - new_g.append("svg:circle") - .attr("cx", function(d) { return d.x - w/2.0 + 15; }) - .attr("cy", function(d) { return d.y - h/2.0 + 15; }) - .attr("r", function(d) { if (d._id=={{ object.id }}) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 }) - .style("fill", function color(d) { if (d._id=={{ object.id }}) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"}); + + 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){ + if(d._id>0 && d.expanded=="false") + { + d3.select("#amazingViz").remove(); + d.expanded="true"; + $.getJSON('/nodetypes/graphs/graph_json/' + d._id , function (json2) { + new_metadata=json2.node_metadata; + new_relations=json2.relations; + new_relnset=json2.relset + metadata=_.union(new_metadata,metadata); + relations=_.union(new_relations,relations); + init(metadata,relations); + load(d._id) + }) + } - new_g.append("svg:text") - .attr("class",function(d) { if (d._id=={{ object.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) - .attr("dy", 20) - .attr("dx", 25) - .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"}) + }); + +} +}); + + -// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"}) + new_g.on("click", function(d) { + + new_g.attr("xlink:href",function(d){return d.url;}); + }); + + + /*new_g.append("svg:ellipse") + .attr("cx", function(d) { return d.x - w/2.0 +15; }) + .attr("cy", function(d) { return d.y - h/2.0 +15 ; }) + .call(force.drag) + .attr("rx", function(d) { return ((d.screen_name).length) +10 }) + .attr("ry", function(d) { if (d._id==key) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 }); + //.style("fill", function color(d) { if (d._id==key) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"});*/ + + + + + + var text1 = new_g.append("svg:text") + .attr("class",function(d) {var e=(d._id).charAt(0); if (d._id==key) return "mainnode";else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode"; else return "node"; }) + .attr("y", 20) + .attr("x", 25) + .attr("dy", ".35em") + .attr("text-anchor","middle") + + // .attr("style",function text(d) { if ((d._id)>0) return "font-size:9.00pt;fill:blue;" ; else return "font-size:9.00pt;fill:black;"}) .text(function(d) { return d.screen_name; }); - node.exit().remove(); - + var bbox = text1.node().getBBox(); + + + new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect") + .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) + .call(force.drag) + .style("fill-opacity", ".1") + .style("stroke", "#000") + .style("stroke-width","1px" ); + + + + + + + new_g.filter(function(d) { return (d._id)>0;}).append("svg:ellipse") + .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) + .style("fill-opacity", ".2") + .style("stroke", "#666") + .style("stroke-width", "1.5px") + .style("fill", function color(d) {var e=(d._id).charAt(0); if (d.expanded=="true") return "red"; else return "none"}); + + + + + + node.exit().remove(); force.on("tick", function() { @@ -509,27 +456,18 @@ $(function fgraph(gid) { .duration(1000) .style("opacity", 1); - /* $('input#follows').change(function(){ - update(all_edges); - }); - */ - - /* $('input#mentions').change(function(){ - update(all_edges); - }); */ - } - }); - -// $("#relation_type").buttonset(); -// $('input#mentions').change(function(){console.log(this)}); -// $('input#follows').change(function(){console.log(this)}); -}); -</script> + +} +}); +//fgraph({{object.id}}); + +</script> + </div> <div id="sidebar"> {% block sidebar %} @@ -537,7 +475,7 @@ $(function fgraph(gid) { </div> - <div id="footer" class="span-24 last"> + <div id="footer"> <p> <a rel="license" @@ -550,6 +488,6 @@ $(function fgraph(gid) { </p> </div> - + </div> </body> </html> diff --git a/gstudio/testloop.py b/gstudio/testloop.py new file mode 100644 index 0000000..8455387 --- /dev/null +++ b/gstudio/testloop.py @@ -0,0 +1,59 @@ +import rdflib +from rdflib.graph import ConjunctiveGraph as Graph +from rdflib import plugin +from rdflib.store import Store, NO_STORE, VALID_STORE +from rdflib.namespace import Namespace +from rdflib.term import Literal +from rdflib.term import URIRef +from tempfile import mkdtemp +from gstudio.models import * + +def rdf_description(name, notation='xml' ): + """ + Funtion takes title of node, and rdf notation. + """ + valid_formats = ["xml", "n3", "ntriples", "trix"] + default_graph_uri = "http://gstudio.gnowledge.org/rdfstore" + configString = "/var/tmp/rdfstore" + + # Get the Sleepycat plugin. + store = plugin.get('IOMemory', Store)('rdfstore') + + # Open previously created store, or create it if it doesn't exist yet + graph = Graph(store="IOMemory", + identifier = URIRef(default_graph_uri)) + path = mkdtemp() + rt = graph.open(path, create=False) + if rt == NO_STORE: + #There is no underlying Sleepycat infrastructure, create it + graph.open(path, create=True) + else: + assert rt == VALID_STORE, "The underlying store is corrupt" + + + # Now we'll add some triples to the graph & commit the changes + rdflib = Namespace('http://sbox.gnowledge.org/gstudio/') + graph.bind("gstudio", "http://gnowledge.org/") + exclusion_fields = ["id", "rght", "node_ptr_id", "image", "lft", "_state", "_altnames_cache", "_tags_cache", "nid_ptr_id", "_mptt_cached_fields"] + node=NID.objects.get(title=name) + node_dict=node.__dict__ + + subject=str(node_dict['id']) + for key in node_dict: + if key not in exclusion_fields: + predicate=str(key) + pobject=str(node_dict[predicate]) + graph.add((rdflib[subject], rdflib[predicate], Literal(pobject))) + + + graph.commit() + + print graph.serialize(format=notation) + + graph.close() +i=0 +p=NID.objects.all() +for each in p: + rdf_description(p[i]) + i=i+1 + diff --git a/gstudio/urls/ajaxurls.py b/gstudio/urls/ajaxurls.py index 778b0de..facc603 100644 --- a/gstudio/urls/ajaxurls.py +++ b/gstudio/urls/ajaxurls.py @@ -20,7 +20,7 @@ from django.conf.urls.defaults import url from django.conf.urls.defaults import patterns urlpatterns = patterns('gstudio.views.ajaxviews', - url(r'^$', 'AjaxAttribute',name='ajax_views'), + url(r'^ajaxattribute/$', 'AjaxAttribute',name='ajax_views'), url(r'^relation/add/ajaxleft/$', 'AjaxRelationleft',name='ajax_relnleft_views'), url(r'^relation/add/ajaxright/$', 'AjaxRelationright',name='ajax_relnright_views'), url(r'^relation/ajaxleft/$', 'AjaxRelationleft',name='ajax_relnleft_views'), diff --git a/gstudio/urls/graphs.py b/gstudio/urls/graphs.py index 952f021..c43b655 100644 --- a/gstudio/urls/graphs.py +++ b/gstudio/urls/graphs.py @@ -27,5 +27,6 @@ from gstudio.settings import ALLOW_FUTURE urlpatterns = patterns( 'gstudio.views.graphs', url(r'^graph_json/(?P<node_id>\d+)$','graph_json', name='graph_json_d3'), + url(r'^graph/(?P<node_id>\d+)$','force_graph', name='force_graph_d3'), ) diff --git a/gstudio/views/add.py b/gstudio/views/add.py index 1ed2791..f6baf6c 100644 --- a/gstudio/views/add.py +++ b/gstudio/views/add.py @@ -20,10 +20,9 @@ from django.http import HttpResponseRedirect from django.template import RequestContext from django.shortcuts import render_to_response from datetime import datetime -from reversion.models import * from gstudio.forms import * -@reversion.create_revision() + def addmetatype(request): if request.method == 'POST': formset = MetatypeForm(request.POST) @@ -43,7 +42,7 @@ def addmetatype(request): return render_to_response(template, variables) -@reversion.create_revision() + def addobjecttype(request): if request.method == 'POST': formset = ObjecttypeForm(request.POST) @@ -62,7 +61,7 @@ def addobjecttype(request): return render_to_response(template, variables) -@reversion.create_revision() + def addrelationtype(request): if request.method == 'POST': formset = RelationtypeForm(request.POST) @@ -80,7 +79,7 @@ def addrelationtype(request): return render_to_response(template, variables) -@reversion.create_revision() + def addattributetype(request): if request.method == 'POST': formset = AttributetypeForm(request.POST) @@ -97,7 +96,7 @@ def addattributetype(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addsystemtype(request): if request.method == 'POST': formset = SystemtypeForm(request.POST) @@ -114,7 +113,7 @@ def addsystemtype(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addprocesstype(request): if request.method == 'POST': formset = ProcesstypeForm(request.POST) @@ -131,7 +130,7 @@ def addprocesstype(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addattribute(request): if request.method == 'POST': formset = AttributeForm(request.POST) @@ -148,7 +147,7 @@ def addattribute(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addrelation(request): if request.method == 'POST': formset = RelationForm(request.POST) @@ -165,7 +164,7 @@ def addrelation(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addcomplement(request): if request.method == 'POST': formset = ComplementForm(request.POST) @@ -182,7 +181,7 @@ def addcomplement(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addunion(request): if request.method == 'POST': formset = UnionForm(request.POST) @@ -199,7 +198,7 @@ def addunion(request): variables = RequestContext(request,{'formset':formset}) return render_to_response(template, variables) -@reversion.create_revision() + def addintersection(request): if request.method == 'POST': formset = IntersectionForm(request.POST) diff --git a/gstudio/views/ajaxviews.py b/gstudio/views/ajaxviews.py index a909db2..23c06e5 100644 --- a/gstudio/views/ajaxviews.py +++ b/gstudio/views/ajaxviews.py @@ -27,10 +27,19 @@ def AjaxAttribute(request): subjecttype = attr.subjecttype returndict = {} - for each in Objecttype.objects.all(): - if attr.subjecttype.id == each.id: - for member in each.get_members: + for ots in Objecttype.objects.all(): + if attr.subjecttype.id ==ots.id: + for member in ots.get_members: returndict[member.id] = member.title + childrenots = ots.get_children() + + if childrenots: + for eachchild in childrenots: + returndict[eachchild.id] = eachchild.title + membs=eachchild.ref.get_members + for each in membs: + returndict[each.id] = each.title + jsonobject = json.dumps(returndict) return HttpResponse(jsonobject, "application/json") @@ -76,22 +85,37 @@ def additemdict(sdict,itemtoadd): sdict[itemtoadd.id]=itemtoadd.title return sdict def selectionlist_OT(obj): + # Basically the filter must filter out the OT, their members, the children and members of the children + global rlist # Return all OTs and members of subtypes of OT obs=Objecttype.objects.filter(title=obj) # Get all members of subtypes of each OT if obs: + # Add the items first + for each in obs: + rlist=additemdict(rlist,each) obs=Objecttype.objects.get(title=obj) + # Add the objects first + # for each in obs: + # rlist = additemdict(rlist,each) memobs=obs.get_members if memobs: for each in memobs: rlist=additemdict(rlist,each) childrenots=obs.get_children() + # Add children first + for each in childrenots: + rlist=additemdict(rlist,each) + # Add memebers of each child if childrenots: for eachchild in childrenots: membs=eachchild.ref.get_members for each in membs: rlist=additemdict(rlist,each) + + + return rlist def selectionlist_MT(obj): @@ -308,12 +332,10 @@ def selectionlist_UP(obj): membs=eachchild.objecttypes.all() def selectionlist_OB(obj): global rlist - - obs=Gbobject.objects.filter(title=obj) + obs=Objecttype.objects.get(title=obj) #Get all members of OB - if obs: - obs=Gbobject.objects.get(title=obj) - rlist=additemdict(rlist,obs) + for each in obs.member_objects.all(): + rlist=additemdict(rlist,each) return rlist diff --git a/gstudio/views/graphs.py b/gstudio/views/graphs.py index 1adffec..8b226e5 100644 --- a/gstudio/views/graphs.py +++ b/gstudio/views/graphs.py @@ -73,30 +73,41 @@ from gstudio.gnowql import * #import d3 import json import os +import ast from gstudio.views.decorators import protect_nodetype from gstudio.views.decorators import update_queryset -def graph_json(request, node_id): + + +def graph_json(request, node_id): + if(node_id=='189087228'): jsonFile = open( os.path.join(os.path.dirname(__file__), '../static/gstudio/js/egonet.json'), "r") - #testjson = json.loads(jsonFile) + testjson = json.loads(jsonFile) return HttpResponse(str(jsonFile.read()), "application/json") try: node = NID.objects.get(id=node_id) - node = node.ref + node = node.ref + + except: - return HttpResponse("Node not found.", "text/html") + + return HttpResponse("node not found", "text/html") return HttpResponse(node.get_graph_json(), "application/json") - + + + + + def force_graph(request, node_id): return render_to_response('gstudio/graph1.html',{'node_id': node_id }) - + #node = get_node(str(object_id)) #ot = Objecttype.objects.get(title='place') #G = ot.get_radial_graph_json() 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() diff --git a/objectapp/models.py b/objectapp/models.py index afa492b..d6c7d30 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -98,7 +98,6 @@ from gstudio.models import Node from gstudio.models import Edge from gstudio.models import Author -import reversion from objectapp.settings import UPLOAD_TO from objectapp.settings import MARKUP_LANGUAGE from objectapp.settings import GBOBJECT_TEMPLATES @@ -113,6 +112,15 @@ from objectapp.moderator import GbobjectCommentModerator from objectapp.url_shortener import get_url_shortener from objectapp.signals import ping_directories_handler from objectapp.signals import ping_external_urls_handler +from objectapp.settings import OBJECTAPP_VERSIONING +if OBJECTAPP_VERSIONING: + import reversion + from reversion.models import * + + + +counter = 1 +attr_counter = -1 ''' class Author(User): @@ -432,21 +440,24 @@ class Gbobject(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] + g_json["relset"]=[] - + global counter + global attr_counter nbh = self.get_nbh predicate_id = {} - counter = 1 + for key in nbh.keys(): - val = "a" + str(counter) + val = str(counter) + "b" predicate_id[key] = val counter = counter + 1 #print predicate_id - attr_counter = -1 + - this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url()} + 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]: @@ -458,20 +469,34 @@ 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()}) - # 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["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 }) + + 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] #for item in value.keys(): - g_json["node_metadata"].append({"_id":attr_counter,"screen_name":nbh[key]}) + g_json["node_metadata"].append({"_id":(str(attr_counter)+"b"),"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":attr_counter }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"b") }) attr_counter-=1 except: @@ -722,6 +747,20 @@ class Gbobject(Node): 'day': self.creation_date.strftime('%d'), 'slug': self.slug}) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. + @property + def ref(self): + return eval(self.nodemodel).objects.get(id=self.id) + + + class Meta: """Gbobject's Meta""" ordering = ['-creation_date'] @@ -761,6 +800,15 @@ class Process(Gbobject): def __unicode__(self): return self.title + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. + + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. + class Meta: verbose_name = _('process') verbose_name_plural = _('processes') @@ -797,21 +845,29 @@ class System(Gbobject): system_set = models.ManyToManyField('self', related_name="in_system_set_of", verbose_name='nested systems', blank=True, null=False) + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(System, self).save(*args, **kwargs) # Call the "real" save() method. + + super(System, self).save(*args, **kwargs) # Call the "real" save() method. def __unicode__(self): return self.title - -if not reversion.is_registered(Process): - reversion.register(Process, follow=["priorstate_attribute_set", "priorstate_relation_set", "poststate_attribute_set", "poststate_relation_set", "prior_nodes", "posterior_nodes"]) +if OBJECTAPP_VERSIONING == True: + if not reversion.is_registered(Process): + reversion.register(Process, follow=["priorstate_attribute_set", "priorstate_relation_set", "poststate_attribute_set", "poststate_relation_set", "prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(System): - reversion.register(System, follow=["systemtypes", "gbobject_set", "relation_set", "attribute_set", "process_set", "system_set", "prior_nodes", "posterior_nodes"]) + if not reversion.is_registered(System): + reversion.register(System, follow=["systemtypes", "gbobject_set", "relation_set", "attribute_set", "process_set", "system_set", "prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(Gbobject): - reversion.register(Gbobject, follow=["objecttypes", "prior_nodes", "posterior_nodes"]) + if not reversion.is_registered(Gbobject): + reversion.register(Gbobject, follow=["objecttypes", "prior_nodes", "posterior_nodes"]) moderator.register(Gbobject, GbobjectCommentModerator) diff --git a/objectapp/settings.py b/objectapp/settings.py index 885a870..ba6004d 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) @@ -133,3 +133,5 @@ TWITTER_ACCESS_SECRET = getattr(settings, 'TWITTER_ACCESS_SECRET', '') USE_TWITTER = getattr(settings, 'OBJECTAPP_USE_TWITTER', bool(TWITTER_ACCESS_KEY and TWITTER_ACCESS_SECRET and \ TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET)) + +OBJECTAPP_VERSIONING = False diff --git a/objectapp/static/objectapp/css/screen.css b/objectapp/static/objectapp/css/screen.css index c69ca99..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: 230px; - margin-right: 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 @@ </div> -</div> + <p> <b>Name: </b> {{ object.title }} <br/> @@ -76,7 +76,7 @@ </p> - +</div> <div class="gbobject-body span-16 last"> diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index 5d6c6cc..0a4a036 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -11,20 +11,20 @@ } .nodetext { #pointer-events: none; - font: 10px Serif; + font: 12px Serif; font-style:italic; } .mainnode{ font: 15px sans-serif; - fill:"red"; + fill:"black"; border-width: 1px; font-weight:bold; border-color: gray; } .relnode { - font: 10px sans-serif; + font: 12px sans-serif; font-weight:bold; fill:#000; } @@ -33,8 +33,9 @@ .node { border-width: 1px; border-color: gray; - fill:"green"; - font: 10px sans-serif; + font: 12px sans-serif; + fill:#25587E; + font-weight:bold; } body { background-color: white; @@ -46,8 +47,8 @@ display: block; } svg { - margin-left: 50%; - margin-right: 50%; + margin-left: 0%; + margin-right: 0%; display: block; position: absolute; } @@ -187,56 +188,20 @@ Javascript for Object type force graph --> <script type="text/javascript" > - - var a = 75 * s; - - if ( a > 700 ) - { - var w = 700; - } - else - { - var w = a; - } - - var h = 75 * s, - - /* var w = 700, - h = 400,*/ - fill = d3.scale.category20(); - - var vis = d3.select("#chart") - .append("svg:svg") - .attr("width", w) - .attr("height", h); - - vis.append("svg:g").attr("class", "edges"); - vis.append("svg:g").attr("class", "nodes"); - -$(function() { - $.ajax({ - url: '/nodetypes/graphs/graph_json/{{ object.id }}', - //crossDomain: true, - dataType: 'json', - success : function(json) { - - //var node = NID.objects.get(slug='{{ slug }}'); - var force; - - // this contains all the nodes as a dict with _id as the key - - var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { +function init(a,b) +{ + + + nodes_by_id = _.reduce(a, function(acc, n) { acc[n._id] = n; return acc; }, {}); + + + all_edges=new Array(); - - -all_edges=new Array(); - - - - all_edges =_(json.relations).chain().map(function(e) { + //this contains all the links between the nodes + all_edges =_(b).chain().map(function(e) { e.source = nodes_by_id[e.from]; e.target = nodes_by_id[e.to]; @@ -245,182 +210,61 @@ all_edges=new Array(); return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" }).value(); - /* var member_of = _(json.member_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'member_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - var contains_subtypes = _(json.contains_subtypes).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'contains_subtypes'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - var contains_members = _(json.contains_members).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'contains_members'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - var left_subjecttype_of = _(json.left_subjecttype_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'left_subjecttype_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - var subjecttype_of = _(json.subjecttype_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'subjecttype_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - var plural = _(json.plural).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'plural'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); +} +$(function fgraph() { + - var altnames = _(json.altnames).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'altnames'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - var authors = _(json.authors).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'authors'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); +$.getJSON('/nodetypes/graphs/graph_json/' + {{object.id}}, function (json1) { + metadata=json1.node_metadata; + relations=json1.relations; + init(metadata,relations); + load({{object.id}}) }); - - var type_of = _(json.type_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'type_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - /*var content = _(json.content).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'content'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - contains_members = _(json.contains_members).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'contains_members'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); +function load(key) +{ - var prior_nodes = _(json.prior_nodes).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'prior_node'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - var posterior_nodes = _(json.posterior_nodes).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'posterior_node'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - - - var right_subjecttype_of = _(json.right_subjecttype_of).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'right_subjecttype_of'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - +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", p) + .attr("height", q); - var follows_edges = _(json.is_followed_by).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'follows_edges'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - + vis.append("svg:g").attr("class", "edges"); + vis.append("svg:g").attr("class", "nodes"); + - var mentions_edges = _(json.is_mentioned_by).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'mentions_edges'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - */ + - nodes_by_id[{{ object.id }}].x = w/2.0; - nodes_by_id[{{ object.id }}].y = h/2.0; + + nodes_by_id[key].x = w/2.0; + nodes_by_id[key].y = h/2.0; - /* all_edges = new Array(); - all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of,type_of,plural,altnames,contains_members, prior_nodes,posterior_nodes); - /* all_edges.concat(follows_edges); - all_edges.concat(member_of_metatype); - all_edges.concat(contains_members); - all_edges.concat(contains_subtypes); - all_edges.concat(mentions_edges); - + - document.getElementById('debugbox1').value= follows_edges; //member_of_metatype - document.getElementById('debugbox2').value= mentions_edges; - //document.getElementById('debugbox2').value= member_of_metatype; - document.getElementById('debugbox3').value= all_edges; - */ - var force = d3.layout.force() + + var force = d3.layout.force() .linkStrength(0.5) - .charge(-2000) + .charge(-5000) .friction(0.7) .gravity(0.7) - .linkDistance(15) + .linkDistance(50) .nodes([]) .links([]) .size([w, h]) @@ -446,18 +290,17 @@ all_edges=new Array(); 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) { return d.source.x; - }) - + }) .attr("y1", function(d) { return d.source.y; }) @@ -470,43 +313,128 @@ all_edges=new Array(); .attr("text", function(d) { return d.type; }) + + .attr("marker-end", "url(#arrowhead)"); + - .append("a") - .text(function(d) { return d.type; }); - + - var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); + + var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); - - + + + var new_g = node.enter().append("svg:a") - .attr("class", function(d) { if (d._id=={{ object.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) - .attr("xlink:href", function(d){return d.url;}) + .attr("class", function(d) { var e=(d._id).charAt(0); if (d._id==key) return "mainnode"; else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode" ; else return "node"; }) + .call(force.drag); - - - new_g.append("svg:circle") - .attr("cx", function(d) { return d.x - w/2.0 + 15; }) - .attr("cy", function(d) { return d.y - h/2.0 + 15; }) - .attr("r", function(d) { if (d._id=={{ object.id }}) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 }) - .style("fill", function color(d) { if (d._id=={{ object.id }}) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"}); + + 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){ + if(d._id>0 && d.expanded=="false") + { + d3.select("#amazingViz").remove(); + d.expanded="true"; + $.getJSON('/nodetypes/graphs/graph_json/' + d._id , function (json2) { + new_metadata=json2.node_metadata; + new_relations=json2.relations; + metadata=_.union(new_metadata,metadata); + relations=_.union(new_relations,relations); + init(metadata,relations); + load(d._id) + }) - new_g.append("svg:text") - .attr("class",function(d) { if (d._id=={{ object.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) + } + }); +} +}); + + new_g.on("click", function(d) { + + new_g.attr("xlink:href",function(d){return d.url;}); + }); + + + /*new_g.append("svg:ellipse") + .attr("cx", function(d) { return d.x - w/2.0 +15; }) + .attr("cy", function(d) { return d.y - h/2.0 +15 ; }) + .call(force.drag) + .attr("rx", function(d) { return ((d.screen_name).length) +10 }) + .attr("ry", function(d) { if (d._id==key) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 }); + //.style("fill", function color(d) { if (d._id==key) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"});*/ + + + + + + var text1 = new_g.append("svg:text") + .attr("class",function(d) {var e=(d._id).charAt(0); if (d._id==key) return "mainnode";else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode"; else return "node"; }) .attr("dy", 20) .attr("dx", 25) - .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"}) - -// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"}) + .attr("text-anchor","middle") + + // .attr("style",function text(d) { if ((d._id)>0) return "font-size:9.00pt;fill:blue;" ; else return "font-size:9.00pt;fill:black;"}) .text(function(d) { return d.screen_name; }); - - node.exit().remove(); - + var bbox = text1.node().getBBox(); + + + new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect") + .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) + .call(force.drag) + .style("fill-opacity", ".1") + .style("stroke", "#000") + .style("stroke-width","1px" ); + + + + + + + + new_g.filter(function(d) { return (d._id)>0;}).append("svg:ellipse") + .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 + 55)}) + .attr("ry",14) + .style("fill-opacity", ".2") + .style("stroke", "#666") + .style("stroke-width", "1.5px") + .style("fill", function color(d) {var e=(d._id).charAt(0); if (d.expanded=="true") return "red"; else return "none"}); + + + + + node.exit().remove(); force.on("tick", function() { @@ -523,44 +451,47 @@ all_edges=new Array(); }); } - + + + update(all_edges); + vis.style("opacity", 1e-6) .transition() .duration(1000) .style("opacity", 1); - /* $('input#follows').change(function(){ - update(all_edges); - }); - */ - - /* $('input#mentions').change(function(){ - update(all_edges); - }); */ - } - }); - -// $("#relation_type").buttonset(); -// $('input#mentions').change(function(){console.log(this)}); -// $('input#follows').change(function(){console.log(this)}); -}); + +} + + +}); +//fgraph({{object.id}}); + </script> {% block graph %} {% endblock %} </div> - <div id="sidebar" class="span-8 last"> + <div id="sidebar"> {% block sidebar %} {% endblock %} </div> - </div> - <div id="footer" class="span-24 last"> - <p>Powered by <a href="http://www.djangoproject.com" title="http://www.djangoproject.com">Django</a> and <a href="http://github.com/gnowgi/django-gstudio" title="http://github.com/gnowgi/django-gstudio">Gstudio {{ GSTUDIO_VERSION }}</a>.</p> + + <div id="footer"> + <p> + + <a rel="license" + href="http://creativecommons.org/licenses/by-sa/3.0/" title="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative + Commons License" style="border-width:0"src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png"/></a> All material is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/" title = "http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a> unless mentioned otherwise. + <br/> + Poweredby <a href="http://www.djangoproject.com" title="https://www.djangoproject.com/">Django</a> + and <a href="https://github.com/gnowgi/gnowsys-studio" title="https://github.com/gnowgi/gnowsys-studio">Gstudio + {{ GSTUDIO_VERSION }}</a>. + </p> </div> </div> </body> </html> - diff --git a/objectapp/views/add.py b/objectapp/views/add.py index afe96f9..356cc78 100644 --- a/objectapp/views/add.py +++ b/objectapp/views/add.py @@ -68,9 +68,10 @@ from django.template import RequestContext from django.shortcuts import render_to_response from datetime import datetime from objectapp.forms import * -from reversion.models import * -@reversion.create_revision() + + + def addgbobject(request): if request.method == 'POST': formset = GbobjectForm(request.POST) @@ -91,7 +92,7 @@ def addgbobject(request): -@reversion.create_revision() + def addprocess(request): if request.method == 'POST': formset = ProcessForm(request.POST) @@ -111,7 +112,7 @@ def addprocess(request): return render_to_response(template, variables) -@reversion.create_revision() + def addsystem(request): if request.method == 'POST': formset = ProcessForm(request.POST) |