diff options
-rw-r--r-- | gstudio/admin/objecttype.py | 1 | ||||
-rw-r--r-- | gstudio/models.py | 793 | ||||
-rw-r--r-- | gstudio/templates/gstudio/display.html | 261 | ||||
-rw-r--r-- | gstudio/templates/gstudio/skeleton.html | 2 | ||||
-rw-r--r-- | gstudio/templates/gstudio/version_diff.html | 333 | ||||
-rw-r--r-- | gstudio/urls/history.py | 6 | ||||
-rw-r--r-- | gstudio/views/history.py | 519 | ||||
-rw-r--r-- | objectapp/models.py | 86 | ||||
-rw-r--r-- | objectapp/templates/objectapp/base.html | 14 | ||||
-rw-r--r-- | objectapp/templates/objectapp/display.html | 609 | ||||
-rw-r--r-- | objectapp/templates/objectapp/gbobject_list.html | 2 | ||||
-rw-r--r-- | objectapp/templates/objectapp/version_base.html | 129 | ||||
-rw-r--r-- | objectapp/templates/objectapp/version_diff.html | 262 | ||||
-rw-r--r-- | objectapp/urls/__init__.py | 1 | ||||
-rw-r--r-- | objectapp/urls/history.py | 10 | ||||
-rw-r--r-- | objectapp/views/history.py | 436 |
16 files changed, 3047 insertions, 417 deletions
diff --git a/gstudio/admin/objecttype.py b/gstudio/admin/objecttype.py index 5072fe9..45e07c0 100644 --- a/gstudio/admin/objecttype.py +++ b/gstudio/admin/objecttype.py @@ -177,7 +177,6 @@ class ObjecttypeAdmin(parent_class): if not form.cleaned_data.get('authors'): form.cleaned_data['authors'].append(request.user) - nodetype.save() # nodetype.nbhood = nodetype.get_nbh # nodetype.last_update = datetime.now() diff --git a/gstudio/models.py b/gstudio/models.py index 86fa130..535aded 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -304,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 @@ -417,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): @@ -478,7 +477,7 @@ class NID(models.Model): class Meta: """NID's Meta""" - + class Node(NID): """ @@ -498,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): @@ -506,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): @@ -664,13 +655,28 @@ 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 = [] @@ -680,7 +686,7 @@ class Metatype(Node): 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 @@ -719,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(): @@ -882,8 +888,8 @@ class Nodetype(Node): rels['possible_rightroles'] = right_subset return rels - - + + def get_graph_json(self): @@ -891,7 +897,7 @@ class Nodetype(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] - g_json["relset"]=[] + global counter global attr_counter @@ -908,7 +914,7 @@ class Nodetype(Node): this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"expanded":"true"} g_json["node_metadata"].append(this_node) - g_json["relset"].append(self.id) + for key in predicate_id.keys(): if nbh[key]: @@ -928,7 +934,7 @@ class Nodetype(Node): # 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"}) - g_json["relset"].append(item.id) + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) @@ -961,7 +967,8 @@ class Nodetype(Node): pass #print g_json - return json.dumps(g_json) + return json.dumps(g_json) + @property def get_possible_attributes(self): """ @@ -1040,7 +1047,7 @@ class Nodetype(Node): return relations @property - def get_relations1(self): + def get_rendered_relations(self): """ Returns all the relations of the nodetype """ @@ -1064,7 +1071,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 @@ -1104,6 +1111,7 @@ class Nodetype(Node): relations['rrelations']=reltype return relations + @property def get_attributes(self): attributes_dict = {} @@ -1129,12 +1137,26 @@ 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']) @@ -1197,8 +1219,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={} @@ -1206,7 +1228,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() @@ -1219,7 +1241,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() @@ -1249,7 +1271,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 @@ -1380,16 +1402,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 @@ -1499,61 +1512,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 @@ -1565,15 +1707,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. - - @@ -1608,6 +1757,139 @@ class Relationtype(Nodetype): 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 @@ -1637,6 +1919,7 @@ class Relationtype(Nodetype): return nbh + class Meta: """ relation type's meta class @@ -1650,12 +1933,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. @@ -1689,6 +1972,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 @@ -1712,13 +2129,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): @@ -1814,14 +2235,22 @@ class Relation(Edge): # 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 @@ -1904,7 +2333,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. @@ -1921,11 +2351,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): @@ -1941,6 +2374,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. @@ -1956,7 +2391,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. @@ -1974,6 +2410,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): @@ -1982,6 +2420,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): @@ -1996,6 +2445,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. @@ -2010,8 +2461,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): @@ -2027,7 +2478,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. @@ -2042,7 +2494,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. @@ -2059,6 +2512,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. @@ -2074,7 +2529,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. @@ -2091,7 +2547,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. @@ -2108,7 +2565,8 @@ 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. @@ -2124,7 +2582,8 @@ 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. @@ -2141,7 +2600,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. @@ -2158,7 +2618,8 @@ 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. @@ -2172,6 +2633,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. @@ -2188,7 +2654,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. @@ -2205,7 +2672,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. @@ -2235,11 +2703,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. + @@ -2276,13 +2746,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): """ @@ -2510,7 +2979,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"]) @@ -2523,7 +2992,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"]) @@ -2533,10 +3002,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"]) diff --git a/gstudio/templates/gstudio/display.html b/gstudio/templates/gstudio/display.html index 184b58d..9d48285 100644 --- a/gstudio/templates/gstudio/display.html +++ b/gstudio/templates/gstudio/display.html @@ -1,4 +1,3 @@ - {% load i18n comments gstudio_tags %} {% load gstudio_tags i18n %} {% get_tags as nodetype_tags %} @@ -6,7 +5,6 @@ - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xml:lang="{{ LANGUAGE_CODE }}" lang="{{ LANGUAGE_CODE }}" version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml"> <head> @@ -165,7 +163,7 @@ .attr("width", w) .attr("height", h); - vis.append("svg:g").attr("class", "edges"); + vis.append("svg:g").attr("class", "edges"); vis.append("svg:g").attr("class", "nodes"); $(function() { @@ -176,7 +174,7 @@ $(function() { success : function(json) { //var node = NID.objects.get(slug='{{ slug }}'); - var force; + var force; // this contains all the nodes as a dict with _id as the key @@ -336,18 +334,18 @@ $(function() { nodes_by_id[{{ nt.id }}].y = h/2.0; all_edges = new Array(); - all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of, type_of,plural,altnames,contains_members,content, prior_nodes, posterior_nodes); - /* all_edges.concat(follows_edges); - all_edges.concat(member_of_metatype); + all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of, type_of,plural,altnames,contains_members,content, prior_nodes, posterior_nodes); + /* all_edges.concat(follows_edges); + all_edges.concat(member_of_metatype); all_edges.concat(contains_members); - all_edges.concat(contains_subtypes); - all_edges.concat(mentions_edges); + all_edges.concat(contains_subtypes); + all_edges.concat(mentions_edges); - document.getElementById('debugbox1').value= follows_edges; //member_of_metatype + document.getElementById('debugbox1').value= follows_edges; //member_of_metatype document.getElementById('debugbox2').value= mentions_edges; - //document.getElementById('debugbox2').value= member_of_metatype; - document.getElementById('debugbox3').value= all_edges; + //document.getElementById('debugbox2').value= member_of_metatype; + document.getElementById('debugbox3').value= all_edges; */ var force = d3.layout.force() .linkStrength(0.5) @@ -372,7 +370,7 @@ $(function() { if(nodes_by_id[e.to] && !nodes_by_id[e.to].added){ nodes_by_id[e.to].added = true; acc.push(nodes_by_id[e.to]); - } + } return acc; }, []); @@ -390,7 +388,7 @@ $(function() { } */ ) .attr("x1", function(d) { return d.source.x; - }) + }) .attr("y1", function(d) { return d.source.y; }) @@ -405,13 +403,13 @@ $(function() { }) .append("a") - .text(function(d) { return d.type; }); + .text(function(d) { return d.type; }); - var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); + var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); var new_g = node.enter().append("svg:a") - .attr("class", function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) + .attr("class", function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) .attr("xlink:href",function(d){return d.url;}) .call(force.drag); @@ -428,14 +426,14 @@ $(function() { new_g.append("svg:text") .attr("class",function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) .attr("dy", 20) - .attr("dx", 25) - .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"}) + .attr("dx", 25) + .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"}) -// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"}) +// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"}) .text(function(d) { return d.screen_name; - }); + }); node.exit().remove(); @@ -465,7 +463,7 @@ $(function() { /* $('input#follows').change(function(){ update(all_edges); }); - */ + */ /* $('input#mentions').change(function(){ update(all_edges); @@ -480,9 +478,12 @@ $(function() { }); -</script> +</script> </div> </div> + + + <div> {% include "gstudio/_header.html" %} <div id="breadcrumbs" class="span-24 last"> @@ -493,81 +494,186 @@ $(function() { <h3>{% block content %} {% block nodetype-content %} <h2 class="nodetype-title"> - <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_dict.title }} {{ nt.id }}.{{ cnt }} + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_nbh_dict.title }} {{ nt.id }}.{{ version_no }} </a> + <a href="{{ nt.get_edit_url }}/history/{{ ssid }}" target="_blank" title = "edit">[edit]</a> </h2> - {% with nt.html_content|safe as object_content %} - <b>Name:<nbsp></b>{{ ver_dict.title }}<br/> - {% if ver_dict.altnames %} - <b> Alternate names:<nbsp></b>{{ ver_dict.altnames}} - <br/> - {% endif %} - {% if ver_dict.plural %} - <b> Plural Name:<nbsp></b>{{ ver_dict.plural }} <br/> - {% endif %} - {% if nt.get_rendered_nbh.authors %}<b>Authors: <nbsp> </b> - {% endif %} - {% for author in nt.authors.all %} - <span class="vcard author"> - <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" - title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> - </span>{% if not forloop.last %}, {% endif %} - {% endfor %} <br/> - {% endwith %} - {% endblock %} - {% endblock %} + {% with nt.html_content|safe as object_content %} + <b>Name:<nbsp></b> {{ ver_nbh_dict.title }} <br/> + + {% if ver_nbh_dict.plural %} + <b> Plural Name:<nbsp></b> + {{ ver_nbh_dict.plural}} <br/> + {% endif %} + {% if ver_nbh_dict.altnames %} + <b> Alternate names:<nbsp></b> + {{ ver_nbh_dict.altnames}} <br/> + {% endif %} + {% if ver_nbh_dict.type_of %} + <b> Type of:<nbsp></b> + {% for typekey,typevalue in ver_nbh_dict.type_of.items %} + <a href="{{typevalue}}" title = "{{typekey}}">{{typekey}}</a>; + {% endfor %}<br/> + {% endif %} + + + {% if ver_nbh_dict.member_of_metatypes %} + + + <b> Member of Metatypes:<nbsp></b> + {% for mkey,mvalue in ver_nbh_dict.member_of_metatypes.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + + + {% if ver_nbh_dict.contains_subtypes %} + <b> Contains SubTypes:<nbsp></b> + {% for stkey,stvalue in ver_nbh_dict.contains_subtypes.items %} + <a href="{{stvalue}}" title = "{{stkey}}">{{stkey}}</a>; + {% endfor %}<br/> + {% endif %} + + + {% if ver_nbh_dict.contains_members %} + + + <b>Contains Members:<nbsp></b> + {% for mkey,mvalue in ver_nbh_dict.contains_members.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + + + + + + <b>Authors: <nbsp> </b> + + + + + {% for author in nt.authors.all %} + <span class="vcard author"> + <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" + title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> + </span>{% if not forloop.last %}, {% endif %} + {% endfor %} <br/> + + + + {% if ver_nbh_dict.priornodes %} + + + <b>Prior nodes:<nbsp></b> + {% for mkey,mvalue in ver_nbh_dict.priornodes.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + {% if ver_nbh_dict.posteriornodes %} + + + <b>Posterior nodes:<nbsp></b> + {% for mkey,mvalue in ver_nbh_dict.posteriornodes.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + {% if ver_nbh_dict.relations %} + + + {% for relkey,relvalue in ver_nbh_dict.relations.items %} + <b>{{relkey}}:<nbsp></b> + {% for relk, relv in relvalue.items %} + <a href="{{relv}}" title = "{{relk}}">{{relk}}</a>; + {% endfor %}<br/> + {% endfor %} + {% endif %} + + {% if ver_nbh_dict.attributes %} + + {% for atkey,atvalue in ver_nbh_dict.attributes.items %} + {% if atvalue %} + <b>{{atkey}}:<nbsp> </b> + {% for atr in atvalue %} + {{atr}}; + {% endfor %} <br/> + {% endif %} + {% endfor %} + {% endif %} + {% if ver_nbh_dict.leftroles %} + + + <b>Left roles:<nbsp> </b> + + {% for lrkey,lrvalue in ver_nbh_dict.leftroles.items %} + <a href="{{lrvalue}}" title = "{{lrkey}}">{{lrkey}}</a>; + {% endfor %} <br/> + {% endif %} + + {% if ver_nbh_dict.rightroles %} + + <b>Right roles:<nbsp> </b> + + {% for rrkey,rrvalue in ver_nbh_dict.rightroles.items %} + <a href="{{rrvalue}}" title = "{{rrkey}}">{{rrkey}}</a>; + {% endfor %} <br/> + {% endif %} + + + {% if ver_nbh_dict.ats %} + + + <b>Subjecttype of:<nbsp> </b> + + {% for atkey,atvalue in ver_nbh_dict.ats.items %} + <a href="{{atvalue}}" title = "{{atkey}}">{{atkey}}</a>; + {% endfor %} <br/> + {% endif %} + + + <b>Content:<nbsp></b>{{ ver_nbh_dict.content }} + + + {% endwith %} + {% endblock %} + {% endblock %} </div> <div id="sidebar"> {% block sidebar %} <div class="History"> - + <h3>{% trans "Versions" %}</h3> - <script type="text/javascript"> - function go_to_loc(sid) - { - - <!-- var len=document.history.group2.length --> - <!-- for(var i=0;i<len;i++) --> - <!-- { --> - <!-- var r=window.document.history.group2[i] --> - <!-- if(sid==r.) --> - <!-- { --> - <!-- r.disabled="false" --> - <!-- } --> - <!-- else --> - <!-- { --> - <!-- r.enabled="true" --> - <!-- } --> - <!-- } --> - - - } - </script> - <form name="history" action="/nodetypes/display/showhistory/{{ ssid }}" > + <form name="history" action="/nodetypes/display/compare_history/{{ ssid }}" > <table cellspacing="0" border="2"> <tr> - <td> <input type="radio" name="group1" value="{{ ssid }}" checked >{{ nt.id }}.{{ cnt }}</input></td> + <td> <input type="radio" name="group1" value="{{ ssid }}.{{ version_no }}" checked >{{ nt.id }}.{{ version_no }}</input></td> <td></td></tr> + {% for sid in nt.get_ssid %} - {% ifnotequal forloop.counter cnt %} + + {% if sid|stringformat:"s" != ssid|stringformat:"s" %} <tr> <td> </td> <td> - <input type="radio" id="{{ sid }}"name="group2" value="{{ sid }}" >{{ nt.id }}.{{ forloop.counter }}</input> - </td>{% endifnotequal %} - {% endfor %}</tr></table> + <input type="radio" id="{{ sid }}"name="group2" value="{{ sid }}.{{ forloop.counter }}" >{{ nt.id }}.{{ forloop.counter }}</input> + </td></tr>{% endif %} + {% endfor %}</table> <input type="submit" value="Compare" /> </form> - + </div> - + {% endblock %} </div> @@ -583,13 +689,8 @@ $(function() { {{ GSTUDIO_VERSION }}</a>. </p> </div> - </div> + </div> </div> </body> </html> - - - - - diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index eba5e28..ad6cf4a 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -207,7 +207,7 @@ $(function fgraph() { $.getJSON('/nodetypes/graphs/graph_json/' + {{object.id}}, function (json1) { metadata=json1.node_metadata; relations=json1.relations; - relnset=json1.relset + init(metadata,relations); load({{object.id}}) }); diff --git a/gstudio/templates/gstudio/version_diff.html b/gstudio/templates/gstudio/version_diff.html index a640f07..4a11ec2 100644 --- a/gstudio/templates/gstudio/version_diff.html +++ b/gstudio/templates/gstudio/version_diff.html @@ -108,38 +108,154 @@ <h3>{% block content %} {% block nodetype-content %} <h2 class="nodetype-title"> - <a href="{{ nt1.get_absolute_url }}" title="{{ nt1.title }}" rel="bookmark">{{ ver_new.title }} + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_new_dict.title }} {{ nt.id }}.{{ version_no1 }} </a> </h2> - <!-- {% block content56 %}{% for each in diffs1 %} --> - <!-- {% autoescape off %} --> - <!-- {{ each }}<br> --> - <!-- {% endautoescape %}{% endfor %} {% endblock %} --> - <!-- <br> --> - {% with nt1.html_content|safe as object_content %}<br> - <b>Name:<nbsp></b>{{ ver_new.title }}<br/> - {% if ver_new.altnames %} - <b> Alternate names:<nbsp></b>{{ ver_new.altnames }} - <br/> - {% endif %} - {% if ver_new.plural %} - <b> Plural Name:<nbsp></b>{{ ver_new.plural }} <br/> - {% endif %} - - <b> Content:<nbsp></b>{{ ver_new.content }} <br/> - + + {% with nt.html_content|safe as object_content %}<br> - {% if nt1.get_rendered_nbh.authors %}<b>Authors: <nbsp> </b> - {% endif %} - {% for author in nt1.authors.all %} - <span class="vcard author"> - <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" - title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> - </span>{% if not forloop.last %}, {% endif %} - {% endfor %} <br/> - {% endwith %} - {% endblock %} - {% endblock %} + <b>Name:<nbsp></b> {{ ver_new_nbh_dict.title }} <br/> + + {% if ver_new_nbh_dict.plural or ver_old_nbh_dict.plural %} + <b> Plural Name:<nbsp></b> + {{ ver_new_nbh_dict.plural}} <br/> + {% endif %} + {% if ver_new_nbh_dict.altnames or ver_old_nbh_dict.altnames%} + <b> Alternate names:<nbsp></b> + {{ ver_new_nbh_dict.altnames}} <br/> + {% endif %} + {% if ver_new_nbh_dict.type_of or ver_old_nbh_dict.type_of %} + <b> Type of:<nbsp></b> + {% for typekey,typevalue in ver_new_nbh_dict.type_of.items %} + <a href="{{typevalue}}" title = "{{typekey}}">{{typekey}}</a>; + {% endfor %}<br/> + {% endif %} + + + {% if ver_new_nbh_dict.member_of_metatypes or ver_old_nbh_dict.member_of_metatypes %} + + + <b> Member of Metatypes:<nbsp></b> + {% for mkey,mvalue in ver_new_nbh_dict.member_of_metatypes.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + + + {% if ver_new_nbh_dict.contains_subtypes or ver_old_nbh_dict.contains_subtypes %} + <b> Contains SubTypes:<nbsp></b> + {% for stkey,stvalue in ver_new_nbh_dict.items %} + <a href="{{stvalue}}" title = "{{stkey}}">{{stkey}}</a>; + {% endfor %}<br/> + {% endif %} + + + {% if ver_new_nbh_dict.contains_members or ver_old_nbh_dict.contains_members %} + + + <b>Contains Members:<nbsp></b> + {% for mkey,mvalue in ver_new_nbh_dict.contains_members.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + + + + + + <!-- <b>Authors: <nbsp> </b> --> + + + + + <!-- {% for author in nt.authors.all %} --> + <!-- <span class="vcard author"> --> + <!-- <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" --> + <!-- title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> --> + <!-- </span>{% if not forloop.last %}, {% endif %} --> + <!-- {% endfor %} <br/> --> + + + + {% if ver_new_nbh_dict.priornodes or ver_old_nbh_dict.priornodes %} + + + <b>Prior nodes:<nbsp></b> + {% for mkey,mvalue in ver_new_nbh_dict.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + {% if ver_new_nbh_dict.posteriornodes or ver_old_nbh_dict.posteriornodes %} + + + <b>Posterior nodes:<nbsp></b> + {% for mkey,mvalue in ver_new_nbh_dict.items %} + <a href="{{mvalue}}" title = "{{mkey}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + {% if ver_new_nbh_dict.relations or ver_old_nbh_dict.relations %} + + + {% for relkey,relvalue in ver_new_nbh_dict.relations.items %} + <b>{{relkey}}:<nbsp></b> + {% for relk, relv in relvalue.items %} + <a href="{{relv}}" title = "{{relk}}">{{relk}}</a>; + {% endfor %}<br/> + {% endfor %} + {% endif %} + + {% if ver_new_nbh_dict.attributes or ver_old_nbh_dict.attributes %} + + {% for atkey,atvalue in ver_new_nbh_dict.attributes.items %} + {% if atvalue %} + <b>{{atkey}}:<nbsp> </b> + {% for atr in atvalue %} + {{atr}}; + {% endfor %} <br/> + {% endif %} + {% endfor %} + {% endif %} + {% if ver_new_nbh_dict.leftroles or ver_old_nbh_dict.leftroles %} + + + <b>Left roles:<nbsp> </b> + + {% for lrkey,lrvalue in ver_new_nbh_dict.leftroles.items %} + <a href="{{lrvalue}}" title = "{{lrkey}}">{{lrkey}}</a>; + {% endfor %} <br/> + {% endif %} + + {% if ver_new_nbh_dict.rightroles or ver_old_nbh_dict.rightroles %} + + <b>Right roles:<nbsp> </b> + + {% for rrkey,rrvalue in ver_new_nbh_dict.rightroles.items %} + <a href="{{rrvalue}}" title = "{{rrkey}}">{{rrkey}}</a>; + {% endfor %} <br/> + {% endif %} + + + {% if ver_new_nbh_dict.ats or ver_old_nbh_dict.ats %} + + + <b>Subjecttype of:<nbsp> </b> + + {% for atkey,atvalue in ver_new_nbh_dict.ats.items %} + <a href="{{atvalue}}" title = "{{atkey}}">{{atkey}}</a>; + {% endfor %} <br/> + {% endif %} + + {% if ver_new_nbh_dict.content or ver_old_nbh_dict.content %} + <b>Content:<nbsp></b>{{ ver_new_nbh_dict.content }} + {% endif %} + + {% endwith %} + {% endblock %} + {% endblock %} </td> <td> @@ -147,71 +263,126 @@ <h3>{% block content1 %} {% block nodetype-content1 %} <h2 class="nodetype-title"> - <a href="{{ nt1.get_absolute_url }}" title="{{ nt1.title }}" rel="bookmark">{{ ver_old.title }} + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_old_dict.title }} {{ nt.id }}.{{ version_no2 }} </a> - </h2><!-- <b> --> - <!-- {% block content85 %}{% for each in diffs %} --> - <!-- {% autoescape off %} --> - <!-- {{ each }}<br> --> - <!-- {% endautoescape %}{% endfor %} {% endblock %}</b> --> - <br> - {% with nt1.html_content|safe as object_content %} + </h2> <br> + {% with nt.html_content|safe as object_content %} + <b>Name:<nbsp></b>{% autoescape off %} - {{ diffs.0 }} + {{ compare_dict.title }} {% endautoescape %}<br> - {% if ver_old.altnames %} + {% if ver_old_nbh_dict.plural or ver_new_nbh_dict.plural %} + <b> Plural Name:<nbsp></b> {% autoescape off %} + {{ compare_dict.plural }} + {% endautoescape %} <br/> + {% endif %} + {% if ver_old_nbh_dict.altnames or ver_new_nbh_dict.altnames %} <b> Alternate names:<nbsp></b> {% autoescape off %} - {{ diffs.1 }} + {{ compare_dict.altnames }} {% endautoescape %} <br/> {% endif %} - {% if ver_old.plural %} - <b> Plural Name:<nbsp></b> {% autoescape off %} - {{ diffs.2 }} - {% endautoescape %} <br/> + {% if ver_new_nbh_dict.type_of or ver_old_nbh_dict.type_of %} + <b> Type of:<nbsp></b> {% autoescape off %} + {{ compare_dict.type_of }} + {% endautoescape %} + <br/> {% endif %} - - <b> Content:<nbsp></b> {% autoescape off %} - {{ diffs.3 }} + {% if ver_new_nbh_dict.member_of_metatypes or ver_old_nbh_dict.member_of_metatypes %} + <b>Member of Metatypes:<nbsp></b> {% autoescape off %} + {{ compare_dict.member_of_metatypes }} + {% endautoescape %} + <br/> + {% endif %} + {% if ver_new_nbh_dict.contains_subtypes or ver_old_nbh_dict.contains_subtypes %} + <b>Contain subtypes:<nbsp></b> {% autoescape off %} + {{ compare_dict.contains_subtypes }} + {% endautoescape %} + <br/> + {% endif %} + + {% if ver_old_nbh_dict.contains_members or ver_new_nbh_dict.contains_members %} + <b>Contains Members:<nbsp></b>{% autoescape off %} + {{ compare_dict.contains_members }} {% endautoescape %} <br/> + {% endif %} + {% if ver_new_nbh_dict.priornodes or ver_old_nbh_dict.priornodes %} + <b>Prior nodes:<nbsp></b> {% autoescape off %} + {{ compare_dict.priornodes }} + {% endautoescape %}<br/> + + + {% endif %} + {% if ver_new_nbh_dict.posteriornodes or ver_old_nbh_dict.posteriornodes %} + <b>Posterior nodes:<nbsp></b> {% autoescape off %} + {{ compare_dict.posteriornodes }} + {% endautoescape %}<br/> + + + {% endif %} + + {% if ver_new_nbh_dict.relations or ver_old_nbh_dict.relations %} + {% for relkey,relvalue in compare_dict.relations.items %} + <b>{{relkey}}:<nbsp></b> + {% autoescape off %} + + + {{ relvalue }} + + + {% endautoescape %} + <br/> + {% endfor %} + {% endif %} + + {% if ver_new_nbh_dict.attributes or ver_old_nbh_dict.attributes %} + <b>Attributes:<nbsp></b> {% autoescape off %} + {{ compare_dict.attributes }} + {% endautoescape %}<br/> + {% endif %} - - {% if nt1.get_rendered_nbh.authors %}<b>Authors: <nbsp> </b> - {% endif %} - {% for author in nt1.authors.all %} - <span class="vcard author"> - <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" - title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> - </span>{% if not forloop.last %}, {% endif %} - {% endfor %} <br/> + + {% if ver_new_nbh_dict.leftroles or ver_old_nbh_dict.leftroles %} + <b>Left roles:<nbsp> </b> {% autoescape off %} + {{ compare_dict.leftroles }} + {% endautoescape %} + <br/> + {% endif %} + {% if ver_new_nbh_dict.rightroles or ver_old_nbh_dict.rightroles %} + <b>Right roles:<nbsp> </b> {% autoescape off %} + {{ compare_dict.rightroles }} + {% endautoescape %} + <br/> + {% endif %} + {% if ver_new_nbh_dict.ats or ver_old_nbh_dict.ats %} + + + <b>Subjecttype of:<nbsp> </b> {% autoescape off %} + {{ compare_dict.ats }} + {% endautoescape %}<br> + {% endif %} + {% if ver_new_nbh_dict.content or ver_old_nbh_dict.content %} + <b> Content:<nbsp></b> {% autoescape off %} + {{ compare_dict.content }} + {% endautoescape %} <br/> + {% endif %} {% endwith %} {% endblock %} {% endblock %} - - </td> - -<!-- <th><b><i><br><u>Difference between Selected Versions</u></b></i><br><br> --> -<!-- {% block content6 %}{% for each in diffs %} --> -<!-- {% autoescape off %} --> -<!-- {{ each }}<br> --> -<!-- {% endautoescape %}{% endfor %} {% endblock %} --> -<!-- </th> --> - - </tr> -<tr><td><input type="button" value="Merge"></input><input type="button" value="RollBack"></input></td> -<td><input type="button" value="Merge"></input><input type="button" value="RollBack"></input></td> </tr> -<!-- <tr><th><b><i>Difference between Selected Versions<b><i><th><tr> --> -<!-- <tr><td><b>{% block content5 %}{% for each in diffs %} --> -<!-- {% autoescape off %} --> -<!-- {{ each }}<br> --> -<!-- {% endautoescape %}{% endfor %} {% endblock %} </b> </td></tr> --> -<!-- </table> --> - - - - - - </body> +<br> +</td></tr> +<tr><td> +<form method="get" action="/nodetypes/display/merge/{{ ssid1 }}/{{ ssid2 }}"> +<input type="submit" value="Merge {{ nt.id }}.{{ version_no1 }} with {{ nt.id }}.{{ version_no2 }}" id="merge1" name="left" ></input></td> +<td><input type="submit" value="Merge {{ nt.id }}.{{ version_no2 }} with {{ nt.id }}.{{ version_no1 }}" id="merge2" name="right"></input></td></form> +</tr> +<tr><td> +<form method="get" action="/nodetypes/display/revert" > +<input type="submit" value="Revert" name="{{ ssid1 }}"></input></td> +<td><input type="submit" value="Revert" name="{{ ssid2 }}"></input></td> +</form></tr> +</table> +</body> </html> diff --git a/gstudio/urls/history.py b/gstudio/urls/history.py index 3932cd6..b2c489e 100644 --- a/gstudio/urls/history.py +++ b/gstudio/urls/history.py @@ -3,6 +3,8 @@ from django.conf.urls.defaults import url from django.conf.urls.defaults import patterns urlpatterns = patterns('gstudio.views.history', - url(r'^viewhistory/(?P<ssid>\d+)/(?P<cnt>\d+)/$', 'history', + url(r'^viewhistory/(?P<ssid>\d+)/(?P<version_no>\d+)/$', 'history', name='gstudio_history'), - url(r'^showhistory/(?P<ssid>\d+)/$','showHistory'),) + url(r'^compare_history/(?P<ssid>\d+)/$','compare_history'), + url(r'^merge/(?P<ssid1>\d+)/(?P<ssid2>\d+)/$','merge_version'), + url(r'^revert/$','revert_version'),) diff --git a/gstudio/views/history.py b/gstudio/views/history.py index d4adac9..10fc7ab 100644 --- a/gstudio/views/history.py +++ b/gstudio/views/history.py @@ -12,94 +12,491 @@ from gstudio.views.decorators import protect_nodetype from gstudio.views.decorators import update_queryset import ast -def history(request,ssid,cnt): +def history(request,ssid,version_no): # iden=request.GET["id"] nt1=Version.objects.get(id=ssid) nt=nt1.object.ref ver_dict=nt.version_info(ssid) - variables = RequestContext(request,{'ver_dict':ver_dict ,'nt':nt,'ssid':ssid,'cnt':cnt }) + ver_nbh=ver_dict['nbhood'] + ver_nbh_dict=ast.literal_eval(ver_nbh) + content=ver_dict['content'] + content=content[3:-4] + ver_nbh_dict['content']=content + + variables = RequestContext(request,{'ver_nbh_dict':ver_nbh_dict ,'nt':nt,'ssid':ssid,'version_no':version_no}) template="gstudio/display.html" return render_to_response(template,variables) -def showHistory(request,ssid): - # vid1=request.GET["group1"] - vid1=ssid - vid2=request.GET["group2"] - nt=Version.objects.get(id=vid1) - nt1=nt.object.ref +def get_version_counter(value): + counter1=str(value) + index=counter1.rfind(".") + counter1=counter1[index+1:] + version_no=int(counter1) + return version_no + + +def get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,field): + ver_new="" + ver_old="" + diffs="" + if ver_new_nbh_dict[field] or ver_old_nbh_dict[field]: + for each in ver_new_nbh_dict[field]: + ver_new+=str(each)+"," + ver_new=ver_new[0:-1] + for each in ver_old_nbh_dict[field]: + ver_old+=str(each)+"," + ver_old=ver_old[0:-1] + diffs = dmp.diff_main(ver_new, ver_old) + return diffs + +def compare_history(request,ssid): + ssid1=ssid + + version_counter1=request.GET["group1"] + version_no1=get_version_counter(version_counter1) + version_counter2=request.GET["group2"] + version_no2=get_version_counter(version_counter2) + counter2=float(version_counter2) + ssid2=int(counter2) + + ver_obj=Version.objects.get(id=ssid1) + ot=ver_obj.object.ref pp=pprint.PrettyPrinter(indent=4) - ver_new1=Version.objects.get(id=vid1) - ver_old1=Version.objects.get(id=vid2) - ver_new_dict=nt1.version_info(request.GET["group1"]) + ver_new_dict=ot.version_info(ssid1) content=str(ver_new_dict['content']) content=content[3:-4] ver_new_dict['content']=content - ver_old_dict=nt1.version_info(request.GET["group2"]) + + ver_old_dict=ot.version_info(ssid2) content=str(ver_old_dict['content']) content=content[3:-4] ver_old_dict['content']=content ver_new_nbh=ver_new_dict['nbhood'] - ver_new_dict1=ast.literal_eval(ver_new_nbh) + ver_new_nbh_dict=ast.literal_eval(ver_new_nbh) ver_old_nbh=ver_old_dict['nbhood'] - ver_old_dict1=ast.literal_eval(ver_old_nbh) - - # ver_new_nbh=ver_new_nbh.replace(",","\n") - # ver_old_nbh=ver_old_nbh.replace(",","\n") - d=[] - d1=[] - field=['Name','Plural Name','Alternate Name','Authors','Content'] - for each in ver_new_dict1: + ver_old_nbh_dict=ast.literal_eval(ver_old_nbh) + + compare_dict={} + for each in ver_new_nbh_dict: ver_new="" ver_old="" - if each =='altnames': - ver_new+=ver_new_dict['altnames'] - ver_old+=ver_old_dict['altnames'] - - diffs = dmp.diff_main(ver_new, ver_old) - d.append(dmp.diff_prettyHtml(diffs)) - # diffs = dmp.diff_main(ver_old, ver_new) - # d1.append(dmp.diff_prettyHtml(diffs)) + if each=='altnames': + if ver_new_nbh_dict['altnames'] or ver_old_nbh_dict['altnames']: + ver_new+=ver_new_nbh_dict['altnames'] + ver_old+=ver_old_nbh_dict['altnames'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['altnames']=dmp.diff_prettyHtml(diffs) + - if each =='title': - ver_new+=ver_new_dict['title'] - ver_old+=ver_old_dict['title'] - diffs = dmp.diff_main(ver_new, ver_old) - d.append(dmp.diff_prettyHtml(diffs)) - # diffs = dmp.diff_main(ver_old, ver_new) - # d1.append(dmp.diff_prettyHtml(diffs)) - if each =='plural': - ver_new+=ver_new_dict['plural'] - ver_old+=ver_old_dict['plural'] - diffs = dmp.diff_main(ver_new, ver_old) - d.append(dmp.diff_prettyHtml(diffs)) - # diffs = dmp.diff_main(ver_old, ver_new) - # d1.append(dmp.diff_prettyHtml(diffs)) - # if each =='content': + elif each=='title': + if ver_new_nbh_dict['title'] or ver_old_nbh_dict['title']: + ver_new+=ver_new_nbh_dict['title'] + ver_old+=ver_old_nbh_dict['title'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['title']=dmp.diff_prettyHtml(diffs) + elif each =='plural': + if ver_new_nbh_dict['plural'] or ver_old_nbh_dict['plural']: + ver_new+=ver_new_nbh_dict['plural'] + ver_old+=ver_old_nbh_dict['plural'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['plural']=dmp.diff_prettyHtml(diffs) + elif each =='contains_members': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['contains_members']=dmp.diff_prettyHtml(diffs) + elif each =='leftroles': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['leftroles']=dmp.diff_prettyHtml(diffs) + elif each =='ats': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['ats']=dmp.diff_prettyHtml(diffs) + elif each =='rightroles': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['rightroles']=dmp.diff_prettyHtml(diffs) + elif each =='attributes': + compare_rel_new={} + compare_rel_old={} + compare={} + for rkey,rvalue in ver_new_nbh_dict[each].items(): + ver_new="" + for relvalue in rvalue: + ver_new+=str(relvalue) + "," + ver_new=ver_new[0:-1] + compare_rel_new[str(rkey)]=ver_new + for rkey,rvalue in ver_old_nbh_dict[each].items(): + ver_old="" + for rv in rvalue: + ver_old+=str(rv) + "," + ver_old=ver_old[0:-1] + compare_rel_old[str(rkey)]=ver_old + if len(compare_rel_new) >= len(compare_rel_old): + for rkey,rvalue in compare_rel_new.items(): + if compare_rel_old.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + + else: + diffs=dmp.diff_main(compare_rel_new[str(rkey)],"") + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + for rkey,rvalue in compare_rel_old.items(): + if compare_rel_new.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + diffs=dmp.diff_main("",compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + compare_dict['attributes']=compare + + elif each =='relations': + + ver_new="" + ver_old="" + compare_rel_new={} + compare_rel_old={} + compare={} + for rkey,rvalue in ver_new_nbh_dict[each].items(): + ver_new="" + for relk,relvalue in rvalue.items(): + ver_new+=str(relk) + "," + ver_new=ver_new[0:-1] + compare_rel_new[str(rkey)]=ver_new + for rkey,rvalue in ver_old_nbh_dict[each].items(): + ver_old="" + for relk,relvalue in rvalue.items(): + ver_old+=str(relk) + "," + ver_old=ver_old[0:-1] + compare_rel_old[str(rkey)]=ver_old + if len(compare_rel_new) >= len(compare_rel_old): + for rkey,rvalue in compare_rel_new.items(): + if compare_rel_old.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + + else: + diffs=dmp.diff_main(compare_rel_new[str(rkey)],"") + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + for rkey,rvalue in compare_rel_old.items(): + if compare_rel_new.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + diffs=dmp.diff_main("",compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + compare_dict['relations']=compare + elif each =='priornodes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['priornodes']=dmp.diff_prettyHtml(diffs) + elif each =='posteriornodes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['posteriornodes']=dmp.diff_prettyHtml(diffs) + elif each =='type_of': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['type_of']=dmp.diff_prettyHtml(diffs) + elif each =='contains_subtypes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['contains_subtypes']=dmp.diff_prettyHtml(diffs) + elif each =='member_of_metatypes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['member_of_metatypes']=dmp.diff_prettyHtml(diffs) + + ver_new="" ver_old="" ver_new+=ver_new_dict['content'] ver_old+=ver_old_dict['content'] diffs = dmp.diff_main(ver_new, ver_old) - d.append(dmp.diff_prettyHtml(diffs)) - # diffs = dmp.diff_main(ver_old, ver_new) - # d1.append(dmp.diff_prettyHtml(diffs)) - - # for each in ver_new_dict1: -# ver_new="" - # ver_old="" - # ver_new+=each + ":" + str(ver_new_dict1[each]) -# ver_old+=each + ":" + str(ver_old_dict1[each]) - # diffs = dmp.diff_main(ver_new, ver_old) - # d.append(dmp.diff_prettyHtml(diffs)) - - # return HttpResponse(d) - ver_new=nt1.version_info(request.GET["group1"]) - ver_old=nt1.version_info(request.GET["group2"]) - - variables=RequestContext(request,{'nt':nt1,'ver_old':ver_old_dict,'ver_new':ver_new_dict,'diffs':d ,'vid1':vid1,'vid2':vid2 }) + compare_dict['content']=dmp.diff_prettyHtml(diffs) + ver_new_nbh_dict['content']=ver_new_dict['content'] + ver_old_nbh_dict['content']=ver_old_dict['content'] + + + + variables=RequestContext(request,{'nt':ot,'ver_old_dict':ver_old_dict,'ver_new_dict':ver_new_dict,'compare_dict':compare_dict ,'ssid1':ssid1,'ssid2':ssid2,'version_no1':version_no1,'version_no2':version_no2,'ver_new_nbh_dict':ver_new_nbh_dict,'ver_old_nbh_dict':ver_old_nbh_dict}) template="gstudio/version_diff.html" return render_to_response(template,variables) + +def set_objecttype_field(obj,ver_merge): + # setting the objecttypes fields + obj.slug = ver_merge['slug'] + obj.altnames=ver_merge['altnames'] + obj.rght = ver_merge['rght'] + obj.nodemodel = ver_merge['nodemodel'] + obj.lft = ver_merge['lft'] + obj.comment_enabled = ver_merge['comment_enabled'] + obj.title = ver_merge['title'] + obj.sites = ver_merge['sites'] + obj.content = ver_merge['content'] + obj.template = ver_merge['template'] + obj.tree_id = ver_merge['tree_id'] + obj.plural = ver_merge['plural'] + obj.status = ver_merge['status'] + obj.nid_ptr = NID.objects.get(id=ver_merge['nid_ptr']) + + # obj.nbh=ver_merge['nbh'] + obj.id = ver_merge['id'] + obj.pingback_enabled = ver_merge['pingback_enabled'] + + return obj +def set_attributetype_field(obj,ver_merge): + # setting the objecttypes fields + obj.subjecttype = NID.objects.get(id=ver_merge['nid_ptr']) + obj.applicable_nodetypes=ver_merge['applicable_nodetypes'] + obj.dataType = ver_merge['dataType'] + obj.verbose_name = ver_merge['verbose_name'] + obj.null = ver_merge['null'] + obj.blank = ver_merge['blank'] + obj.help_text = ver_merge['help_text'] + # obj.max_digits = ver_merge['max_digits'] + # obj.decimal_places = ver_merge['decimal_places'] + obj.auto_now = ver_merge['auto_now'] + obj.auto_now_add = ver_merge['auto_now_add'] + obj.upload_to = ver_merge['upload_to'] + obj.path = ver_merge['path'] + obj.verify_exists = ver_merge['verify_exists'] + # obj.min_length= ver_merge['min_length'] + obj.required= ver_merge['required'] + obj.label = ver_merge['label'] + obj.unique = ver_merge['unique'] + # obj.validators= ver_merge['validators'] + obj.default= ver_merge['default'] + obj.editable= ver_merge['editable'] + # return HttpResponse(ver_merge) + return obj +def set_relationtype_field(obj,ver_merge): + + + # setting the relationtype types fields + obj.inverse = ver_merge['inverse'] + obj.left_subjecttype=ver_merge['left_subjecttype'] + obj.left_applicable_nodetypes= ver_merge['left_applicable_nodetypes'] + obj.left_cardinality = ver_merge['left_cardinality'] + obj.right_subjecttype= ver_merge['right_subjecttype'] + obj.right_cadinality= ver_merge['right_cadinality'] + obj.right_cadinality= ver_merge['right_cadinality'] + obj.is_symmetrical= ver_merge['is_symmetrical'] + obj.is_reflexive= ver_merge['is_reflexive'] + obj.is_transitive= ver_merge['is_transitive'] + + return obj + +def set_processtype_field(obj,ver_merge): + # setting the processtype types fields + obj.changing_attributetype_set = ver_merge[''] + obj.changing_relationtype_set=ver_merge[''] + return obj + +def set_systemtype_field(obj,ver_merge): + # setting the systemtype types fields + obj.nodetype_set = ver_merge['nodetype_set'] + obj.relationtype_set=ver_merge['relationtype_set'] + obj.attributetype_set= ver_merge['attributetype_set'] + obj.metatype_set = ver_merge['metatype_set'] + obj.processtype_set= ver_merge['processtype_set'] + return obj + +def get_merge_dict(ssid1,ssid2,direction): + ver_merge={} + ot=Version.objects.get(id=ssid1) + obj=ot.object.ref + ver_left_dict=obj.version_info(ssid1) + ver_right_dict=obj.version_info(ssid2) + + + + if direction =='right': + # swap left and right + temp_dict={} + temp_dict=ver_left_dict + ver_left_dict=ver_right_dict + ver_right_dict=temp_dict + # swap ssid1 and ssid2 for managing nbhood history + temp=int(ssid1) + ssid1=int(ssid2) + ssid2=temp + ver_left_nbh_dict=ast.literal_eval(ver_left_dict['nbhood']) + ver_right_nbh_dict=ast.literal_eval(ver_right_dict['nbhood']) + # By default value of content is removed + if ver_left_dict['content']=='<br />': + ver_left_dict['content']='' + if ver_right_dict['content']=='<br />': + ver_right_dict['content']='' + # Getting merged dictionary + for each in ver_left_dict: + if ver_left_dict[each] and ver_right_dict[each]: + ver_merge[each]=ver_right_dict[each] + elif ver_left_dict[each]: + if not ver_right_dict[each]: + ver_merge[each]=ver_left_dict[each] + elif ver_right_dict[each]: + if not ver_left_dict[each]: + ver_merge[each]=ver_right_dict[each] + else: + if not ver_left_dict[each]: + if not ver_right_dict[each]: + ver_merge[each]=ver_right_dict[each] + ver_merge_nbh_dict={} + # processing nbhood for merged version + for each in ver_left_nbh_dict: + if isinstance(ver_left_nbh_dict[each],dict): + if ver_left_nbh_dict[each] and ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=dict(ver_left_nbh_dict[each].items()+ver_right_nbh_dict[each].items()) + elif ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_left_nbh_dict[each] + elif ver_right_nbh_dict[each]: + if not ver_left_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + else: + if not ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + else: + if ver_left_nbh_dict[each] and ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + elif ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_left_nbh_dict[each] + elif ver_right_nbh_dict[each]: + if not ver_left_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + else: + if not ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + + # Removing auto generated fields + del(ver_merge['start_publication']) + del(ver_merge['end_publication']) + del(ver_merge['creation_date']) + del(ver_merge['last_update']) + + history_left_list=[] + history_right_list=[] + history_merged_list=[] + + history_left_list=ver_left_nbh_dict['history'] + history_left_list.append(ssid1) + history_right_list=ver_right_nbh_dict['history'] + history_right_list.append(ssid2) + history_merged_list.append(history_left_list) + history_merged_list.append(history_right_list) + ver_merge_nbh_dict['history']=history_merged_list + + obj.nbhood = unicode(ver_merge_nbh_dict) + if isinstance(obj,Objecttype): + obj=set_objecttype_field(obj,ver_merge) + if isinstance(obj,Attributetype): + obj=set_objecttype_field(obj,ver_merge) + obj=set_attributetype_field(obj,ver_merge) + if isinstance(obj,Relationtype): + obj=set_objecttype_field(obj,ver_merge) + obj=set_relationtype_field(obj,ver_merge) + if isinstance(obj,Processtype): + obj=set_objecttype_field(obj,ver_merge) + obj=set_processtype_field(obj,ver_merge) + if isinstance(obj,Systemtype): + obj=set_objecttype_field(obj,ver_merge) + obj=set_systemtype_field(obj,ver_merge) + + + obj.save_revert_or_merge() + content=ver_merge['content'] + content=content[3:-4] + ver_merge['content']= content + return ver_merge + + +def merge_version(request,ssid1,ssid2): + direction="" + ver_merge={} + for each in request.GET: + direction=each + ot=Version.objects.get(id=ssid1) + obj=ot.object.ref + ver_merge=get_merge_dict(ssid1,ssid2,direction) + slist=[] + slist=obj.get_ssid + version_counter=len(slist) + merged_ver_ssid=slist[version_counter-1] + ver_merged_dict=obj.version_info(merged_ver_ssid) + ver_merged_nbh_dict=ast.literal_eval(ver_merged_dict['nbhood']) + ver_merged_nbh_dict['content']=ver_merge['content'] + variables = RequestContext(request,{'ver_nbh_dict':ver_merged_nbh_dict ,'nt':obj,'ssid':merged_ver_ssid,'version_no':version_counter}) + template="gstudio/display.html" + return render_to_response(template,variables) + +def revert(ssid): + ver_revert={} + ot=Version.objects.get(id=ssid) + obj=ot.object.ref + ver_revert=obj.version_info(ssid) + + # Removing auto generated fields + del(ver_revert['start_publication']) + del(ver_revert['end_publication']) + del(ver_revert['creation_date']) + del(ver_revert['last_update']) + history=[] + ver_revert_nbh_dict=ast.literal_eval(ver_revert['nbhood']) + + history=ver_revert_nbh_dict['history'] + history.append(ssid) + ver_revert_nbh_dict['history']=history + + + # ver_revert_nbh_dict['history']=ver_revert_nbh_history.append(ssid) + ver_revert['nbhood']=unicode(ver_revert_nbh_dict) + obj.nbhood=ver_revert['nbhood'] + if isinstance(obj,Objecttype): + obj=set_objecttype_field(obj,ver_revert) + if isinstance(obj,Attributetype): + obj=set_objecttype_field(obj,ver_revert) + obj=set_attributetype_field(obj,ver_revert) + if isinstance(obj,Relationtype): + obj=set_objecttype_field(obj,ver_revert) + obj=set_relationtype_field(obj,ver_revert) + if isinstance(obj,Processtype): + obj=set_objecttype_field(obj,ver_revert) + obj=set_processtype_field(obj,ver_revert) + if isinstance(obj,Systemtype): + obj=set_objecttype_field(obj,ver_revert) + obj=set_systemtype_field(obj,ver_revert) + + obj.save_revert_or_merge() + + # formatting content field + content=ver_revert['content'] + content=content[3:-4] + ver_revert['content']= content + + return ver_revert + +def revert_version(request): + ver_revert={} + for each in request.GET: + ssid=each + ssid=int(ssid) + ot=Version.objects.get(id=ssid) + obj=ot.object.ref + + ver_revert=revert(ssid) + ver_revert['nbhood'] + slist=[] + slist=obj.get_ssid + version_counter=len(slist) + revert_ver_ssid=slist[version_counter-1] + ver_revert_dict=obj.version_info(revert_ver_ssid) + ver_revert_nbh_dict=ast.literal_eval(ver_revert_dict['nbhood']) + ver_revert_nbh_dict['content']=ver_revert['content'] + + variables = RequestContext(request,{'ver_nbh_dict':ver_revert_nbh_dict ,'nt':obj,'ssid':revert_ver_ssid,'version_no':version_counter}) + template="gstudio/display.html" + return render_to_response(template,variables) + # return HttpResponse(ver_revert['nbhood']) + + diff --git a/objectapp/models.py b/objectapp/models.py index 6242b15..0d96dc5 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -97,7 +97,7 @@ from gstudio.models import Relation from gstudio.models import Node from gstudio.models import Edge from gstudio.models import Author - +import ast from objectapp.settings import UPLOAD_TO from objectapp.settings import MARKUP_LANGUAGE from objectapp.settings import GBOBJECT_TEMPLATES @@ -518,9 +518,8 @@ class Gbobject(Node): #print g_json return json.dumps(g_json) - @property - def get_relations1(self): + def get_rendered_relations(self): """ Returns all the relations of the nodetype """ @@ -544,7 +543,7 @@ class Gbobject(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 @@ -583,12 +582,26 @@ class Gbobject(Node): reltype[relation]=predicate_values relations['rrelations']=reltype return relations + @property def get_rendered_nbh(self): """ Returns the neighbourhood of the object """ fields = ['title','altname','pluralform'] + history=[] + version_list=self.get_ssid + 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['altnames'] = self.altnames @@ -614,8 +627,8 @@ class Gbobject(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={} @@ -623,9 +636,9 @@ class Gbobject(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() + relnvalue[rgtvalue.title]=rgtvalue.get_absolute_url() relrgt[rgtkey]=relnvalue @@ -636,9 +649,9 @@ class Gbobject(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() + relnvalue[lftvalue.title]=lftvalue.get_absolute_url() rellft[lftkey]=relnvalue @@ -648,7 +661,8 @@ class Gbobject(Node): #get Attributes attributes =self.get_attributes() - nbh['attributes']=attributes + nbh['attributes']=attributes + nbh['history']=history return nbh @@ -751,7 +765,9 @@ class Gbobject(Node): return '%s is a member of objecttype %s' % (self.title, each) return u'%s is not a fully defined name, consider making it a member of a suitable objecttype' % (self.title) - + @property + def ref(self): + return eval(self.nodemodel).objects.get(id=self.id) @models.permalink def get_absolute_url(self): """Return gbobject's URL""" @@ -764,16 +780,16 @@ class Gbobject(Node): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. + + def save_revert_or_merge(self, *args, **kwargs): if OBJECTAPP_VERSIONING: with reversion.create_revision(): super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. - - super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. - @property - def ref(self): - return eval(self.nodemodel).objects.get(id=self.id) - - class Meta: """Gbobject's Meta""" @@ -817,12 +833,18 @@ class Process(Gbobject): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh if OBJECTAPP_VERSIONING: with reversion.create_revision(): - super(Process, self).save(*args, **kwargs) # Call the "real" save() method. - - super(Process, self).save(*args, **kwargs) # Call the "real" save() method. - + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. + + def save_revert_or_merge(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. + class Meta: verbose_name = _('process') verbose_name_plural = _('processes') @@ -862,11 +884,19 @@ class System(Gbobject): # @reversion.create_revision() def save(self, *args, **kwargs): self.nodemodel = self.__class__.__name__ + super(System, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_rendered_nbh if OBJECTAPP_VERSIONING: with reversion.create_revision(): super(System, self).save(*args, **kwargs) # Call the "real" save() method. + + def save_revert_or_merge(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(System, self).save(*args, **kwargs) # Call the "real" save() method. - super(System, self).save(*args, **kwargs) # Call the "real" save() method. + def __unicode__(self): @@ -875,13 +905,13 @@ class System(Gbobject): if OBJECTAPP_VERSIONING == True: if not reversion.is_registered(Process): - reversion.register(Process, follow=["priorstate_attribute_set", "priorstate_relation_set", "poststate_attribute_set", "poststate_relation_set", "prior_nodes", "posterior_nodes"]) + reversion.register(Process, follow=["gbobject_ptr","priorstate_attribute_set", "priorstate_relation_set", "poststate_attribute_set", "poststate_relation_set", "prior_nodes", "posterior_nodes"]) if not reversion.is_registered(System): - reversion.register(System, follow=["systemtypes", "gbobject_set", "relation_set", "attribute_set", "process_set", "system_set", "prior_nodes", "posterior_nodes"]) + reversion.register(System, follow=["gbobject_ptr","systemtypes", "gbobject_set", "relation_set", "attribute_set", "process_set", "system_set", "prior_nodes", "posterior_nodes"]) if not reversion.is_registered(Gbobject): - reversion.register(Gbobject, follow=["objecttypes", "prior_nodes", "posterior_nodes"]) + reversion.register(Gbobject, follow=["node_ptr","objecttypes", "prior_nodes", "posterior_nodes"]) moderator.register(Gbobject, GbobjectCommentModerator) @@ -891,4 +921,4 @@ post_save.connect(ping_directories_handler, sender=Gbobject, post_save.connect(ping_external_urls_handler, sender=Gbobject, dispatch_uid='objectapp.gbobject.post_save.ping_external_urls') - + diff --git a/objectapp/templates/objectapp/base.html b/objectapp/templates/objectapp/base.html index 90e061b..b016197 100644 --- a/objectapp/templates/objectapp/base.html +++ b/objectapp/templates/objectapp/base.html @@ -40,6 +40,20 @@ {% get_objecttypes %} </div> --> +<div class="History"> + + <h3>{% trans "Versions" %}</h3> + <table border="1" cellspacing="0"> + + {% for sid in object.ref.get_ssid %} + + + <a href="/objects/display/viewhistory/{{ sid }}/{{ forloop.counter }}">{{ object.title }} {{ object.id }}.{{ forloop.counter }}</a><br> + + {% endfor %} + +</div> +<br> <div class="authors"> <h3>{% trans "Authors" %}</h3> {% get_authors %} diff --git a/objectapp/templates/objectapp/display.html b/objectapp/templates/objectapp/display.html new file mode 100644 index 0000000..7c92067 --- /dev/null +++ b/objectapp/templates/objectapp/display.html @@ -0,0 +1,609 @@ +{% load i18n comments gstudio_tags %} +{% load gstudio_tags i18n %} +{% get_tags as nodetype_tags %} +{% load adminmedia grp_tags %} + + + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xml:lang="{{ LANGUAGE_CODE }}" lang="{{ LANGUAGE_CODE }}" version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <style type="text/css"> + .link { + stroke: #ccc; + } + .nodetext { + #pointer-events: none; + font: 10px Serif; + font-style:italic; + } + .mainnode{ + + font: 15px sans-serif; + fill:"red"; + border-width: 1px; + font-weight:bold; + border-color: gray; + + } + .relnode { + font: 10px sans-serif; + font-weight:bold; + fill:#000; + } + + + .node { + border-width: 1px; + border-color: gray; + fill:"green"; + font: 10px sans-serif; + } + body { + background-color: white; + display:block; + } + #chart { + height: 90%; + margin: 0 auto; + width: 90%; + display: block; + } + svg { + margin-left: 10%; + margin-right: 10%; + display: block; + position: absolute; + } + + </style> + <!-- the header lines from grappelli --> + {% block blockbots %} + <meta name="robots" content="NONE,NOARCHIVE" /> + {% endblock %} <!-- STYLESHEETS --> + {% block stylesheets %} + <link href="{% admin_media_prefix %}css/base.css" rel="stylesheet" type="text/css" /> + {% if LANGUAGE_BIDI %} + <link href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" rel="stylesheet" type="text/css" /> + {% endif %} + <link href="{% admin_media_prefix %}jquery/ui/css/custom-theme/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" media="screen" title="no title" charset="utf-8" /> + <link href="{% admin_media_prefix %}css/jquery-ui-grappelli-extensions.css" rel="stylesheet" type="text/css" /> + {% endblock %} <!-- EXTRASTYLES --> + {% block extrastyle %}{% endblock %} <!-- JAVASCRIPTS --> + {% block javascripts %} + <script type="text/javascript"> + // GLOBALS + var grappelli = {}, + // TODO: klemens: drop ADMIN_URL + ADMIN_URL = "{% url admin:index %}", + MODEL_URL_ARRAY = {% get_content_types %}, DATE_FORMAT = "{% get_date_format %}", TIME_FORMAT = "{% get_time_format %}", DATETIME_FORMAT = "{% get_datetime_format %}"; + </script> + <!-- jQuery, jQuery-UI --> + <script src="{% admin_media_prefix %}jquery/jquery-1.6.2.min.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}jquery/ui/js/jquery-ui-1.8.15.custom.min.js" type="text/javascript"></script> + <!-- Grappelli Main JS --> + <script src="{% admin_media_prefix %}js/grappelli/grappelli.js" type="text/javascript"></script> + <!-- Grappelli jQuery Plugins, Widgets --> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible_group.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_timepicker.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_fk.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_m2m.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_generic.js" type="text/javascript"></script> + <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}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery-1.5.1.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.core.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.widget.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.tabs.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.position.min.js"></script> + + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery.ui.timepicker.js"></script> + + <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> + <script src="{{STATIC_URL}}gstudio/js/gstudio.js" type="text/javascript"></script> + <!-- EXTRAHEAD --> + {% block extrahead %}{% endblock %} + + {% endblock %} <!-- the header lines from gstudio --> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <meta http-equiv="cache-control" content="public" /> + <meta name="robots" content="follow, all" /> + <meta name="language" content="{{ LANGUAGE_CODE }}" /> + <meta name="description" content="{% block meta-description %}Demonstration of the Gstudio Blog application.{% endblock %}" /> + <meta name="keywords" content="{% block meta-keywords %}django, blog, gstudio, {{ nodetype_tags|join:", "}}{% endblock %}" /> + <meta name="author" content="gnowgi" /> + {% block meta %}{% endblock %} + <link rel="pingback" href="/xmlrpc/" /> + <link rel="shortcut icon" href="{{ STATIC_URL }}gstudio/img/favicon.ico" /> + <link rel="home" href="{% url gstudio_nodetype_archive_index %}" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/grappelli_skin_default.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen_gstudio.css" /> + <link rel="stylesheet" type="text/css" media="print" href="{{ STATIC_URL }}gstudio/css/print.css" /> + <!--[if lt IE 8]> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/ie.css" /> + <![endif]--> + {% block link %}{% endblock %} + {% block script %}{% endblock %} <title>Gnowledge Studio - {% block title %}{% endblock %}</title> + </head> + <body id="gstudio"> + <div class="body" > + <div class="content"> + <!-- + <div id="relation_type" class="ui-buttonset"> + <span>Relation type:</span> + <input checked="checked" value="follows" type="radio" id="follows" name="radio" class="ui-helper-hidden-accessible"><label for="follows" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" aria-pressed="false" role="button" aria-disabled="false"><span class="ui-button-text">Followers</span></label> + <input value="mentions" type="radio" id="mentions" name="radio" class="ui-helper-hidden-accessible"><label for="mentions" aria-pressed="true" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-state-active" role="button" aria-disabled="false"><span class="ui-button-text">Mentions</span></label> + <input value="hashtags" type="radio" id="hashtags" name="radio"/><label for="hashtags">Shared interests</label> + </div> + --> + <div id="chart"> + <svg width="960" height="700" style="opacity: 1; "> + </div> + <script type="text/javascript" src="/static/gstudio/js/jquery.min.js" ></script> + <script type="text/javascript" src="/static/gstudio/js/jquery-ui.js" ></script> + <script type="text/javascript" src="/static/gstudio/js/underscore.js" ></script> + <script type="text/javascript" src="/static/gstudio/js/d3.js"></script> + <script type="text/javascript" src="/static/gstudio/js/d3.layout.js"></script> + <script type="text/javascript" src="/static/gstudio/js/d3.geom.js"></script> + <!-- <script type="text/javascript" src="/static/gstudio/js/force.js"></script> + + Javascript for Object type force graph + --> + <script type="text/javascript" > + + var w = 700, + h = 300, + fill = d3.scale.category20(); + + var vis = d3.select("#chart") + .append("svg:svg") + .attr("width", w) + .attr("height", h); + + vis.append("svg:g").attr("class", "edges"); + vis.append("svg:g").attr("class", "nodes"); + +$(function() { + $.ajax({ + url: '/nodetypes/graphs/version_graph_json/{{ ssid }}', + //crossDomain: true, + dataType: 'json', + success : function(json) { + + //var node = NID.objects.get(slug='{{ slug }}'); + var force; + + // this contains all the nodes as a dict with _id as the key + + var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { + acc[n._id] = n; + return acc; + }, {}); + + var member_of = _(json.member_of).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'member_of'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var contains_subtypes = _(json.contains_subtypes).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'contains_subtypes'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + var contains_members = _(json.contains_members).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'contains_members'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var left_subjecttype_of = _(json.left_subjecttype_of).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'left_subjecttype_of'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var subjecttype_of = _(json.subjecttype_of).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'subjecttype_of'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + var plural = _(json.plural).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'plural'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var altnames = _(json.altnames).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'altnames'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + var content = _(json.content).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'content'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + var contains_members = _(json.contains_members).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'contains_members'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + + var type_of = _(json.type_of).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'type_of'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var right_subjecttype_of = _(json.right_subjecttype_of).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'right_subjecttype_of'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var follows_edges = _(json.is_followed_by).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'follows_edges'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + + var prior_nodes = _(json.prior_nodes).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'prior_node'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + var posterior_nodes = _(json.posterior_nodes).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'posterior_node'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + var mentions_edges = _(json.is_mentioned_by).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'mentions_edges'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); + + + nodes_by_id[{{ nt.id }}].x = w/2.0; + nodes_by_id[{{ nt.id }}].y = h/2.0; + + all_edges = new Array(); + all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of, type_of,plural,altnames,contains_members,content, prior_nodes, posterior_nodes); + /* all_edges.concat(follows_edges); + all_edges.concat(member_of_metatype); + all_edges.concat(contains_members); + all_edges.concat(contains_subtypes); + all_edges.concat(mentions_edges); + + + document.getElementById('debugbox1').value= follows_edges; //member_of_metatype + document.getElementById('debugbox2').value= mentions_edges; + //document.getElementById('debugbox2').value= member_of_metatype; + document.getElementById('debugbox3').value= all_edges; + */ + var force = d3.layout.force() + .linkStrength(0.5) + .charge(-2000) + .friction(0.7) + .gravity(0.7) + .linkDistance(13) + .nodes([]) + .links([]) + .size([w, h]) + .start(); + + function update(edges){ + // for each func + _.each(nodes_by_id, function(n){n.added = false}); + // reduce the nodes list to have only those nodes for a given rel. + nodes = _.reduce(edges, function(acc, e) { + if(nodes_by_id[e.from] && !nodes_by_id[e.from].added){ + nodes_by_id[e.from].added = true; + acc.push(nodes_by_id[e.from]); + } + if(nodes_by_id[e.to] && !nodes_by_id[e.to].added){ + nodes_by_id[e.to].added = true; + acc.push(nodes_by_id[e.to]); + } + return acc; + }, []); + + force.nodes(nodes); + force.links(edges); + force.start(); + + link = d3.select("#chart g.edges").selectAll("line.link") + .data(edges, function(e){return e.from + "-" + e.to + "-" + e.type}); + + link.enter().append("svg:line") + .attr("class", "link") + .style("stroke-width", 2 /* function(d) { + return Math.sqrt(d.value); + } */ ) + .attr("x1", function(d) { + return d.source.x; + }) + .attr("y1", function(d) { + return d.source.y; + }) + .attr("x2", function(d) { + return d.target.x; + }) + .attr("y2", function(d) { + return d.target.y; + }) + .attr("text", function(d) { + return d.type; + }) + + .append("a") + .text(function(d) { return d.type; }); + + + var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); + + var new_g = node.enter().append("svg:a") + .attr("class", function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) + .attr("xlink:href",function(d){return d.url;}) + .call(force.drag); + + + + + new_g.append("svg:circle") + .attr("cx", function(d) { return d.x - w/2.0 + 15; }) + .attr("cy", function(d) { return d.y - h/2.0 + 15; }) + .attr("r", function(d) { if (d._id=={{ nt.id }}) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 }) + .style("fill", function color(d) { if (d._id=={{ nt.id }}) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"}); + + + new_g.append("svg:text") + .attr("class",function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) + .attr("dy", 20) + .attr("dx", 25) + .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"}) + +// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"}) + + .text(function(d) { + return d.screen_name; + }); + + node.exit().remove(); + + + + force.on("tick", function() { + + var x_center = $("#chart").width() / 2; + var y_center = $("#chart").height() / 2; + + link.attr("x1", function(d) { return d.source.x; }) + .attr("y1", function(d) { return d.source.y; }) + .attr("x2", function(d) { return d.target.x; }) + .attr("y2", function(d) { return d.target.y; }); + + node.attr("transform", function(d) { return "translate(" + (d.x-16) + "," + (d.y-16) + ")"; }); + + }); + } + + update(all_edges); + vis.style("opacity", 1e-6) + .transition() + .duration(1000) + .style("opacity", 1); + + /* $('input#follows').change(function(){ + update(all_edges); + }); + */ + + /* $('input#mentions').change(function(){ + update(all_edges); + }); */ + } + }); + +// $("#relation_type").buttonset(); + +// $('input#mentions').change(function(){console.log(this)}); +// $('input#follows').change(function(){console.log(this)}); +}); + + +</script> + </div> +</div> + + + +<div> + {% include "gstudio/_header.html" %} + <div id="breadcrumbs" class="span-24 last"> + / {% block breadcrumbs %}{% endblock %} + </div> + <div id="body" class="span-24 last" > + <div id="content" class="hfeed span-16 border"> + <h3>{% block content %} + {% block nodetype-content %} + <h2 class="nodetype-title"> + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_nbh_dict.title }} {{ nt.id }}.{{ version_no }} + </a> + </h2> + {% with nt.html_content|safe as object_content %} + <b>Name:<nbsp></b> {{ ver_nbh_dict.title }} <br/> + + {% if ver_nbh_dict.plural %} + <b> Plural Name:<nbsp></b> + {{ ver_nbh_dict.plural}} <br/> + {% endif %} + {% if ver_nbh_dict.altnames %} + <b> Alternate names:<nbsp></b> + {{ ver_nbh_dict.altnames}} <br/> + {% endif %} + {% if ver_nbh_dict.member_of %} + <b> Member of :<nbsp></b> + + {% for mkey,mvalue in ver_nbh_dict.member_of.items %} + <a href="{{mvalue}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + {% if ver_nbh_dict.relations %} + + + {% for relkey,relvalue in ver_nbh_dict.relations.items %} + <b>{{relkey}}:<nbsp></b> + {% for relk, relv in relvalue.items %} + <a href="{{relv}}">{{relk}}</a>; + {% endfor %}<br/> + {% endfor %} + + {% endif %} + + {% if ver_nbh_dict.attributes %} + {% for atkey,atvalue in ver_nbh_dict.attributes.items %} + {% if atvalue %} + <b> {{atkey}}:<nbsp></b> + + {% for items in atvalue %} + {{items}};<nbsp> + {% endfor %} + {% endif %}<br/> + {% endfor %} + {% endif %} + <b>Authors: <nbsp> </b> + {% for author in nt.authors.all %} + <span class="vcard author"> + <a href="{% url gstudio_author_detail author %}" class="fn nickname url" rel="author" + title="{% blocktrans with author as author %}Show {{ author }} nodetypes{% endblocktrans %}">{{ author }}</a> + </span>{% if not forloop.last %}, {% endif %} + {% endfor %} <br/> + + + + + + {% endwith %} + {% endblock %} + {% endblock %} +</div> + + <div id="sidebar"> + {% block sidebar %} + + <div class="History"> + + <h3>{% trans "Versions" %}</h3> + + <form name="history" action="/objects/display/compare_history/{{ ssid }}" > + <table cellspacing="0" border="2"> + <tr> + <td> <input type="radio" name="group1" value="{{ ssid }}.{{ version_no }}" checked >{{ nt.id }}.{{ version_no }}</input></td> + <td></td></tr> + + {% for sid in nt.get_ssid %} + + {% if sid|stringformat:"s" != ssid|stringformat:"s" %} + <tr> + <td> + </td> + <td> + + <input type="radio" id="{{ sid }}"name="group2" value="{{ sid }}.{{ forloop.counter }}" >{{ nt.id }}.{{ forloop.counter }}</input> + </td></tr>{% endif %} + {% endfor %}</table> + <input type="submit" value="Compare" /> + </form> + + + </div> + + + {% endblock %} + </div> + + + <div id="footer" class="span-24 last" style="height: 5px; display:none; top: 51px; left: 88px; width: 1364px;"> + <p> + <a rel="license" + href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative + Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png"/></a> All material is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a> unless mentioned otherwise. + <br/> + Powered by <a href="http://www.djangoproject.com">Django</a> + and <a href="http://github.com/gnowgi/django-gstudio">Gstudio + {{ GSTUDIO_VERSION }}</a>. + </p> + </div> + </div> + </div> + </body> +</html> + diff --git a/objectapp/templates/objectapp/gbobject_list.html b/objectapp/templates/objectapp/gbobject_list.html index 73a3adf..3bc34a8 100644 --- a/objectapp/templates/objectapp/gbobject_list.html +++ b/objectapp/templates/objectapp/gbobject_list.html @@ -1,4 +1,4 @@ -{% extends "objectapp/base.html" %} +{% extends "objectapp/version_base.html" %} {% load i18n objectapp_tags %} {% block meta-description %}{% trans "Latest gbobjects for" %} {% if Objecttype %}{% trans "the Objecttype" %} {{ Objecttype }}{% if Objecttype.description %}: {{ Objecttype.description|striptags|safe }}{% endif %}{% endif %}{% if tag %}{% trans "the tag" %} {{ tag }}{% endif %}{% if author %}{% trans "the author" %} {{ author }}{% endif %}{% if page_obj %}{% ifnotequal page_obj.number 1 %} {% trans "page" %} {{ page_obj.number }}{% endifnotequal %}{% endif %}{% endblock %} diff --git a/objectapp/templates/objectapp/version_base.html b/objectapp/templates/objectapp/version_base.html new file mode 100644 index 0000000..6972c9e --- /dev/null +++ b/objectapp/templates/objectapp/version_base.html @@ -0,0 +1,129 @@ +{% extends "gstudio/skeleton.html" %} +{% load gstudio_tags i18n %} +{% load objectapp_tags i18n %} + + {% block meta %} + <meta name="generator" content="Objectapp {{ OBJECTAPP_VERSION }}" /> +{% endblock %} + +{% block link %} + <link rel="index" href="{% url objectapp_gbobject_archive_index %}" /> + <link rel="EditURI" type="application/rsd+xml" href="{% url objectapp_rsd %}" /> + <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="{% url objectapp_wlwmanifest %}" /> + <link rel="search" type="application/opensearchdescription+xml" title="Objectapp's Blog" href="{% url objectapp_opensearch %}" /> + <link rel="alternate" type="application/rss+xml" title="{% trans "RSS Feed of latest gbobjects" %}" href="{% url objectapp_gbobject_latest_feed %}" /> + <!-- {% get_archives_gbobjects "objectapp/tags/archives_gbobjects_link.html" %} --> +{% endblock %} + +{% block breadcrumbs %} + {% gstudio_breadcrumbs %} +{% endblock %} + +{% block sidebar %} + <img src="{{ STATIC_URL }}objectapp/img/rss.png" alt="?" width="20" height="" /> + <a href="{% url objectapp_gbobject_latest_feed %}" class="feeds"><h4>Rssfeed</h4></a> + +<div class="search"> + <h3>{% trans "Search" %}</h3> + <form method="get" id="searchform" action="{% url nodes_search %}"> + <p> + <input type="text" value="{% trans "Keywords..." %}" name="pattern" id="searchbox" onfocus="this.value=''" /> + <input type="submit" class="submitbutton" value="OK" /> + <a title="{% trans 'You can use - to exclude words or phrases, "double quotes" for exact phrases and the AND/OR boolean operators combined with parenthesis for complex searchs.' %}"> + <img src="{{ STATIC_URL }}objectapp/img/help.png" alt="?" width="14" height="14" /> + </a> + </p> + </form> +</div> +<!-- +<div class="objecttypes"> + <h3>{% trans "Objecttypes" %}</h3> + {% get_objecttypes %} +</div> +--> +<div class="History"> + <!-- <script type="text/javascript"> --> + <!-- function go_to_loc(sid) --> + <!-- { --> + <!-- window.location.href = "{{ object.get_version_url }}"+sid --> + <!-- } --> + + <!-- </script> --> +<!-- <h3>{% trans "Versions" %}</h3> --> +<!-- {% for sid in object.get_ssid reversed %} --> +<!-- <input type="radio" name="group1" value="{{ sid }}"><a href="{{ object.get_version_url }}{{ sid }}">{{ sid }}</a></input> --> +<!-- <input type="radio" name="group2" value="{{ sid }}">{{ sid }}</input> --> +<!-- <br> --> +<!-- {% endfor %} --> +<!-- <br> --> +<!-- <input type="submit" value="Compare" /> --> +<!-- </div> --> +<!-- <br> --> + +<div class="authors"> + <h3>{% trans "Authors" %}</h3> + {% get_authors %} +</div> +<div class="calendar"> + <h3>{% trans "Calendar" %}</h3> + {% get_calendar_gbobjects %} +</div> +<div class="tags"> + <h3>{% trans "Tags" %}</h3> + {% get_tag_cloud %} +</div> +<div class="recents"> + <h3>{% trans "Recent gbobjects" %}</h3> + {% get_recent_gbobjects 5 %} +</div> +<div class="comments"> + <h3>{% trans "Recent comments" %}</h3> + {% get_recent_comments 5 %} +</div> +<div class="linkbacks"> + <h3>{% trans "Recent linkbacks" %}</h3> + {% get_recent_linkbacks 5 %} +</div> +<div class="randoms"> + <h3>{% trans "Random gbobjects" %}</h3> + {% get_random_gbobjects 5 %} +</div> +<div class="populars"> + <h3>{% trans "Popular gbobjects" %}</h3> + {% get_popular_gbobjects 5 %} +</div> +<div class="archives"> + <h3>{% trans "Archives" %}</h3> + {% get_archives_gbobjects_tree %} +</div> +{% if user.is_authenticated %} +<div class="tools"> + <h3>{% trans "Tools" %}</h3> + <ul> + {% if perms.objectapp %} + <li> + <a href="{% url admin:app_list "objectapp" %}" title="{% trans "Dashboard" %}"> + {% trans "Dashboard" %} + </a> + </li> + {% endif %} + {% if perms.objectapp.add_gbobject %} + <li> + <a href="{% url admin:objectapp_gbobject_add %}" title="{% trans "Post an gbobject" %}"> + {% trans "Post an gbobject" %} + </a> + </li> + {% endif %} + {% block admin_tools %} + {% endblock %} + <li> + <a href="{% url admin:logout %}" title="{% trans "Log out" %}"> + {% trans "Log out" %} + </a> + </li> + </ul> +</div> +{% endif %} +{% endblock %} + + diff --git a/objectapp/templates/objectapp/version_diff.html b/objectapp/templates/objectapp/version_diff.html new file mode 100644 index 0000000..a552b5c --- /dev/null +++ b/objectapp/templates/objectapp/version_diff.html @@ -0,0 +1,262 @@ + +{% load i18n comments gstudio_tags %} +{% load gstudio_tags i18n %} +{% get_tags as nodetype_tags %} +{% load adminmedia grp_tags %} + + +{% load gstudio_tags i18n %} +{% get_tags as nodetype_tags %} +{% load adminmedia grp_tags %} +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xml:lang="{{ LANGUAGE_CODE }}" lang="{{ LANGUAGE_CODE }}" version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <style type="text/css"> + body { + background-color: white; + display:block; + } + .content + { + } + .content1 + { + } + </style> + {% block blockbots %} + <meta name="robots" content="NONE,NOARCHIVE" /> + {% endblock %} <!-- STYLESHEETS --> + {% block stylesheets %} + <link href="{% admin_media_prefix %}css/base.css" rel="stylesheet" type="text/css" /> + {% if LANGUAGE_BIDI %} + <link href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" rel="stylesheet" type="text/css" /> + {% endif %} + <link href="{% admin_media_prefix %}jquery/ui/css/custom-theme/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" media="screen" title="no title" charset="utf-8" /> + <link href="{% admin_media_prefix %}css/jquery-ui-grappelli-extensions.css" rel="stylesheet" type="text/css" /> + {% endblock %} <!-- EXTRASTYLES --> + {% block extrastyle %}{% endblock %} <!-- JAVASCRIPTS --> + {% block javascripts %} + <script type="text/javascript"> + // GLOBALS + var grappelli = {}, + // TODO: klemens: drop ADMIN_URL + ADMIN_URL = "{% url admin:index %}", + MODEL_URL_ARRAY = {% get_content_types %}, DATE_FORMAT = "{% get_date_format %}", TIME_FORMAT = "{% get_time_format %}", DATETIME_FORMAT = "{% get_datetime_format %}"; + </script> + <!-- jQuery, jQuery-UI --> + <script src="{% admin_media_prefix %}jquery/jquery-1.6.2.min.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}jquery/ui/js/jquery-ui-1.8.15.custom.min.js" type="text/javascript"></script> + <!-- Grappelli Main JS --> + <script src="{% admin_media_prefix %}js/grappelli/grappelli.js" type="text/javascript"></script> + <!-- Grappelli jQuery Plugins, Widgets --> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_collapsible_group.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_timepicker.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_fk.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_m2m.js" type="text/javascript"></script> + <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_related_generic.js" type="text/javascript"></script> + <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}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery-1.5.1.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.core.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.widget.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.tabs.min.js"></script> + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery-ui-timepicker-0.2.9/include/jquery.ui.position.min.js"></script> + + <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/jquery.ui.timepicker.js"></script> + + <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> + <script src="{{STATIC_URL}}gstudio/js/gstudio.js" type="text/javascript"></script> + <!-- EXTRAHEAD --> + {% block extrahead %}{% endblock %} + + {% endblock %} + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <meta http-equiv="cache-control" content="public" /> + <meta name="robots" content="follow, all" /> + <meta name="language" content="{{ LANGUAGE_CODE }}" /> + <meta name="description" content="{% block meta-description %}Demonstration of the Gstudio Blog application.{% endblock %}" /> + <meta name="keywords" content="{% block meta-keywords %}django, blog, gstudio, {{ nodetype_tags|join:", "}}{% endblock %}" /> + <meta name="author" content="gnowgi" /> + {% block meta %}{% endblock %} + <link rel="pingback" href="/xmlrpc/" /> + <link rel="shortcut icon" href="{{ STATIC_URL }}gstudio/img/favicon.ico" /> + <link rel="home" href="{% url gstudio_nodetype_archive_index %}" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/grappelli_skin_default.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen.css" /> + <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}gstudio/css/screen_gstudio.css" /> + <link rel="stylesheet" type="text/css" media="print" href="{{ STATIC_URL }}gstudio/css/print.css" /> + {% block link %}{% endblock %} + {% block script %}{% endblock %} <title>Gnowledge Studio - {% block title %}{% endblock %}</title> + </head> + <body id="gstudio"> + + + + + + + {% include "gstudio/_header.html" %} + <div id="breadcrumbs" class="span-24 last"> + / {% block breadcrumbs %}{% endblock %} + </div> + <!-- <div id="body" class="span-24 last" > --> + <table border="0" > + <tr><td> + + <h3>{% block content %} + {% block nodetype-content %} + <h2 class="nodetype-title"> + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_new_dict.title }} {{ nt.id }}.{{ version_no1 }} + </a> + </h2> + + {% with nt.html_content|safe as object_content %}<br> + + <b>Name:<nbsp></b> {{ ver_new_nbh_dict.title }} <br/> + + {% if ver_new_nbh_dict.plural or ver_old_nbh_dict.plural %} + <b> Plural Name:<nbsp></b> + {{ ver_new_nbh_dict.plural}} <br/> + {% endif %} + {% if ver_new_nbh_dict.altnames or ver_old_nbh_dict.altnames%} + <b> Alternate names:<nbsp></b> + {{ ver_new_nbh_dict.altnames}} <br/> + {% endif %} + {% if ver_new_nbh_dict.member_of or ver_old_nbh_dict.member_of %} + <b> Member of :<nbsp></b> + + {% for mkey,mvalue in ver_new_nbh_dict.member_of.items %} + <a href="{{mvalue}}">{{mkey}}</a>; + {% endfor %}<br/> + {% endif %} + + {% if ver_new_nbh_dict.relations or ver_old_nbh_dict.relations %} + + {% for relkey,relvalue in ver_new_nbh_dict.relations.items %} + <b>{{relkey}}:<nbsp></b> + {% for relk, relv in relvalue.items %} + <a href="{{relv}}">{{relk}}</a>; + {% endfor %}<br/> + {% endfor %} + + {% endif %} + + {% if ver_new_nbh_dict.attributes or ver_old_nbh_dict.attributes%} + {% for atkey,atvalue in ver_new_nbh_dict.attributes.items %} + {% if atvalue %} + <b> {{atkey}}:<nbsp></b> + + {% for items in atvalue %} + {{items}};<nbsp> + {% endfor %} + {% endif %}<br/> + {% endfor %} + {% endif %} + {% if ver_new_nbh_dict.content or ver_old_nbh_dict.content %} + <b> Content:<nbsp></b>{{ ver_new_nbh_dict }} <br/> + {% endif %} + + + {% endwith %} + {% endblock %} + {% endblock %} + + </td> + <td> + + <h3>{% block content1 %} + {% block nodetype-content1 %} + <h2 class="nodetype-title"> + <a href="{{ nt.get_absolute_url }}" title="{{ nt.title }}" rel="bookmark">{{ ver_old_dict.title }} {{ nt.id }}.{{ version_no2 }} + </a> + </h2> <br> + {% with nt.html_content|safe as object_content %} + + <b>Name:<nbsp></b>{% autoescape off %} + {{ compare_dict.title }} + {% endautoescape %}<br> + {% if ver_old_nbh_dict.plural or ver_new_nbh_dict.plural %} + <b> Plural Name:<nbsp></b> {% autoescape off %} + {{ compare_dict.plural }} + {% endautoescape %} <br/> + {% endif %} + {% if ver_old_nbh_dict.altnames or ver_new_nbh_dict.altnames %} + <b> Alternate names:<nbsp></b> {% autoescape off %} + {{ compare_dict.altnames }} + {% endautoescape %} + <br/> + {% endif %} + {% if ver_new_nbh_dict.member_of or ver_old_nbh_dict.member_of %} + <b> Member of:<nbsp></b> {% autoescape off %} + {{ compare_dict.member_of }} + {% endautoescape %} + <br/> + {% endif %} + + {% if ver_new_nbh_dict.relations or ver_old_nbh_dict.relations %} + {% for relkey,relvalue in compare_dict.relations.items %} + <b>{{relkey}}:<nbsp></b> + {% autoescape off %} + + + {{ relvalue }} + + + {% endautoescape %} + <br/> + {% endfor %} + + {% endif %} + + {% if ver_old_nbh_dict.attributes or ver_new_nbh_dict.attributes %} + {% for relkey,revalue in compare_dict.attributes.items %} + <b>{{relkey}}:<nbsp></b> + {% autoescape off %} + + + {{ revalue }} + + + {% endautoescape %} + <br/> + {% endfor %} + + {% endif %} + + + {% if ver_new_nbh_dict.ats or ver_old_nbh_dict.ats %} + + + <b>Subjecttype of:<nbsp> </b> {% autoescape off %} + {{ compare_dict.ats }} + {% endautoescape %}<br> + {% endif %} + {% if ver_new_nbh_dict.content or ver_old_nbh_dict.content %} + <b> Content:<nbsp></b> {% autoescape off %} + {{ compare_dict.content }} + {% endautoescape %} <br/> + {% endif %} + {% endwith %} + {% endblock %} + {% endblock %} +<br> +</td></tr> +<tr><td> +<form method="get" action="/objects/display/merge/{{ ssid1 }}/{{ ssid2 }}"> +<input type="submit" value="Merge {{ nt.id }}.{{ version_no1 }} with {{ nt.id }}.{{ version_no2 }}" id="merge1" name="left" ></input></td> +<td><input type="submit" value="Merge {{ nt.id }}.{{ version_no2 }} with {{ nt.id }}.{{ version_no1 }}" id="merge2" name="right"></input></td></form> +</tr> +<tr><td> +<form method="get" action="/objects/display/revert" > +<input type="submit" value="Revert" name="{{ ssid1 }}"></input></td> +<td><input type="submit" value="Revert" name="{{ ssid2 }}"></input></td> +</form></tr> +</table> +</body> +</html> + + + + diff --git a/objectapp/urls/__init__.py b/objectapp/urls/__init__.py index 1406f49..12cffc5 100644 --- a/objectapp/urls/__init__.py +++ b/objectapp/urls/__init__.py @@ -78,6 +78,7 @@ urlpatterns = patterns( url(r'^trackback/', include('objectapp.urls.trackback')), url(r'^discussions/', include('objectapp.urls.discussions')), url(r'^add/', include('objectapp.urls.add')), + url(r'^display/',include('objectapp.urls.history')), url(r'^', include('objectapp.urls.quick_gbobject')), url(r'^', include('objectapp.urls.capabilities')), url(r'^', include('objectapp.urls.gbobjects')), diff --git a/objectapp/urls/history.py b/objectapp/urls/history.py new file mode 100644 index 0000000..83e5345 --- /dev/null +++ b/objectapp/urls/history.py @@ -0,0 +1,10 @@ +"""Urls for Gstudio forms""" +from django.conf.urls.defaults import url +from django.conf.urls.defaults import patterns + +urlpatterns = patterns('objectapp.views.history', + url(r'^viewhistory/(?P<ssid>\d+)/(?P<version_no>\d+)/$', 'history', + name='gstudio_history'), + url(r'^compare_history/(?P<ssid>\d+)/$','compare_history'), + url(r'^merge/(?P<ssid1>\d+)/(?P<ssid2>\d+)/$','merge_version'), + url(r'^revert/$','revert_version'),) diff --git a/objectapp/views/history.py b/objectapp/views/history.py new file mode 100644 index 0000000..e5e2ff1 --- /dev/null +++ b/objectapp/views/history.py @@ -0,0 +1,436 @@ +from django.http import * +from reversion.models import * +from gstudio.models import * +from django.template import RequestContext +from django.shortcuts import render_to_response +from django.views.generic.date_based import object_detail +from reversion.helpers import * +import pprint +from gstudio.models import * +from reversion.models import * +from gstudio.views.decorators import protect_nodetype +from gstudio.views.decorators import update_queryset +import ast +from objectapp.models import * + +def history(request,ssid,version_no): + # iden=request.GET["id"] + nt1=Version.objects.get(id=ssid) + nt=nt1.object.ref + ver_dict=nt.version_info(ssid) + ver_nbh=ver_dict['nbhood'] + ver_nbh_dict=ast.literal_eval(ver_nbh) + content=ver_dict['content'] + content=content[3:-4] + ver_nbh_dict['content']=content + + variables = RequestContext(request,{'ver_nbh_dict':ver_nbh_dict ,'nt':nt,'ssid':ssid,'version_no':version_no}) + template="objectapp/display.html" + return render_to_response(template,variables) + +def get_version_counter(value): + counter1=str(value) + index=counter1.rfind(".") + counter1=counter1[index+1:] + version_no=int(counter1) + return version_no + + +def get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,field): + ver_new="" + ver_old="" + diffs="" + ver_new_dict={} + ver_old_dict={} + + if ver_new_nbh_dict[field] or ver_old_nbh_dict[field]: +# if isinstance(ver_new_nbh_dict[field],dict): + for each in ver_new_nbh_dict[field]: + #ver_new=ver_new_dict[each]= + ver_new+=str(each)+"," + ver_new=ver_new[0:-1] + for each in ver_old_nbh_dict[field]: + ver_old+=str(each)+"," + ver_old=ver_old[0:-1] + diffs = dmp.diff_main(ver_new, ver_old) + return diffs + +def get_diff_from_nested_dict(ver_new_nbh_dict,ver_old_nbh_dict,field): + + + return compare +def compare_history(request,ssid): + ssid1=ssid + + version_counter1=request.GET["group1"] + version_no1=get_version_counter(version_counter1) + version_counter2=request.GET["group2"] + version_no2=get_version_counter(version_counter2) + counter2=float(version_counter2) + ssid2=int(counter2) + + ver_obj=Version.objects.get(id=ssid1) + ot=ver_obj.object.ref + pp=pprint.PrettyPrinter(indent=4) + + ver_new_dict=ot.version_info(ssid1) + content=str(ver_new_dict['content']) + content=content[3:-4] + ver_new_dict['content']=content + + ver_old_dict=ot.version_info(ssid2) + content=str(ver_old_dict['content']) + content=content[3:-4] + ver_old_dict['content']=content + + ver_new_nbh=ver_new_dict['nbhood'] + ver_new_nbh_dict=ast.literal_eval(ver_new_nbh) + + ver_old_nbh=ver_old_dict['nbhood'] + ver_old_nbh_dict=ast.literal_eval(ver_old_nbh) + + compare_dict={} + for each in ver_new_nbh_dict: + ver_new="" + ver_old="" + if each=='altnames': + if ver_new_nbh_dict['altnames'] or ver_old_nbh_dict['altnames']: + ver_new+=ver_new_nbh_dict['altnames'] + ver_old+=ver_old_nbh_dict['altnames'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['altnames']=dmp.diff_prettyHtml(diffs) + + + elif each=='title': + if ver_new_nbh_dict['title'] or ver_old_nbh_dict['title']: + ver_new+=ver_new_nbh_dict['title'] + ver_old+=ver_old_nbh_dict['title'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['title']=dmp.diff_prettyHtml(diffs) + elif each =='plural': + if ver_new_nbh_dict['plural'] or ver_old_nbh_dict['plural']: + ver_new+=ver_new_nbh_dict['plural'] + ver_old+=ver_old_nbh_dict['plural'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['plural']=dmp.diff_prettyHtml(diffs) + elif each =='member_of': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['member_of']=dmp.diff_prettyHtml(diffs) + elif each =='leftroles': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['leftroles']=dmp.diff_prettyHtml(diffs) + elif each =='ats': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['ats']=dmp.diff_prettyHtml(diffs) + elif each =='rightroles': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['rightroles']=dmp.diff_prettyHtml(diffs) + elif each =='attributes': + + compare_rel_new={} + compare_rel_old={} + compare={} + for rkey,rvalue in ver_new_nbh_dict[each].items(): + ver_new="" + for relvalue in rvalue: + ver_new+=str(relvalue) + "," + ver_new=ver_new[0:-1] + compare_rel_new[str(rkey)]=ver_new + for rkey,rvalue in ver_old_nbh_dict[each].items(): + ver_old="" + for rv in rvalue: + ver_old+=str(rv) + "," + ver_old=ver_old[0:-1] + compare_rel_old[str(rkey)]=ver_old + if len(compare_rel_new) >= len(compare_rel_old): + for rkey,rvalue in compare_rel_new.items(): + if compare_rel_old.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + + else: + diffs=dmp.diff_main(compare_rel_new[str(rkey)],"") + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + for rkey,rvalue in compare_rel_old.items(): + if compare_rel_new.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + diffs=dmp.diff_main("",compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + compare_dict['attributes']=compare + + elif each =='relations': + ver_new="" + ver_old="" + compare_rel_new={} + compare_rel_old={} + compare={} + for rkey,rvalue in ver_new_nbh_dict[each].items(): + ver_new="" + for relk,relvalue in rvalue.items(): + ver_new+=str(relk) + "," + ver_new=ver_new[0:-1] + compare_rel_new[str(rkey)]=ver_new + for rkey,rvalue in ver_old_nbh_dict[each].items(): + ver_old="" + for relk,relvalue in rvalue.items(): + ver_old+=str(relk) + "," + ver_old=ver_old[0:-1] + compare_rel_old[str(rkey)]=ver_old + if len(compare_rel_new) >= len(compare_rel_old): + for rkey,rvalue in compare_rel_new.items(): + if compare_rel_old.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + + else: + diffs=dmp.diff_main(compare_rel_new[str(rkey)],"") + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + for rkey,rvalue in compare_rel_old.items(): + if compare_rel_new.has_key(rkey): + diffs=dmp.diff_main(compare_rel_new[str(rkey)],compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + else: + diffs=dmp.diff_main("",compare_rel_old[str(rkey)]) + compare[str(rkey)]=dmp.diff_prettyHtml(diffs) + compare_dict['relations']=compare + elif each =='priornodes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['priornodes']=dmp.diff_prettyHtml(diffs) + elif each =='posteriornodes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['posteriornodes']=dmp.diff_prettyHtml(diffs) + elif each =='type_of': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['type_of']=dmp.diff_prettyHtml(diffs) + elif each =='contains_subtypes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['contains_subtypes']=dmp.diff_prettyHtml(diffs) + elif each =='member_of_metatypes': + diffs=get_diff_from_dict(ver_new_nbh_dict,ver_old_nbh_dict,each) + compare_dict['member_of_metatypes']=dmp.diff_prettyHtml(diffs) + + + ver_new="" + ver_old="" + ver_new+=ver_new_dict['content'] + ver_old+=ver_old_dict['content'] + diffs = dmp.diff_main(ver_new, ver_old) + compare_dict['content']=dmp.diff_prettyHtml(diffs) + ver_new_nbh_dict['content']=ver_new_dict['content'] + ver_old_nbh_dict['content']=ver_old_dict['content'] + + + + variables=RequestContext(request,{'nt':ot,'ver_old_dict':ver_old_dict,'ver_new_dict':ver_new_dict,'compare_dict':compare_dict ,'ssid1':ssid1,'ssid2':ssid2,'version_no1':version_no1,'version_no2':version_no2,'ver_new_nbh_dict':ver_new_nbh_dict,'ver_old_nbh_dict':ver_old_nbh_dict}) + template="objectapp/version_diff.html" + return render_to_response(template,variables) + + +def get_merge_dict(ssid1,ssid2,direction): + ver_merge={} + ot=Version.objects.get(id=ssid1) + obj=ot.object.ref + ver_left_dict=obj.version_info(ssid1) + ver_right_dict=obj.version_info(ssid2) + + + + if direction =='right': + # swap left and right + temp_dict={} + temp_dict=ver_left_dict + ver_left_dict=ver_right_dict + ver_right_dict=temp_dict + # swap ssid1 and ssid2 for managing nbhood history + temp=int(ssid1) + ssid1=int(ssid2) + ssid2=temp + ver_left_nbh_dict=ast.literal_eval(ver_left_dict['nbhood']) + ver_right_nbh_dict=ast.literal_eval(ver_right_dict['nbhood']) + # By default value of content is removed + if ver_left_dict['content']=='<br />': + ver_left_dict['content']='' + if ver_right_dict['content']=='<br />': + ver_right_dict['content']='' + # Getting merged dictionary + for each in ver_left_dict: + if ver_left_dict[each] and ver_right_dict[each]: + ver_merge[each]=ver_right_dict[each] + elif ver_left_dict[each]: + if not ver_right_dict[each]: + ver_merge[each]=ver_left_dict[each] + elif ver_right_dict[each]: + if not ver_left_dict[each]: + ver_merge[each]=ver_right_dict[each] + elif not ver_left_dict[each]: + if not ver_right_dict[each]: + ver_merge[each]='' + ver_merge_nbh_dict={} + # processing nbhood for merged version + for each in ver_left_nbh_dict: + if isinstance(ver_left_nbh_dict[each],dict): + if ver_left_nbh_dict[each] and ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=dict(ver_left_nbh_dict[each].items()+ver_right_nbh_dict[each].items()) + elif ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_left_nbh_dict[each] + elif ver_right_nbh_dict[each]: + if not ver_left_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + else: + if not ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + else: + if ver_left_nbh_dict[each] and ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + elif ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_left_nbh_dict[each] + elif ver_right_nbh_dict[each]: + if not ver_left_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + else: + if not ver_left_nbh_dict[each]: + if not ver_right_nbh_dict[each]: + ver_merge_nbh_dict[each]=ver_right_nbh_dict[each] + + # Removing auto generated fields + del(ver_merge['start_publication']) + del(ver_merge['end_publication']) + del(ver_merge['creation_date']) + del(ver_merge['last_update']) + + history_left_list=[] + history_right_list=[] + history_merged_list=[] + + history_left_list=ver_left_nbh_dict['history'] + history_left_list.append(ssid1) + history_right_list=ver_right_nbh_dict['history'] + history_right_list.append(ssid2) + history_merged_list.append(history_left_list) + history_merged_list.append(history_right_list) + ver_merge_nbh_dict['history']=history_merged_list + obj.nbhood = unicode(ver_merge_nbh_dict) + + # setting the objecttypes fields + obj.slug = ver_merge['slug'] + obj.altnames=ver_merge['altnames'] + obj.nodemodel = ver_merge['nodemodel'] + obj.comment_enabled = ver_merge['comment_enabled'] + obj.title = ver_merge['title'] + obj.sites = ver_merge['sites'] + obj.content = ver_merge['content'] + obj.template = ver_merge['template'] + + obj.plural = ver_merge['plural'] + obj.status = ver_merge['status'] + obj.nid_ptr = NID.objects.get(id=ver_merge['nid_ptr']) + obj.nbhood = ver_merge_nbh_dict + # obj.nbh=ver_merge['nbh'] + obj.id = ver_merge['id'] + obj.pingback_enabled = ver_merge['pingback_enabled'] + obj.save_revert_or_merge() + # formatting content field + content=ver_merge['content'] + content=content[3:-4] + ver_merge['content']= content + + return ver_merge + + +def merge_version(request,ssid1,ssid2): + direction="" + ver_merge={} + for each in request.GET: + direction=each + ot=Version.objects.get(id=ssid1) + obj=ot.object.ref + ver_merge=get_merge_dict(ssid1,ssid2,direction) + slist=[] + slist=obj.get_ssid + version_counter=len(slist) + merged_ver_ssid=slist[version_counter-1] + ver_merged_dict=obj.version_info(merged_ver_ssid) + ver_merged_nbh_dict=ast.literal_eval(ver_merged_dict['nbhood']) + ver_merged_nbh_dict['content']=ver_merge['content'] + variables = RequestContext(request,{'ver_nbh_dict':ver_merged_nbh_dict ,'nt':obj,'ssid':merged_ver_ssid,'version_no':version_counter}) + template="objectapp/display.html" + return render_to_response(template,variables) + +def revert(ssid): + ver_revert={} + ot=Version.objects.get(id=ssid) + obj=ot.object.ref + ver_revert=obj.version_info(ssid) + + # Removing auto generated fields + del(ver_revert['start_publication']) + del(ver_revert['end_publication']) + del(ver_revert['creation_date']) + del(ver_revert['last_update']) + + # setting nbhood history + history=[] + ver_revert_nbh_dict=ast.literal_eval(ver_revert['nbhood']) + + history=ver_revert_nbh_dict['history'] + history.append(ssid) + ver_revert_nbh_dict['history']=history + + # setting the revert version fields + obj.slug = ver_revert['slug'] + obj.altnames=ver_revert['altnames'] + + obj.nodemodel = ver_revert['nodemodel'] + + obj.comment_enabled = ver_revert['comment_enabled'] + obj.title = ver_revert['title'] + obj.sites = ver_revert['sites'] + obj.content = ver_revert['content'] + obj.template = ver_revert['template'] + + obj.plural = ver_revert['plural'] + obj.status = ver_revert['status'] + obj.nid_ptr = NID.objects.get(id=ver_revert['nid_ptr']) + obj.nbhood = unicode(ver_revert_nbh_dict) + # obj.nbh=ver_revert['nbh'] + obj.id = ver_revert['id'] + obj.pingback_enabled = ver_revert['pingback_enabled'] + obj.save_revert_or_merge() + # formatting content field + content=ver_revert['content'] + content=content[3:-4] + ver_revert['content']= content + + return ver_revert + +def revert_version(request): + ver_revert={} + for each in request.GET: + ssid=each + ssid=int(ssid) + ot=Version.objects.get(id=ssid) + obj=ot.object.ref + + ver_revert=revert(ssid) + ver_revert['nbhood'] + slist=[] + slist=obj.get_ssid + version_counter=len(slist) + revert_ver_ssid=slist[version_counter-1] + ver_revert_dict=obj.version_info(revert_ver_ssid) + ver_revert_nbh_dict=ast.literal_eval(ver_revert_dict['nbhood']) + ver_revert_nbh_dict['content']=ver_revert['content'] + + variables = RequestContext(request,{'ver_nbh_dict':ver_revert_nbh_dict ,'nt':obj,'ssid':revert_ver_ssid,'version_no':version_counter}) + template="objectapp/display.html" + return render_to_response(template,variables) + # return HttpResponse(ver_revert['nbhood']) + + |