From 73d6a58a88f8d6e63404bbf90dc378ade3509662 Mon Sep 17 00:00:00 2001 From: met2012 Date: Fri, 25 May 2012 17:10:31 +0530 Subject: Returned strings made unicode --- gstudio/models.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'gstudio/models.py') diff --git a/gstudio/models.py b/gstudio/models.py index 2c9d51fa..7b1093bd 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -540,7 +540,7 @@ class Metatype(Node): nbh['typeof'] = self.parent # generate ids and names of children/members nbh['contains_subtypes'] = self.children.get_query_set() - nbh['contains_members'] = self.nodetypes.all() + nbh['contains_members'] = self.nodetypes_published() nbh['left_subjecttype_of'] = Relationtype.objects.filter(left_subjecttype=self.id) nbh['right_subjecttype_of'] = Relationtype.objects.filter(right_subjecttype=self.id) nbh['attributetypes'] = Attributetype.objects.filter(subjecttype=self.id) @@ -648,7 +648,7 @@ class Metatype(Node): # generate ids and names of children nbh['contains_subtypes'] = self.children.get_query_set() contains_members_list = [] - for each in self.nodetypes.all(): + for each in self.nodetypes_published(): contains_members_list.append('%s' % (each.get_absolute_url(), each.title)) nbh['contains_members'] = contains_members_list nbh['left_subjecttype_of'] = Relationtype.objects.filter(left_subjecttype=self.id) @@ -663,7 +663,7 @@ class Metatype(Node): def tree_path(self): """Return metatype's tree path, by its ancestors""" if self.parent: - return '%s/%s' % (self.parent.tree_path, self.slug) + return u'%s/%s' % (self.parent.tree_path, self.slug) return self.slug def __unicode__(self): @@ -673,8 +673,8 @@ class Metatype(Node): def composed_sentence(self): "composes the relation as a sentence in triple format." if self.parent: - return '%s is a kind of %s' % (self.title, self.parent.tree_path) - return '%s is a root node' % (self.slug) + return u'%s is a kind of %s' % (self.title, self.parent.tree_path) + return u'%s is a root node' % (self.slug) @models.permalink @@ -968,15 +968,15 @@ class Nodetype(Node): def tree_path(self): """Return nodetype's tree path, by its ancestors""" if self.parent: - return '%s/%s' % (self.parent.tree_path, self.slug) + return u'%s/%s' % (self.parent.tree_path, self.slug) return self.slug @property def tree_path_sentence(self): """ Return the parent of the nodetype in a triple form """ if self.parent: - return '%s is a kind of %s' % (self.title, self.parent.tree_path) - return '%s is a root node' % (self.title) + return u'%s is a kind of %s' % (self.title, self.parent.tree_path) + return u'%s is a root node' % (self.title) @property @@ -1304,22 +1304,22 @@ class Nodetype(Node): if self.metatypes.count: for each in self.metatypes.all(): - return '%s is a member of metatype %s' % (self.title, each) - return '%s is not a fully defined name, consider making it a member of a suitable metatype' % (self.title) + return u'%s is a member of metatype %s' % (self.title, each) + return u'%s is not a fully defined name, consider making it a member of a suitable metatype' % (self.title) @property def subtypeof_sentence(self): "composes the relation as a sentence in triple format." if self.parent: - return '%s is a subtype of %s' % (self.title, self.parent.tree_path) - return '%s is a root node' % (self.title) + return u'%s is a subtype of %s' % (self.title, self.parent.tree_path) + return u'%s is a root node' % (self.title) composed_sentence = property(subtypeof_sentence) def subtypeof(self): "retuns the parent nodetype." if self.parent: - return '%s' % (self.parent.tree_path) + return u'%s' % (self.parent.tree_path) return None @models.permalink @@ -1723,12 +1723,12 @@ class Relation(Edge): @property def composed_sentence(self): "composes the relation as a sentence in a triple format." - return '%s %s %s %s %s %s' % (self.left_subject_scope, self.left_subject, self.relationtype_scope, self.relationtype, self.right_subject_scope, self.right_subject) + return u'%s %s %s %s %s %s' % (self.left_subject_scope, self.left_subject, self.relationtype_scope, self.relationtype, self.right_subject_scope, self.right_subject) @property def inversed_sentence(self): "composes the inverse relation as a sentence in a triple format." - return '%s %s %s %s %s' % (self.objectScope, self.right_subject, self.relationtype.inverse, self.left_subject_scope, self.left_subject ) + return u'%s %s %s %s %s' % (self.objectScope, self.right_subject, self.relationtype.inverse, self.left_subject_scope, self.left_subject ) @property def key_value(self): @@ -1745,14 +1745,14 @@ class Relation(Edge): if self.relationtype: # for relation in self.relationtype(): - return '%s %s %s' % (self.left_subject,self.relationtype,self.right_subject ) + return u'%s %s %s' % (self.left_subject,self.relationtype,self.right_subject ) @property def partial_composition(self): ''' 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) + return u'%s as a %s' % (self.right_subject, self.relationtype) # Save for Relation @@ -1816,21 +1816,21 @@ class Attribute(Edge): ''' composes the attribution as a sentence in a triple format. ''' - return '%s %s has %s %s %s %s' % (self.subject_scope, self.subject, self.attributetype_scope, self.attributetype, self.value_scope, self.svalue) + return u'%s %s has %s %s %s %s' % (self.subject_scope, self.subject, self.attributetype_scope, self.attributetype, self.value_scope, self.svalue) @property def composed_attribution(self): ''' composes a name to the attribute ''' - return 'the %s of %s is %s' % (self.attributetype, self.subject, self.svalue) + return u'the %s of %s is %s' % (self.attributetype, self.subject, self.svalue) @property def partial_composition(self): ''' function that composes the value and attribute name, as in "red as color", "4 as length" ''' - return '%s as %s' % (self.svalue, self.attributetype) + return u'%s as %s' % (self.svalue, self.attributetype) def subject_filter(self,attr): @@ -2247,7 +2247,7 @@ class AttributeSpecification(Node): subjects = u'' for each in self.subjects.all(): subjects = subjects + each.title + ' ' - return 'the %s of %s' % (self.attributetype, subjects) + return u'the %s of %s' % (self.attributetype, subjects) def __unicode__(self): @@ -2288,7 +2288,7 @@ class RelationSpecification(Node): subjects = u'' for each in self.subjects.all(): subjects = subjects + each.title + ' ' - return 'the %s of %s' % (self.relationtype, subjects) + return u'the %s of %s' % (self.relationtype, subjects) def __unicode__(self): return self.composed_subject @@ -2330,7 +2330,7 @@ class NodeSpecification(Node): attributes = u'' for each in self.attributes.all(): attributes = attributes + each.partial_composition + ', ' - return 'the %s with %s, %s' % (self.subject, self.relations, self.attributes) + return u'the %s with %s, %s' % (self.subject, self.relations, self.attributes) def __unicode__(self): return self.composed_subject @@ -2369,7 +2369,7 @@ class Expression(Node): @property def composed_sentence(self): "composes the relation as a sentence in a triple format." - return '%s %s %s' % (self.left_term, self.relationtype, self.right_term) + return u'%s %s %s' % (self.left_term, self.relationtype, self.right_term) class Meta: -- cgit v1.2.3-70-g09d2 From ccd58321500b40ddeed94a9016e7f97fa0731bb2 Mon Sep 17 00:00:00 2001 From: met2012 Date: Fri, 25 May 2012 17:19:42 +0530 Subject: Return string converted to unicode.Minor changes in Metatype class --- gstudio/models.py | 1 + objectapp/models.py | 1 + 2 files changed, 2 insertions(+) (limited to 'gstudio/models.py') diff --git a/gstudio/models.py b/gstudio/models.py index 7b1093bd..18ecf465 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -65,6 +65,7 @@ + """Super models of Gstudio """ import warnings diff --git a/objectapp/models.py b/objectapp/models.py index 8aa779f7..7aad9858 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -113,6 +113,7 @@ 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 * -- cgit v1.2.3-70-g09d2 From f28648fce9a224b6f4c3a24cfaf4b29082dbb775 Mon Sep 17 00:00:00 2001 From: csitifr Date: Mon, 28 May 2012 18:40:43 +0530 Subject: Relation can be now saved and viewed hierachy wise.Attribute does not get saved in duplicate --- demo/settings.py | 6 +- gstudio/models.py | 73 ++++-- gstudio/templates/gstudio/nodetype_detail.html | 3 +- objectapp/models.py | 61 +++-- objectapp/static/objectapp/js/savert.js | 2 +- objectapp/templates/objectapp/fillAT.html | 4 +- objectapp/templates/objectapp/gbobject_detail.html | 34 +-- objectapp/templates/objectapp/selectRT.html | 3 +- objectapp/views/dynamicAT.py | 41 ++- objectapp/views/dynamicRT.py | 282 +++++++++++++++------ 10 files changed, 352 insertions(+), 157 deletions(-) (limited to 'gstudio/models.py') diff --git a/demo/settings.py b/demo/settings.py index 77296fb8..96de64f0 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 5b5cf424..d4cdc5f2 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 7947e585..1a012799 100644 --- a/gstudio/templates/gstudio/nodetype_detail.html +++ b/gstudio/templates/gstudio/nodetype_detail.html @@ -250,6 +250,7 @@ {% endblock %} +{% if user.is_authenticated %}

{% if object.reftype == 'Objecttype' %} Add Attributes: @@ -264,7 +265,7 @@ {{ i }}; {% endfor %} {% endif %} - +{% endif %}

diff --git a/objectapp/models.py b/objectapp/models.py index d6c7d308..c0c2d5ba 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 549e8196..b5294cc5 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 6a474d0d..95bea924 100644 --- a/objectapp/templates/objectapp/fillAT.html +++ b/objectapp/templates/objectapp/fillAT.html @@ -2,12 +2,12 @@ {% load i18n %} {% block content %} -
+ {% csrf_token %} {{ title }} {% for field in form %} -{{ field }} {{ field.errors }} +{{ field }} {{ field.errors }} {{ field.widget }} {% endfor %} diff --git a/objectapp/templates/objectapp/gbobject_detail.html b/objectapp/templates/objectapp/gbobject_detail.html index 283f9c68..5e7108e0 100644 --- a/objectapp/templates/objectapp/gbobject_detail.html +++ b/objectapp/templates/objectapp/gbobject_detail.html @@ -73,6 +73,25 @@ {% endwith %} {% endblock %} + +
+


+ +{% if user.is_authenticated %} +AddAttributes: + +{% for i in object.getattributetypes %} +{{ i }}; +{% endfor %} +

+

+Add Relations: +{% for i in object.getrelationtypes %} +{{ i }}; +{% endfor %} +

+{% endif %} + {% block gbobject-widgets %}
{% with object.next_gbobject as next_gbobject %} @@ -128,21 +147,6 @@ {% endblock %} - -


-Add Attributes: - -{% for i in object.getattributetypes %} -{{ i }}; -{% endfor %} -

-

-Add Relations: -{% for i in object.getrelationtypes %} -{{ i }}; -{% endfor %} -

- {% block gbobject-comments %}

{% trans "Comments" %}

diff --git a/objectapp/templates/objectapp/selectRT.html b/objectapp/templates/objectapp/selectRT.html index 713a45cf..5ceae85e 100644 --- a/objectapp/templates/objectapp/selectRT.html +++ b/objectapp/templates/objectapp/selectRT.html @@ -5,7 +5,8 @@ {% block content %} {% csrf_token %} -Details of {{ gb }} +{{ gb }} +{{ reltit }} diff --git a/objectapp/views/dynamicAT.py b/objectapp/views/dynamicAT.py index aec02fc2..a5d71de9 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 78370b54..f85fe53e 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 -- cgit v1.2.3-70-g09d2 From 81f1310e441c5dfd71e332aaa09e0964052ab9e3 Mon Sep 17 00:00:00 2001 From: Neha shah Date: Tue, 29 May 2012 16:23:34 +0530 Subject: nbh added for relatiotype --- gstudio/models.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'gstudio/models.py') diff --git a/gstudio/models.py b/gstudio/models.py index 105dc7bf..f6c5efeb 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -1140,8 +1140,12 @@ class Nodetype(Node): nbh['count_title'] = len(nbh['title']) nbh['altnames'] = self.altnames nbh['count_altnames'] = len(nbh['altnames']) - nbh['plural'] = self.plural - nbh['count_plural'] = len(nbh['plural']) + nbh['plural'] = self.plural + try: + nbh['count_plural'] = len(nbh['plural']) + except: + pass + #get all MTs member_of_dict = {} for each in self.metatypes.all(): @@ -1393,11 +1397,7 @@ class Objecttype(Nodetype): def __unicode__(self): return self.title - - - - - + @property def get_attributetypes(self): @@ -1607,6 +1607,37 @@ class Relationtype(Nodetype): def __unicode__(self): return self.title + @property + def get_nbh(self): + """ + Returns the neighbourhood of the nodetype + """ + nbh = {} + nbh['title'] = self.title + nbh['altnames'] = self.altnames + nbh['plural'] = self.plural + + nbh['contains_subtypes'] = Nodetype.objects.filter(parent=self.id) + # get all the objects inheriting this OT + nbh['contains_members'] = self.member_objects.all() + nbh['prior_nodes'] = self.prior_nodes.all() + nbh['posterior_nodes'] = self.posterior_nodes.all() + nbh['inverse']=self.inverse + nbh['left_subjecttype']=self.left_subjecttype + nbh['left_applicable_nodetypes']=self.left_applicable_nodetypes + nbh['left_cardinality']=self.left_cardinality + nbh['right_subjecttype']=self.right_subjecttype + nbh['right_applicable_nodetypes']=self.right_applicable_nodetypes + nbh['right_cardinality']=self.right_cardinality + nbh['is_symmetrical']=self.is_symmetrical + nbh['is_reflexive']=self.is_reflexive + nbh['is_transitive']=self.is_transitive + + + + return nbh + + class Meta: """ relation type's meta class -- cgit v1.2.3-70-g09d2