diff options
author | csitifr <csitifr@gmail.com> | 2012-05-11 16:31:53 +0530 |
---|---|---|
committer | csitifr <csitifr@gmail.com> | 2012-05-11 16:31:53 +0530 |
commit | ffa1efc1acfc176c1dbf659210b41a51eb4d4cad (patch) | |
tree | 65f2e9ba8073f153673701c7a829a261e92b0612 /objectapp | |
parent | 850672379e02b758d89ed609e7f8a9c009853104 (diff) | |
download | gnowsys-ffa1efc1acfc176c1dbf659210b41a51eb4d4cad.tar.gz |
Dynamic mapping for attribute types done.Dynamic form for relation types added for both types and tokens.Properties for getting ATs and RTs added into models
Diffstat (limited to 'objectapp')
-rw-r--r-- | objectapp/forms.py | 18 | ||||
-rw-r--r-- | objectapp/models.py | 75 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/savert.js | 10 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/setMember.js | 12 | ||||
-rw-r--r-- | objectapp/templates/objectapp/fillAT.html | 27 | ||||
-rw-r--r-- | objectapp/templates/objectapp/gbobject_detail.html | 27 | ||||
-rw-r--r-- | objectapp/templates/objectapp/selectRT.html | 24 | ||||
-rw-r--r-- | objectapp/templates/objectapp/skeleton.html | 5 | ||||
-rw-r--r-- | objectapp/urls/ATurl.py | 8 | ||||
-rw-r--r-- | objectapp/urls/RTurl.py | 11 | ||||
-rw-r--r-- | objectapp/views/dynamicAT.py | 166 | ||||
-rw-r--r-- | objectapp/views/dynamicRT.py | 323 |
12 files changed, 277 insertions, 429 deletions
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..afa492b 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -201,6 +201,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 +312,8 @@ class Gbobject(Node): relation_set.update(rel_dict['right_subjecttypes']) return relation_set - + + def get_attributes(self): attributes_dict = {} 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/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..283f9c6 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 %} @@ -132,11 +126,22 @@ </div> </div> {% 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"> 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..5d6c6cc 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -96,17 +96,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 %} 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/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/") |