src/catedit/utils.py
changeset 10 7d016d52be36
parent 0 54f4e0f9d636
child 11 f2d54d2841f3
--- a/src/catedit/utils.py	Tue Dec 09 12:39:38 2014 +0100
+++ b/src/catedit/utils.py	Fri Dec 12 16:45:47 2014 +0100
@@ -1,13 +1,22 @@
 from flask.ext.restful import abort
-from models import Category
+from models import Category, CategoryManager
+from rdflib.compare import *
 
-# def check_if_cat_exists(catID):
-#     idInGraph=False
-#     catToReturn="NotFound"
-#     for cat in categories:
-#         if cat.catID == catID:
-#             idInGraph=True
-#             catToReturn=cat
-#     if not(idInGraph):
-#         abort(404, message="Category doesn't exist")
-#     return catToReturn
+'''
+    This function will compare two categories from their Graph object serializations
+    Exact return values are to be defined, some ideas
+    * check if the 2 categories are the same? (same ID, isomorphic)
+    * check if the 2 categories are the same but different version? (same ID, not isomorphic)
+    * check if unique, non empty parameters changed and list them (label and description)
+    * returns 2 lists of properties: only_in_first, only_in_second
+    * more?
+'''
+
+def compare_two_cat(cat_serial_1, cat_serial_2):
+    cat1 = Category(cat_serial_1)
+    cat2 = Category(cat_serial_2)
+    iso_cat1 = cat1.cat_graph.to_isomorphic()
+    iso_cat2 = cat2.cat_graph.to_isomorphic()
+    if iso_cat1 != iso_cat2:
+        in_both_cats, only_in_cat1, only_in_cat2 = graph_diff(cat1, cat2)
+    return