summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demo/grappelli/templates/admin/change_form.html119
-rw-r--r--demo/urls.py1
-rw-r--r--gstudio/admin/relation.py3
-rw-r--r--gstudio/forms.py94
-rw-r--r--gstudio/static/gstudio/js/URI.js128
-rw-r--r--gstudio/urls/ajaxurls.py8
-rw-r--r--gstudio/views/ajaxviews.py283
7 files changed, 538 insertions, 98 deletions
diff --git a/demo/grappelli/templates/admin/change_form.html b/demo/grappelli/templates/admin/change_form.html
index 3670165..c5a2654 100644
--- a/demo/grappelli/templates/admin/change_form.html
+++ b/demo/grappelli/templates/admin/change_form.html
@@ -8,12 +8,128 @@
{{ block.super }}
{% endblock %}
+
<!-- JAVASCRIPTS -->
{% block javascripts %}
{{ block.super }}
{% url admin:jsi18n as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:'../../../jsi18n/' }}"></script>
<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() {
+ $("#id_relationtype").change(function() {
+
+ p = $("#id_relationtype").val()
+ test="?id=" + p;
+
+ var url = new URI("ajaxleft/?id=" )+ test;
+ var smpl_uri = new URI("/admin/gstudio/relation/ajaxleft/?id=11");
+
+ var blah = new URI(test);
+ var url = blah.resolve(smpl_uri);
+
+ $.get(url,
+ function(data){
+
+ $("#id_left_subject").empty()
+
+ for (var key in data) {
+
+
+ $('#id_left_subject').append(
+ $('<option></option>').val(key).html(data[key])
+ );
+ }
+ });
+
+ url = "ajaxright/?id=" + test
+ var some_uri = new URI("/admin/gstudio/relation/ajaxright/?id=11");
+
+
+ var blah = new URI(test);
+ var url = blah.resolve(some_uri);
+
+ $.get(url,
+ function(data){
+
+ $("#id_right_subject").empty()
+
+ for (var key in data) {
+
+
+ $('#id_right_subject').append(
+ $('<option></option>').val(key).html(data[key])
+ );
+ }
+ });
+
+
+ });
+ });
+ })(django.jQuery);
+
+ </script>
+{% else %}
+ <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/URI.js"></script>
+ <script type="text/javascript" charset="utf-8">
+ (function($){
+ $(document).ready(function() {
+ $("#id_relationtype").change(function() {
+
+ p = $("#id_relationtype").val()
+ test="?id=" + p;
+ var url = new URI("ajaxleft/?id=" )+ test;
+ var some_uri = new URI("/admin/gstudio/relation/add/ajaxleft/?id=11");
+
+ var blah = new URI(test);
+ var url = blah.resolve(some_uri);
+
+ $.get(url,
+ function(data){
+
+ $("#id_left_subject").empty()
+
+ for (var key in data) {
+
+
+ $('#id_left_subject').append(
+ $('<option></option>').val(key).html(data[key])
+ );
+ }
+ });
+
+ url = "ajaxright/?id=" + test
+ var some_uri = new URI("/admin/gstudio/relation/add/ajaxright/?id=11");
+
+
+ var blah = new URI(test);
+ var url = blah.resolve(some_uri);
+
+ $.get(url,
+ function(data){
+
+ $("#id_right_subject").empty()
+
+ for (var key in data) {
+
+
+ $('#id_right_subject').append(
+ $('<option></option>').val(key).html(data[key])
+ );
+ }
+ });
+
+
+ });
+ });
+ })(django.jQuery);
+
+ </script>
+{% endif %}
+
<script type="text/javascript" charset="utf-8">
(function($) {
$(document).ready(function() {
@@ -102,6 +218,7 @@
{% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="focus" target="_blank">{% trans "View on site" %}</a></li>{% endif%}
{% endblock %}
</ul>
+
{% endif %}
{% endif %}
{% endblock %}
@@ -113,7 +230,7 @@
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
<!-- Popup Hidden Field -->
- {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
+ {% if is_popup %}tretret<input type="hidden" name="_popup" value="1" />{% endif %}
<!-- Submit-Row -->
{% if save_on_top %}{% submit_row %}{% endif %}
diff --git a/demo/urls.py b/demo/urls.py
index ce2e623..fba068c 100644
--- a/demo/urls.py
+++ b/demo/urls.py
@@ -91,6 +91,7 @@ urlpatterns = patterns(
url(r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc'),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+ url(r'^admin/gstudio/', include('gstudio.urls.ajaxurls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^objects/admin/', include(admin.site.urls)),
url(r'^nodetypes/admin/', include(admin.site.urls)),
diff --git a/gstudio/admin/relation.py b/gstudio/admin/relation.py
index 04b4e8b..688ad6e 100644
--- a/gstudio/admin/relation.py
+++ b/gstudio/admin/relation.py
@@ -7,6 +7,9 @@ from gstudio.admin.forms import RelationAdminForm
import reversion
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')}),
+
+)
def save_model(self, request, relation, form, change):
relation.title = relation.composed_sentence
relation.save()
diff --git a/gstudio/forms.py b/gstudio/forms.py
deleted file mode 100644
index c4a1a0d..0000000
--- a/gstudio/forms.py
+++ /dev/null
@@ -1,94 +0,0 @@
-# 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
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-
-from gstudio.models import *
-from django.forms import ModelForm
-from django.contrib.admin import widgets
-
-class MetatypeForm(ModelForm):
-
- class Meta:
- model = Metatype
-
-class ObjecttypeForm(ModelForm):
-
-
-
-
-
-
- class Meta:
- model = Objecttype
- fields = ('title', 'altnames','plural','parent','slug','metatypes','tags',
- 'status','content','prior_nodes','posterior_nodes','password','login_required','sites')
-
-class AttributetypeForm(ModelForm):
-
- class Meta:
- model = Attributetype
- fields =('title','altnames','subjecttype','applicable_nodetypes','dataType',
- 'slug','status','content','prior_nodes','posterior_nodes','password','login_required','sites')
-
-class RelationtypeForm(ModelForm):
-
- class Meta:
- model = Relationtype
- fields =('title','altnames','slug','inverse','left_subjecttype','left_applicable_nodetypes','right_subjecttype',
- 'right_applicable_nodetypes','content','prior_nodes','posterior_nodes','sites')
-class SystemtypeForm(ModelForm):
-
- class Meta:
- model =Systemtype
- fields =('title','altnames','content','parent','slug','status','nodetype_set','relationtype_set','attributetype_set','metatype_set','processtype_set',
- 'prior_nodes','posterior_nodes','sites')
-
-
-class ProcesstypeForm(ModelForm):
-
- class Meta:
- model =Processtype
- fields =('title','altnames','content','parent','slug','status','changing_attributetype_set','changing_relationtype_set',
- 'prior_nodes','posterior_nodes','sites')
-
-
-class RelationForm(ModelForm):
- class Meta:
- model = Relation
-
-class AttributeForm(ModelForm):
- def __init__(self, *args, **kwargs):
- super(AttributeForm, self).__init__(*args, **kwargs)
- self.fields['last_update'].widget = widgets.AdminSplitDateTime()
- self.fields['creation_date'].widget = widgets.AdminSplitDateTime()
-
- class Meta:
- model = Attribute
-
-
-class ComplementForm(ModelForm):
- class Meta:
- model = Complement
-
-class UnionForm(ModelForm):
- class Meta:
- model = Union
-
-class IntersectionForm(ModelForm):
- class Meta:
- model = Intersection
-
-
diff --git a/gstudio/static/gstudio/js/URI.js b/gstudio/static/gstudio/js/URI.js
new file mode 100644
index 0000000..451a383
--- /dev/null
+++ b/gstudio/static/gstudio/js/URI.js
@@ -0,0 +1,128 @@
+/*
+ * An URI datatype. Based upon examples in RFC3986.
+ *
+ * TODO %-escaping
+ * TODO split apart authority
+ * TODO split apart query_string (on demand, anyway)
+ *
+ * @(#) $Id$
+ */
+
+// Constructor for the URI object. Parse a string into its components.
+function URI(str) {
+ if (!str) str = "";
+ // Based on the regex in RFC2396 Appendix B.
+ var parser = /^(?:([^:\/?\#]+):)?(?:\/\/([^\/?\#]*))?([^?\#]*)(?:\?([^\#]*))?(?:\#(.*))?/;
+ var result = str.match(parser);
+ this.scheme = result[1] || null;
+ this.authority = result[2] || null;
+ this.path = result[3] || null;
+ this.query = result[4] || null;
+ this.fragment = result[5] || null;
+}
+
+// Restore the URI to it's stringy glory.
+URI.prototype.toString = function () {
+ var str = "";
+ if (this.scheme) {
+ str += this.scheme + ":";
+ }
+ if (this.authority) {
+ str += "//" + this.authority;
+ }
+ if (this.path) {
+ str += this.path;
+ }
+ if (this.query) {
+ str += "?" + this.query;
+ }
+ if (this.fragment) {
+ str += "#" + this.fragment;
+ }
+ return str;
+};
+
+// Introduce a new scope to define some private helper functions.
+(function () {
+ // RFC3986 §5.2.3 (Merge Paths)
+ function merge(base, rel_path) {
+ var dirname = /^(.*)\//;
+ if (base.authority && !base.path) {
+ return "/" + rel_path;
+ }
+ else {
+ return base.path.match(dirname)[0] + rel_path;
+ }
+ }
+
+ // Match two path segments, where the second is ".." and the first must
+ // not be "..".
+ var DoubleDot = /\/((?!\.\.\/)[^\/]*)\/\.\.\//;
+
+ function remove_dot_segments(path) {
+ if (!path) return "";
+ // Remove any single dots
+ var newpath = path.replace(/\/\.\//g, '/');
+ // Remove any trailing single dots.
+ newpath = newpath.replace(/\/\.$/, '/');
+ // Remove any double dots and the path previous. NB: We can't use
+ // the "g", modifier because we are changing the string that we're
+ // matching over.
+ while (newpath.match(DoubleDot)) {
+ newpath = newpath.replace(DoubleDot, '/');
+ }
+ // Remove any trailing double dots.
+ newpath = newpath.replace(/\/([^\/]*)\/\.\.$/, '/');
+ // If there are any remaining double dot bits, then they're wrong
+ // and must be nuked. Again, we can't use the g modifier.
+ while (newpath.match(/\/\.\.\//)) {
+ newpath = newpath.replace(/\/\.\.\//, '/');
+ }
+ return newpath;
+ }
+
+ // RFC3986 §5.2.2. Transform References;
+ URI.prototype.resolve = function (base) {
+ var target = new URI();
+ if (this.scheme) {
+ target.scheme = this.scheme;
+ target.authority = this.authority;
+ target.path = remove_dot_segments(this.path);
+ target.query = this.query;
+ }
+ else {
+ if (this.authority) {
+ target.authority = this.authority;
+ target.path = remove_dot_segments(this.path);
+ target.query = this.query;
+ }
+ else {
+ // XXX Original spec says "if defined and empty"…;
+ if (!this.path) {
+ target.path = base.path;
+ if (this.query) {
+ target.query = this.query;
+ }
+ else {
+ target.query = base.query;
+ }
+ }
+ else {
+ if (this.path.charAt(0) === '/') {
+ target.path = remove_dot_segments(this.path);
+ } else {
+ target.path = merge(base, this.path);
+ target.path = remove_dot_segments(target.path);
+ }
+ target.query = this.query;
+ }
+ target.authority = base.authority;
+ }
+ target.scheme = base.scheme;
+ }
+
+ target.fragment = this.fragment;
+
+ return target;
+ };
+})();
diff --git a/gstudio/urls/ajaxurls.py b/gstudio/urls/ajaxurls.py
index 4b84de3..778b0de 100644
--- a/gstudio/urls/ajaxurls.py
+++ b/gstudio/urls/ajaxurls.py
@@ -20,7 +20,9 @@ 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',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'),
+ url(r'^relation/ajaxright/$', 'AjaxRelationright',name='ajax_relnright_views'),
)
diff --git a/gstudio/views/ajaxviews.py b/gstudio/views/ajaxviews.py
index 2bb64a3..a909db2 100644
--- a/gstudio/views/ajaxviews.py
+++ b/gstudio/views/ajaxviews.py
@@ -19,6 +19,7 @@ from django.http import HttpResponse
import json
from gstudio.models import *
from objectapp.models import *
+rlist={}
def AjaxAttribute(request):
iden = request.GET["id"]
@@ -32,6 +33,288 @@ def AjaxAttribute(request):
returndict[member.id] = member.title
jsonobject = json.dumps(returndict)
return HttpResponse(jsonobject, "application/json")
+
+def AjaxRelationleft(request):
+ global rlist
+ rlist={}
+ idenid=request.GET["id"]
+ rts=Relationtype.objects.filter(id=idenid)
+ for each in rts:
+ subj=str(each.left_subjecttype.title)
+ appltype=each.left_applicable_nodetypes
+ fnname= "selectionlist_"+appltype+"('"+subj+"')"
+
+ exec fnname
+
+ returndict=rlist
+ jsonobject = json.dumps(returndict)
+ return HttpResponse(jsonobject, "application/json")
+
+def AjaxRelationright(request):
+ global rlist
+ rlist={}
+ idenid = request.GET["id"]
+ rts=Relationtype.objects.filter(id=idenid)
+ print "rtsright",rts
+ for each in rts:
+ subj=str(each.right_subjecttype.title)
+ appltype=each.right_applicable_nodetypes
+ fnname="selectionlist_"+appltype+"('"+subj+"')"
+
+ exec fnname
+
+ returndict=rlist
+ jsonobject = json.dumps(returndict)
+ return HttpResponse(jsonobject, "application/json")
+
+def additemdict(sdict,itemtoadd):
+ fl=0
+ for key,value in sdict.items():
+ if value==itemtoadd:
+ fl=1
+ if fl==0:
+ sdict[itemtoadd.id]=itemtoadd.title
+ return sdict
+def selectionlist_OT(obj):
+ 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:
+ obs=Objecttype.objects.get(title=obj)
+ memobs=obs.get_members
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=obs.get_children()
+ 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):
+ global rlist
+ # Return all MTs and members of subtypes of MT
+ obs=Metatype.objects.filter(title=obj)
+ #Get all members of subtypes of each MT
+ if obs:
+ obs=Metatype.objects.get(title=obj)
+ memobs=obs.member_types.all()
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=each.ref.get_members
+ if childrenots:
+ for eachchild in childrenots:
+ rlist=additemdict(rlist,eachchild)
+
+ return rlist
+def selectionlist_NT(obj):
+ global rlist
+ # Return all NTs and members of subtypes of NT
+ obs=Nodetype.objects.filter(title=obj)
+ #Get all members of subtypes of each NT
+ if obs:
+ obs=Nodetype.objects.get(title=obj)
+ memobs=obs.get_members
+
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=obs.get_children()
+
+ if childrenots:
+ for eachchild in childrenots:
+ membs=eachchild.ref.get_members
+ for each in membs:
+ rlist=additemdict(rlist,each)
+ return rlist
+def selectionlist_AT(obj):
+ global rlist
+ # Return all ATs and members of subtypes of AT
+ obs=Attributetype.objects.filter(title=obj)
+ #Get all members of subtypes of each AT
+ if obs:
+ obs=Attributetype.objects.get(title=obj)
+ memobs=obs.get_members
+
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=obs.get_children()
+
+ if childrenots:
+ for eachchild in childrenots:
+ membs=eachchild.ref.get_members
+ for each in membs:
+ rlist=additemdict(rlist,each)
+ return rlist
+def selectionlist_ST(obj):
+ global rlist
+ # Return all STs and members of subtypes of ST
+ obs=Systemtype.objects.filter(title=obj)
+ #Get all members of subtypes of each ST
+ if obs:
+ obs=Systemtype.objects.get(title=obj)
+ memobs=obs.get_members
+
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=obs.get_children()
+
+ if childrenots:
+ for eachchild in childrenots:
+ membs=eachchild.ref.get_members
+ for each in membs:
+ rlist=additemdict(rlist,each)
+ return rlist
+def selectionlist_PT(obj):
+ global rlist
+ # Return all PTs and members of subtypes of PT
+ obs=Processtype.objects.filter(title=obj)
+ #Get all members of subtypes of each PT
+ if obs:
+ obs=Processtype.objects.get(title=obj)
+ memobs=obs.get_members
+
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=obs.get_children()
+
+ if childrenots:
+ for eachchild in childrenots:
+ membs=eachchild.ref.get_members
+ for each in membs:
+ rlist=additemdict(rlist,each)
+ return rlist
+def selectionlist_RT(obj):
+ global rlist
+ # Return all RTs and members of subtypes of RT
+ obs=Relationtype.objects.filter(title=obj)
+ #Get all members of subtypes of each RT
+ if obs:
+ obs=Relationtype.objects.get(title=obj)
+ memobs=obs.get_members
+
+ if memobs:
+ for each in memobs:
+ rlist=additemdict(rlist,each)
+ childrenots=obs.get_children()
+
+ if childrenots:
+ for eachchild in childrenots:
+ membs=eachchild.ref.get_members
+ for each in membs:
+ rlist=additemdict(rlist,each)
+ return rlist
+
+def selectionlist_RN(obj):
+ global rlist
+
+ obs=Relation.objects.filter(title=obj)
+ #Get all members of RN
+ if obs:
+ obs=Relation.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+
+def selectionlist_AS(obj):
+ global rlist
+
+ obs=AttributeSpecification.objects.filter(title=obj)
+ #Get all members of AS
+ if obs:
+ obs=AttributeSpecification.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+def selectionlist_NS(obj):
+ global rlist
+
+ obs=NodeSpecification.objects.filter(title=obj)
+ #Get all members of NS
+ if obs:
+ obs=NodeSpecification.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+def selectionlist_SY(obj):
+ global rlist
+
+ obs=System.objects.filter(title=obj)
+ #Get all members of SY
+ if obs:
+ obs=System.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+def selectionlist_RS(obj):
+ global rlist
+ # Return all members of RS
+ obs=RelationSpecification.objects.filter(title=obj)
+ if obs:
+ obs=RelationSpecification.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+
+def selectionlist_ND(obj):
+ global rlist
+
+ obs=Node.objects.filter(title=obj)
+ #Get all members of ND
+ if obs:
+ obs=Node.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+def selectionlist_ED(obj):
+ global rlist
+
+ obs=Edge.objects.filter(title=obj)
+ #Get all members of ED
+ if obs:
+ obs=Edge.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+def selectionlist_IN(obj):
+ global rlist
+
+ obs=Intersection.objects.filter(title=obj)
+ #Get all members of IN
+ if obs:
+ obs=Intersection.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+
+def selectionlist_CP(obj):
+ global rlist
+
+ obs=Complement.objects.filter(title=obj)
+ #Get all members of CP
+ if obs:
+ obs=Complement.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist
+
+def selectionlist_UP(obj):
+ global rlist
+
+ obs=Objecttype.objects.all()
+ #Get all members UP
+ print 'obs=',obs
+ for each in obs:
+ childrenots=each.get_children()
+ for eachchild in childrenots:
+ membs=eachchild.objecttypes.all()
+def selectionlist_OB(obj):
+ global rlist
+
+ obs=Gbobject.objects.filter(title=obj)
+ #Get all members of OB
+ if obs:
+ obs=Gbobject.objects.get(title=obj)
+ rlist=additemdict(rlist,obs)
+ return rlist