# HG changeset patch # User Nicolas DURAND # Date 1416823508 -3600 # Node ID f7bc7942969aa9c26e3dbf8bb4ac7854ab82a591 # Parent 83d266c0c8324e6e3ac08280a0c9553995e7b2c0 removed log folder from repo + changed property edition form + started refactoring property list so adding a new property is easier diff -r 83d266c0c832 -r f7bc7942969a .hgignore --- a/.hgignore Fri Nov 21 14:19:20 2014 +0100 +++ b/.hgignore Mon Nov 24 11:05:08 2014 +0100 @@ -2,4 +2,5 @@ dev/.vagrant/ files/ *.pyc -src\catedit\config.py \ No newline at end of file +src\catedit\config.py +src/catedit/log/ \ No newline at end of file diff -r 83d266c0c832 -r f7bc7942969a src/catedit/api.py --- a/src/catedit/api.py Fri Nov 21 14:19:20 2014 +0100 +++ b/src/catedit/api.py Mon Nov 24 11:05:08 2014 +0100 @@ -14,6 +14,8 @@ cat_parser.add_argument('label', type=str) cat_parser.add_argument('description', type=str) cat_parser.add_argument('commit_message', type=str) +cat_parser.add_argument('property_predicate', type=str, action="append") +cat_parser.add_argument('property_object', type=str, action="append") class CategoryAPI(Resource): @@ -37,13 +39,14 @@ cat_manager_instance = CategoryManager() new_property_list=[] + # print args["property_predicate"] + # print args["property_object"] for property_predicate, property_object in zip( - request.form.getlist('property_predicate'), - request.form.getlist('property_object')): + args["property_predicate"], + args["property_object"]): if property_object: new_property_list.append((property_predicate, property_object)) - print new_property_list - + # print new_property_list c = cat_manager_instance.load_cat(cat_id) c.edit_category(new_description=args["description"], new_label=args["label"], @@ -55,6 +58,8 @@ def post(self): args = cat_parser.parse_args() property_list = [] + print args["property_predicate"] + print args["property_object"] for property_predicate, property_object in zip( request.form.getlist('property_predicate'), request.form.getlist('property_object')): diff -r 83d266c0c832 -r f7bc7942969a src/catedit/app.py --- a/src/catedit/app.py Fri Nov 21 14:19:20 2014 +0100 +++ b/src/catedit/app.py Mon Nov 24 11:05:08 2014 +0100 @@ -7,9 +7,8 @@ # set up app and database app = Flask(__name__) app.config.from_object(appSettings) -app.config.from_object(systemSettings) -# app.config['GITHUB_CLIENT_ID'] = LOCAL_APPLICATION_GITHUB_ID -# app.config['GITHUB_CLIENT_SECRET'] = LOCAL_APPLICATION_GITHUB_SECRET +# app.config.from_object(systemSettings) + github = GitHub(app) # set up logging diff -r 83d266c0c832 -r f7bc7942969a src/catedit/models.py --- a/src/catedit/models.py Fri Nov 21 14:19:20 2014 +0100 +++ b/src/catedit/models.py Mon Nov 24 11:05:08 2014 +0100 @@ -20,42 +20,6 @@ class Category(object): - - """ - property_list = { - "subClassOf": { - "descriptive_label_fr" : "Sous-classe de", - "descriptive_label_en" : "Subclass of", - "rdflib_class" : RDFS.subClassOf, - "rdflib_object" : "uriref" - }, - "value": { - "descriptive_label_fr" : "Valeur", - "descriptive_label_en" : "Value", - "rdflib_class" : RDF.value, - "rdflib_object" : "literal" - }, - "type": { - "descriptive_label_fr" : "Type", - "descriptive_label_en" : "Type", - "rdflib_class" : RDF.type, - "rdflib_object" : "uriref" - }, - "resource": { - "descriptive_label_fr" : "Ressource", - "descriptive_label_en" : "Resource", - "rdflib_class" : RDFS.Resource, - "rdflib_object" : "uriref" - }, - } - """ - - property_dict = { - "subClassOf": RDFS.subClassOf, - "value": RDF.value, - "type": RDF.type, - } - def __init__(self, label=None, description=None, other_properties=None, graph=None): if not(graph): @@ -79,7 +43,9 @@ if other_properties: for (predicate, obj) in other_properties: self.cat_graph.add((self.this_category, - Category.property_dict[predicate], + app.config["PROPERTY_LIST"] + [predicate] + ["rdflib_class"], Literal(obj))) else: @@ -110,12 +76,14 @@ @property def properties(self): - # list of properties from the property_dict + # list of properties from the PROPERTY_LIST defined in settings.py property_list = [] - for key in Category.property_dict: + for key in app.config["PROPERTY_LIST"]: for obj in self.cat_graph \ .objects(subject=self.this_category, - predicate=Category.property_dict[key]): + predicate=app.config["PROPERTY_LIST"] + [key] + ["rdflib_class"]): property_list.append((key, obj.toPython())) return property_list @@ -144,13 +112,17 @@ # Did the properties change? if new_other_properties is not None or self.properties is not None: - for key in Category.property_dict: + for key in app.config["PROPERTY_LIST"]: self.cat_graph.remove((self.this_category, - Category.property_dict[key], + app.config["PROPERTY_LIST"] + [key] + ["rdflib_class"], None)) for (predicate,obj) in new_other_properties: self.cat_graph.add((self.this_category, - Category.property_dict[predicate], + app.config["PROPERTY_LIST"] + [predicate] + ["rdflib_class"], Literal(obj))) diff -r 83d266c0c832 -r f7bc7942969a src/catedit/settings.py --- a/src/catedit/settings.py Fri Nov 21 14:19:20 2014 +0100 +++ b/src/catedit/settings.py Mon Nov 24 11:05:08 2014 +0100 @@ -1,5 +1,4 @@ -# GLOBAL APPLICATION SETTINGS - +from rdflib import * # Category persistence parameters @@ -30,3 +29,32 @@ GITHUB_CLIENT_ID = "3e31f3b000a4914f75ef" GITHUB_CLIENT_SECRET = "bc17eb0ec11385628c2e75aacb5ff8ef5f29e490" + + # Property List + + PROPERTY_LIST = { + "subClassOf": { + "descriptive_label_fr" : "Sous-classe de", + "descriptive_label_en" : "Subclass of", + "rdflib_class" : RDFS.subClassOf, + "rdflib_object" : "uriref", + }, + "value": { + "descriptive_label_fr" : "Valeur", + "descriptive_label_en" : "Value", + "rdflib_class" : RDF.value, + "rdflib_object" : "literal", + }, + "type": { + "descriptive_label_fr" : "Type", + "descriptive_label_en" : "Type", + "rdflib_class" : RDF.type, + "rdflib_object" : "uriref", + }, + "resource": { + "descriptive_label_fr" : "Ressource", + "descriptive_label_en" : "Resource", + "rdflib_class" : RDFS.Resource, + "rdflib_object" : "uriref", + }, + } diff -r 83d266c0c832 -r f7bc7942969a src/catedit/static/js/property_functions.js --- a/src/catedit/static/js/property_functions.js Fri Nov 21 14:19:20 2014 +0100 +++ b/src/catedit/static/js/property_functions.js Mon Nov 24 11:05:08 2014 +0100 @@ -1,7 +1,11 @@ var CatEditScripts=CatEditScripts||(function(){ var propertyCount=0; + var createdProperties=0; return { + initCreatedProperties : function(initValue){ + createdProperties=initValue; + }, initPropertyCount : function(divName,initValue){ propertyCount=initValue; @@ -10,31 +14,45 @@ } }, - addProperty : function(divName){ + addProperty : function(divName, type){ + var selectElement = document.getElementById('property_type_selector'); + var selectedOptionValue = selectElement.options[selectElement.selectedIndex].value; + var selectedOptionText = selectElement.options[selectElement.selectedIndex].text + var selectedOptionObject = selectElement.options[selectElement.selectedIndex].label var newProperty = document.createElement('div'); - newProperty.innerHTML = '
\ -
\ - \ -
\ -
\ - \ -
\ -
'; - parentElement=document.getElementById(divName) + newProperty.setAttribute('id','property_div'+(createdProperties+1)); + newProperty.setAttribute('class','row property-row'); + var optionObjectHTML = ""; + switch(selectedOptionObject) { + case "literal": + optionObjectHTML = ''; + break; + default: + optionObjectHTML='' + } + + var newPropertyHTML = '
\ + \ + ' + +optionObjectHTML+ + ' \ +
'; + + newProperty.innerHTML = newPropertyHTML ; + parentElement=document.getElementById(divName) ; parentElement.insertBefore(newProperty, parentElement.firstChild); + createdProperties++; propertyCount++; if (propertyCount > 0) { document.getElementById(divName).className="visible"; } }, - removeLastProperty : function(divName){ + removeProperty : function(index){ if (propertyCount > 0) { - divItem=document.getElementById("property_div"+propertyCount); + divItem=document.getElementById("property_div"+index); divItem.parentNode.removeChild(divItem); propertyCount--; if (propertyCount == 0) { diff -r 83d266c0c832 -r f7bc7942969a src/catedit/templates/cateditor.html --- a/src/catedit/templates/cateditor.html Fri Nov 21 14:19:20 2014 +0100 +++ b/src/catedit/templates/cateditor.html Mon Nov 24 11:05:08 2014 +0100 @@ -75,25 +75,33 @@ {% endif %} {{ form.label.label }}
{{ form.label(size=40, class="form-control", readonly=readonly, placeholder=label_placeholder) }}
{{ form.description.label }}
{{ form.description(size=150, class="form-control", readonly=readonly, placeholder=description_placeholder) }}
-

+ +
+ + +