summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsitifr <csitifr@gmail.com>2012-05-28 18:40:43 +0530
committercsitifr <csitifr@gmail.com>2012-05-28 18:40:43 +0530
commitf28648fce9a224b6f4c3a24cfaf4b29082dbb775 (patch)
treeb15ab0641c907405928c7997d3bc0a3f2c1d52d9
parent15c2f2561c23a656d792003b089e28ecc500b720 (diff)
downloadgnowsys-f28648fce9a224b6f4c3a24cfaf4b29082dbb775.tar.gz
Relation can be now saved and viewed hierachy wise.Attribute does not get saved in duplicate
-rw-r--r--demo/settings.py6
-rw-r--r--gstudio/models.py73
-rw-r--r--gstudio/templates/gstudio/nodetype_detail.html3
-rw-r--r--objectapp/models.py61
-rw-r--r--objectapp/static/objectapp/js/savert.js2
-rw-r--r--objectapp/templates/objectapp/fillAT.html4
-rw-r--r--objectapp/templates/objectapp/gbobject_detail.html34
-rw-r--r--objectapp/templates/objectapp/selectRT.html3
-rw-r--r--objectapp/views/dynamicAT.py41
-rw-r--r--objectapp/views/dynamicRT.py282
10 files changed, 352 insertions, 157 deletions
diff --git a/demo/settings.py b/demo/settings.py
index 77296fb..96de64f 100644
--- a/demo/settings.py
+++ b/demo/settings.py
@@ -78,8 +78,10 @@ DATABASES = {'default':
STATIC_URL = '/static/'
MEDIA_URL = '/static'
-MEDIA_ROOT = '/static'
+#MEDIA_ROOT = '/static'
+MEDIA_ROOT = os.path.join(os.path.dirname(__file__), '../gstudio/static')
+GSTUDIO_UPLOAD_TO = 'img/'
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"
@@ -157,7 +159,7 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.sites',
'mptt',
- # 'reversion',
+ 'reversion',
'tagging',
'django_xmlrpc',
'grappelli.dashboard',
diff --git a/gstudio/models.py b/gstudio/models.py
index 5b5cf42..d4cdc5f 100644
--- a/gstudio/models.py
+++ b/gstudio/models.py
@@ -288,36 +288,61 @@ class NID(models.Model):
@property
def getat(self):
+
"""This is will give the possible attributetypes """
try:
+ pt = []
attributetype = []
- ot = self.ref
- attributetype.append(ot.subjecttype_of.all())
+ returndict = {}
+
+ pt.append(self.ref)
+ obj = self.ref
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj=obj.parent
+
+ for each in pt:
+ attributetype.append(each.subjecttype_of.all())
+
attributetype = [num for elem in attributetype for num in elem]
- return attributetype
+
+ for i in attributetype:
+ if str(i.applicable_nodetypes) == 'OT':
+ returndict.update({str(i.title):i.id})
+
+ return returndict.keys()
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 =[] 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 =[]
+ reltype =[]
+ titledict = {}
+ inverselist = []
+ finaldict = {}
+ listval=[]
+
pt.append(self.ref)
+ obj = self.ref
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj=obj.parent
+
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})
@@ -325,16 +350,16 @@ class NID(models.Model):
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]})
+ if pt[j].id == listval[i].left_subjecttype_id and str(listval[i].left_applicable_nodetypes) == 'OT' :
+ finaldict.update({titledict.keys()[i]:titledict.values()[i]})
+ if pt[j].id == listval[i].right_subjecttype_id and str(listval[i].right_applicable_nodetypes)=='OT':
+ finaldict.update({inverselist[i]:titledict.values()[i]})
+
- return finaldict.values()
+ return finaldict.keys()
@property
@@ -1959,7 +1984,7 @@ class AttributeTimeField(Attribute):
class AttributeEmailField(Attribute):
- value = models.CharField(max_length=100,verbose_name='value')
+ value = models.EmailField(max_length=100,verbose_name='value')
def __unicode__(self):
return self.title
@@ -1975,7 +2000,7 @@ class AttributeEmailField(Attribute):
class AttributeFileField(Attribute):
- value = models.FileField(upload_to='/media', verbose_name='file')
+ value = models.FileField(upload_to='media/'+UPLOAD_TO, verbose_name='file')
def __unicode__(self):
return self.title
@@ -2009,7 +2034,7 @@ class AttributeFilePathField(Attribute):
class AttributeImageField(Attribute):
- value = models.ImageField(upload_to='/media', verbose_name='image')
+ value = models.ImageField(upload_to='media/'+UPLOAD_TO, verbose_name='image')
def __unicode__(self):
return self.title
diff --git a/gstudio/templates/gstudio/nodetype_detail.html b/gstudio/templates/gstudio/nodetype_detail.html
index 7947e58..1a01279 100644
--- a/gstudio/templates/gstudio/nodetype_detail.html
+++ b/gstudio/templates/gstudio/nodetype_detail.html
@@ -250,6 +250,7 @@
{% endblock %}
<!-- Dynamic form begins -->
+{% if user.is_authenticated %}
<p>
{% if object.reftype == 'Objecttype' %}
<b>Add Attributes:</b>
@@ -264,7 +265,7 @@
<a href="{{ get_absolute_url }}/objects/dynamicRelation/displaymem/{{ i }}/{{ object.title }}">{{ i }}</a><nbsp>;
{% endfor %}
{% endif %}
-
+{% endif %}
</p>
<!-- Dyanic form ends -->
<div class="nodetype-content">
diff --git a/objectapp/models.py b/objectapp/models.py
index d6c7d30..c0c2d5b 100644
--- a/objectapp/models.py
+++ b/objectapp/models.py
@@ -208,12 +208,6 @@ class Gbobject(Node):
objects = models.Manager()
published = GbobjectPublishedManager()
-
- # @property
- # def getdataType(self):
- # gb = 'attribute'+str(self.get_dataType.display())
- # gb = gb.lower()
- # return gb
@property
def getattributetypes(self):
@@ -221,17 +215,30 @@ class Gbobject(Node):
Returns the attributetypes of self as well as its parent's attributetype.
"""
try:
- parenttype = []
+ originalnt = []
+ pt = []
attributetype = []
- returnlist = []
+ returndict = {}
obj = self
- parenttype = obj.objecttypes.all()
+ originalnt = obj.objecttypes.all()
+
+ for i in range(len(originalnt)):
+ obj = originalnt[i].ref
+ pt.append(obj)
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj = obj.parent
+
attributetype.append(obj.subjecttype_of.all())
- for each in parenttype:
+ for each in pt:
attributetype.append(each.subjecttype_of.all())
attributetype = [num for elem in attributetype for num in elem]
- return attributetype
+
+ for i in attributetype:
+ returndict.update({str(i.title):i.id})
+
+ return returndict.keys()
except:
return None
@@ -240,6 +247,8 @@ class Gbobject(Node):
@property
def getrelationtypes(self):
+ originalnt= []
+ originalpt = []
pt =[] #contains parenttype
reltype =[] #contains relationtype
titledict = {} #contains relationtype's title
@@ -247,19 +256,22 @@ class Gbobject(Node):
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()
+ gb=self.ref
+ originalnt = gb.objecttypes.all()
+ for i in originalnt:
+ pt.append(i.ref)
+
+ for i in range(len(originalnt)):
+ obj = originalnt[i].ref
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj = obj.parent
+ pt.append(gb)
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]
@@ -273,13 +285,14 @@ class Gbobject(Node):
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]})
+ if pt[j].id == listval[i].left_subjecttype_id and (str(listval[i].left_applicable_nodetypes) == 'OT' or str(listval[i].left_applicable_nodetypes) == 'OB'):
+ finaldict.update({titledict.keys()[i]:titledict.values()[i]})
+ if pt[j].id == listval[i].right_subjecttype_id and (str(listval[i].right_applicable_nodetypes)=='OT' or str(listval[i].right_applicable_nodetypes) == 'OB'):
+ finaldict.update({inverselist[i]:titledict.values()[i]})
+
- return finaldict.values()
+ return finaldict.keys()
def get_relations(self):
relation_set = {}
diff --git a/objectapp/static/objectapp/js/savert.js b/objectapp/static/objectapp/js/savert.js
index 549e819..b5294cc 100644
--- a/objectapp/static/objectapp/js/savert.js
+++ b/objectapp/static/objectapp/js/savert.js
@@ -48,7 +48,7 @@ $ = django.jQuery
absolute_url = document.getElementById("id_back_url")
url = "/objects/dynamicRelation/save/"+ left.value+"/"+rt.value+"/"+right.value+"/"
//alert(url);
- $.get(url,function(data){
+ $.get(url, function(data){
window.location.replace(absolute_url.value);
});
diff --git a/objectapp/templates/objectapp/fillAT.html b/objectapp/templates/objectapp/fillAT.html
index 6a474d0..95bea92 100644
--- a/objectapp/templates/objectapp/fillAT.html
+++ b/objectapp/templates/objectapp/fillAT.html
@@ -2,12 +2,12 @@
{% load i18n %}
{% block content %}
-<form action="." method="POST">
+<form action="." method="POST" enctype="multipart/form-data">
{% csrf_token %}
<b>{{ title }}</b>
{% for field in form %}
-{{ field }} {{ field.errors }}
+{{ field }} {{ field.errors }} {{ field.widget }}
{% endfor %}
<input type="submit" id="id_submit" value="Go"/>
<input type="button" id="id_back" value="Back"/>
diff --git a/objectapp/templates/objectapp/gbobject_detail.html b/objectapp/templates/objectapp/gbobject_detail.html
index 283f9c6..5e7108e 100644
--- a/objectapp/templates/objectapp/gbobject_detail.html
+++ b/objectapp/templates/objectapp/gbobject_detail.html
@@ -73,6 +73,25 @@
{% endwith %}
{% endblock %}
+
+<br/>
+<p><br/>
+
+{% if user.is_authenticated %}
+<b>AddAttributes: </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>
+{% endif %}
+
{% block gbobject-widgets %}
<div class="gbobject-widgets span-16 last">
{% with object.next_gbobject as next_gbobject %}
@@ -128,21 +147,6 @@
{% 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>
-
{% 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 713a45c..5ceae85 100644
--- a/objectapp/templates/objectapp/selectRT.html
+++ b/objectapp/templates/objectapp/selectRT.html
@@ -5,7 +5,8 @@
{% block content %}
<form method="." action="POST">
{% csrf_token %}
-<b>Details of {{ gb }}</b>
+<b>{{ gb }}</b>
+<b>{{ reltit }}</b>
<!-- -------------------------------------------- -->
diff --git a/objectapp/views/dynamicAT.py b/objectapp/views/dynamicAT.py
index aec02fc..a5d71de 100644
--- a/objectapp/views/dynamicAT.py
+++ b/objectapp/views/dynamicAT.py
@@ -15,35 +15,62 @@ def MakeForm(model_cls, *args, **kwargs):
class ContextForm(ModelForm):
class Meta:
model = model_cls.values()[0]
+ print 'model' ,model
fields = ('value',)
+ print 'fields',fields
+
def __init__(self, *args, **kwargs):
+
super(ContextForm,self).__init__(*args, **kwargs)
return ContextForm(*args, **kwargs)
+
+
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()
+
at = Attributetype.objects.get(title = str(attit))
dt = str(at.get_dataType_display())
MyModel = eval('Attribute'+dt)
+
rdict.update({str(at.title):MyModel})
+ print "rdict",str(rdict)
+
if request.method == 'POST':
- form = MakeForm(rdict,request.POST)
- if form.is_valid():
- 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)
+ form = MakeForm(rdict,request.POST,request.FILES)
+ try:
+ if form.is_valid():
+ value = form.cleaned_data['value']
+
+ if Attribute.objects.filter(subject = memtit.id) and Attribute.objects.filter(attributetype = at.id):
+ att = Attribute.objects.get(subject = memtit.id, attributetype = at.id)
+ att.delete()
+ del att
+ savedict = {'title':str(value),'slug':str(value),'svalue':str(value),'subject':memtit, 'attributetype':at,'value':str(value)}
+ att = MyModel.objects.create(**savedict)
+ att.save()
+ print 'savedict',str(savedict)
+ return HttpResponseRedirect(absolute_url_node)
+ else:
+ savedict = {'title':str(value),'slug':str(value),'svalue':str(value),'subject':memtit, 'attributetype':at,'value':str(value)}
+ att = MyModel.objects.create(**savedict)
+ att.save()
+ print 'savedict',str(savedict)
+ return HttpResponseRedirect(absolute_url_node)
+ except:
+ raise Http404()
else:
form = MakeForm(rdict)
+
template = "objectapp/fillAT.html"
context = RequestContext(request,{'form' : form,'title':str(attit), 'absolute_url_node':absolute_url_node})
return render_to_response(template,context)
diff --git a/objectapp/views/dynamicRT.py b/objectapp/views/dynamicRT.py
index 78370b5..f85fe53 100644
--- a/objectapp/views/dynamicRT.py
+++ b/objectapp/views/dynamicRT.py
@@ -8,96 +8,181 @@ from django.forms import ModelForm
from gstudio.models import *
from objectapp.models import *
-
def context_member(request,reltit , memtit):
+ member = []
+ subtype = []
+ subtypemember = []
+ finaldict = {}
+ nt = []
+ parenttype = []
+
+#-------------------------------------------------------------
+ if Objecttype.objects.filter(title = str(memtit)):
+ ot = Objecttype.objects.get(title = str(memtit))
+ absolute_url_node = ot.get_absolute_url()
+ elif Gbobject.objects.filter(title = str(memtit)):
+ ot = Gbobject.objects.get(title = str(memtit))
+ absolute_url_node = ot.get_absolute_url()
+#--------------------------------------------------------------
+
if Relationtype.objects.filter(title = str(reltit)):
r =Relationtype.objects.get(title = str(reltit))
+ role = r.left_subjecttype.ref
+ roletype = str(r.left_applicable_nodetypes)
+ print "Original is left role of relation"
+ newrole = r.right_subjecttype.ref
+ newroletype = str(r.right_applicable_nodetypes)
+ print 'original ' ,str(role)
+ print 'newrole (i.e right)', str(newrole)
+
else:
r = Relationtype.objects.get(inverse = str(reltit))
+ role = r.right_subjecttype.ref
+ roletype = str(r.right_applicable_nodetypes)
+ print "Original is right role of relation"
+ newrole = r.left_subjecttype.ref
+ newroletype = str(r.left_applicable_nodetypes)
+ print 'original ' ,str(role)
+ print 'newrole (i.e left)', str(newrole)
- gbdict = {}
- otmem=[]
- childpt = []
- childmem = []
- finaldict={}
- memdict = {} #otmem + childmem
-
- if Objecttype.objects.filter(title = str(memtit)):
- flag = 1
- 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 = []
+#---------------------------------------------------------------------
+
+ if newrole.reftype == 'Objecttype' and newroletype == 'OT':
+ print "Objecttype and OT"
+ for i in newrole.get_members:
+ member.append(i)
+
+ for i in member:
+ finaldict.update({i.id:str(i.title)})
+
+ # for i in newrole.get_children():
+ # subtype.append(i.ref)
+ for i in newrole.get_descendants():
+ subtype.append(i.ref)
+
+ for i in subtype:
+ finaldict.update({i.id:str(i.title)})
+
+ for i in subtype:
+ subtypemember.append(i.get_members)
+
+ subtypemember = [num for elem in subtypemember for num in elem]
+
+ for i in subtypemember:
+ finaldict.update({i.id:str(i.title)})
+
+ finaldict.update({newrole.id:str(newrole.title)})
+
+ elif newrole.reftype == 'Gbobject' and newroletype == 'OB':
+ print "Gbobject and OB"
+ nt = newrole.objecttypes.all()
+
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)
+ parenttype.append(i.ref)
+
+ for i in parenttype:
+ member.append(i.get_members)
+
+ member = [num for elem in member for num in elem]
+ subtypent = []
- otmem = [num for elem in otmem for num in elem]
- gbdict.update({name.id :str(name.title)})
+ # for i in parenttype:
+ # subtypent.append(i.get_children())
+ # subtypent = [num for elem in subtypent for num in elem]
-#-----------------------------------------------------------------------
-
- 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)
+ # for i in subtypent:
+ # subtype.append(i.ref)
+ # subtype = [num for elem in subtype for num in elem]
+
+ for i in parenttype:
+ subtypent.append(i.get_descendants())
-#------------------------------------------------------------------------
+ for i in subtypent:
+ subtype.append(i.ref)
- if nodetype=="OB" and flag==0:# gb itself
- finaldict=gbdict
- for i in otmem:
+ for i in subtype:
+ subtypemember.append(i.get_members)
+ subtypemember = [num for elem in subtypemember for num in elem]
+
+
+ for i in member:
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
+ for i in subtypemember:
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:
+
+ elif newrole.reftype == 'Objecttype' and newroletype == 'OB':
+ print "Objecttype and OB"
+ for i in newrole.get_members:
+ member.append(i)
+
+ for i in member:
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
-
+ # for i in newrole.get_children():
+ # subtype.append(i.ref)
+
+ for i in newrole.get_descendants():
+ subtype.append(i.ref)
+ for i in subtype:
+ subtypemember.append(i.get_members)
+
+ subtypemember = [num for elem in subtypemember for num in elem]
+
+ for i in subtypemember:
+ finaldict.update({i.id:str(i.title)})
+
+ print 'member',str(member)
+ print 'subtype', str(subtype)
+ print 'subtypemember', str(subtypemember)
+ elif newrole.reftype == 'Gbobject' and newroletype == 'OT':
+ print "Gbobject and OT"
+ nt = newrole.objecttypes.all()
+ for i in nt:
+ parenttype.append(i.ref)
+
+ for i in parenttype:
+ member.append(i.get_members)
+
+ member = [num for elem in member for num in elem]
+ subtypent = []
+
+ # for i in parenttype:
+ # subtypent.append(i.get_children())
+ # subtypent = [num for elem in subtypent for num in elem]
+
+ # for i in subtypent:
+ # subtype.append(i.ref)
+ # subtype = [num for elem in subtype for num in elem]
+ for i in parenttype:
+ subtypent.append(i.get_descendants())
+
+ for i in subtypent:
+ subtype.append(i.ref)
+
+ for i in subtype:
+ subtypemember.append(i.get_members)
+ subtypemember = [num for elem in subtypemember for num in elem]
+
+
+ for i in subtype:
+ finaldict.update({i.id:str(i.title)})
+
+ for i in parenttype:
+ finaldict.update({i.id:str(i.title)})
+
+ for i in member:
+ finaldict.update({i.id:str(i.title)})
+
+ for i in subtypemember:
+ finaldict.update({i.id:str(i.title)})
+
+
+ print 'absolute_url_node', str(absolute_url_node)
template="objectapp/selectRT.html"
- context = RequestContext(request,{'finaldict':finaldict,'gb':name,'reltit':reltit, 'absolute_url_node': absolute_url_node})
+ context = RequestContext(request,{'finaldict':finaldict,'gb':memtit,'reltit':reltit, 'absolute_url_node': absolute_url_node})
return render_to_response(template,context)
@@ -107,37 +192,74 @@ def context_save(request,leftmem, reltype, rightmem):
reltype = str(reltype)
rightmem = str(rightmem)
+
+
+ print 'leftmem :', leftmem, 'rightmem :', rightmem
+ pt = []
+ nt = []
+
left = NID.objects.get(title = leftmem)
+ print 'leftid', str(left.id)
right = NID.objects.get(title = rightmem)
-
+ print 'rightid', str(right.id)
+
if Relationtype.objects.filter(title=reltype):
relation = Relationtype.objects.get(title = reltype)
else:
relation = Relationtype.objects.get(inverse = reltype)
rightrole = relation.right_subjecttype_id
+ r = relation.right_subjecttype.ref
+ print 'rightrole', str(r)
leftrole = relation.left_subjecttype_id
+ l=relation.left_subjecttype.ref
+ print 'leftrole', str(l)
#-----------------------------------------------------------------------
flag = 1
if Objecttype.objects.filter(title = leftmem):
- if left.id == leftrole :
- flag = 0
- print "Objecttype flag = 0 "
- else:
- print "Objecttype flag = 1 "
+
+ obj = Objecttype.objects.get(title = leftmem)
+ print 'OT', str(obj)
+
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj=obj.parent
+ for i in range(len(pt)):
+ if pt[i].id == leftrole :
+ flag = 0
+ print "Objecttype flag = 0 "
+ break
+ else:
+ print "Objecttype flag = 1 "
+
elif Gbobject.objects.filter(title = leftmem):
gb = Gbobject.objects.get(title = leftmem)
- pt = gb.objecttypes.all()
+ print 'Ob', str(gb)
+ nt = gb.objecttypes.all()
+ print 'nt ', str(nt)
+
+
+ for i in range(len(nt)):
+ pt.append(nt[i].ref)
+ obj = nt[i].ref
+ while obj.parent:
+ pt.append(obj.parent.ref)
+ obj = obj.parent
+
+ print 'pt ', str(pt)
for i in range(len(pt)):
if left.id == leftrole or pt[i].id == leftrole:
flag = 0
print "Object flag = 0"
+ break
else:
print "Object flag = 1"
-
+ print 'pt:',str(pt)
#-----------------------------------------------------------------------------------
+
if flag == 0:
+ print 'left_subject_id', l
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':right.id, 'right_subject_id':left.id, 'relationtype_id':relation.id, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' '}
@@ -152,6 +274,6 @@ def context_save(request,leftmem, reltype, rightmem):
#return savedict
except IntegrityError: #Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc.
- raise Http404()
+ return HttpResponseRedirect("/nodetypes/")
#pass