diff options
-rw-r--r-- | gstudio/models.py | 94 | ||||
-rw-r--r-- | gstudio/templates/gstudio/base.html | 10 | ||||
-rw-r--r-- | gstudio/templates/gstudio/display.html | 35 | ||||
-rw-r--r-- | gstudio/templates/gstudio/version_diff.html | 103 | ||||
-rw-r--r-- | gstudio/views/graphs.py | 2 | ||||
-rw-r--r-- | gstudio/views/history.py | 87 |
6 files changed, 203 insertions, 128 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index 8177cefb..c4ee0c70 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -66,6 +66,7 @@ """Super models of Gstudio """ + import warnings from datetime import datetime from django.db import models @@ -213,17 +214,6 @@ class NID(models.Model): max_length=255) - def convert(self,data): - if isinstance(data, unicode): - return str(data) - elif isinstance(data, collections.Mapping): - return dict(map(convert, data.iteritems())) - elif isinstance(data, collections.Iterable): - return type(data)(map(convert, data)) - else: - return data - - @property def get_revisioncount(self): """ @@ -274,8 +264,6 @@ class NID(models.Model): ver_nbh_dict[each]=ver_dict[each] return ver_nbh_dict - - def get_serialized_dict(self): """ return the fields in a serialized form of the current object using the __dict__ function. @@ -303,7 +291,7 @@ class NID(models.Model): """ # Retrieving only the relevant tupleset for the versioned objects - vrs = Version.objects.filter(type=0 , object_id=self.id) + vrs = Version.objects.filter(type=1 , object_id=self.id) # Returned value is a list, so splice it. vrs = vrs[0] except: @@ -326,7 +314,7 @@ class NID(models.Model): version = Version.objects.get(id=self.id) return version.serialized_data - + def get_Version_graph_json(self,ssid): @@ -406,9 +394,7 @@ class Node(NID): sites = models.ManyToManyField(Site, verbose_name=_('sites publication'), related_name='nodetypes') nbhood = models.TextField(help_text="The serialized nbh of this version of the Node.") - - - + published = NodePublishedManager() def __unicode__(self): return self.title @@ -619,9 +605,11 @@ class Metatype(Node): # Save for metatype @reversion.create_revision() def save(self, *args, **kwargs): -# self.nbhood=self.get_nbh - super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. - + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_nbh + with reversion.create_revision(): + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + @@ -780,35 +768,6 @@ class Nodetype(Node): return rels - - @property - def get_possible_attributes(self): - """ - Gets the relations possible for this metatype - 1. Recursively create a set of all the ancestors i.e. parent/subtypes of the MT. - 2. Get all the RT's linked to each ancestor - """ - #Step 1. - ancestor_list = [] - this_parent = self.parent - - # recursive thru parent field and append - while this_parent: - ancestor_list.append(this_parent) - this_parent = this_parent.parent - - #Step 2. - attrs = [] - - for each in ancestor_list: - # retrieve all the AT's from each ancestor - attrs.extend(Attribute.objects.filter(subject=each.id)) - - return attrs - - - - def get_graph_json(self): @@ -887,6 +846,33 @@ class Nodetype(Node): #print g_json return json.dumps(g_json) + @property + def get_possible_attributes(self): + """ + Gets the relations possible for this metatype + 1. Recursively create a set of all the ancestors i.e. parent/subtypes of the MT. + 2. Get all the RT's linked to each ancestor + """ + #Step 1. + ancestor_list = [] + this_parent = self.parent + + # recursive thru parent field and append + while this_parent: + ancestor_list.append(this_parent) + this_parent = this_parent.parent + + #Step 2. + attrs = [] + + for each in ancestor_list: + # retrieve all the AT's from each ancestor + attrs.extend(Attribute.objects.filter(subject=each.id)) + + return attrs + + + @property def tree_path(self): @@ -1279,7 +1265,7 @@ class Nodetype(Node): @reversion.create_revision() def save(self, *args, **kwargs): super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. - + class Objecttype(Nodetype): @@ -1462,8 +1448,10 @@ class Objecttype(Nodetype): # Save for Objecttype @reversion.create_revision() def save(self, *args, **kwargs): - # self.nbhood=self.get_nbh - super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + self.nbhood=self.get_nbh + with reversion.create_revision(): + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. diff --git a/gstudio/templates/gstudio/base.html b/gstudio/templates/gstudio/base.html index d0363f3e..435a6539 100644 --- a/gstudio/templates/gstudio/base.html +++ b/gstudio/templates/gstudio/base.html @@ -42,16 +42,10 @@ </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> <table border="1" cellspacing="0"> - {% for sid in object.get_ssid reversed %} + {% for sid in object.ref.get_ssid %} <a href="{{ object.get_version_url }}{{ sid }}">{{ object.title }}{{ object.id }}{{ sid }}</a><br> {% endfor %} </div> diff --git a/gstudio/templates/gstudio/display.html b/gstudio/templates/gstudio/display.html index f2053a6e..67d9fffb 100644 --- a/gstudio/templates/gstudio/display.html +++ b/gstudio/templates/gstudio/display.html @@ -523,28 +523,39 @@ $(function() { {% block sidebar %} <div class="History"> + + <h3>{% trans "Versions" %}</h3> <script type="text/javascript"> - <!-- function go_to_loc(sid) --> - <!-- { --> - - <!-- window.location.href = "{{ nt.get_version_url }}"+sid --> - + 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> --> - <h3>{% trans "Versions" %}</h3> + } + </script> - <form action="/nodetypes/display/showhistory/" > + <form name="history" action="/nodetypes/display/showhistory/" > <table cellspacing="0" border="2"> {% for sid in nt.get_ssid reversed %} <tr> <td> - <input type="radio" name="group1" value="{{ sid }}"><a href="{{ nt.get_version_url }}{{ sid }}">{{ nt.id }}.{{ sid }}</a></input> + <input type="radio" name="group1" value="{{ sid }}" onclick="go_to_loc('{{ sid }}')" ><a href="{{ nt.get_version_url }}{{ sid }}">{{ nt.id }}.{{ sid }}</a></input> </td> <td> - <input type="radio" name="group2" value="{{ sid }}">{{ nt.id }}.{{ sid }}</input> + <input type="radio" id="{{ sid }}"name="group2" value="{{ sid }}" >{{ nt.id }}.{{ sid }}</input> </td> {% endfor %} diff --git a/gstudio/templates/gstudio/version_diff.html b/gstudio/templates/gstudio/version_diff.html index 81305749..ee5e305c 100644 --- a/gstudio/templates/gstudio/version_diff.html +++ b/gstudio/templates/gstudio/version_diff.html @@ -111,24 +111,32 @@ <a href="{{ nt1.get_absolute_url }}" title="{{ nt1.title }}" rel="bookmark">{{ ver_new.title }} </a> </h2> - <br> - {% with nt1.html_content|safe as object_content %} - <b>Name:<nbsp></b>{{ ver_new.title }}<br/> - {% if ver_new.altnames %} - <b> Alternate names:<nbsp></b> {{ diffs }} - <br/> - {% endif %} - {% if ver_new.plural %} - <b> Plural Name:<nbsp></b>{{ ver_new.plural }} <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/> + {% block content56 %}{% for each in diffs1 %} + {% autoescape off %} + {{ each }}<br> + {% endautoescape %}{% endfor %} {% endblock %} + <!-- <br> --> + <!-- {% with nt1.html_content|safe as object_content %} --> + <!-- <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 %} --> + <!-- {% if ver_new.content %} --> + <!-- <b> Content:<nbsp></b>{{ ver_new.content }} <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/> --> {% endwith %} {% endblock %} {% endblock %} @@ -142,30 +150,53 @@ <a href="{{ nt1.get_absolute_url }}" title="{{ nt1.title }}" rel="bookmark">{{ ver_old.title }} </a> </h2> - <br> - {% with nt1.html_content|safe as object_content %} - <b>Name:<nbsp></b>{{ ver_old.title }}<br/> - {% if ver_old.altnames %} - <b> Alternate names:<nbsp></b>{{ ver_old.altnames}} - <br/> - {% endif %} - {% if ver_old.plural %} - <b> Plural Name:<nbsp></b>{{ ver_old.plural }} <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/> + {% block content85 %}{% for each in diffs %} + {% autoescape off %} + {{ each }}<br> + {% endautoescape %}{% endfor %} {% endblock %} + <!-- <br> --> + <!-- {% with nt1.html_content|safe as object_content %} --> + <!-- <b>Name:<nbsp></b>{{ ver_old.title }}<br/> --> + <!-- {% if ver_old.altnames %} --> + <!-- <b> Alternate names:<nbsp></b>{{ ver_old.altnames}} --> + <!-- <br/> --> + <!-- {% endif %} --> + <!-- {% if ver_old.plural %} --> + <!-- <b> Plural Name:<nbsp></b>{{ ver_old.plural }} <br/> --> + <!-- {% endif %} --> + <!-- {% if ver_old.content %} --> + <!-- <b> Content:<nbsp></b>{{ ver_old.content }} <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/> --> {% 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> diff --git a/gstudio/views/graphs.py b/gstudio/views/graphs.py index 757a838e..ff2fa401 100644 --- a/gstudio/views/graphs.py +++ b/gstudio/views/graphs.py @@ -114,7 +114,7 @@ def version_graph_json(request,ssid): try: node = Version.objects.get(id=ssid) - node = node.object + node = node.object.ref except: return HttpResponse("Node not found.", "text/html") diff --git a/gstudio/views/history.py b/gstudio/views/history.py index 7e0c7078..1c05b848 100644 --- a/gstudio/views/history.py +++ b/gstudio/views/history.py @@ -10,11 +10,12 @@ from gstudio.models import * from reversion.models import * from gstudio.views.decorators import protect_nodetype from gstudio.views.decorators import update_queryset +import ast def history(request,ssid): # iden=request.GET["id"] nt1=Version.objects.get(id=ssid) - nt=nt1.object + nt=nt1.object.ref ver_dict=nt.version_info(ssid) variables = RequestContext(request,{'ver_dict':ver_dict ,'nt':nt,'ssid':ssid }) template="gstudio/display.html" @@ -26,26 +27,76 @@ def showHistory(request): nt=Version.objects.get(id=vid1) nt1=nt.object pp=pprint.PrettyPrinter(indent=4) - # ver_new=Version.objects.get(id=vid1) - # ver_old=Version.objects.get(id=vid2) + ver_new1=Version.objects.get(id=vid1) + ver_old1=Version.objects.get(id=vid2) + ver_new_dict=nt1.version_info(request.GET["group1"]) + content=str(ver_new_dict['content']) + content=content[3:-4] + ver_new_dict['content']=content ver_old_dict=nt1.version_info(request.GET["group2"]) + 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_old_nbh=ver_old_dict['nbhood'] + ver_old_dict1=ast.literal_eval(ver_old_nbh) + ver_new_nbh=ver_new_nbh.replace(",","\n") - ver_new_nbh=ver_old_nbh.replace(",","\n") - # ver_new="" - # ver_old="" - # for each in ver_new_nbh: - # ver_new+=each + ":" + str(ver_new_nbh[each])+'\n' - # for each in ver_old_nbh: - # ver_old+=each + ":" + str(ver_old_nbh[each])+'\n' - diffs = dmp.diff_main(ver_new_nbh, ver_old_nbh) - d=dmp.diff_prettyHtml(diffs) - return HttpResponse(d) - # ver_new=nt1.version_info(request.GET["group1"]) - # ver_old=nt1.version_info(request.GET["group2"]) + ver_old_nbh=ver_old_nbh.replace(",","\n") + d=[] + d1=[] + field=['Name','Plural Name','Alternate Name','Authors','Content'] + for each in ver_new_dict: + ver_new="" + ver_old="" + if each =='altnames': + ver_new+=field[2] + ":" + ver_new_dict['altnames'] + ver_old+=field[2] + ":" + 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 =='title': + ver_new+=field[0] + ":" + ver_new_dict['title'] + ver_old+=field[0] + ":" + 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+=field[1] + ":" + ver_new_dict['plural'] + ver_old+=field[1] + ":" + 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': + ver_new+=field[4] + ":" + ver_new_dict['content'] + ver_old+=field[4] + ":" + 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,'ver_new':ver_new,'diffs':diffs }) - # template="gstudio/version_diff.html" - # return render_to_response(template,variables) + variables=RequestContext(request,{'nt':nt1,'ver_old':ver_old_dict,'ver_new':ver_new_dict,'diffs':d ,'vid1':vid1,'vid2':vid2,'diffs1':d1}) + template="gstudio/version_diff.html" + return render_to_response(template,variables) + |