diff options
Diffstat (limited to 'gstudio/models.py')
-rw-r--r-- | gstudio/models.py | 172 |
1 files changed, 135 insertions, 37 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index 0b6886d..5129716 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -107,6 +107,7 @@ import reversion from reversion.models import Version from django.core import serializers from reversion.models import * +from reversion.helpers import * NODETYPE_CHOICES = ( ('ND', 'Nodes'), @@ -210,7 +211,70 @@ class NID(models.Model): slug = models.SlugField(help_text=_('used for publication'), unique_for_date='creation_date', 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): + """ + Returns Number of Version + """ + i=0 + ver=Version.objects.get_for_object(self) + for each in ver: + i=i+1 + return i + + @property + def get_version_list(self): + """ + Returns Version list + """ + ver=Version.objects.get_for_object(self) + return ver + @property + def get_ssid(self): + """ + return snapshot ids (revision id). + returns a list. + """ + slist=[] + vlist=self.get_version_list + for each in vlist: + slist.append(each.id) + return slist + + def version_info(self,ssid): + version_object=Version.objects.get(id=ssid) + return version_object.field_dict + + + def get_version_nbh(self,ssid): + """ + Returns Version nbh + """ + ver_dict=self.version_info(ssid) + ver_nbh_list=[] + ver_nbh_dict={} + for item in self.get_nbh.keys(): + if item in ver_dict.keys(): + ver_nbh_list.append(item) + for each in ver_nbh_list: + ver_nbh_dict[each]=ver_dict[each] + return ver_nbh_dict + + def get_serialized_dict(self): """ @@ -218,26 +282,15 @@ class NID(models.Model): """ return self.__dict__ - @property - def get_app_name(self): - if self.ref.__class__.__name__=='Gbobject' or self.ref.__class__.__name__=='Process' or self.ref.__class__.__name__=='System' : - return 'type' - @models.permalink def get_absolute_url(self): """Return nodetype's URL""" - if self.get_app_name=='type': - return ('objectapp_gbobject_detail', (), { - 'year': self.creation_date.strftime('%Y'), - 'month': self.creation_date.strftime('%m'), - 'day': self.creation_date.strftime('%d'), - 'slug': self.slug}) - else: - return ('gstudio_nodetype_detail', (), { - 'year': self.creation_date.strftime('%Y'), - 'month': self.creation_date.strftime('%m'), - 'day': self.creation_date.strftime('%d'), - 'slug': self.slug}) + + return ('gstudio_nodetype_detail', (), { + 'year': self.creation_date.strftime('%Y'), + 'month': self.creation_date.strftime('%m'), + 'day': self.creation_date.strftime('%d'), + 'slug': self.slug}) @property def ref(self): @@ -257,23 +310,6 @@ class NID(models.Model): return None return vrs.object - - @property - def reftype(self): - """ - Returns the type the id belongs to. - """ - try: - """ - ALGO: simple wrapper for the __class__.__name__ so that it can be used in templates - """ - obj = self.ref - return obj.__class__.__name__ - - except: - return None - - @property def get_edit_url(self): @@ -290,6 +326,59 @@ class NID(models.Model): version = Version.objects.get(id=self.id) return version.serialized_data + + + 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) + + 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 }) + + 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) + + def __unicode__(self): return self.title @@ -298,7 +387,6 @@ class NID(models.Model): """NID's Meta""" - class Node(NID): """ Super class @@ -317,6 +405,10 @@ 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 @@ -326,6 +418,7 @@ class Node(NID): @reversion.create_revision() def save(self, *args, **kwargs): + # self.nbhood=self.get_nbh super(Node, self).save(*args, **kwargs) # Call the "real" save() method. @@ -526,6 +619,7 @@ 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. @@ -625,8 +719,8 @@ class Nodetype(Node): reltypes['possible_rightroles'] = right_subset return reltypes - - + + @property def get_possible_attributetypes(self): """ @@ -1156,6 +1250,9 @@ class Nodetype(Node): 'month': self.creation_date.strftime('%m'), 'day': self.creation_date.strftime('%d'), 'slug': self.slug}) + def get_version_url(self): + """Return nodetype's URL""" + return "/nodetypes/display/viewhistory/" def get_serialized_data(self): """ @@ -1361,6 +1458,7 @@ 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. |