def version_node(request, group_id, node_id, version_no=None): """Renders either a single or compared version-view based on request. In single version-view, all information of the node for the given version-number is provided. In compared version-view, comparitive information in tabular form about the node for the given version-numbers is provided. """ # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) d = diff_match_patch() view = "" # either single or compare selected_versions = {} node = node_collection.one({"_id": ObjectId(node_id)}) node1 = node_collection.one({"_id": ObjectId(node_id)}) fp = history_manager.get_file_path(node) listform = [ 'modified_by', 'created_by', 'last_update', 'name', 'content', 'contributors', 'rating', 'location', 'access_policy', 'type_of', 'status', 'tags', 'language', 'member_of', 'url', 'created_at', 'author_set', 'group_set', 'collection_set', 'prior_node', 'attribute_set', 'relation_set' ] versions = get_published_version_list(request, node) if not version_no: if versions: version_no = versions.pop() versions.append(version_no) else: version_no = node.current_version if request.method == "POST": view = "compare" version_1 = request.POST["version_1"] version_2 = request.POST["version_2"] #diff = get_html_diff(fp, version_1, version_2) selected_versions = {"1": version_1, "2": version_2} doc = history_manager.get_version_document(node, version_1) doc1 = history_manager.get_version_document(node, version_2) parse_data(doc) parse_data(doc1) for i in node1: try: s = htmldiff(str(doc[i]), str(doc1[i]), True) node1[i] = s except: node1[i] = node1[i] content = doc content_1 = node1 content['content'] = doc['content'].replace("<", "<").replace( ">", ">").replace(""", "\"") content_1['content'] = content_1['content'].replace( "insert:", " ").replace("delete:", "").replace("<tt>", "").replace("</tt>", "") content_1['content'] = content_1['content'].replace( "<", "<").replace(">", ">").replace(""", "\"") new_content = [] new_content1 = [] for i in listform: new_content.append({i: str(content[i])}) new_content1.append({i: content_1[i]}) content = new_content content_1 = new_content1 else: view = "single" data = None data = history_manager.get_version_document(node, version_no) parse_data(data) new_content = [] selected_versions = {"1": version_no, "2": ""} for i in listform: new_content.append({i: str(data[i])}) content = new_content #content = data content_1 = "none" return render_to_response("ndf/version_page.html", { 'view': view, 'node': node, 'group_id': group_id, 'groupid': group_id, 'selected_versions': selected_versions, 'content': content, 'content1': content_1, 'publishedversions': versions }, context_instance=RequestContext(request))
def version_node(request, group_id, node_id, version_no = None): """Renders either a single or compared version-view based on request. In single version-view, all information of the node for the given version-number is provided. In compared version-view, comparitive information in tabular form about the node for the given version-numbers is provided. """ # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) d=diff_match_patch() view = "" # either single or compare selected_versions = {} node = node_collection.one({"_id": ObjectId(node_id)}) node1 = node_collection.one({"_id": ObjectId(node_id)}) fp = history_manager.get_file_path(node) listform = ['modified_by','created_by','last_update','name','content','contributors','rating','location','access_policy', 'type_of','status','tags','language','member_of','url','created_at','author_set', 'group_set', 'collection_set','prior_node','attribute_set', 'relation_set'] versions= get_published_version_list(request,node) if not version_no: if versions: version_no = versions.pop() versions.append(version_no) else: version_no = node.current_version if request.method == "POST": view = "compare" version_1 = request.POST["version_1"] version_2 = request.POST["version_2"] #diff = get_html_diff(fp, version_1, version_2) selected_versions = {"1": version_1, "2": version_2} doc=history_manager.get_version_document(node,version_1) doc1=history_manager.get_version_document(node,version_2) parse_data(doc) parse_data(doc1) for i in node1: try: s=htmldiff(str(doc[i]),str(doc1[i]),True) node1[i]=s except: node1[i]=node1[i] content = doc content_1 = node1 content['content'] = doc['content'].replace("<","<").replace(">",">").replace(""","\"") content_1['content'] = content_1['content'].replace("insert:"," ").replace("delete:","").replace("<tt>","").replace("</tt>","") content_1['content'] = content_1['content'].replace("<","<").replace(">",">").replace(""","\"") new_content = [] new_content1= [] for i in listform: new_content.append({i:str(content[i])}) new_content1.append({i:content_1[i]}) content = new_content content_1 = new_content1 else: view = "single" data = None data = history_manager.get_version_document(node,version_no) parse_data(data) new_content = [] selected_versions = {"1": version_no, "2": ""} for i in listform: new_content.append({i:str(data[i])}) content = new_content #content = data content_1="none" return render_to_response("ndf/version_page.html", {'view': view, 'node': node, 'group_id':group_id, 'groupid':group_id, 'selected_versions': selected_versions, 'content': content, 'content1':content_1, 'publishedversions':versions }, context_instance = RequestContext(request) )
def version_node(request, group_id, node_id, version_no): """Renders either a single or compared version-view based on request. In single version-view, all information of the node for the given version-number is provided. In compared version-view, comparitive information in tabular form about the node for the given version-numbers is provided. """ ins_objectid = ObjectId() if ins_objectid.is_valid(group_id) is False : group_ins = collection.Node.find_one({'_type': "Group","name": group_id}) auth = collection.Node.one({'_type': 'Author', 'name': unicode(request.user.username) }) if group_ins: group_id = str(group_ins._id) else : auth = collection.Node.one({'_type': 'Author', 'name': unicode(request.user.username) }) if auth : group_id = str(auth._id) else : pass d=diff_match_patch() view = "" # either single or compare selected_versions = {} node = collection.Node.one({"_id": ObjectId(node_id)}) node1 = collection.Node.one({"_id": ObjectId(node_id)}) fp = history_manager.get_file_path(node) if request.method == "POST": view = "compare" version_1 = request.POST["version_1"] version_2 = request.POST["version_2"] diff = get_html_diff(fp, version_1, version_2) selected_versions = {"1": version_1, "2": version_2} doc=history_manager.get_version_document(node,version_1) doc1=history_manager.get_version_document(node,version_2) for i in node1: try: s=d.diff_compute(str(doc[i]),str(doc1[i]),True) l=diff_prettyHtml(s) node1[i]=l except: node1[i]=node1[i] content = node1 content_1=doc else: view = "single" # Retrieve rcs-file for a given version-number rcs.checkout((fp, version_no)) # Copy content from rcs-version-file data = None with open(fp, 'r') as sf: data = sf.read() # Used json.loads(x) -- to covert string to dictionary object # If want to use key from this converted dictionay, use array notation because dot notation doesn't works! data = json.loads(data) # Remove retrieved rcs-file belonging to the given version-number rcs.checkin(fp) selected_versions = {"1": version_no, "2": ""} content = data content_1='none' return render_to_response("ndf/version_page.html", {'view': view, 'node': node, 'group_id':group_id, 'groupid':group_id, 'selected_versions': selected_versions, 'content': content, 'content1':content_1, }, context_instance = RequestContext(request) )