diff options
author | amita singh <amitacr@gmail.com> | 2012-05-25 15:30:57 +0530 |
---|---|---|
committer | amita singh <amitacr@gmail.com> | 2012-05-25 15:30:57 +0530 |
commit | 217b435377e7ae911bd8c47d13fda75a90d305df (patch) | |
tree | 744cc87b81b143700ab3c58ff6dc48f22773966e | |
parent | a6e51038363f855d21bf3910fa8cc2c9bf9cb432 (diff) | |
parent | 877ab256f5943bb1c617d176e8af2b142ed3547b (diff) | |
download | gnowsys-217b435377e7ae911bd8c47d13fda75a90d305df.tar.gz |
Merge remote-tracking branch 'gn1/master'
111 files changed, 3504 insertions, 1298 deletions
@@ -1,2 +1,11 @@ build/ demo/demo.db + +### tilde, pyc and hash files + +*.pyc +*~ +\#*\# + + + @@ -1,73 +1,130 @@ -================== -gstudio: Gnowledge Studio -================== +============== +GNOWSYS Studio +============== -A collaborative workspace for constructing and publishing semantic -knowledge networks and ontologies as blogs. +A collaborative workspace (studio) for constructing and publishing semantic +knowledge networks and ontologies. -Features taking shape -===================== -As and when a feature is tested and working it will be listed below. +Features +======== -Nodes implemented -================= +The application is devided into two sub-apps. Gstudio and +Objectapp. The former includes classes for organizing the network or +constructing an ontology. The latter includes classes for holding the +instances of object-types, process-types and system-types. Gstudio Components ------------------ * Metatypes + + To hold Classes which have other classes as its members. e.g. "abstract noun", "adjective", "phylem", "class", "genus", "species" etc. * Object types + + To hold Classes: e.g. "thing", "being", "living being", "animals", "cat", "place", "person" etc. * Relation types + +To define binary relations (object properties) between classes and objects. e.g., "part of", "friend of", "composed of", "located in" etc. * Attribute types -* System types + + To define datatype properties for classes and objects. e.g., "population", "size", "length", "height", "first name", "phone number" etc. +* System types + + To bring together some of the classes into a system or + an ontology, a collection of the types defined above for + convenience. You can bring together the required classes, relations + and attributes into * Process types + + To define a process as prior and post states of classes or objects. * Attributes + + To store attributes * Relations + + To store binary relations * Node Specification + + A node specified (described) by its relations or attributes or both. * Relation Specification + + To create an expression using a relation with a subject, e.g., + "friend of Tom", "components of a cell" etc. + * Attribute Specification + + To specify an attribute by a subject to say for example: + population of India, color of a flower etc. These do not yeild a + proposition but an expression, which can be used as a subject in + another sentence. + +* Expression + + Expression is more like a relation between two terms, but it does not yeild a proposition, e.g., + "Researchers in India", "students residing in India" etc. It is modelled more like relation + class, except that the result is not a proposition/triple. + * Union + + To define a class by a union relation between two or more classes. + * Complement + + To define a class as a compleemnt of two or more classes. + * Intersection + To define a class as an intersection between two or more classes. Objectapp Components ------------------ * Objects + + To hold the instances of Object types: "Mumbai", "Tom" etc. + * Systems + + To hold the instances of System types. + * Processes + To hold the instances of processes. + Online Collaborative Platform ============================= -The application is built as a collaborative on line platform. +The application is built as a collaborative on line platform with the following features. Version Control --------------- -All the nodes above are also registered with django-reversion for -version control using django-reversion. + +All the changes by the users will be recorded. This feature is implemented using using django-reversion. User Registration ----------------- -Basic registration using django-registration +Basic registration, authentication mechanism. -Features you will see soon: -=========================== +Network Navigation using SVG graphs +================================== * neighbourhood graphs and concept graphs -* dynamic forms for adding attributes and relations following the - definition -Other Semantic Web features to come -=================================== + + +Other Semantic Web features +=========================== * data in RDF format * rdf feed to a triple store * sparql endpoint + +Features to be implemented +========================== + * export and import of standard knowledge representation languages: CL, OWL, XTM etc. Features adopted from Django-Blog-Zinnia @@ -79,42 +136,51 @@ django-blog-zinnia, which taught us best software development practices as well! After reviewing each feature for the purpose of semantic blogging, we will retain or extend the following features. + + * Comments -* `Sitemaps`_ +* Sitemaps * Archives views * Related entries * Private entries * RSS or Atom Feeds -* Tags and categories views -* `Advanced search engine`_ +* Tags +* Advanced search engine * Prepublication and expiration -* Edition in `MarkDown`_, `Textile`_ or `reStructuredText`_ +* Edition in MarkDown, Textile or reStructuredText * Widgets (Popular entries, Similar entries, ...) -* Spam protection with `Akismet`_ or `TypePad`_ +* Spam protection with Akismet or TypePad * Admin dashboard -* `MetaWeblog API`_ +* MetaWeblog API, xmlrpc * Ping Directories * Ping External links -* `Bit.ly`_ support -* `Twitter`_ support -* `Gravatar`_ support -* `Django-CMS`_ plugins +* Bit.ly support +* Twitter support +* Gravatar support +* Django-CMS plugins * Collaborative work * Tags autocompletion -* `Entry model extendable`_ +* Entry model extendable * Pingback/Trackback support -* `Blogger conversion utility`_ -* `WordPress conversion utility`_ -* `WYMeditor`_, `TinyMCE`_ and `MarkItUp`_ support +* Blogger conversion utility +* WordPress conversion utility +* WYMeditor, TinyMCE and MarkItUp support * Ready to use and extendables templates -* `Windows Live Writer`_ compatibility +* Windows Live Writer compatibility Examples ======== -We will soon create a sandbox site for users to play and test the features. +A sandbox site will give you a preview of the application. Visit http://sbox.gnowledge.org/ Project Page ============ -https://www.metastudio.org/groups/gstudio/overview +The project management is done from Savannah: https://savannah.gnu.org/projects/gnowsys/ + +Mailing list +============ + +Join this list if you are intersted in using or contributing as a hacker. + +http://gnowledge.org/cgi-bin/mailman/listinfo/gnowsys-dev 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.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..20dcfd9 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,30 @@ from django.utils.html import escape from gstudio.admin.forms import AttributeAdminForm from gstudio.models import * import reversion +from django.template.defaultfilters import slugify +from gstudio.settings import GSTUDIO_VERSIONING + +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin + +class AttributeAdmin(parent_class): + fieldsets=((_('Attribute'),{'fields': ('attributetype','attributetype_scope','subject','subject_scope','svalue','value_scope')}), + +) + + -class AttributeAdmin(reversion.VersionAdmin): 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/attribute_bigintegerfield.py b/gstudio/admin/attribute_bigintegerfield.py index 53085fb..277623f 100644 --- a/gstudio/admin/attribute_bigintegerfield.py +++ b/gstudio/admin/attribute_bigintegerfield.py @@ -1,9 +1,13 @@ from django.contrib import admin from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ +from gstudio.settings import GSTUDIO_VERSIONING from gstudio.admin.forms import AttributeBigIntegerFieldAdminForm import reversion - -class AttributeBigIntegerFieldAdmin(reversion.VersionAdmin): +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin +class AttributeBigIntegerFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_booleanfield.py b/gstudio/admin/attribute_booleanfield.py index e6ce41f..17c3efe 100644 --- a/gstudio/admin/attribute_booleanfield.py +++ b/gstudio/admin/attribute_booleanfield.py @@ -3,7 +3,11 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeBooleanFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion - -class AttributeBooleanFieldAdmin(reversion.VersionAdmin): +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin +class AttributeBooleanFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_charfield.py b/gstudio/admin/attribute_charfield.py index 138d89d..6f41aa4 100644 --- a/gstudio/admin/attribute_charfield.py +++ b/gstudio/admin/attribute_charfield.py @@ -1,10 +1,14 @@ from django.contrib import admin from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ - +from gstudio.settings import GSTUDIO_VERSIONING from gstudio.admin.forms import AttributeCharFieldAdminForm import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeCharFieldAdmin(reversion.VersionAdmin): +class AttributeCharFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_commaseparatedintegerfield.py b/gstudio/admin/attribute_commaseparatedintegerfield.py index 4202f61..c3701d9 100644 --- a/gstudio/admin/attribute_commaseparatedintegerfield.py +++ b/gstudio/admin/attribute_commaseparatedintegerfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeCommaSeparatedIntegerFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeCommaSeparatedIntegerFieldAdmin(reversion.VersionAdmin): +class AttributeCommaSeparatedIntegerFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_datefield.py b/gstudio/admin/attribute_datefield.py index 9619547..b62d2ca 100644 --- a/gstudio/admin/attribute_datefield.py +++ b/gstudio/admin/attribute_datefield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeDateFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeDateFieldAdmin(reversion.VersionAdmin): +class AttributeDateFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_datetimefield.py b/gstudio/admin/attribute_datetimefield.py index bdbdfa5..74bc7ca 100644 --- a/gstudio/admin/attribute_datetimefield.py +++ b/gstudio/admin/attribute_datetimefield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeDateTimeFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeDateTimeFieldAdmin(reversion.VersionAdmin): +class AttributeDateTimeFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_decimalfield.py b/gstudio/admin/attribute_decimalfield.py index 168ad06..9c9dd96 100644 --- a/gstudio/admin/attribute_decimalfield.py +++ b/gstudio/admin/attribute_decimalfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeDecimalFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeDecimalFieldAdmin(reversion.VersionAdmin): +class AttributeDecimalFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_emailfield.py b/gstudio/admin/attribute_emailfield.py index 8173f2c..a69196a 100644 --- a/gstudio/admin/attribute_emailfield.py +++ b/gstudio/admin/attribute_emailfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeEmailFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeEmailFieldAdmin(reversion.VersionAdmin): +class AttributeEmailFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_filefield.py b/gstudio/admin/attribute_filefield.py index a2553c6..11b90e4 100644 --- a/gstudio/admin/attribute_filefield.py +++ b/gstudio/admin/attribute_filefield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeFileFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeFileFieldAdmin(reversion.VersionAdmin): +class AttributeFileFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_filepathfield.py b/gstudio/admin/attribute_filepathfield.py index 76d483d..c65346d 100644 --- a/gstudio/admin/attribute_filepathfield.py +++ b/gstudio/admin/attribute_filepathfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeFilePathFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeFilePathFieldAdmin(reversion.VersionAdmin): +class AttributeFilePathFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_floatfield.py b/gstudio/admin/attribute_floatfield.py index 0f97b7c..1563f92 100644 --- a/gstudio/admin/attribute_floatfield.py +++ b/gstudio/admin/attribute_floatfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeFloatFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeFloatFieldAdmin(reversion.VersionAdmin): +class AttributeFloatFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_imagefield.py b/gstudio/admin/attribute_imagefield.py index 80515a6..c203e83 100644 --- a/gstudio/admin/attribute_imagefield.py +++ b/gstudio/admin/attribute_imagefield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeImageFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeImageFieldAdmin(reversion.VersionAdmin): +class AttributeImageFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_integerfield.py b/gstudio/admin/attribute_integerfield.py index a170c95..b98251f 100644 --- a/gstudio/admin/attribute_integerfield.py +++ b/gstudio/admin/attribute_integerfield.py @@ -3,7 +3,13 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeIntegerFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeIntegerFieldAdmin(reversion.VersionAdmin): + +class AttributeIntegerFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_ipaddressfield.py b/gstudio/admin/attribute_ipaddressfield.py index 1fa9a1b..05570fc 100644 --- a/gstudio/admin/attribute_ipaddressfield.py +++ b/gstudio/admin/attribute_ipaddressfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeIPAddressFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeIPAddressFieldAdmin(reversion.VersionAdmin): +class AttributeIPAddressFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_nullbooleanfield.py b/gstudio/admin/attribute_nullbooleanfield.py index fba5208..6a4d7f1 100644 --- a/gstudio/admin/attribute_nullbooleanfield.py +++ b/gstudio/admin/attribute_nullbooleanfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeNullBooleanFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeNullBooleanFieldAdmin(reversion.VersionAdmin): +class AttributeNullBooleanFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_positiveintegerfield.py b/gstudio/admin/attribute_positiveintegerfield.py index 1404449..54fd939 100644 --- a/gstudio/admin/attribute_positiveintegerfield.py +++ b/gstudio/admin/attribute_positiveintegerfield.py @@ -3,7 +3,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributePositiveIntegerFieldAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributePositiveIntegerFieldAdmin(reversion.VersionAdmin): +class AttributePositiveIntegerFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_textfield.py b/gstudio/admin/attribute_textfield.py index 7786af1..5ba20f3 100644 --- a/gstudio/admin/attribute_textfield.py +++ b/gstudio/admin/attribute_textfield.py @@ -4,6 +4,11 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeTextFieldAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeTextFieldAdmin(reversion.VersionAdmin): +class AttributeTextFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_timefield.py b/gstudio/admin/attribute_timefield.py index 929b028..c719082 100644 --- a/gstudio/admin/attribute_timefield.py +++ b/gstudio/admin/attribute_timefield.py @@ -4,6 +4,11 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeTimeFieldAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeTimeFieldAdmin(reversion.VersionAdmin): +class AttributeTimeFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attribute_urlfield.py b/gstudio/admin/attribute_urlfield.py index 952beec..75f9f80 100644 --- a/gstudio/admin/attribute_urlfield.py +++ b/gstudio/admin/attribute_urlfield.py @@ -4,6 +4,11 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeURLFieldAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeURLFieldAdmin(reversion.VersionAdmin): +class AttributeURLFieldAdmin(parent_class): pass diff --git a/gstudio/admin/attributespecification.py b/gstudio/admin/attributespecification.py index 3e7f6e1..781343b 100644 --- a/gstudio/admin/attributespecification.py +++ b/gstudio/admin/attributespecification.py @@ -4,7 +4,12 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import AttributeSpecificationAdminForm +from gstudio.settings import GSTUDIO_VERSIONING import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class AttributeSpecificationAdmin(reversion.VersionAdmin): +class AttributeSpecificationAdmin(parent_class): pass diff --git a/gstudio/admin/attributetype.py b/gstudio/admin/attributetype.py index c1f03d9..c44db82 100644 --- a/gstudio/admin/attributetype.py +++ b/gstudio/admin/attributetype.py @@ -20,11 +20,15 @@ from gstudio.managers import HIDDEN from gstudio.managers import PUBLISHED from gstudio.ping import DirectoryPinger from gstudio.admin.forms import AttributetypeAdminForm +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin - -class AttributetypeAdmin(reversion.VersionAdmin): +class AttributetypeAdmin(parent_class): """Admin for Attributetype model""" form = AttributetypeAdminForm date_hierarchy = 'creation_date' diff --git a/gstudio/admin/complement.py b/gstudio/admin/complement.py index b35ad6c..305bb46 100644 --- a/gstudio/admin/complement.py +++ b/gstudio/admin/complement.py @@ -4,6 +4,11 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import ComplementAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class ComplementAdmin(reversion.VersionAdmin): +class ComplementAdmin(parent_class): pass diff --git a/gstudio/admin/expression.py b/gstudio/admin/expression.py index a6a8fd2..cebd696 100644 --- a/gstudio/admin/expression.py +++ b/gstudio/admin/expression.py @@ -5,8 +5,13 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import ExpressionAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class ExpressionAdmin(reversion.VersionAdmin): +class ExpressionAdmin(parent_class): def save_model(self, request, expression, form, change): expression.title = expression.composed_sentence expression.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/intersection.py b/gstudio/admin/intersection.py index 6e9dd3e..49f2c5d 100644 --- a/gstudio/admin/intersection.py +++ b/gstudio/admin/intersection.py @@ -4,6 +4,11 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import IntersectionAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class IntersectionAdmin(reversion.VersionAdmin): +class IntersectionAdmin(parent_class): pass diff --git a/gstudio/admin/metatype.py b/gstudio/admin/metatype.py index bb24fc7..f110bac 100644 --- a/gstudio/admin/metatype.py +++ b/gstudio/admin/metatype.py @@ -5,8 +5,13 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import MetatypeAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class MetatypeAdmin(reversion.VersionAdmin): +class MetatypeAdmin(parent_class): """Admin for Metatype model""" form = MetatypeAdminForm fields = ('title','altnames', 'parent', 'description', 'slug') diff --git a/gstudio/admin/nodespecification.py b/gstudio/admin/nodespecification.py index aaf784e..f55bd05 100644 --- a/gstudio/admin/nodespecification.py +++ b/gstudio/admin/nodespecification.py @@ -4,6 +4,11 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import NodeSpecificationAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class NodeSpecificationAdmin(reversion.VersionAdmin): +class NodeSpecificationAdmin(parent_class): pass diff --git a/gstudio/admin/objecttype.py b/gstudio/admin/objecttype.py index c98a0d7..5072fe9 100644 --- a/gstudio/admin/objecttype.py +++ b/gstudio/admin/objecttype.py @@ -14,16 +14,22 @@ from django.core.urlresolvers import reverse, NoReverseMatch from tagging.models import Tag import reversion + from gstudio import settings from gstudio.managers import HIDDEN from gstudio.managers import PUBLISHED from gstudio.ping import DirectoryPinger from gstudio.admin.forms import ObjecttypeAdminForm +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class ObjecttypeAdmin(reversion.VersionAdmin): +class ObjecttypeAdmin(parent_class): """Admin for Objecttype model""" form = ObjecttypeAdminForm date_hierarchy = 'creation_date' @@ -172,8 +178,10 @@ class ObjecttypeAdmin(reversion.VersionAdmin): if not form.cleaned_data.get('authors'): form.cleaned_data['authors'].append(request.user) - nodetype.last_update = datetime.now() nodetype.save() + # nodetype.nbhood = nodetype.get_nbh + # nodetype.last_update = datetime.now() + # nodetype.save() def queryset(self, request): """Make special filtering by user permissions""" diff --git a/gstudio/admin/processtype.py b/gstudio/admin/processtype.py index 72a795b..1862de3 100644 --- a/gstudio/admin/processtype.py +++ b/gstudio/admin/processtype.py @@ -20,11 +20,14 @@ from gstudio.managers import HIDDEN from gstudio.managers import PUBLISHED from gstudio.ping import DirectoryPinger from gstudio.admin.forms import ProcesstypeAdminForm +from gstudio.settings import GSTUDIO_VERSIONING - - -class ProcesstypeAdmin(reversion.VersionAdmin): +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin +class ProcesstypeAdmin(parent_class): """Admin for Processtype model""" form = ProcesstypeAdminForm date_hierarchy = 'creation_date' diff --git a/gstudio/admin/relation.py b/gstudio/admin/relation.py index 688ad6e..7009afb 100644 --- a/gstudio/admin/relation.py +++ b/gstudio/admin/relation.py @@ -5,12 +5,31 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import RelationAdminForm import reversion +from django.template.defaultfilters import slugify +from gstudio.settings import GSTUDIO_VERSIONING -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')}), +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin + +class RelationAdmin(parent_class): + 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/admin/relationspecification.py b/gstudio/admin/relationspecification.py index 5da162b..6018236 100644 --- a/gstudio/admin/relationspecification.py +++ b/gstudio/admin/relationspecification.py @@ -4,6 +4,12 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import RelationSpecificationAdminForm import reversion +from gstudio.settings import GSTUDIO_VERSIONING -class RelationSpecificationAdmin(reversion.VersionAdmin): +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin + +class RelationSpecificationAdmin(parent_class): pass diff --git a/gstudio/admin/relationtype.py b/gstudio/admin/relationtype.py index 374f9a8..37e1a33 100644 --- a/gstudio/admin/relationtype.py +++ b/gstudio/admin/relationtype.py @@ -19,11 +19,15 @@ from gstudio.managers import HIDDEN from gstudio.managers import PUBLISHED from gstudio.ping import DirectoryPinger from gstudio.admin.forms import RelationtypeAdminForm +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin - -class RelationtypeAdmin(reversion.VersionAdmin): +class RelationtypeAdmin(parent_class): """Admin for Relationtype model""" form = RelationtypeAdminForm date_hierarchy = 'creation_date' diff --git a/gstudio/admin/systemtype.py b/gstudio/admin/systemtype.py index 8a12856..7041db0 100644 --- a/gstudio/admin/systemtype.py +++ b/gstudio/admin/systemtype.py @@ -20,11 +20,15 @@ from gstudio.managers import HIDDEN from gstudio.managers import PUBLISHED from gstudio.ping import DirectoryPinger from gstudio.admin.forms import SystemtypeAdminForm +from gstudio.settings import GSTUDIO_VERSIONING +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin - -class SystemtypeAdmin(reversion.VersionAdmin): +class SystemtypeAdmin(parent_class): """Admin for Systemtype model""" form = SystemtypeAdminForm date_hierarchy = 'creation_date' diff --git a/gstudio/admin/union.py b/gstudio/admin/union.py index 0836936..d9bc092 100644 --- a/gstudio/admin/union.py +++ b/gstudio/admin/union.py @@ -3,7 +3,13 @@ from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import UnionAdminForm +from gstudio.settings import GSTUDIO_VERSIONING + import reversion +if GSTUDIO_VERSIONING == True: + parent_class = reversion.VersionAdmin +else: + parent_class = admin.ModelAdmin -class UnionAdmin(reversion.VersionAdmin): +class UnionAdmin(parent_class): pass diff --git a/gstudio/management/commands/register-peer.py b/gstudio/management/commands/register-peer.py index a068b2f..afe2b50 100644 --- a/gstudio/management/commands/register-peer.py +++ b/gstudio/management/commands/register-peer.py @@ -13,40 +13,40 @@ # 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() +# 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 a9d6928..2c9d51f 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -66,6 +66,7 @@ """Super models of Gstudio """ + import warnings from datetime import datetime from django.db import models @@ -93,6 +94,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 +104,16 @@ 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 * +from reversion.helpers import * +import ast + NODETYPE_CHOICES = ( ('ND', 'Nodes'), @@ -168,6 +176,10 @@ STATUS_CHOICES = ((DRAFT, _('draft')), (HIDDEN, _('hidden')), (PUBLISHED, _('published'))) + +counter = 1 +attr_counter = -1 + class Author(User): """Proxy Model around User""" @@ -205,53 +217,96 @@ 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) + + @property + def get_revisioncount(self): + """ + Returns Number of Version + """ + i=0 + ver=Version.objects.get_for_object(self) + for each in ver: + i=i+1 + return i + @property + def get_version_list(self): + """ + Returns Version list + """ + ver=Version.objects.get_for_object(self) + return ver + @property + def get_ssid(self): + """ + return snapshot ids (revision id). + returns a list. + """ + slist=[] + vlist=self.get_version_list + for each in vlist: + slist.append(each.id) + return slist + + def version_info(self,ssid): + version_object=Version.objects.get(id=ssid) + return version_object.field_dict + + + def get_version_nbh(self,ssid): + """ + Returns Version nbh + """ + ver_dict=self.version_info(ssid) + ver_nbh_list=[] + ver_nbh_dict={} + for item in self.get_nbh.keys(): + if item in ver_dict.keys(): + ver_nbh_list.append(item) + for each in ver_nbh_list: + ver_nbh_dict[each]=ver_dict[each] + return ver_nbh_dict + def get_serialized_dict(self): """ return the fields in a serialized form of the current object using the __dict__ function. """ return self.__dict__ - @property - def get_app_name(self): - if self.ref.__class__.__name__=='Gbobject' or self.ref.__class__.__name__=='Process' or self.ref.__class__.__name__=='System' : - return 'type' - @models.permalink def get_absolute_url(self): """Return nodetype's URL""" - if self.get_app_name=='type': - return ('objectapp_gbobject_detail', (), { - 'year': self.creation_date.strftime('%Y'), - 'month': self.creation_date.strftime('%m'), - 'day': self.creation_date.strftime('%d'), - 'slug': self.slug}) - else: - return ('gstudio_nodetype_detail', (), { - 'year': self.creation_date.strftime('%Y'), - 'month': self.creation_date.strftime('%m'), - 'day': self.creation_date.strftime('%d'), - 'slug': self.slug}) + + return ('gstudio_nodetype_detail', (), { + 'year': self.creation_date.strftime('%Y'), + 'month': self.creation_date.strftime('%m'), + 'day': self.creation_date.strftime('%d'), + 'slug': self.slug}) @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) - return vrs.object + # """ + # 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 + @property def reftype(self): @@ -261,13 +316,64 @@ class NID(models.Model): try: """ ALGO: simple wrapper for the __class__.__name__ so that it can be used in templates + """ + # return self.__class__.__name__ obj = self.ref return obj.__class__.__name__ except: return None + @property + def getat(self): + """This is will give the possible attributetypes """ + try: + attributetype = [] + ot = self.ref + attributetype.append(ot.subjecttype_of.all()) + attributetype = [num for elem in attributetype for num in elem] + return attributetype + except: + return None + + @property + def getrt(self): + pt =[] #contains parenttype + reltype =[] #contains relationtype + titledict = {} #contains relationtype's title + inverselist = [] #contains relationtype's inverse + finaldict = {} #contains either title of relationtype or inverse of relationtype + listval=[] #contains keys of titledict to check whether parenttype id is equals to listval's left or right subjecttypeid + # pt.append(Objecttype.objects.get(title = str(gbid))) + # name = NID.objects.get(title = str(gbid)) + pt.append(self.ref) + for i in range(len(pt)): + if Relationtype.objects.filter(left_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.filter(left_subjecttype = pt[i].id)) + if Relationtype.objects.filter(right_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.filter(right_subjecttype = pt[i].id)) + + # it converts 2 or more list as one list + reltype = [num for elem in reltype for num in elem] #this rqud for filtering + + for i in reltype: + titledict.update({i:i.id}) + + + for i in range(len(titledict)): + listval.append(Relationtype.objects.get(title = titledict.keys()[i])) + inverselist.append(str(titledict.keys()[i].inverse)) + + + for j in range(len(pt)): + for i in range(len(listval)): + if pt[j].id == listval[i].left_subjecttype_id : + finaldict.update({titledict.values()[i]:titledict.keys()[i]}) + elif pt[j].id == listval[i].right_subjecttype_id: + finaldict.update({titledict.values()[i]:inverselist[i]}) + + return finaldict.values() @property @@ -285,6 +391,61 @@ class NID(models.Model): version = Version.objects.get(id=self.id) return version.serialized_data + + + def get_Version_graph_json(self,ssid): + + + # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} + # slist=self.get_ssid + ver_dict=self.version_info(ssid) + # ver_dict=str(ver['nbhood']) + # ver_dict=ast.literal_eval(ver_dict) + + g_json = {} + g_json["node_metadata"]= [] + predicate_id = {} + counter = 1 + for key in ver_dict.keys(): + val = "a" + str(counter) + predicate_id[key] = val + counter = counter + 1 + #print predicate_id + + attr_counter = -1 + + this_node = {"_id":str(ver_dict['id']),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()} + g_json["node_metadata"].append(this_node) + + for key in predicate_id.keys(): + if ver_dict[key]: + try: + g_json[str(key)]=[] + g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key}) + g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + if not isinstance(ver_dict[key],basestring): + for item in ver_dict[key]: + # user + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()}) + g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + + 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":ver_dict[key]}) + g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + attr_counter-=1 + + except: + pass + # print g_json + + + + return json.dumps(g_json) + + def __unicode__(self): return self.title @@ -293,7 +454,6 @@ class NID(models.Model): """NID's Meta""" - class Node(NID): """ Super class @@ -312,6 +472,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 @@ -319,6 +481,18 @@ class Node(NID): class Meta: abstract=False + + def save(self, *args, **kwargs): + + # self.nbhood=self.get_nbh + 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): @@ -327,6 +501,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): @@ -508,6 +689,18 @@ class Metatype(Node): verbose_name = _('metatype') verbose_name_plural = _('metatypes') + # Save for metatype + + def save(self, *args, **kwargs): + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_nbh + + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + + + @@ -604,8 +797,8 @@ class Nodetype(Node): reltypes['possible_rightroles'] = right_subset return reltypes - - + + @property def get_possible_attributetypes(self): """ @@ -665,32 +858,6 @@ class Nodetype(Node): return rels - - @property - def get_possible_attributes(self): - """ - Gets the relations possible for this metatype - 1. Recursively create a set of all the ancestors i.e. parent/subtypes of the MT. - 2. Get all the RT's linked to each ancestor - """ - #Step 1. - ancestor_list = [] - this_parent = self.parent - - # recursive thru parent field and append - while this_parent: - ancestor_list.append(this_parent) - this_parent = this_parent.parent - - #Step 2. - attrs = [] - - for each in ancestor_list: - # retrieve all the AT's from each ancestor - attrs.extend(Attribute.objects.filter(subject=each.id)) - - return attrs - def get_graph_json(self): @@ -698,21 +865,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]: @@ -725,28 +895,74 @@ 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 }) + + 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":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":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 + def get_possible_attributes(self): + """ + Gets the relations possible for this metatype + 1. Recursively create a set of all the ancestors i.e. parent/subtypes of the MT. + 2. Get all the RT's linked to each ancestor + """ + #Step 1. + ancestor_list = [] + this_parent = self.parent + + # recursive thru parent field and append + while this_parent: + ancestor_list.append(this_parent) + this_parent = this_parent.parent + + #Step 2. + attrs = [] + + for each in ancestor_list: + # retrieve all the AT's from each ancestor + attrs.extend(Attribute.objects.filter(subject=each.id)) + + return attrs + + + @property def tree_path(self): @@ -1114,6 +1330,9 @@ class Nodetype(Node): 'month': self.creation_date.strftime('%m'), 'day': self.creation_date.strftime('%d'), 'slug': self.slug}) + def get_version_url(self): + """Return nodetype's URL""" + return "/nodetypes/display/viewhistory/" def get_serialized_data(self): """ @@ -1131,6 +1350,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): @@ -1141,7 +1368,7 @@ class Objecttype(Nodetype): def __unicode__(self): return self.title - #def get_graph_json(self): + @@ -1243,7 +1470,7 @@ class Objecttype(Nodetype): nbh['posterior_nodes'] = self.posterior_nodes.all() - nbh['authors'] = self.authors.all() + #nbh['authors'] = self.authors.all() return nbh @@ -1310,6 +1537,18 @@ 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__ + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_nbh + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + + + @@ -1319,10 +1558,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?') @@ -1351,6 +1590,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): ''' @@ -1385,6 +1636,13 @@ class Attributetype(Nodetype): def __unicode__(self): return self.title + + @property + def getdataType(self): + at = 'attribute'+str(self.get_dataType_display()) + at = at.lower() + return at + class Meta: """ attribute type's meta class @@ -1394,6 +1652,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__ + +# self.nbhood=self.get_nbh + 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): @@ -1484,6 +1753,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): @@ -1560,6 +1840,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. + @@ -1570,12 +1861,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') @@ -1583,6 +1894,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') @@ -1590,6 +1912,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') @@ -1604,12 +1934,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): @@ -1618,12 +1965,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): @@ -1632,6 +1997,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') @@ -1639,12 +2013,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): @@ -1653,6 +2046,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') @@ -1660,6 +2063,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') @@ -1667,6 +2079,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') @@ -1674,6 +2096,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') @@ -1681,6 +2113,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') @@ -1688,6 +2126,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') @@ -1695,6 +2143,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): @@ -1718,6 +2176,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. + @@ -1749,6 +2216,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): @@ -1774,6 +2251,7 @@ class AttributeSpecification(Node): def __unicode__(self): + self.nodemodel = self.__class__.__name__ return self.composed_subject @@ -1782,6 +2260,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): """ @@ -1805,11 +2294,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): """ @@ -1841,6 +2341,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): """ @@ -1868,6 +2379,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): @@ -1879,6 +2400,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): @@ -1890,6 +2421,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 @@ -1898,44 +2439,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. + + super(Intersection, self).save(*args, **kwargs) # Call the "real" save() method. + + +if GSTUDIO_VERSIONING == True: + reversion.register(NID) -if not reversion.is_registered(Systemtype): - reversion.register(Systemtype) + if not reversion.is_registered(Systemtype): + reversion.register(Systemtype) -if not reversion.is_registered(Objecttype): - reversion.register(Objecttype , follow=["nodetype_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(Node): + reversion.register(Node , follow=["nid_ptr"]) -if not reversion.is_registered(Edge): - reversion.register(Edge , follow=["nid_ptr"]) + if not reversion.is_registered(Edge): + reversion.register(Edge , follow=["nid_ptr"]) -if not reversion.is_registered(Processtype): - reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"]) + 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(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(Metatype): + reversion.register(Metatype, follow=["node_ptr","parent"]) -if not reversion.is_registered(Relationtype): - reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) + if not reversion.is_registered(Relationtype): + reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) -if not reversion.is_registered(Attributetype): - reversion.register(Attributetype, follow=["subjecttype"]) + 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(Attribute): + reversion.register(Attribute, follow=["subject", "attributetype"]) -if not reversion.is_registered(Relation): - reversion.register(Relation, follow=["left_subject", "right_subject", "relationtype"]) + 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']) 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/_header.html b/gstudio/templates/gstudio/_header.html index 23d4d43..2e05c8c 100644 --- a/gstudio/templates/gstudio/_header.html +++ b/gstudio/templates/gstudio/_header.html @@ -12,7 +12,7 @@ | <a href="{{ get_absolute_url }}/objects">objects</a> {% if user.is_authenticated %} - | <a href="{{ get_absolute_url }}/nodetypes/userdashboard">My Dashboard</a> + {% if user.is_staff %} | <a href="{{ get_absolute_url }}/admin">Admin Dashboard</a> diff --git a/gstudio/templates/gstudio/base.html b/gstudio/templates/gstudio/base.html index 94a72eb..f1c4aa1 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> + + <a href="{% url gstudio_nodetype_latest_feed %}" class="feeds" title="Rssfeed"><img src="{{ STATIC_URL }}gstudio/img/rss.png" alt="?" width="20" height="" /></a> <div class="search"> <h3>{% trans "Search" %}</h3> @@ -41,6 +41,22 @@ {% get_objecttypes %} </div> --> +<div class="History"> + + <h3>{% trans "Versions" %}</h3> + <table border="1" cellspacing="0"> + + {% for sid in object.ref.get_ssid %} + + + <a href="{{ object.get_version_url }}{{ sid }}/{{ forloop.counter }}">{{ object.title }} {{ object.id }}.{{ forloop.counter }}</a><br> + + {% endfor %} + </table> + +</div> +<br> + <div class="authors"> <h3>{% trans "Authors" %}</h3> {% get_authors %} diff --git a/gstudio/templates/gstudio/display.html b/gstudio/templates/gstudio/display.html new file mode 100644 index 0000000..184b58d --- /dev/null +++ b/gstudio/templates/gstudio/display.html @@ -0,0 +1,595 @@ + +{% load i18n comments gstudio_tags %} +{% load gstudio_tags i18n %} +{% get_tags as nodetype_tags %} +{% load adminmedia grp_tags %} + + + + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xml:lang="{{ LANGUAGE_CODE }}" lang="{{ LANGUAGE_CODE }}" version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <style type="text/css"> + .link { + stroke: #ccc; + } + .nodetext { + #pointer-events: none; + font: 10px Serif; + font-style:italic; + } + .mainnode{ + + font: 15px sans-serif; + fill:"red"; + border-width: 1px; + font-weight:bold; + border-color: gray; + + } + .relnode { + font: 10px sans-serif; + font-weight:bold; + fill:#000; + } + + + .node { + border-width: 1px; + border-color: gray; + fill:"green"; + font: 10px sans-serif; + } + body { + background-color: white; + display:block; + } + #chart { + height: 90%; + margin: 0 auto; + width: 90%; + display: block; + } + svg { + margin-left: 10%; + margin-right: 10%; + display: block; + position: absolute; + } + + </style> + <!-- the header lines from grappelli --> + {% block blockbots %} + <meta name="robots" content="NONE,NOARCHIVE" /> + {% endblock %} <!-- STYLESHEETS --> + {% block stylesheets %} + <link href="{% admin_media_prefix %}css/base.css" rel="stylesheet" type="text/css" /> + {% if LANGUAGE_BIDI %} + <link href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" rel="stylesheet" type="text/css" /> + {% endif %} + <link href="{% admin_media_prefix %}jquery/ui/css/custom-theme/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" media="screen" title="no title" charset="utf-8" /> + <link href="{% admin_media_prefix %}css/jquery-ui-grappelli-extensions.css" rel="stylesheet" type="text/css" /> + {% endblock %} <!-- EXTRASTYLES --> + {% block extrastyle %}{% endblock %} <!-- JAVASCRIPTS --> + {% block javascripts %} + <script type="text/javascript"> + // GLOBALS + var grappelli = {}, + // TODO: klemens: drop ADMIN_URL + ADMIN_URL = "{% url admin:index %}", + MODEL_URL_ARRAY = {% get_content_types %}, DATE_FORMAT = "{% get_date_format %}", TIME_FORMAT = "{% get_time_format %}", DATETIME_FORMAT = "{% get_datetime_format %}"; + </script> + <!-- jQuery, jQuery-UI --> + <script src="{% admin_media_prefix %}jquery/jquery-1.6.2.min.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}jquery/ui/js/jquery-ui-1.8.15.custom.min.js" type="text/javascript"></script> + <!-- Grappelli Main JS --> + <script src="{% admin_media_prefix %}js/grappelli/grappelli.js" type="text/javascript"></script> + <!-- Grappelli jQuery Plugins, Widgets --> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible_group.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_timepicker.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_fk.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_m2m.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_generic.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_fk.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_m2m.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_generic.js" type="text/javascript"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery-1.5.1.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.core.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.widget.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.tabs.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.position.min.js"></script> + + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery.ui.timepicker.js"></script> + + <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> + <script src="{{STATIC_URL}}gstudio/js/gstudio.js" type="text/javascript"></script> + <!-- EXTRAHEAD --> + {% block extrahead %}{% endblock %} + + {% endblock %} <!-- the header lines from gstudio --> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <meta http-equiv="cache-control" content="public" /> + <meta name="robots" content="follow, all" /> + <meta name="language" content="{{ LANGUAGE_CODE }}" /> + <meta name="description" content="{% block meta-description %}Demonstration of the Gstudio Blog application.{% endblock %}" /> + <meta name="keywords" content="{% block meta-keywords %}django, blog, gstudio, {{ nodetype_tags|join:", "}}{% endblock %}" /> + <meta name="author" content="gnowgi" /> + {% block meta %}{% endblock %} + <link rel="pingback" href="/xmlrpc/" /> + <link rel="shortcut icon" href="{{ STATIC_URL }}gstudio/img/favicon.ico" /> + <link rel="home" href="{% url gstudio_nodetype_archive_index %}" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/grappelli_skin_default.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen_gstudio.css" /> + <link rel="stylesheet" type="text/css" media="print" href="{{ STATIC_URL }}gstudio/css/print.css" /> + <!--[if lt IE 8]> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/ie.css" /> + <![endif]--> + {% block link %}{% endblock %} + {% block script %}{% endblock %} <title>Gnowledge Studio - {% block title %}{% endblock %}</title> + </head> + <body id="gstudio"> + <div class="body" > + <div class="content"> + <!-- + <div id="relation_type" class="ui-buttonset"> + <span>Relation type:</span> + <input checked="checked" value="follows" type="radio" id="follows" name="radio" class="ui-helper-hidden-accessible"><label for="follows" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" aria-pressed="false" role="button" aria-disabled="false"><span class="ui-button-text">Followers</span></label> + <input value="mentions" type="radio" id="mentions" name="radio" class="ui-helper-hidden-accessible"><label for="mentions" aria-pressed="true" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-state-active" role="button" aria-disabled="false"><span class="ui-button-text">Mentions</span></label> + <input value="hashtags" type="radio" id="hashtags" name="radio"/><label for="hashtags">Shared interests</label> + </div> + --> + <div id="chart"> + <svg width="960" height="700" style="opacity: 1; "> + </div> + <script type="text/javascript" src="/static/gstudio/js/jquery.min.js" ></script> + <script type="text/javascript" src="/static/gstudio/js/jquery-ui.js" ></script> + <script type="text/javascript" src="/static/gstudio/js/underscore.js" ></script> + <script type="text/javascript" src="/static/gstudio/js/d3.js"></script> + <script type="text/javascript" src="/static/gstudio/js/d3.layout.js"></script> + <script type="text/javascript" src="/static/gstudio/js/d3.geom.js"></script> + <!-- <script type="text/javascript" src="/static/gstudio/js/force.js"></script> + + Javascript for Object type force graph + --> + <script type="text/javascript" > + + 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"); + +$(function() { + $.ajax({ + url: '/nodetypes/graphs/version_graph_json/{{ ssid }}', + //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) { + acc[n._id] = n; + return acc; + }, {}); + + 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(); + + + 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 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(); + + 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(); + + + 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(); + + + nodes_by_id[{{ nt.id }}].x = w/2.0; + nodes_by_id[{{ nt.id }}].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,content, 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() + .linkStrength(0.5) + .charge(-2000) + .friction(0.7) + .gravity(0.7) + .linkDistance(13) + .nodes([]) + .links([]) + .size([w, h]) + .start(); + + function update(edges){ + // for each func + _.each(nodes_by_id, function(n){n.added = false}); + // reduce the nodes list to have only those nodes for a given rel. + nodes = _.reduce(edges, function(acc, e) { + if(nodes_by_id[e.from] && !nodes_by_id[e.from].added){ + nodes_by_id[e.from].added = true; + acc.push(nodes_by_id[e.from]); + } + if(nodes_by_id[e.to] && !nodes_by_id[e.to].added){ + nodes_by_id[e.to].added = true; + acc.push(nodes_by_id[e.to]); + } + return acc; + }, []); + + force.nodes(nodes); + force.links(edges); + force.start(); + + link = d3.select("#chart g.edges").selectAll("line.link") + .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) { + return Math.sqrt(d.value); + } */ ) + .attr("x1", function(d) { + return d.source.x; + }) + .attr("y1", function(d) { + return d.source.y; + }) + .attr("x2", function(d) { + return d.target.x; + }) + .attr("y2", function(d) { + return d.target.y; + }) + .attr("text", function(d) { + return d.type; + }) + + .append("a") + .text(function(d) { return d.type; }); + + + var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); + + var new_g = node.enter().append("svg:a") + .attr("class", function(d) { if (d._id=={{ nt.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;}) + .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=={{ nt.id }}) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 }) + .style("fill", function color(d) { if (d._id=={{ nt.id }}) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"}); + + + new_g.append("svg:text") + .attr("class",function(d) { if (d._id=={{ nt.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;"}) + + .text(function(d) { + return d.screen_name; + }); + + node.exit().remove(); + + + + force.on("tick", function() { + + var x_center = $("#chart").width() / 2; + var y_center = $("#chart").height() / 2; + + link.attr("x1", function(d) { return d.source.x; }) + .attr("y1", function(d) { return d.source.y; }) + .attr("x2", function(d) { return d.target.x; }) + .attr("y2", function(d) { return d.target.y; }); + + node.attr("transform", function(d) { return "translate(" + (d.x-16) + "," + (d.y-16) + ")"; }); + + }); + } + + 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)}); +}); + + +</script> + </div> +</div> +<div> + {% include "gstudio/_header.html" %} + <div id="breadcrumbs" class="span-24 last"> + / {% block breadcrumbs %}{% endblock %} + </div> + <div id="body" class="span-24 last" > + <div id="content" class="hfeed span-16 border"> + <h3>{% block content %} + {% block nodetype-content %} + <h2 class="nodetype-title"> + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_dict.title }} {{ nt.id }}.{{ cnt }} + </a> + </h2> + {% with nt.html_content|safe as object_content %} + <b>Name:<nbsp></b>{{ ver_dict.title }}<br/> + {% if ver_dict.altnames %} + <b> Alternate names:<nbsp></b>{{ ver_dict.altnames}} + <br/> + {% endif %} + {% if ver_dict.plural %} + <b> Plural Name:<nbsp></b>{{ ver_dict.plural }} <br/> + {% endif %} + {% if nt.get_rendered_nbh.authors %}<b>Authors: <nbsp> </b> + {% endif %} + {% for author in nt.authors.all %} + <span class="vcard author"> + <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" + title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> + </span>{% if not forloop.last %}, {% endif %} + {% endfor %} <br/> + {% endwith %} + {% endblock %} + {% endblock %} +</div> + + <div id="sidebar"> + {% block sidebar %} + + <div class="History"> + + <h3>{% trans "Versions" %}</h3> + <script type="text/javascript"> + function go_to_loc(sid) + { + + <!-- var len=document.history.group2.length --> + <!-- for(var i=0;i<len;i++) --> + <!-- { --> + <!-- var r=window.document.history.group2[i] --> + <!-- if(sid==r.) --> + <!-- { --> + <!-- r.disabled="false" --> + <!-- } --> + <!-- else --> + <!-- { --> + <!-- r.enabled="true" --> + <!-- } --> + <!-- } --> + + + } + </script> + + <form name="history" action="/nodetypes/display/showhistory/{{ ssid }}" > + <table cellspacing="0" border="2"> + <tr> + <td> <input type="radio" name="group1" value="{{ ssid }}" checked >{{ nt.id }}.{{ cnt }}</input></td> + <td></td></tr> + {% for sid in nt.get_ssid %} + {% ifnotequal forloop.counter cnt %} + <tr> + <td> + </td> + <td> + + <input type="radio" id="{{ sid }}"name="group2" value="{{ sid }}" >{{ nt.id }}.{{ forloop.counter }}</input> + </td>{% endifnotequal %} + {% endfor %}</tr></table> + <input type="submit" value="Compare" /> + </form> + + + </div> + + + {% endblock %} + </div> + + + <div id="footer" class="span-24 last" style="height: 5px; display:none; top: 51px; left: 88px; width: 1364px;"> + <p> + <a rel="license" + href="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/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a> unless mentioned otherwise. + <br/> + Powered by <a href="http://www.djangoproject.com">Django</a> + and <a href="http://github.com/gnowgi/django-gstudio">Gstudio + {{ GSTUDIO_VERSION }}</a>. + </p> + </div> + </div> + </div> + </body> +</html> + + + + + + 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/nodetype_detail.html b/gstudio/templates/gstudio/nodetype_detail.html index 404adb9..7947e58 100644 --- a/gstudio/templates/gstudio/nodetype_detail.html +++ b/gstudio/templates/gstudio/nodetype_detail.html @@ -243,18 +243,30 @@ s = parseInt(s) //alert(s) } - </script> - + </script> {% endwith %} {% endblock %} -{% if object.reftype == 'Objecttype'%} -<a href="{{ get_absolute_url }}/objects/dynamicAttribute/save/{{ object.title }}">Add Attribute</a> -<br/> -<a href="{{ get_absolute_url }}/objects/dynamicRelation/displayRT/{{ object.title }}">Add Relation</a> -{% endif %} +<!-- Dynamic form begins --> +<p> +{% if object.reftype == 'Objecttype' %} +<b>Add Attributes:</b> +{% for i in object.getat %} +<a href="{{ get_absolute_url }}/objects/dynamicAttribute/save/{{ i }}/{{ object.title }}">{{ i }}</a><nbsp>; +{% endfor %} +</p> + +<p> +<b>Add Relations: </b> +{% for i in object.getrt %} +<a href="{{ get_absolute_url }}/objects/dynamicRelation/displaymem/{{ i }}/{{ object.title }}">{{ i }}</a><nbsp>; +{% endfor %} +{% endif %} + +</p> +<!-- Dyanic form ends --> <div class="nodetype-content"> </div> diff --git a/gstudio/templates/gstudio/nodetype_list.html b/gstudio/templates/gstudio/nodetype_list.html index f4f75bd..ebaae5c 100644 --- a/gstudio/templates/gstudio/nodetype_list.html +++ b/gstudio/templates/gstudio/nodetype_list.html @@ -1,5 +1,7 @@ -{% extends "gstudio/base.html" %} +{% extends "gstudio/version_base.html" %} {% load i18n gstudio_tags %} +{% load i18n objectapp_tags %} + {% block meta-description %}{% trans "Latest nodetypes for" %} {% if metatype %}{% trans "the metatype" %} {{ metatype }}{% if metatype.description %}: {{ metatype.description|striptags|safe }}{% endif %}{% endif %}{% if tag %}{% trans "the tag" %} {{ tag }}{% endif %}{% if author %}{% trans "the author" %} {{ author }}{% endif %}{% if page_obj %}{% ifnotequal page_obj.number 1 %} {% trans "page" %} {{ page_obj.number }}{% endifnotequal %}{% endif %}{% endblock %} diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index 1fcf9cc..eba5e28 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 = 620; + var q = 3 * s + 75 + "%"; + }else{ + var w = 700; + var p = 100 + "%"; + var h = 620; + 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/templates/gstudio/version_base.html b/gstudio/templates/gstudio/version_base.html new file mode 100644 index 0000000..15ee3a8 --- /dev/null +++ b/gstudio/templates/gstudio/version_base.html @@ -0,0 +1,129 @@ +{% extends "gstudio/skeleton.html" %} +{% load gstudio_tags i18n %} +{% load objectapp_tags i18n %} + + {% block meta %} + <meta name="generator" content="Objectapp {{ OBJECTAPP_VERSION }}" /> +{% endblock %} + +{% block link %} + <link rel="index" href="{% url objectapp_gbobject_archive_index %}" /> + <link rel="EditURI" type="application/rsd+xml" href="{% url objectapp_rsd %}" /> + <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="{% url objectapp_wlwmanifest %}" /> + <link rel="search" type="application/opensearchdescription+xml" title="Objectapp's Blog" href="{% url objectapp_opensearch %}" /> + <link rel="alternate" type="application/rss+xml" title="{% trans "RSS Feed of latest gbobjects" %}" href="{% url objectapp_gbobject_latest_feed %}" /> + <!-- {% get_archives_gbobjects "objectapp/tags/archives_gbobjects_link.html" %} --> +{% endblock %} + +{% block breadcrumbs %} + {% gstudio_breadcrumbs %} +{% 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> + +<div class="search"> + <h3>{% trans "Search" %}</h3> + <form method="get" id="searchform" action="{% url nodes_search %}"> + <p> + <input type="text" value="{% trans "Keywords..." %}" name="pattern" id="searchbox" onfocus="this.value=''" /> + <input type="submit" class="submitbutton" value="OK" /> + <a title="{% trans 'You can use - to exclude words or phrases, "double quotes" for exact phrases and the AND/OR boolean operators combined with parenthesis for complex searchs.' %}"> + <img src="{{ STATIC_URL }}objectapp/img/help.png" alt="?" width="14" height="14" /> + </a> + </p> + </form> +</div> +<!-- +<div class="objecttypes"> + <h3>{% trans "Objecttypes" %}</h3> + {% get_objecttypes %} +</div> +--> +<div class="History"> + <!-- <script type="text/javascript"> --> + <!-- function go_to_loc(sid) --> + <!-- { --> + <!-- window.location.href = "{{ object.get_version_url }}"+sid --> + <!-- } --> + + <!-- </script> --> +<!-- <h3>{% trans "Versions" %}</h3> --> +<!-- {% for sid in object.get_ssid reversed %} --> +<!-- <input type="radio" name="group1" value="{{ sid }}"><a href="{{ object.get_version_url }}{{ sid }}">{{ sid }}</a></input> --> +<!-- <input type="radio" name="group2" value="{{ sid }}">{{ sid }}</input> --> +<!-- <br> --> +<!-- {% endfor %} --> +<!-- <br> --> +<!-- <input type="submit" value="Compare" /> --> +</div> +<br> + +<div class="authors"> + <h3>{% trans "Authors" %}</h3> + {% get_authors %} +</div> +<div class="calendar"> + <h3>{% trans "Calendar" %}</h3> + {% get_calendar_gbobjects %} +</div> +<div class="tags"> + <h3>{% trans "Tags" %}</h3> + {% get_tag_cloud %} +</div> +<div class="recents"> + <h3>{% trans "Recent gbobjects" %}</h3> + {% get_recent_gbobjects 5 %} +</div> +<div class="comments"> + <h3>{% trans "Recent comments" %}</h3> + {% get_recent_comments 5 %} +</div> +<div class="linkbacks"> + <h3>{% trans "Recent linkbacks" %}</h3> + {% get_recent_linkbacks 5 %} +</div> +<div class="randoms"> + <h3>{% trans "Random gbobjects" %}</h3> + {% get_random_gbobjects 5 %} +</div> +<div class="populars"> + <h3>{% trans "Popular gbobjects" %}</h3> + {% get_popular_gbobjects 5 %} +</div> +<div class="archives"> + <h3>{% trans "Archives" %}</h3> + {% get_archives_gbobjects_tree %} +</div> +{% if user.is_authenticated %} +<div class="tools"> + <h3>{% trans "Tools" %}</h3> + <ul> + {% if perms.objectapp %} + <li> + <a href="{% url admin:app_list "objectapp" %}" title="{% trans "Dashboard" %}"> + {% trans "Dashboard" %} + </a> + </li> + {% endif %} + {% if perms.objectapp.add_gbobject %} + <li> + <a href="{% url admin:objectapp_gbobject_add %}" title="{% trans "Post an gbobject" %}"> + {% trans "Post an gbobject" %} + </a> + </li> + {% endif %} + {% block admin_tools %} + {% endblock %} + <li> + <a href="{% url admin:logout %}" title="{% trans "Log out" %}"> + {% trans "Log out" %} + </a> + </li> + </ul> +</div> +{% endif %} +{% endblock %} + + diff --git a/gstudio/templates/gstudio/version_diff.html b/gstudio/templates/gstudio/version_diff.html new file mode 100644 index 0000000..a640f07 --- /dev/null +++ b/gstudio/templates/gstudio/version_diff.html @@ -0,0 +1,219 @@ + +{% load i18n comments gstudio_tags %} +{% load gstudio_tags i18n %} +{% get_tags as nodetype_tags %} +{% load adminmedia grp_tags %} + + +{% load gstudio_tags i18n %} +{% get_tags as nodetype_tags %} +{% load adminmedia grp_tags %} +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xml:lang="{{ LANGUAGE_CODE }}" lang="{{ LANGUAGE_CODE }}" version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <style type="text/css"> + body { + background-color: white; + display:block; + } + .content + { + } + .content1 + { + } + </style> + {% block blockbots %} + <meta name="robots" content="NONE,NOARCHIVE" /> + {% endblock %} <!-- STYLESHEETS --> + {% block stylesheets %} + <link href="{% admin_media_prefix %}css/base.css" rel="stylesheet" type="text/css" /> + {% if LANGUAGE_BIDI %} + <link href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" rel="stylesheet" type="text/css" /> + {% endif %} + <link href="{% admin_media_prefix %}jquery/ui/css/custom-theme/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" media="screen" title="no title" charset="utf-8" /> + <link href="{% admin_media_prefix %}css/jquery-ui-grappelli-extensions.css" rel="stylesheet" type="text/css" /> + {% endblock %} <!-- EXTRASTYLES --> + {% block extrastyle %}{% endblock %} <!-- JAVASCRIPTS --> + {% block javascripts %} + <script type="text/javascript"> + // GLOBALS + var grappelli = {}, + // TODO: klemens: drop ADMIN_URL + ADMIN_URL = "{% url admin:index %}", + MODEL_URL_ARRAY = {% get_content_types %}, DATE_FORMAT = "{% get_date_format %}", TIME_FORMAT = "{% get_time_format %}", DATETIME_FORMAT = "{% get_datetime_format %}"; + </script> + <!-- jQuery, jQuery-UI --> + <script src="{% admin_media_prefix %}jquery/jquery-1.6.2.min.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}jquery/ui/js/jquery-ui-1.8.15.custom.min.js" type="text/javascript"></script> + <!-- Grappelli Main JS --> + <script src="{% admin_media_prefix %}js/grappelli/grappelli.js" type="text/javascript"></script> + <!-- Grappelli jQuery Plugins, Widgets --> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible_group.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_timepicker.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_fk.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_m2m.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_generic.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_fk.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_m2m.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_generic.js" type="text/javascript"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery-1.5.1.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.core.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.widget.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.tabs.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.position.min.js"></script> + + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery.ui.timepicker.js"></script> + + <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> + <script src="{{STATIC_URL}}gstudio/js/gstudio.js" type="text/javascript"></script> + <!-- EXTRAHEAD --> + {% block extrahead %}{% endblock %} + + {% endblock %} + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <meta http-equiv="cache-control" content="public" /> + <meta name="robots" content="follow, all" /> + <meta name="language" content="{{ LANGUAGE_CODE }}" /> + <meta name="description" content="{% block meta-description %}Demonstration of the Gstudio Blog application.{% endblock %}" /> + <meta name="keywords" content="{% block meta-keywords %}django, blog, gstudio, {{ nodetype_tags|join:", "}}{% endblock %}" /> + <meta name="author" content="gnowgi" /> + {% block meta %}{% endblock %} + <link rel="pingback" href="/xmlrpc/" /> + <link rel="shortcut icon" href="{{ STATIC_URL }}gstudio/img/favicon.ico" /> + <link rel="home" href="{% url gstudio_nodetype_archive_index %}" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/grappelli_skin_default.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen_gstudio.css" /> + <link rel="stylesheet" type="text/css" media="print" href="{{ STATIC_URL }}gstudio/css/print.css" /> + {% block link %}{% endblock %} + {% block script %}{% endblock %} <title>Gnowledge Studio - {% block title %}{% endblock %}</title> + </head> + <body id="gstudio"> + + + + + + + {% include "gstudio/_header.html" %} + <div id="breadcrumbs" class="span-24 last"> + / {% block breadcrumbs %}{% endblock %} + </div> + <!-- <div id="body" class="span-24 last" > --> + <table border="0" > + <tr><td> + + <h3>{% block content %} + {% block nodetype-content %} + <h2 class="nodetype-title"> + <a href="{{ nt1.get_absolute_url }}" title="{{ nt1.title }}" rel="bookmark">{{ ver_new.title }} + </a> + </h2> + <!-- {% block content56 %}{% for each in diffs1 %} --> + <!-- {% autoescape off %} --> + <!-- {{ each }}<br> --> + <!-- {% endautoescape %}{% endfor %} {% endblock %} --> + <!-- <br> --> + {% with nt1.html_content|safe as object_content %}<br> + <b>Name:<nbsp></b>{{ ver_new.title }}<br/> + {% if ver_new.altnames %} + <b> Alternate names:<nbsp></b>{{ ver_new.altnames }} + <br/> + {% endif %} + {% if ver_new.plural %} + <b> Plural Name:<nbsp></b>{{ ver_new.plural }} <br/> + {% endif %} + + <b> Content:<nbsp></b>{{ ver_new.content }} <br/> + + + {% if nt1.get_rendered_nbh.authors %}<b>Authors: <nbsp> </b> + {% endif %} + {% for author in nt1.authors.all %} + <span class="vcard author"> + <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" + title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> + </span>{% if not forloop.last %}, {% endif %} + {% endfor %} <br/> + {% endwith %} + {% endblock %} + {% endblock %} + + </td> + <td> + + <h3>{% block content1 %} + {% block nodetype-content1 %} + <h2 class="nodetype-title"> + <a href="{{ nt1.get_absolute_url }}" title="{{ nt1.title }}" rel="bookmark">{{ ver_old.title }} + </a> + </h2><!-- <b> --> + <!-- {% block content85 %}{% for each in diffs %} --> + <!-- {% autoescape off %} --> + <!-- {{ each }}<br> --> + <!-- {% endautoescape %}{% endfor %} {% endblock %}</b> --> + <br> + {% with nt1.html_content|safe as object_content %} + <b>Name:<nbsp></b>{% autoescape off %} + {{ diffs.0 }} + {% endautoescape %}<br> + {% if ver_old.altnames %} + <b> Alternate names:<nbsp></b> {% autoescape off %} + {{ diffs.1 }} + {% endautoescape %} + <br/> + {% endif %} + {% if ver_old.plural %} + <b> Plural Name:<nbsp></b> {% autoescape off %} + {{ diffs.2 }} + {% endautoescape %} <br/> + {% endif %} + + <b> Content:<nbsp></b> {% autoescape off %} + {{ diffs.3 }} + {% endautoescape %} <br/> + + + {% if nt1.get_rendered_nbh.authors %}<b>Authors: <nbsp> </b> + {% endif %} + {% for author in nt1.authors.all %} + <span class="vcard author"> + <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" + title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> + </span>{% if not forloop.last %}, {% endif %} + {% endfor %} <br/> + {% endwith %} + {% endblock %} + {% endblock %} + + </td> + +<!-- <th><b><i><br><u>Difference between Selected Versions</u></b></i><br><br> --> +<!-- {% block content6 %}{% for each in diffs %} --> +<!-- {% autoescape off %} --> +<!-- {{ each }}<br> --> +<!-- {% endautoescape %}{% endfor %} {% endblock %} --> +<!-- </th> --> + + </tr> +<tr><td><input type="button" value="Merge"></input><input type="button" value="RollBack"></input></td> +<td><input type="button" value="Merge"></input><input type="button" value="RollBack"></input></td> </tr> +<!-- <tr><th><b><i>Difference between Selected Versions<b><i><th><tr> --> +<!-- <tr><td><b>{% block content5 %}{% for each in diffs %} --> +<!-- {% autoescape off %} --> +<!-- {{ each }}<br> --> +<!-- {% endautoescape %}{% endfor %} {% endblock %} </b> </td></tr> --> +<!-- </table> --> + + + + + + </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/__init__.py b/gstudio/urls/__init__.py index b04f148..20ac065 100644 --- a/gstudio/urls/__init__.py +++ b/gstudio/urls/__init__.py @@ -32,6 +32,7 @@ urlpatterns = patterns( url(r'^discussions/', include('gstudio.urls.discussions')), url(r'^add/', include('gstudio.urls.add')), url(r'^ajax/', include('gstudio.urls.ajaxurls')), + url(r'^display/',include('gstudio.urls.history')), url(r'^graphs/', include('gstudio.urls.graphs')), url(r'^userdashboard/', include('gstudio.urls.dashboard')), url(r'^', include('gstudio.urls.quick_nodetype')), 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..4aa8c4b 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'^version_graph_json/(?P<ssid>\d+)$','version_graph_json', name='version_graph_d3'), url(r'^graph/(?P<node_id>\d+)$','force_graph', name='force_graph_d3'), ) diff --git a/gstudio/urls/history.py b/gstudio/urls/history.py new file mode 100644 index 0000000..3932cd6 --- /dev/null +++ b/gstudio/urls/history.py @@ -0,0 +1,8 @@ +"""Urls for Gstudio forms""" +from django.conf.urls.defaults import url +from django.conf.urls.defaults import patterns + +urlpatterns = patterns('gstudio.views.history', + url(r'^viewhistory/(?P<ssid>\d+)/(?P<cnt>\d+)/$', 'history', + name='gstudio_history'), + url(r'^showhistory/(?P<ssid>\d+)/$','showHistory'),) 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..ff2fa40 100644 --- a/gstudio/views/graphs.py +++ b/gstudio/views/graphs.py @@ -73,30 +73,53 @@ from gstudio.gnowql import * #import d3 import json import os - 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 }) - +def version_graph_json(request,ssid): + + if(ssid=='189087228'): + jsonFile = open( os.path.join(os.path.dirname(__file__), '../static/gstudio/js/egonet.json'), "r") + #testjson = json.loads(jsonFile) + + return HttpResponse(str(jsonFile.read()), "application/json") + + try: + node = Version.objects.get(id=ssid) + + node = node.object.ref + except: + return HttpResponse("Node not found.", "text/html") + + return HttpResponse(node.get_Version_graph_json(ssid), "application/json") + #node = get_node(str(object_id)) #ot = Objecttype.objects.get(title='place') #G = ot.get_radial_graph_json() diff --git a/gstudio/views/history.py b/gstudio/views/history.py new file mode 100644 index 0000000..d4adac9 --- /dev/null +++ b/gstudio/views/history.py @@ -0,0 +1,105 @@ +from django.http import * +from reversion.models import * +from gstudio.models import * +from django.template import RequestContext +from django.shortcuts import render_to_response +from django.views.generic.date_based import object_detail +from reversion.helpers import * +import pprint +from gstudio.models import * +from reversion.models import * +from gstudio.views.decorators import protect_nodetype +from gstudio.views.decorators import update_queryset +import ast + +def history(request,ssid,cnt): + # iden=request.GET["id"] + nt1=Version.objects.get(id=ssid) + nt=nt1.object.ref + ver_dict=nt.version_info(ssid) + variables = RequestContext(request,{'ver_dict':ver_dict ,'nt':nt,'ssid':ssid,'cnt':cnt }) + template="gstudio/display.html" + return render_to_response(template,variables) + +def showHistory(request,ssid): + # vid1=request.GET["group1"] + vid1=ssid + vid2=request.GET["group2"] + nt=Version.objects.get(id=vid1) + nt1=nt.object.ref + pp=pprint.PrettyPrinter(indent=4) + ver_new1=Version.objects.get(id=vid1) + ver_old1=Version.objects.get(id=vid2) + + ver_new_dict=nt1.version_info(request.GET["group1"]) + content=str(ver_new_dict['content']) + content=content[3:-4] + ver_new_dict['content']=content + ver_old_dict=nt1.version_info(request.GET["group2"]) + content=str(ver_old_dict['content']) + content=content[3:-4] + ver_old_dict['content']=content + + ver_new_nbh=ver_new_dict['nbhood'] + ver_new_dict1=ast.literal_eval(ver_new_nbh) + + ver_old_nbh=ver_old_dict['nbhood'] + ver_old_dict1=ast.literal_eval(ver_old_nbh) + + # ver_new_nbh=ver_new_nbh.replace(",","\n") + # ver_old_nbh=ver_old_nbh.replace(",","\n") + d=[] + d1=[] + field=['Name','Plural Name','Alternate Name','Authors','Content'] + for each in ver_new_dict1: + ver_new="" + ver_old="" + if each =='altnames': + ver_new+=ver_new_dict['altnames'] + ver_old+=ver_old_dict['altnames'] + + diffs = dmp.diff_main(ver_new, ver_old) + d.append(dmp.diff_prettyHtml(diffs)) + # diffs = dmp.diff_main(ver_old, ver_new) + # d1.append(dmp.diff_prettyHtml(diffs)) + + if each =='title': + ver_new+=ver_new_dict['title'] + ver_old+=ver_old_dict['title'] + diffs = dmp.diff_main(ver_new, ver_old) + d.append(dmp.diff_prettyHtml(diffs)) + # diffs = dmp.diff_main(ver_old, ver_new) + # d1.append(dmp.diff_prettyHtml(diffs)) + if each =='plural': + ver_new+=ver_new_dict['plural'] + ver_old+=ver_old_dict['plural'] + diffs = dmp.diff_main(ver_new, ver_old) + d.append(dmp.diff_prettyHtml(diffs)) + # diffs = dmp.diff_main(ver_old, ver_new) + # d1.append(dmp.diff_prettyHtml(diffs)) + # if each =='content': + ver_new="" + ver_old="" + ver_new+=ver_new_dict['content'] + ver_old+=ver_old_dict['content'] + diffs = dmp.diff_main(ver_new, ver_old) + d.append(dmp.diff_prettyHtml(diffs)) + # diffs = dmp.diff_main(ver_old, ver_new) + # d1.append(dmp.diff_prettyHtml(diffs)) + + # for each in ver_new_dict1: +# ver_new="" + # ver_old="" + # ver_new+=each + ":" + str(ver_new_dict1[each]) +# ver_old+=each + ":" + str(ver_old_dict1[each]) + # diffs = dmp.diff_main(ver_new, ver_old) + # d.append(dmp.diff_prettyHtml(diffs)) + + # return HttpResponse(d) + ver_new=nt1.version_info(request.GET["group1"]) + ver_old=nt1.version_info(request.GET["group2"]) + + variables=RequestContext(request,{'nt':nt1,'ver_old':ver_old_dict,'ver_new':ver_new_dict,'diffs':d ,'vid1':vid1,'vid2':vid2 }) + template="gstudio/version_diff.html" + return render_to_response(template,variables) + 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/forms.py b/objectapp/forms.py index 1d12315..a117b33 100644 --- a/objectapp/forms.py +++ b/objectapp/forms.py @@ -15,12 +15,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -from django import forms -from django.forms import ModelForm -from django.forms.fields import DateField -from django.contrib.admin import widgets -from django.contrib.admin.widgets import AdminDateWidget +from django.forms import ModelForm from gstudio.models import * from objectapp.models import * @@ -38,15 +34,3 @@ class SystemForm(ModelForm): class Meta: model = System - - -class ContextForm(forms.Form): - - def __init__(self,rdict, *args, **kwargs): - super(ContextForm, self).__init__(*args, **kwargs) - for key, val in rdict.iteritems(): - print key, val - self.fields[str(key)+"_"+str(val)] = getattr(forms,rdict.get(key))(required = False) - - - diff --git a/objectapp/models.py b/objectapp/models.py index c4a612d..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): @@ -201,6 +209,78 @@ class Gbobject(Node): published = GbobjectPublishedManager() + # @property + # def getdataType(self): + # gb = 'attribute'+str(self.get_dataType.display()) + # gb = gb.lower() + # return gb + + @property + def getattributetypes(self): + """ + Returns the attributetypes of self as well as its parent's attributetype. + """ + try: + parenttype = [] + attributetype = [] + returnlist = [] + obj = self + parenttype = obj.objecttypes.all() + attributetype.append(obj.subjecttype_of.all()) + for each in parenttype: + attributetype.append(each.subjecttype_of.all()) + + attributetype = [num for elem in attributetype for num in elem] + return attributetype + + except: + return None + + + + @property + def getrelationtypes(self): + pt =[] #contains parenttype + reltype =[] #contains relationtype + titledict = {} #contains relationtype's title + inverselist = [] #contains relationtype's inverse + finaldict = {} #contains either title of relationtype or inverse of relationtype + listval=[] #contains keys of titledict to check whether parenttype id is equals to listval's left or right subjecttypeid + + #gb= Gbobject.objects.get(title=str(gbid)) + gb=self + pt = gb.objecttypes.all() + for i in range(len(pt)): + if Relationtype.objects.filter(left_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.filter(left_subjecttype = pt[i].id)) + if Relationtype.objects.filter(right_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.filter(right_subjecttype = pt[i].id)) + if Relationtype.objects.filter(left_subjecttype = gb): + reltype.append(Relationtype.objects.filter(left_subjecttype = gb)) + if Relationtype.objects.filter(right_subjecttype = gb): + reltype.append(Relationtype.objects.filter(right_subjecttype = gb)) + + + reltype = [num for elem in reltype for num in elem] + + for i in reltype: + titledict.update({i:i.id}) + + + for i in range(len(titledict)): + listval.append(Relationtype.objects.get(title = titledict.keys()[i])) + inverselist.append(titledict.keys()[i].inverse) + + for j in range(len(pt)): + for i in range(len(listval)): + if pt[j].id == listval[i].left_subjecttype_id or gb.id == listval[i].left_subjecttype_id : + finaldict.update({titledict.values()[i]: titledict.keys()[i]}) + elif pt[j].id == listval[i].right_subjecttype_id or gb.id == listval[i].right_subjecttype_id: + finaldict.update({titledict.values()[i]:inverselist[i]}) + + + return finaldict.values() + def get_relations(self): relation_set = {} # ALGO to find the relations and their left-subjecttypes and right_subjecttypes @@ -240,7 +320,8 @@ class Gbobject(Node): relation_set.update(rel_dict['right_subjecttypes']) return relation_set - + + def get_attributes(self): attributes_dict = {} @@ -359,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]: @@ -385,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: @@ -649,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'] @@ -688,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') @@ -724,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/static/objectapp/js/savert.js b/objectapp/static/objectapp/js/savert.js index 0e1f8b0..549e819 100644 --- a/objectapp/static/objectapp/js/savert.js +++ b/objectapp/static/objectapp/js/savert.js @@ -3,7 +3,7 @@ $ = django.jQuery $(document).ready(function() { - $("#id_submit_rt").ajaxSend(function(e,xhr,settings){ + $("#id_go").ajaxSend(function(e,xhr,settings){ function getCookie(name) { @@ -41,13 +41,13 @@ $ = django.jQuery xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); } }); - $("#id_submit_rt").click(function(){ + $("#id_go").click(function(){ left = document.getElementById("id_left") - rt = document.getElementById("id_reltype") + rt = document.getElementById("id_rel") right = document.getElementById("id_right") absolute_url = document.getElementById("id_back_url") - url = "/objects/dynamicRelation/save/"+ left.value + "/" +rt.value+"/"+right.value+"/" - // alert(url); + url = "/objects/dynamicRelation/save/"+ left.value+"/"+rt.value+"/"+right.value+"/" + //alert(url); $.get(url,function(data){ window.location.replace(absolute_url.value); }); diff --git a/objectapp/static/objectapp/js/setMember.js b/objectapp/static/objectapp/js/setMember.js index a71b675..977bd63 100644 --- a/objectapp/static/objectapp/js/setMember.js +++ b/objectapp/static/objectapp/js/setMember.js @@ -42,10 +42,16 @@ $ = django.jQuery } }); $("#id_select_mem").change(function(){ - right_member = $(this).val() - document.getElementById("id_right").value = right_member; - // alert("hello "+ right_member); + right = $(this).val() + left =document.getElementById("id_left") + rel=document.getElementById("id_rel") + document.getElementById("id_right").value = right; + //url="/objects/dynamicRelation/save/"+left.value+"/"+rel.value+"/"+right+"/" + //alert("hello "+ ur); + }); }); + + 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/base.html b/objectapp/templates/objectapp/base.html index d2b78ce..90e061b 100644 --- a/objectapp/templates/objectapp/base.html +++ b/objectapp/templates/objectapp/base.html @@ -19,8 +19,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> + + <a href="{% url objectapp_gbobject_latest_feed %}" class="feeds" title="Rssfeed"><img src="{{ STATIC_URL }}objectapp/img/rss.png" alt="?" width="20" height="" /></a> <div class="search"> <h3>{% trans "Search" %}</h3> diff --git a/objectapp/templates/objectapp/fillAT.html b/objectapp/templates/objectapp/fillAT.html index 6ddabe4..6a474d0 100644 --- a/objectapp/templates/objectapp/fillAT.html +++ b/objectapp/templates/objectapp/fillAT.html @@ -1,28 +1,17 @@ {% extends "objectapp/base.html" %} {% load i18n %} {% block content %} -<form action="." method="POST"> +<form action="." method="POST"> {% csrf_token %} -<b>Details of {{ name }} </b> -<table id= "id_table" class = "class_table"> - <tr> - <th> Attribute Type </th> - <th> Value </th> - </tr> - {% for field in form %} - <tr> - <td>{{ field.label_tag }}</td> - <td>{{ field }} {{ field.errors }}</td> - </tr> - {% endfor %} - <tr> - <td><input type="submit" id="id_submit" value="Go"/></td> - <td><input type="button" id="id_back" value="Back"/></td> - </tr> -</table> +<b>{{ title }}</b> +{% for field in form %} +{{ field }} {{ field.errors }} +{% endfor %} +<input type="submit" id="id_submit" value="Go"/> +<input type="button" id="id_back" value="Back"/> <input type="hidden" id="id_back_url" value="{{ absolute_url_node }}"/> -<input type="hidden" id="id_hidden" value=" "/> + </form> {% endblock %} diff --git a/objectapp/templates/objectapp/gbobject_detail.html b/objectapp/templates/objectapp/gbobject_detail.html index b8ce726..cfe1651 100644 --- a/objectapp/templates/objectapp/gbobject_detail.html +++ b/objectapp/templates/objectapp/gbobject_detail.html @@ -1,6 +1,5 @@ {% extends "objectapp/base.html" %} {% load i18n comments objectapp_tags %} - {% block title %}{{ object.title }}{% endblock %} {% block meta-description %}{% if object.excerpt %}{{ object.excerpt|striptags }}{% else %}{{ object.content|striptags|truncatewords:100 }}{% endif %}{% endblock %} @@ -30,15 +29,12 @@ {% endblock %} - - {% block content %} {% block gbobject-content %} {% with object.html_content|safe as object_content %} {% include "objectapp/_gbobject_detail.html" %} - <script type="text/javascript" > var s = 0 var i @@ -77,8 +73,6 @@ {% endwith %} {% endblock %} - - {% block gbobject-widgets %} <div class="gbobject-widgets span-16 last"> {% with object.next_gbobject as next_gbobject %} @@ -130,14 +124,25 @@ <h3>{% trans "Similar objects" %}</h3> {% get_similar_gbobjects 5 %} </div> -</div> -{% endblock %} - - - - - +{% endblock %} + + + +<p><br/> +<b>Add Attributes: </b> +<input type="hidden" id="id_object" value="{{ object.title }}"/> +{% for i in object.getattributetypes %} +<a href="{{ get_absolute_url }}/objects/dynamicAttribute/save/{{ i }}/{{ object.title }}/">{{ i }}</a><nbsp>; +{% endfor %} +</p> +<p> +<b>Add Relations: </b> +{% for i in object.getrelationtypes %} +<a href=" {{ get_absolute_url }}/objects/dynamicRelation/displaymem/{{ i }}/{{ object.title }}/">{{ i }}</a><nbsp>; +{% endfor %} +</p> +</div> {% block gbobject-comments %} <div id="comments" class="span-16 last"> <h3>{% trans "Comments" %}</h3> diff --git a/objectapp/templates/objectapp/selectRT.html b/objectapp/templates/objectapp/selectRT.html index cfec3c7..713a45c 100644 --- a/objectapp/templates/objectapp/selectRT.html +++ b/objectapp/templates/objectapp/selectRT.html @@ -9,29 +9,25 @@ <!-- -------------------------------------------- --> -<select id ="id_select_rt"> +<select id ="id_select_mem"> <option>-select-</option> -{% if final %} -{% for key, val in final.iteritems %} - <option value="{{ key }}">{{ val }}</option> +{% if finaldict %} +{% for key, val in finaldict.iteritems %} + <option value="{{ val }}">{{ val }}</option> {% endfor %} {% else %} - <option> No Relation </option> + <option> No Member </option> <input type="button" id="id_back" value="Back"/> {% endif %} </select> <!-- -------------------------------------------- --> - -<input id="id_left" type="hidden" value="{{ gbid }}"> -<input id="id_right" type="hidden" value=" "> -<input id="id_reltype" type="hidden" value=" "> +<input type="button" id="id_go" value="GO"/> +<input type="button" id="id_back" value="Back"/> +<input id="id_left" type="hidden" value="{{ gb }}"> +<input id="id_rel" type="hidden" value="{{ reltit }}"> <input id="id_back_url" type="hidden" value="{{ absolute_url_node }}"> - -<!-- -------------------------------------------- --> - -<div id = "id_div1"> -</div> +<input id="id_right" type="hidden" value=" "> <!-- -------------------------------------------- --> diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index 4d4b0a2..d04b02f 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; } @@ -96,17 +97,18 @@ <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_fk.js" type="text/javascript"></script> <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_m2m.js" type="text/javascript"></script> <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_generic.js" type="text/javascript"></script> - <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/saveat.js"></script> - <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/selectRT.js"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/setMember.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/savert.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/noat.js"></script> + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/setdate.js"></script> + <!-- EXTRAHEAD --> {% block extrahead %}{% endblock %} @@ -186,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]; @@ -244,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(); +$(function fgraph() { + - 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(); - - - 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 = 680; +var q = 3 * s + 80 + "%"; +}else{ +var w = 700; +var p = 122 + "%"; +var h = 680; +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]) @@ -445,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; }) @@ -469,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() { @@ -522,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/urls/ATurl.py b/objectapp/urls/ATurl.py index 00122fb..2363fd8 100644 --- a/objectapp/urls/ATurl.py +++ b/objectapp/urls/ATurl.py @@ -1,12 +1,8 @@ from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns
-#from objectapp.views import testview
+
urlpatterns = patterns('objectapp.views.dynamicAT',
- url(r'^dynamicattr/$','dynamic_view',
- name = 'objectapp_dynamic_view'),
- url(r'^save/(\w.+)/$','dynamic_save',
+ url(r'^save/(\w.+)/(\w.+)/$','dynamic_save',
name='objectapp_dynamic_save'),
- # url(r'^dynamicOT/(\w.+)/$','dynamic_objecttype',
- # name='objectapp_dynamic_objecttype'),
)
diff --git a/objectapp/urls/RTurl.py b/objectapp/urls/RTurl.py index cea15cd..53cfb8d 100644 --- a/objectapp/urls/RTurl.py +++ b/objectapp/urls/RTurl.py @@ -1,13 +1,12 @@ from django.conf.urls.defaults import url from django.conf.urls.defaults import patterns -#from objectapp.views import testview -urlpatterns = patterns('objectapp.views.dynamicRT', - url(r'^displayRT/(\w.+)/$','context_RT', - name='objectapp_context_view'), - url(r'^displaymem/(\w+)/(\w+)/$','context_member', + +urlpatterns = patterns('objectapp.views.dynamicRT', + url(r'^displaymem/(\w.+)/(\w.+)/$','context_member', name='objectapp_context_display'), - url(r'^save/(\w+)/(\w+)/(\w+)/$','context_save', + + url(r'^save/(\w.+)/(\w.+)/(\w.+)/$','context_save', name='objectapp_context_save'), ) 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) diff --git a/objectapp/views/dynamicAT.py b/objectapp/views/dynamicAT.py index 52a6256..aec02fc 100644 --- a/objectapp/views/dynamicAT.py +++ b/objectapp/views/dynamicAT.py @@ -1,155 +1,53 @@ from django.http import * -from django import forms +from django.forms import ModelForm from django.shortcuts import render_to_response from django.template import RequestContext +from django.forms.models import modelform_factory from objectapp.models import * from objectapp.forms import * from gstudio.models import * +from gstudio.admin.forms import * + +def MakeForm(model_cls, *args, **kwargs): + class ContextForm(ModelForm): + class Meta: + model = model_cls.values()[0] + fields = ('value',) + def __init__(self, *args, **kwargs): + super(ContextForm,self).__init__(*args, **kwargs) + + + return ContextForm(*args, **kwargs) -def dynamic_view(request): - rdict = {} - for j in Gbobject.objects.all(): - rdict.update({j.id:j.title}) - - template="objectapp/selectAT.html" - context= RequestContext(request,{ 'rdict':rdict }) - return render_to_response(template,context) - -def dynamic_save(request,tit): #view for gb and ot too - testlst = [] - parenttype = [] - attributetype = [] - rdict = {} - nodelist = [] - syst = []#parent for system - try: - offset = str(tit) - except ValueError: - raise Http404() - - #flag = 0 #means its object - - if Objecttype.objects.filter(title = offset): - flag = 1 - elif Gbobject.objects.filter(title = offset): - flag = 0 - elif Systemtype.objects.filter(title = offset): - flag = 2 - - if flag == 1: - parenttype.append(Objecttype.objects.get(title = offset)) - pt_id = NID.objects.get(title = offset) - name = pt_id - - elif flag == 0: - #utit = Gbobject.objects.get(title = offset) - gb=Gbobject.objects.get(title=offset) - name = gb - # checking whether object is gb or system coz created objects are treated as Gbobject n then System objects - if System.objects.filter(title = (gb.ref).title): - gb = System.objects.get(title = offset) - syst = gb.systemtypes.all() - for i in syst: - nodelist = i.nodetype_set.all() - parenttype.append(i) - - for i in nodelist: - parenttype.append(i.ref) - - elif Gbobject.objects.filter(title = (gb.ref).title): - parenttype = gb.objecttypes.all() - - pt_id = NID.objects.get(id = gb.id) - - elif flag == 2: - systype = Systemtype.objects.get(title = offset) - nodelist = systype.nodetype_set.all() - parenttype.append(Systemtype.objects.get(title = offset)) - for i in nodelist: - parenttype.append(i.ref) - pt_id = NID.objects.get(title = offset) - name = pt_id - - +def dynamic_save(request, attit, memtit): + rdict ={} + savedict = {} + memtit = NID.objects.get(title = str(memtit)) + name = memtit.ref absolute_url_node = name.get_absolute_url() - for each in parenttype: - attributetype.append(each.subjecttype_of.all()) - - attributetype = [num for elem in attributetype for num in elem] - - for each in range(len(attributetype)): - rdict.update({attributetype[each]:str(Attributetype.get_dataType_display(attributetype[each]))}) - - if request.method=='POST': - form = ContextForm(rdict,request.POST) - bound= form.is_bound - + at = Attributetype.objects.get(title = str(attit)) + dt = str(at.get_dataType_display()) + MyModel = eval('Attribute'+dt) + rdict.update({str(at.title):MyModel}) + if request.method == 'POST': + form = MakeForm(rdict,request.POST) if form.is_valid(): - for key,val in rdict.items(): - testlst.append(str(request.POST[str(key)+"_"+str(val)])) - - for val in range(len(testlst)): - if testlst[val] != '' : - savedict = {'title':testlst[val],'slug':testlst[val], 'svalue':testlst[val], 'subject':pt_id, 'attributetype':rdict.keys()[val]} - att = Attribute.objects.create(**savedict) - att.save() + value = form.cleaned_data['value'] + savedict = {'title':value,'slug':value,'svalue':value,'subject':memtit, 'attributetype':at,'value':value} + att = MyModel.objects.create(**savedict) + att.save() + return HttpResponseRedirect(absolute_url_node) - return HttpResponseRedirect(absolute_url_node) else: - form = ContextForm(rdict) - + form = MakeForm(rdict) template = "objectapp/fillAT.html" - context = RequestContext(request,{'form' : form, 'name':name,'absolute_url_node':absolute_url_node}) + context = RequestContext(request,{'form' : form,'title':str(attit), 'absolute_url_node':absolute_url_node}) return render_to_response(template,context) -# def dynamic_objecttype(request,iden): #gb view for dynamic at -# testlst = [] -# attributetype = [] -# rdict = {} -# try: -# offset = str(iden) -# except ValueError: -# raise Http404() - -# #uid = Gbobject.objects.get(title = offset) -# gb=Gbobject.objects.get(title=offset) -# parenttype = gb.objecttypes.all() -# pt_id = NID.objects.get(id = gb.id) - - -# for each in parenttype: -# attributetype.append(each.subjecttype_of.all()) - -# attributetype = [num for elem in attributetype for num in elem] - -# for each in range(len(attributetype)): -# rdict.update({attributetype[each]:str(Attributetype.get_dataType_display(attributetype[each]))}) - -# if request.method=='POST': -# form = ContextForm(rdict,request.POST) -# bound= form.is_bound - -# if form.is_valid(): -# for key,val in rdict.items(): -# testlst.append(str(request.POST[str(key)+"_"+str(val)])) - -# for val in range(len(testlst)): -# if testlst[val] != '' : -# savedict = {'title':testlst[val],'slug':testlst[val], 'svalue':testlst[val], 'subject':pt_id, 'attributetype':rdict.keys()[val]} -# att = Attribute.objects.create(**savedict) -# att.save() - -# return HttpResponseRedirect("/objects/") -# else: -# form = ContextForm(rdict) - -# template = "objectapp/fillAT.html" -# context = RequestContext(request,{'form' : form}) -# return render_to_response(template,context) diff --git a/objectapp/views/dynamicRT.py b/objectapp/views/dynamicRT.py index f078168..78370b5 100644 --- a/objectapp/views/dynamicRT.py +++ b/objectapp/views/dynamicRT.py @@ -1,250 +1,151 @@ -from gstudio.models import * -from objectapp.models import * + from django.http import * from django.shortcuts import render_to_response from django.template import RequestContext from django.db import IntegrityError +from django.forms import ModelForm +from gstudio.models import * +from objectapp.models import * -def context_RT(request, gbid): - pt =[] #contains parenttype - reltype =[] #contains relationtype - titledict = {} #contains relationtype's title - inverselist = [] #contains relationtype's inverse - finaldict = {} #contains either title of relationtype or inverse of relationtype - listval=[] #contains keys of titledict to check whether parenttype id is equals to listval's left or right subjecttypeid - #flag = 0 #check whether OT or OB, flag = 0 means it is OB +def context_member(request,reltit , memtit): - # if its an OT, then parse separately - if Objecttype.objects.filter(title=str(gbid)): + if Relationtype.objects.filter(title = str(reltit)): + r =Relationtype.objects.get(title = str(reltit)) + else: + r = Relationtype.objects.get(inverse = str(reltit)) + + gbdict = {} + otmem=[] + childpt = [] + childmem = [] + finaldict={} + memdict = {} #otmem + childmem + + if Objecttype.objects.filter(title = str(memtit)): flag = 1 - elif Gbobject.objects.filter(title = str(gbid)): - flag = 0 - elif Systemtype.objects.filter(title = str(gbid)): - flag = 2 - - if flag == 1: - pt.append(Objecttype.objects.get(title = str(gbid))) - name = NID.objects.get(title = str(gbid)) - - for i in range(len(pt)): - if Relationtype.objects.filter(left_subjecttype = pt[i].id): - reltype.append(Relationtype.objects.get(left_subjecttype = pt[i].id)) - if Relationtype.objects.filter(right_subjecttype = pt[i].id): - reltype.append(Relationtype.objects.get(right_subjecttype = pt[i].id)) - - # it converts 2 or more list as one list - #reltype = [num for elem in reltype for num in elem] #this rqud for filtering - - for i in reltype: - titledict.update({i:i.id}) - - - for i in range(len(titledict)): - listval.append(Relationtype.objects.get(title = titledict.keys()[i])) - inverselist.append(titledict.keys()[i].inverse) - - - for j in range(len(pt)): - for i in range(len(listval)): - if pt[j].id == listval[i].left_subjecttype_id : - finaldict.update({titledict.values()[i]:titledict.keys()[i]}) - elif pt[j].id == listval[i].right_subjecttype_id: - finaldict.update({titledict.values()[i]:inverselist[i]}) - - - elif flag == 0: - gb= Gbobject.objects.get(title=str(gbid)) - name = gb - pt = gb.objecttypes.all() - for i in range(len(pt)): - if Relationtype.objects.filter(left_subjecttype = pt[i].id): - reltype.append(Relationtype.objects.get(left_subjecttype = pt[i].id)) - if Relationtype.objects.filter(right_subjecttype = pt[i].id): - reltype.append(Relationtype.objects.get(right_subjecttype = pt[i].id)) - if Relationtype.objects.filter(left_subjecttype = gb): - reltype.append(Relationtype.objects.get(left_subjecttype = gb)) - if Relationtype.objects.filter(right_subjecttype = gb): - reltype.append(Relationtype.objects.get(right_subjecttype = gb)) - - - #reltype = [num for elem in reltype for num in elem] - - for i in reltype: - titledict.update({i:i.id}) - - - for i in range(len(titledict)): - listval.append(Relationtype.objects.get(title = titledict.keys()[i])) - inverselist.append(titledict.keys()[i].inverse) - - for j in range(len(pt)): - for i in range(len(listval)): - if pt[j].id == listval[i].left_subjecttype_id or gb.id == listval[i].left_subjecttype_id : - finaldict.update({titledict.values()[i]: titledict.keys()[i]}) - elif pt[j].id == listval[i].right_subjecttype_id or gb.id == listval[i].right_subjecttype_id: - finaldict.update({titledict.values()[i]:inverselist[i]}) - - elif flag == 2: - systype = Systemtype.objects.get(title = str(gbid)) - nodelist = [] - nodelist = systype.nodetype_set.all() - for i in nodelist: - pt.append(i.ref) - pt.append(systype) - name = NID.objects.get(title = str(gbid)) - - for i in range(len(pt)): - if Relationtype.objects.filter(left_subjecttype = pt[i].id): - reltype.append(Relationtype.objects.get(left_subjecttype = pt[i].id)) - if Relationtype.objects.filter(right_subjecttype = pt[i].id): - reltype.append(Relationtype.objects.get(right_subjecttype = pt[i].id)) - - # it converts 2 or more list as one list - #reltype = [num for elem in reltype for num in elem] #this rqud for filtering - - for i in reltype: - titledict.update({i:i.id}) - - - for i in range(len(titledict)): - listval.append(Relationtype.objects.get(title = titledict.keys()[i])) - inverselist.append(titledict.keys()[i].inverse) - - - for j in range(len(pt)): - for i in range(len(listval)): - if pt[j].id == listval[i].left_subjecttype_id : - finaldict.update({titledict.values()[i]:titledict.keys()[i]}) - elif pt[j].id == listval[i].right_subjecttype_id: - finaldict.update({titledict.values()[i]:inverselist[i]}) - - + name = Objecttype.objects.get(title = str(memtit)) + #get members of name + for i in name.get_members: + otmem.append(i) + + #get children of name + for i in name.children.all(): + childpt.append(Objecttype.objects.get(title = NID.objects.get(title = i.title))) + #get child's members + for i in childpt: + childmem = i.get_members + for i in otmem: + memdict.update({i.id:str(i.title)}) + for i in childmem: + memdict.update({i.id:str(i.title)}) + + elif Gbobject.objects.filter(title = str(memtit)): + flag = 0 + nt = [] + name = Gbobject.objects.get(title = str(memtit)) + nt = name.objecttypes.all() #nodetype + pt = [] + for i in nt: + pt.append(Objecttype.objects.get(title = NID.objects.get(title = i.title))) + for i in pt: + otmem.append(i.get_members) + + otmem = [num for elem in otmem for num in elem] + gbdict.update({name.id :str(name.title)}) + +#----------------------------------------------------------------------- + + memid = name.id + if r.left_subjecttype_id == memid: + nodetype = str(r.right_applicable_nodetypes) + print"equal to left" + else: + print"equal to right" + nodetype = str(r.left_applicable_nodetypes) + +#------------------------------------------------------------------------ + + if nodetype=="OB" and flag==0:# gb itself + finaldict=gbdict + for i in otmem: + finaldict.update({i.id:str(i.title)}) + print "nodetype OB and Flag 0" + + elif nodetype=="OT" and flag==1:#name,name ka child ,member of both + print "nodetype OT and Flag 1" + finaldict.update({name.id:str(name.title)})#ot itself + for i in childpt:#otchild + finaldict.update({i.id:str(i.title)}) + for i in range(len(memdict)):#member of both + finaldict.update({memdict.keys()[i]:memdict.values()[i]}) + + elif nodetype=="OT" and flag==0: #name,name ka ot ,ot ka mem + print "nodetype OT and Flag 0" + finaldict.update({name.id:str(name.title)}) + for i in name.objecttypes.all(): + finaldict.update({i.id : str(i.title)}) + for i in otmem: + finaldict.update({i.id:str(i.title)}) + + elif nodetype=="OB" and flag==1: #child of both + print "nodetype OB and Flag 1" + finaldict=memdict + absolute_url_node = name.get_absolute_url() - + print finaldict + template="objectapp/selectRT.html" - context = RequestContext(request,{'final':finaldict , 'gb':name ,'gbid':name.id, 'absolute_url_node':absolute_url_node}) + context = RequestContext(request,{'finaldict':finaldict,'gb':name,'reltit':reltit, 'absolute_url_node': absolute_url_node}) return render_to_response(template,context) -def context_member(request,relid, memid):#id of relationtype, id of selected object +def context_save(request,leftmem, reltype, rightmem): try: - relid = int(relid) #relationtype - memid = int(memid) #left member id - except: - raise Http404() - - # checks wheter memid is OT or OB - flag=0 #means OB - - if Objecttype.objects.filter(id = memid): - flag=1 + leftmem = str(leftmem) + reltype = str(reltype) + rightmem = str(rightmem) - nt =[] #contains parent as <Nodetype:parent> - pt= [] #contains parent as <Objecttype:parent> - - if flag == 1: - pt.append(Objecttype.objects.get(id=memid)) - - else: - gb = Gbobject.objects.get(id = memid) - nt = gb.objecttypes.all() - for i in range(len(nt)): #conversion of nodetype in objecttype - pt.append(Objecttype.objects.get(id = nt[i].id)) - - memlist = [] #contains OB and OT for appearing in 1st combo box - - r = Relationtype.objects.get(id = relid) #contains RelationType - - # extracting left and right applicable nodetypes(OB or OT) of RelationType - lefttype = str(r.left_applicable_nodetypes) - righttype = str(r.right_applicable_nodetypes) - - if lefttype == righttype: - if lefttype == "OB" and righttype == "OB": - - if r.left_subjecttype_id == memid: - memlist.append(Gbobject.objects.get(id = r.right_subjecttype_id)) - else : - memlist.append(Gbobject.objects.get(id = r.left_subjecttype_id)) - - elif lefttype == "OT" and righttype == "OT": - for each in range(len(pt)): - if r.left_subjecttype_id == memid or r.left_subjecttype_id == pt[each].id: - o = Objecttype.objects.get(title = NID.objects.get(title=(r.right_subjecttype).title)) - memlist.append(o) - for i in o.get_members: - memlist.append(i) - # elif r.right_subjecttype_id == memid or r.right_subejcttype_id == pt[each].id: - else: - o = Objecttype.objects.get(title = NID.objects.get(title=(r.left_subjecttype).title)) - memlist.append(o) - for i in o.get_members: - memlist.append(i) - else: - if r.left_subjecttype_id == memid: - if righttype == "OB": - memlist.append(Gbobject.objects.get(id = r.right_subjecttype_id)) - - else : - o = Objecttype.objects.get(title = NID.objects.get(title=(r.right_subjecttype).title)) - memlist.append(o) - for i in o.get_members: - memlist.append(i) - - else: - if lefttype == "OB": - memlist.append(Gbobject.objects.get(id = r.left_subjecttype_id)) - - else : - o = Objecttype.objects.get(title = NID.objects.get(title=(r.left_subjecttype).title)) - memlist.append(o) - for i in o.get_members: - memlist.append(i) - - memdict = {} #converting list into dict and to set id of right member as hidden field - for i in memlist: - memdict.update({i.id:i}) + left = NID.objects.get(title = leftmem) + right = NID.objects.get(title = rightmem) + if Relationtype.objects.filter(title=reltype): + relation = Relationtype.objects.get(title = reltype) + else: + relation = Relationtype.objects.get(inverse = reltype) - template="objectapp/fillRT.html" - context = RequestContext(request,{'memdict':memdict}) - return render_to_response(template,context) - -def context_save(request,leftmem, reltype, rightmem): - try: - leftmem = int(leftmem) - reltype = int(reltype) - rightmem = int(rightmem) - - relation = Relationtype.objects.get(id = reltype) rightrole = relation.right_subjecttype_id leftrole = relation.left_subjecttype_id +#----------------------------------------------------------------------- flag = 1 - if Objecttype.objects.filter(id = leftmem): - if leftmem == leftrole : + if Objecttype.objects.filter(title = leftmem): + if left.id == leftrole : flag = 0 print "Objecttype flag = 0 " else: print "Objecttype flag = 1 " - elif Gbobject.objects.filter(id = leftmem): - gb = Gbobject.objects.get(id = leftmem) + elif Gbobject.objects.filter(title = leftmem): + gb = Gbobject.objects.get(title = leftmem) pt = gb.objecttypes.all() for i in range(len(pt)): - if leftmem == leftrole or pt[i].id == leftrole: + if left.id == leftrole or pt[i].id == leftrole: flag = 0 print "Object flag = 0" else: print "Object flag = 1" + +#----------------------------------------------------------------------------------- + if flag == 0: - savedict = {'title':relation, 'slug':relation, 'left_subject_id':leftmem, 'right_subject_id':rightmem, 'relationtype_id':reltype, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' ' } + savedict = {'title':relation, 'slug':relation, 'left_subject_id':left.id, 'right_subject_id':right.id, 'relationtype_id':relation.id, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' ' } else: - savedict = {'title':relation, 'slug':relation, 'left_subject_id':rightmem, 'right_subject_id':leftmem, 'relationtype_id':reltype, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' '} + savedict = {'title':relation, 'slug':relation, 'left_subject_id':right.id, 'right_subject_id':left.id, 'relationtype_id':relation.id, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' '} rtt = Relation.objects.create(**savedict) rtt.save() - print "leftmem"+ str(leftmem) + " rightmem" + str(rightmem) + " reltype" +str(reltype)+ " leftrole"+ str(leftrole) + " rightrole " + str(rightrole) + print "left"+ str(left) + " right" + str(right) + " reltype" +str(relation)+ " leftrole"+ str(leftrole) + " rightrole " + str(rightrole) + print savedict return HttpResponseRedirect("/nodetypes/") |