from datetime import datetime
from gnowsys_ndf.ndf.models import *
from gnowsys_ndf.ndf.views.methods import *
incorrect_value_gattr = []

start_time_at = node_collection.one({'_type': "AttributeType", 'name': 'start_time'})

end_time_at = node_collection.one({'_type': "AttributeType", 'name': 'end_time'})

start_enroll_at = node_collection.one({'_type': "AttributeType", 'name': 'start_enroll'})

end_enroll_at = node_collection.one({'_type': "AttributeType", 'name': 'end_enroll'})

all_date_gattr = triple_collection.find({'_type': "GAttribute", 'attribute_type.$id': {'$in': [start_time_at._id, end_time_at._id, start_enroll_at._id, end_enroll_at._id]}})

date_gattr = all_date_gattr.count()

if date_gattr > 0:
	for each in all_date_gattr:
		#print type(each.object_value)
		if type(each.object_value) == long:
			incorrect_value_gattr.append(each)
	print "\n Total nodes to be fixed: ", len(incorrect_value_gattr)
	if incorrect_value_gattr:
		for each_gattr in incorrect_value_gattr:
			attr_type_name = each_gattr.attribute_type.name
			if attr_type_name == "start_enroll":
				at_node = start_enroll_at
			elif attr_type_name == "end_enroll":
				at_node = end_enroll_at
			elif attr_type_name == "start_time":
				at_node = start_time_at
			elif attr_type_name == "end_time":
				at_node = end_time_at
			old_object_value = each_gattr.object_value
			new_object_value = datetime.fromtimestamp(old_object_value/1e3)
			create_gattribute(each_gattr.subject, at_node, new_object_value)

# gr.collection_set = list(set(gr.collection_set))
# gr.save()
# for cs_id in gr.collection_set:
# 	cs_node = node_collection.one({'_id': ObjectId(cs_id)})
# 	if cs_node.collection_set:
# 		cs_node.collection_set = list(set(cs_node.collection_set))
# 		cs_node.save()
# 		for css_id in cs_node.collection_set:
# 			css_node = node_collection.one({'_id': ObjectId(css_id)})
# 			if css_node.collection_set:
# 				css_node.collection_set = list(set(css_node.collection_set))
# 				css_node.save()
# 				for cu_id in css_node.collection_set:
# 					cu_node = node_collection.one({'_id': ObjectId(cu_id)})
# 					if cu_node.collection_set:
# 						cu_node.collection_set = list(set(cu_node.collection_set))
# 						cu_node.save()

@@ -1488,18 +1488,90 @@
 value)%0A%0A
-# 
+gr = node_collection.one(%7B'name':'I2C-V2'%7D)%0Aif gr and gr.collection_set:%0A%09
 gr.colle
@@ -1611,18 +1611,17 @@
 n_set))%0A
-# 
+%09
 gr.save(
@@ -1622,18 +1622,17 @@
 .save()%0A
-# 
+%09
 for cs_i
@@ -1655,18 +1655,17 @@
 on_set:%0A
-# 
+%09
 %09cs_node
@@ -1713,18 +1713,17 @@
 s_id)%7D)%0A
-# 
+%09
 %09if cs_n
@@ -1742,18 +1742,17 @@
 on_set:%0A
-# 
+%09
 %09%09cs_nod
@@ -1804,18 +1804,17 @@
 n_set))%0A
-# 
+%09
 %09%09cs_nod
@@ -1822,18 +1822,17 @@
 .save()%0A
-# 
+%09
 %09%09for cs
@@ -1863,18 +1863,17 @@
 on_set:%0A
-# 
+%09
 %09%09%09css_n
@@ -1925,18 +1925,17 @@
 s_id)%7D)%0A
-# 
+%09
 %09%09%09if cs
@@ -1953,26 +1953,25 @@
 ection_set:%0A
-# 
+%09
 %09%09%09%09css_node
@@ -2019,26 +2019,25 @@
 ction_set))%0A
-# 
+%09
 %09%09%09%09css_node
@@ -2044,18 +2044,17 @@
 .save()%0A
-# 
+%09
 %09%09%09%09for 
@@ -2083,26 +2083,25 @@
 ection_set:%0A
-# 
+%09
 %09%09%09%09%09cu_node
@@ -2149,18 +2149,17 @@
 u_id)%7D)%0A
-# 
+%09
 %09%09%09%09%09if 
@@ -2182,18 +2182,17 @@
 on_set:%0A
-# 
+%09
 %09%09%09%09%09%09cu
@@ -2252,10 +2252,9 @@
 t))%0A
-# 
+%09
 %09%09%09%09

Fix nodes updated