diff options
author | shefali shetty <sshefali44@gmail.com> | 2012-06-05 11:28:01 +0530 |
---|---|---|
committer | shefali shetty <sshefali44@gmail.com> | 2012-06-05 11:28:01 +0530 |
commit | 8075ac70992db19a0d77b277f13af07f9f4f8b39 (patch) | |
tree | e2c3dc81dc1b5a000c8e8ab97aa3795a39b41c47 /gstudio/models.py | |
parent | 82e6b6a0535a9ffb202ed8c6bb786bdf41a7bb80 (diff) | |
parent | 909ba6f95a054a1bbec0045cbc9a64f34582529e (diff) | |
download | gnowsys-8075ac70992db19a0d77b277f13af07f9f4f8b39.tar.gz |
collapsing done with Ctrl+click event
Diffstat (limited to 'gstudio/models.py')
-rw-r--r-- | gstudio/models.py | 962 |
1 files changed, 745 insertions, 217 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index 167ed8c..5712194 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -65,6 +65,7 @@ + """Super models of Gstudio """ import warnings @@ -303,8 +304,7 @@ class NID(models.Model): # # Returned value is a list, so splice it. # vrs = vrs[0] # except: - # return None - + # return None # return vrs.object @@ -327,36 +327,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}) @@ -364,16 +389,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 @@ -391,59 +416,59 @@ class NID(models.Model): version = Version.objects.get(id=self.id) return version.serialized_data + - - def get_Version_graph_json(self,ssid): + # def get_Version_graph_json(self,ssid): - # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} - # slist=self.get_ssid - ver_dict=self.version_info(ssid) - # ver_dict=str(ver['nbhood']) - # ver_dict=ast.literal_eval(ver_dict) + # # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} + # # slist=self.get_ssid + # ver_dict=self.version_info(ssid) + # #ver_dict=str(ver['nbhood']) + # ver_dict=ast.literal_eval(ver_dict['nbhood']) - g_json = {} - g_json["node_metadata"]= [] - predicate_id = {} - counter = 1 - for key in ver_dict.keys(): - val = "a" + str(counter) - predicate_id[key] = val - counter = counter + 1 - #print predicate_id - - attr_counter = -1 - - this_node = {"_id":str(ver_dict['id']),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()} - g_json["node_metadata"].append(this_node) - - for key in predicate_id.keys(): - if ver_dict[key]: - try: - g_json[str(key)]=[] - g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key}) - g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) - if not isinstance(ver_dict[key],basestring): - for item in ver_dict[key]: - # user - g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()}) - g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + # g_json = {} + # g_json["node_metadata"]= [] + # predicate_id = {} + # counter = 1 + # for key in ver_dict.keys(): + # val = "a" + str(counter) + # predicate_id[key] = val + # counter = counter + 1 + # #print predicate_id + + # attr_counter = -1 + + # this_node = {"_id":str(self.id),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()} + # g_json["node_metadata"].append(this_node) + + # for key in predicate_id.keys(): + # if ver_dict[key]: + # try: + # g_json[str(key)]=[] + # g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key}) + # g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + # if not isinstance(ver_dict[key],basestring): + # for item in ver_dict[key]: + # # user + # g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()}) + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) - else: - #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} - #this_node[str(key)]=nbh[key] key, nbh[key] - #for item in value.keys(): - g_json["node_metadata"].append({"_id":attr_counter,"screen_name":ver_dict[key]}) - g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) - attr_counter-=1 + # else: + # #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} + # #this_node[str(key)]=nbh[key] key, nbh[key] + # #for item in value.keys(): + # g_json["node_metadata"].append({"_id":attr_counter,"screen_name":ver_dict[key]}) + # g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + # attr_counter-=1 - except: - pass - # print g_json + # except: + # pass + # # print g_json - return json.dumps(g_json) + # return json.dumps(g_json) def __unicode__(self): @@ -452,7 +477,7 @@ class NID(models.Model): class Meta: """NID's Meta""" - + class Node(NID): """ @@ -472,7 +497,8 @@ class Node(NID): sites = models.ManyToManyField(Site, verbose_name=_('sites publication'), related_name='nodetypes') - nbhood = models.TextField(help_text="The neighbourhood of the model.") + nbhood = models.TextField(help_text="The rendered neighbourhood of the model.") + # nbh = models.TextField(help_text="The neighbourhood of the model.") published = NodePublishedManager() def __unicode__(self): @@ -480,18 +506,9 @@ class Node(NID): class Meta: abstract=False - + + - def save(self, *args, **kwargs): - - # self.nbhood=self.get_nbh - if GSTUDIO_VERSIONING: - with reversion.create_revision(): - super(Node, self).save(*args, **kwargs) # Call the "real" save() method. - - super(Node, self).save(*args, **kwargs) # Call the "real" save() method. - - class Edge(NID): @@ -540,7 +557,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) @@ -638,23 +655,38 @@ class Metatype(Node): """ Returns the neighbourhood of the metatype """ + history=[] + version_list=self.get_ssid + if version_list: + length=len(version_list) + history_ssid=version_list[length-1] + history_dict=self.version_info(history_ssid) + history_nbh_dict=ast.literal_eval(history_dict['nbhood']) + #ssid_current.append(history_ssid) + history=history_nbh_dict['history'] + history.append(history_ssid) + else: + history.append(0) nbh = {} + history_list=self.get_ssid nbh['title'] = self.title nbh['altnames'] = self.altnames nbh['plural'] = self.plural if self.parent: - nbh['typeof'] = self.parent + obj=NID.objects.get(id=self.parent) + typeof[parent] = obj.ref.get_absolute_url() + #nbh['typeof'] = self.parent # 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('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) nbh['contains_members'] = contains_members_list 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) - + nbh['history']=history return nbh @@ -663,7 +695,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 +705,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 @@ -693,7 +725,7 @@ class Metatype(Node): def save(self, *args, **kwargs): super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. - self.nbhood=self.get_nbh + self.nbhood=self.get_rendered_nbh if GSTUDIO_VERSIONING: with reversion.create_revision(): @@ -856,8 +888,8 @@ class Nodetype(Node): rels['possible_rightroles'] = right_subset return rels - - + + def get_graph_json(self): @@ -865,6 +897,7 @@ class Nodetype(Node): g_json["node_metadata"]= [] g_json["relations"]=[] + global counter global attr_counter nbh = self.get_nbh @@ -875,9 +908,9 @@ class Nodetype(Node): predicate_id[key] = val counter = counter + 1 - this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"expanded":"true","refType":self.reftype} + this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"refType":self.reftype} g_json["node_metadata"].append(this_node) - + for key in predicate_id.keys(): if nbh[key]: @@ -895,10 +928,11 @@ class Nodetype(Node): flag=0 # create nodes - g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"expanded":"false","refType":item.reftype,"inverse":item.inverse,"flag":flag}) + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"refType":item.reftype,"inverse":item.inverse,"flag":flag}) - g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"expanded":"false","refType":item.reftype}) + + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"refType":item.reftype}) #create links g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) @@ -913,6 +947,7 @@ class Nodetype(Node): pass + return json.dumps(g_json) @@ -950,15 +985,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 @@ -996,7 +1031,7 @@ class Nodetype(Node): return relations @property - def get_relations1(self): + def get_rendered_relations(self): """ Returns all the relations of the nodetype """ @@ -1020,7 +1055,7 @@ class Nodetype(Node): if each.relationtype.title==key: fl=1 predicate_values.append(predicate) - reltype[key]=predicate_values + reltype[key]=predicate_values if fl==0: predicate_values=predicate reltype[relation]=predicate_values @@ -1060,6 +1095,7 @@ class Nodetype(Node): relations['rrelations']=reltype return relations + @property def get_attributes(self): attributes_dict = {} @@ -1085,19 +1121,37 @@ class Nodetype(Node): val.extend(value) attributes_dict[atr_key]=val return attributes_dict - + + # def history(self,ssid): + #ver @property def get_rendered_nbh(self): """ Returns the neighbourhood of the nodetype """ + history=[] + version_list=self.get_ssid + if version_list: + length=len(version_list) + history_ssid=version_list[length-1] + history_dict=self.version_info(history_ssid) + history_nbh_dict=ast.literal_eval(history_dict['nbhood']) + #ssid_current.append(history_ssid) + history=history_nbh_dict['history'] + history.append(history_ssid) + else: + history.append(0) nbh = {} nbh['title'] = self.title 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(): @@ -1149,8 +1203,8 @@ class Nodetype(Node): relns={} rellft={} relrgt={} - if self.get_relations1: - NTrelns=self.get_relations1 + if self.get_rendered_relations: + NTrelns=self.get_rendered_relations for key,value in NTrelns.items(): if key=="rrelations": relrgt={} @@ -1158,7 +1212,7 @@ class Nodetype(Node): relnvalue={} if isinstance(rgtvalue,list): for items in rgtvalue: - relnvalue[items]=items.get_absolute_url() + relnvalue[items.title]=items.get_absolute_url() else: relnvalue[rgtvalue]=rgtvalue.get_absolute_url() @@ -1171,7 +1225,7 @@ class Nodetype(Node): relnvalue={} if isinstance(lftvalue,list): for items in lftvalue: - relnvalue[items]=items.get_absolute_url() + relnvalue[items.title]=items.get_absolute_url() else: relnvalue[lftvalue]=lftvalue.get_absolute_url() @@ -1201,7 +1255,7 @@ class Nodetype(Node): rightroles[each.title]=each.get_absolute_url() nbh['rightroles']=rightroles nbh['count_rightroles'] = len(nbh['rightroles']) - + nbh['history']=history return nbh @@ -1286,22 +1340,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 @@ -1332,16 +1386,7 @@ class Nodetype(Node): verbose_name_plural = _('node types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - - # Save for nodetype - def save(self, *args, **kwargs): - if GSTUDIO_VERSIONING: - with reversion.create_revision(): - super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. - super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. - - - + class Objecttype(Nodetype): ''' Object class @@ -1349,11 +1394,7 @@ class Objecttype(Nodetype): def __unicode__(self): return self.title - - - - - + @property def get_attributetypes(self): @@ -1455,61 +1496,190 @@ class Objecttype(Nodetype): #nbh['authors'] = self.authors.all() return nbh - @property def get_rendered_nbh(self): + """ + Returns the neighbourhood of the nodetype """ - Returns the neighbourhood of the nodetype with the hyperlinks of nodes rendered - """ + history=[] + version_list=self.get_ssid + if version_list: + length=len(version_list) + history_ssid=version_list[length-1] + history_dict=self.version_info(history_ssid) + history_nbh_dict=ast.literal_eval(history_dict['nbhood']) + #ssid_current.append(history_ssid) + history=history_nbh_dict['history'] + history.append(history_ssid) + else: + history.append(0) nbh = {} nbh['title'] = self.title + nbh['count_title'] = len(nbh['title']) nbh['altnames'] = self.altnames - nbh['plural'] = self.plural - member_of_metatypes_list = [] + nbh['count_altnames'] = len(nbh['altnames']) + nbh['plural'] = self.plural + #nbh['count_plural'] = len(nbh['plural']) + #get all MTs + member_of_dict = {} for each in self.metatypes.all(): - member_of_metatypes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) - nbh['member_of_metatypes'] = member_of_metatypes_list - - - attributetypes_list = [] - for each in self.get_attributetypes: - attributetypes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) - nbh['attributetypes'] = attributetypes_list - - - # get all the RTs for the objecttype - reltypes_list = [] - for each in self.get_relationtypes: - reltypes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) - nbh['relationtypes'] = reltypes_list - - nbh['type_of'] = self.parent - - nbh['contains_subtypes'] = Nodetype.objects.filter(parent=self.id) - # get all the objects inheriting this OT - contains_members_list = [] - for each in self.gbobjects.all(): - contains_members_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) - nbh['contains_members'] = contains_members_list - - prior_nodes_list = [] + member_of_dict[each.title]= each.get_absolute_url() + nbh['member_of_metatypes']=member_of_dict + nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes']) + typeof={} + parent=self.parent_id + if parent: + obj=NID.objects.get(id=parent) + typeof[parent] = obj.ref.get_absolute_url() + nbh['type_of']=typeof + nbh['count_type_of'] = len(nbh['type_of']) + #get all subtypes + subtypes={} + for each in Nodetype.objects.filter(parent=self.id): + subtypes[each.title] =each.get_absolute_url() + nbh['contains_subtypes']=subtypes + nbh['count_contains_subtypes'] = len(nbh['contains_subtypes']) + # get all the objects inheriting this OT + contains_members_dict = {} + for each in self.member_objects.all(): + contains_members_dict[each.title]= each.get_absolute_url() + nbh['contains_members'] = contains_members_dict + nbh['count_contains_members'] = len(nbh['contains_members']) + #get prior nodes + priornodes_dict = {} for each in self.prior_nodes.all(): - prior_nodes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) - nbh['prior_nodes'] = prior_nodes_list - - posterior_nodes_list = [] + priornodes_dict[each.title]= each.get_absolute_url() + nbh['priornodes'] = priornodes_dict + nbh['count_priornodes'] = len(nbh['priornodes']) + #get posterior nodes + posteriornodes_dict = {} for each in self.posterior_nodes.all(): - posterior_nodes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title)) - nbh['posterior_nodes'] = posterior_nodes_list - - author_list = [] + posteriornodes_dict[each.title]= each.get_absolute_url() + nbh['posteriornodes'] = posteriornodes_dict + nbh['count_posteriornodes'] = len(nbh['posteriornodes']) + #get authors + author_dict = {} for each in self.authors.all(): - author_list.append('<a href="%s"></a>' % (each.get_absolute_url())) - nbh['authors'] = author_list + author_dict['User'] = each.get_absolute_url() + nbh['authors'] = author_dict + #get siblings + siblings={} + for each in self.get_siblings(): + siblings[each.title]=each.get_absolute_url() + nbh['siblings']=siblings + nbh['count_siblings'] = len(nbh['siblings']) + #get Relations + relns={} + rellft={} + relrgt={} + if self.get_rendered_relations: + NTrelns=self.get_rendered_relations + for key,value in NTrelns.items(): + if key=="rrelations": + relrgt={} + for rgtkey,rgtvalue in value.items(): + relnvalue={} + if isinstance(rgtvalue,list): + for items in rgtvalue: + relnvalue[items.title]=items.get_absolute_url() + else: + relnvalue[rgtvalue]=rgtvalue.get_absolute_url() + + relrgt[rgtkey]=relnvalue + + else: + rellft={} + relns['left']=rellft + for lftkey,lftvalue in value.items(): + relnvalue={} + if isinstance(lftvalue,list): + for items in lftvalue: + relnvalue[items.title]=items.get_absolute_url() + else: + relnvalue[lftvalue]=lftvalue.get_absolute_url() + + rellft[lftkey]=relnvalue + + nbh['relations']=relrgt + + nbh['relations'].update(rellft) + nbh['count_relations'] = len(nbh['relations']) + #get Attributes + attributes =self.get_attributes + nbh['attributes']=attributes + nbh['count_attributes'] = len(nbh['attributes']) + #get ATs + attributetypes={} + for each in self.subjecttype_of.all(): + attributetypes[each.title]=each.get_absolute_url() + nbh['ats']=attributetypes + #get RTs as leftroles and rightroles + leftroles = {} + for each in self.left_subjecttype_of.all(): + leftroles[each.title]=each.get_absolute_url() + nbh['leftroles']=leftroles + nbh['count_leftroles'] = len(nbh['leftroles']) + rightroles = {} + for each in self.right_subjecttype_of.all(): + rightroles[each.title]=each.get_absolute_url() + nbh['rightroles']=rightroles + nbh['count_rightroles'] = len(nbh['rightroles']) + nbh['history']=history return nbh + + def get_Version_graph_json(self,ssid): + + + # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} + # slist=self.get_ssid + ver_dict=self.version_info(ssid) + ver_dict1=self.version_info(ssid) + #ver_dict=str(ver['nbhood']) + ver_dict=ast.literal_eval(ver_dict['nbhood']) + g_json = {} + g_json["node_metadata"]= [] + predicate_id = {} + counter = 1 + for key in ver_dict.keys(): + val = "a" + str(counter) + predicate_id[key] = val + counter = counter + 1 + #print predicate_id + attr_counter = -1 + + this_node = {"_id":str(self.id),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()} + g_json["node_metadata"].append(this_node) + for key in predicate_id.keys(): + if ver_dict[key]: + try: + g_json[str(key)]=[] + g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key}) + g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + if not isinstance(ver_dict[key],basestring): + for item in ver_dict[key]: + # user + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()}) + g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + + else: + #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} + #this_node[str(key)]=nbh[key] key, nbh[key] + #for item in value.keys(): + g_json["node_metadata"].append({"_id":attr_counter,"screen_name":ver_dict[key]}) + g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + attr_counter-=1 + + except: + pass + # print g_json + + + return json.dumps(g_json) + + class Meta: """ object type's meta class @@ -1521,15 +1691,22 @@ class Objecttype(Nodetype): # Save for Objecttype # @reversion.create_revision() - def save(self, *args, **kwargs): + def save(self,*args, **kwargs): self.nodemodel = self.__class__.__name__ super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. - self.nbhood=self.get_nbh + self.nbhood=self.get_rendered_nbh + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + self.nodemodel = self.__class__.__name__ + if self.parent: + ot=NID.objects.get(id=self.parent.id) + ot.ref.save() + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + + def save_revert_or_merge(self,*args, **kwargs): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. - - @@ -1563,6 +1740,171 @@ class Relationtype(Nodetype): def __unicode__(self): return self.title + @property + + def get_rendered_nbh(self): + """ + Returns the neighbourhood of the Relationtype + """ + history=[] + version_list=self.get_ssid + if version_list: + length=len(version_list) + history_ssid=version_list[length-1] + history_dict=self.version_info(history_ssid) + history_nbh_dict=ast.literal_eval(history_dict['nbhood']) + #ssid_current.append(history_ssid) + history=history_nbh_dict['history'] + history.append(history_ssid) + else: + history.append(0) + nbh = {} + nbh['title'] = self.title + 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']) + #get all MTs + member_of_dict = {} + for each in self.metatypes.all(): + member_of_dict[each.title]= each.get_absolute_url() + nbh['member_of_metatypes']=member_of_dict + nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes']) + typeof={} + parent=self.parent_id + if parent: + obj=NID.objects.get(id=parent) + typeof[parent] = obj.ref.get_absolute_url() + nbh['type_of']=typeof + nbh['count_type_of'] = len(nbh['type_of']) + #get all subtypes + subtypes={} + for each in Nodetype.objects.filter(parent=self.id): + subtypes[each.title] =each.get_absolute_url() + nbh['contains_subtypes']=subtypes + nbh['count_contains_subtypes'] = len(nbh['contains_subtypes']) + # get all the objects inheriting this OT + contains_members_dict = {} + for each in self.member_objects.all(): + contains_members_dict[each.title]= each.get_absolute_url() + nbh['contains_members'] = contains_members_dict + nbh['count_contains_members'] = len(nbh['contains_members']) + #get prior nodes + priornodes_dict = {} + for each in self.prior_nodes.all(): + priornodes_dict[each.title]= each.get_absolute_url() + nbh['priornodes'] = priornodes_dict + nbh['count_priornodes'] = len(nbh['priornodes']) + #get posterior nodes + posteriornodes_dict = {} + for each in self.posterior_nodes.all(): + posteriornodes_dict[each.title]= each.get_absolute_url() + nbh['posteriornodes'] = posteriornodes_dict + nbh['count_posteriornodes'] = len(nbh['posteriornodes']) + #get authors + author_dict = {} + for each in self.authors.all(): + author_dict['User'] = each.get_absolute_url() + nbh['authors'] = author_dict + #get siblings + siblings={} + for each in self.get_siblings(): + siblings[each.title]=each.get_absolute_url() + nbh['siblings']=siblings + nbh['count_siblings'] = len(nbh['siblings']) + #get Relations + relns={} + rellft={} + relrgt={} + if self.get_rendered_relations: + NTrelns=self.get_rendered_relations + for key,value in NTrelns.items(): + if key=="rrelations": + relrgt={} + for rgtkey,rgtvalue in value.items(): + relnvalue={} + if isinstance(rgtvalue,list): + for items in rgtvalue: + relnvalue[items]=items.get_absolute_url() + else: + relnvalue[rgtvalue]=rgtvalue.get_absolute_url() + + relrgt[rgtkey]=relnvalue + + else: + rellft={} + relns['left']=rellft + for lftkey,lftvalue in value.items(): + relnvalue={} + if isinstance(lftvalue,list): + for items in lftvalue: + relnvalue[items]=items.get_absolute_url() + else: + relnvalue[lftvalue]=lftvalue.get_absolute_url() + + rellft[lftkey]=relnvalue + + nbh['relations']=relrgt + + nbh['relations'].update(rellft) + nbh['count_relations'] = len(nbh['relations']) + #get Attributes + attributes =self.get_attributes + nbh['attributes']=attributes + nbh['count_attributes'] = len(nbh['attributes']) + #get ATs + attributetypes={} + for each in self.subjecttype_of.all(): + attributetypes[each.title]=each.get_absolute_url() + nbh['ats']=attributetypes + #get RTs as leftroles and rightroles + leftroles = {} + for each in self.left_subjecttype_of.all(): + leftroles[each.title]=each.get_absolute_url() + nbh['leftroles']=leftroles + nbh['count_leftroles'] = len(nbh['leftroles']) + rightroles = {} + for each in self.right_subjecttype_of.all(): + rightroles[each.title]=each.get_absolute_url() + nbh['rightroles']=rightroles + nbh['count_rightroles'] = len(nbh['rightroles']) + nbh['history']=history + return nbh + + + + 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 @@ -1576,12 +1918,12 @@ class Relationtype(Nodetype): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh if GSTUDIO_VERSIONING: with reversion.create_revision(): self.nodemodel = self.__class__.__name__ - - - super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1615,6 +1957,140 @@ class Attributetype(Nodetype): editable=models.NullBooleanField(verbose_name='required', null=True, blank=True, help_text='If False, the field will not be editable') + + @property + def get_rendered_nbh(self): + """ + Returns the neighbourhood of the Attributetype + """ + history=[] + version_list=self.get_ssid + if version_list: + length=len(version_list) + history_ssid=version_list[length-1] + history_dict=self.version_info(history_ssid) + history_nbh_dict=ast.literal_eval(history_dict['nbhood']) + #ssid_current.append(history_ssid) + history=history_nbh_dict['history'] + history.append(history_ssid) + else: + history.append(0) + nbh = {} + nbh['title'] = self.title + 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']) + #get all MTs + member_of_dict = {} + for each in self.metatypes.all(): + member_of_dict[each.title]= each.get_absolute_url() + nbh['member_of_metatypes']=member_of_dict + nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes']) + typeof={} + parent=self.parent_id + if parent: + obj=NID.objects.get(id=parent) + typeof[parent] = obj.ref.get_absolute_url() + nbh['type_of']=typeof + nbh['count_type_of'] = len(nbh['type_of']) + #get all subtypes + subtypes={} + for each in Nodetype.objects.filter(parent=self.id): + subtypes[each.title] =each.get_absolute_url() + nbh['contains_subtypes']=subtypes + nbh['count_contains_subtypes'] = len(nbh['contains_subtypes']) + # get all the objects inheriting this OT + contains_members_dict = {} + for each in self.member_objects.all(): + contains_members_dict[each.title]= each.get_absolute_url() + nbh['contains_members'] = contains_members_dict + nbh['count_contains_members'] = len(nbh['contains_members']) + #get prior nodes + priornodes_dict = {} + for each in self.prior_nodes.all(): + priornodes_dict[each.title]= each.get_absolute_url() + nbh['priornodes'] = priornodes_dict + nbh['count_priornodes'] = len(nbh['priornodes']) + #get posterior nodes + posteriornodes_dict = {} + for each in self.posterior_nodes.all(): + posteriornodes_dict[each.title]= each.get_absolute_url() + nbh['posteriornodes'] = posteriornodes_dict + nbh['count_posteriornodes'] = len(nbh['posteriornodes']) + #get authors + author_dict = {} + for each in self.authors.all(): + author_dict['User'] = each.get_absolute_url() + nbh['authors'] = author_dict + #get siblings + siblings={} + for each in self.get_siblings(): + siblings[each.title]=each.get_absolute_url() + nbh['siblings']=siblings + nbh['count_siblings'] = len(nbh['siblings']) + #get Relations + relns={} + rellft={} + relrgt={} + if self.get_rendered_relations: + NTrelns=self.get_rendered_relations + for key,value in NTrelns.items(): + if key=="rrelations": + relrgt={} + for rgtkey,rgtvalue in value.items(): + relnvalue={} + if isinstance(rgtvalue,list): + for items in rgtvalue: + relnvalue[items]=items.get_absolute_url() + else: + relnvalue[rgtvalue]=rgtvalue.get_absolute_url() + + relrgt[rgtkey]=relnvalue + + else: + rellft={} + relns['left']=rellft + for lftkey,lftvalue in value.items(): + relnvalue={} + if isinstance(lftvalue,list): + for items in lftvalue: + relnvalue[items]=items.get_absolute_url() + else: + relnvalue[lftvalue]=lftvalue.get_absolute_url() + + rellft[lftkey]=relnvalue + + nbh['relations']=relrgt + + nbh['relations'].update(rellft) + nbh['count_relations'] = len(nbh['relations']) + #get Attributes + attributes =self.get_attributes + nbh['attributes']=attributes + nbh['count_attributes'] = len(nbh['attributes']) + #get ATs + attributetypes={} + for each in self.subjecttype_of.all(): + attributetypes[each.title]=each.get_absolute_url() + nbh['ats']=attributetypes + #get RTs as leftroles and rightroles + leftroles = {} + for each in self.left_subjecttype_of.all(): + leftroles[each.title]=each.get_absolute_url() + nbh['leftroles']=leftroles + nbh['count_leftroles'] = len(nbh['leftroles']) + rightroles = {} + for each in self.right_subjecttype_of.all(): + rightroles[each.title]=each.get_absolute_url() + nbh['rightroles']=rightroles + nbh['count_rightroles'] = len(nbh['rightroles']) + nbh['history']=history + + return nbh + + def __unicode__(self): return self.title @@ -1638,13 +2114,17 @@ class Attributetype(Nodetype): def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ - -# self.nbhood=self.get_nbh + super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh if GSTUDIO_VERSIONING: with reversion.create_revision(): super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. - - super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. + def save_revert_or_merge(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. + class Relation(Edge): @@ -1705,12 +2185,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): @@ -1727,27 +2207,35 @@ 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 def save(self, *args, **kwargs): + + """ + left_subject and right_subject should be saved after creating the relation + """ self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: with reversion.create_revision(): super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. + left_subject = self.left_subject + right_subject = self.right_subject + left_subject.ref.save() + right_subject.ref.save() super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. - class Attribute(Edge): ''' Attribute value store for default datatype varchar. Subject can be any of the @@ -1798,21 +2286,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): @@ -1830,7 +2318,8 @@ class Attribute(Edge): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1847,11 +2336,14 @@ class AttributeCharField(Attribute): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeTextField(Attribute): @@ -1867,6 +2359,8 @@ class AttributeTextField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. + subject=self.subject + subject.ref.save() super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1882,7 +2376,8 @@ class AttributeIntegerField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1900,6 +2395,8 @@ class AttributeCommaSeparatedIntegerField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + subject=self.subject + subject.ref.save() super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeBigIntegerField(Attribute): @@ -1908,6 +2405,17 @@ class AttributeBigIntegerField(Attribute): def __unicode__(self): return self.title + + # @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeBigIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + subject=self.subject + subject.ref.save() + super(AttributeBigIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributePositiveIntegerField(Attribute): @@ -1922,6 +2430,8 @@ class AttributePositiveIntegerField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + subject=self.subject + subject.ref.save() super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1936,8 +2446,8 @@ class AttributeDecimalField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. - - + subject=self.subject + subject.ref.save() super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeFloatField(Attribute): @@ -1953,7 +2463,8 @@ class AttributeFloatField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1968,7 +2479,8 @@ class AttributeBooleanField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1985,6 +2497,8 @@ class AttributeNullBooleanField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + subject=self.subject + subject.ref.save() super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2000,7 +2514,8 @@ class AttributeDateField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2017,7 +2532,8 @@ class AttributeDateTimeField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2034,13 +2550,14 @@ class AttributeTimeField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. 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 @@ -2050,13 +2567,14 @@ class AttributeEmailField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. 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 @@ -2067,7 +2585,8 @@ class AttributeFileField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2084,13 +2603,14 @@ class AttributeFilePathField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeImageField(Attribute): - value = models.ImageField(upload_to='/media', verbose_name='image') + value = models.ImageField(upload_to = UPLOAD_TO, verbose_name='image') def __unicode__(self): return self.title @@ -2098,6 +2618,11 @@ class AttributeImageField(Attribute): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method. + subject=self.subject + subject.ref.save() super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2114,7 +2639,8 @@ class AttributeURLField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2131,7 +2657,8 @@ class AttributeIPAddressField(Attribute): if GSTUDIO_VERSIONING: with reversion.create_revision(): super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. - + subject=self.subject + subject.ref.save() super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2161,11 +2688,13 @@ class Processtype(Nodetype): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh if GSTUDIO_VERSIONING: with reversion.create_revision(): super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. - super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. + @@ -2202,13 +2731,12 @@ class Systemtype(Nodetype): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh if GSTUDIO_VERSIONING: with reversion.create_revision(): super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. - super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. - - class AttributeSpecification(Node): """ @@ -2229,7 +2757,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): @@ -2270,7 +2798,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 @@ -2312,7 +2840,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 @@ -2351,7 +2879,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: @@ -2436,7 +2964,7 @@ if GSTUDIO_VERSIONING == True: reversion.register(NID) if not reversion.is_registered(Systemtype): - reversion.register(Systemtype) + reversion.register(Systemtype,follow=["nodetype_ptr"] ) if not reversion.is_registered(Objecttype): reversion.register(Objecttype , follow=["nodetype_ptr"]) @@ -2449,7 +2977,7 @@ if GSTUDIO_VERSIONING == True: if not reversion.is_registered(Processtype): - reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"]) + reversion.register(Processtype, follow=["nodetype_ptr","changing_attributetype_set", "changing_relationtype_set"]) if not reversion.is_registered(Nodetype): reversion.register(Nodetype, follow=["node_ptr","parent", "metatypes","prior_nodes", "posterior_nodes"]) @@ -2459,10 +2987,10 @@ if GSTUDIO_VERSIONING == True: if not reversion.is_registered(Relationtype): - reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) + reversion.register(Relationtype, follow=["nodetype_ptr","left_subjecttype", "right_subjecttype"]) if not reversion.is_registered(Attributetype): - reversion.register(Attributetype, follow=["subjecttype"]) + reversion.register(Attributetype, follow=["nodetype_ptr","subjecttype"]) if not reversion.is_registered(Attribute): reversion.register(Attribute, follow=["subject", "attributetype"]) |