def version_history(self, root_id): # extract root from r = Root.objects(id=root_id)[0] print "FIRST = " + str(r.id) history = [] prev = r.previous while (prev != None and prev != ""): history.append(prev) root = Root.objects(id=prev)[0] prev = root.previous return history
def switch_to_last(self, root_id): print "\n --------------------- VERSION MANAGER ----------------------- \n" v = Version() # take root object root = Root.objects(id=root_id)[0] # take it ancestor (as object) previous_root = Root.objects(id=root.previous)[0] # list for sections storage current_sections = [] old_sections = [] temp_collection = root.sections # add sections to temporary lists, recursively! while (len(temp_collection) != 0): next_collection = [] for sec in temp_collection: current_sections.append(LatestSection.objects(object_id=sec)[0]) for s in (LatestSection.objects(object_id=sec)[0]).subsections: next_collection.append(s) temp_collection = next_collection # the same operation for ancestor temp_collection = previous_root.sections while (len(temp_collection) != 0): next_collection = [] for sec in temp_collection: old_sections.append(OldSection.objects(object_id=sec)[0]) for s in (OldSection.objects(object_id=sec)[0]).subsections: next_collection.append(s) temp_collection = next_collection # old code, delete # for sec in previous_root.sections: # old_sections.append(OldSection.objects(object_id=sec)[0]) # move sections from old to temp old_counter = 0 for s in old_sections: if (TempSection.objects(object_id = s.object_id)).count() == 0: print "[ " + s.name + " -> TEMP]" v.save_section(s, "temp") # s.delete() # print "latest del" old_counter += 1 # move sections from latest to old current_counter = 0 for s in current_sections: if (OldSection.objects(object_id = s.object_id)).count() == 0: print "[ " + s.name + " -> OLD]" v.save_section(s, "old") # s.delete() # print "old del" current_counter += 1 # move sections from temp to latest for x in range(0,7): print "----------------------" temp_counter = 0 for sec in TempSection.objects(): print str(sec.id) + " : " + str(sec.name) + " : " + str(sec.object_id) for subsec in sec.subsections: print "sub: " + subsec print " " temp_counter += 1 print "~~~ \n" print "old_counter == " + str(old_counter) print "current_counter == " + str(current_counter) print "temp_counter == " + str(temp_counter) print "current_sections == " + str(len(old_sections)) print "old_sections == " + str(len(current_sections)) for s in TempSection.objects(): # print "s.name == " + str(s.name) if (LatestSection.objects(object_id = s.object_id)).count() == 0: print "[ " + s.name + " -> LATEST]" v.save_section(s, "latest") # s.delete() # print "temp del" v.clear_trash()