Added commit message to category deletion + config.py tmpl + persistence method is now configurable in settings and instanciated from a string + removed log.txt from tracking
--- a/src/catedit/api.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/api.py Fri Nov 28 14:50:37 2014 +0100
@@ -16,6 +16,7 @@
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")
+#cat_parser.add_argument('delete_message', type=str)
class CategoryAPI(Resource):
@@ -28,14 +29,14 @@
cat_manager_instance = CategoryManager()
if cat_id is not None:
c = cat_manager_instance.load_cat(cat_id)
- print "get id: "+c.cat_id
+ # print "get id: "+c.cat_id
return c.cat_graph.serialize(format='turtle')
else:
response=[]
for c in cat_manager_instance.list_cat():
response.append(c.cat_graph.serialize(format='turtle'))
# print response
- print "get id: None"
+ # print "get id: None"
return response
# update category cat_id
@@ -66,7 +67,7 @@
new_label=args["label"],
new_other_properties=new_property_list)
cat_manager_instance.save_cat(c, message=args["commit_message"])
- print "put id: "+c.cat_id
+ # print "put id: "+c.cat_id
cache.clear()
return c.cat_graph.serialize(format='turtle'), 200
# Maybe not send the whole cat back, see if it's worth it
@@ -83,7 +84,7 @@
if property_object:
if app.config["PROPERTY_LIST"] \
[property_predicate] \
- ["object_type"]=="uriref-category":
+ ["object_type"] == "uriref-category":
property_list.append((property_predicate,
app.config["ONTOLOGY_NAMESPACE"]
+property_object))
@@ -96,15 +97,19 @@
other_properties=property_list)
cat_manager_instance = CategoryManager()
cat_manager_instance.save_cat(c, message=args["commit_message"])
- print "post id: "+c.cat_id
+ # print "post id: "+c.cat_id
cache.clear()
return c.cat_graph.serialize(format='turtle'), 201
@classmethod
def delete(self, cat_id):
cat_manager_instance = CategoryManager()
- cat_manager_instance.delete_cat(cat_id)
- print "delete id: "+cat_id
+ if not request.form["delete_message"]:
+ message = "Deleting category "+cat_id
+ else:
+ message = request.form["delete_message"]
+ cat_manager_instance.delete_cat(cat_id, message=message)
+ # print "delete id: "+cat_id
cache.clear()
return 204
--- a/src/catedit/app.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/app.py Fri Nov 28 14:50:37 2014 +0100
@@ -9,7 +9,7 @@
app = Flask(__name__)
app.config.from_object(appSettings)
cache = Cache(app, config={"CACHE_TYPE": "simple"})
-# app.config.from_object(systemSettings)
+app.config.from_object(appConfig)
github = GitHub(app)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/catedit/config.py.tmpl Fri Nov 28 14:50:37 2014 +0100
@@ -0,0 +1,11 @@
+# Overwriting settings
+class appConfig(object):
+
+ DEBUG = False
+ LOGGING = False
+
+ # Repository settings
+
+ REPOSITORY_NAME = "habitabilite-prototype"
+ REPOSITORY_OWNER = "catedit-system"
+ CATEGORIES_PATH = "categories/"
--- a/src/catedit/main.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/main.py Fri Nov 28 14:50:37 2014 +0100
@@ -5,5 +5,4 @@
from views import *
if __name__ == '__main__':
- app.debug = True
app.run(host='0.0.0.0')
--- a/src/catedit/models.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/models.py Fri Nov 28 14:50:37 2014 +0100
@@ -4,9 +4,7 @@
from uuid import uuid4
from StringIO import StringIO
from app import *
-from persistence import *
-
-app.config["PERSISTENCE_METHOD"] = PersistenceToGithub
+import persistence
"""
Namespace: ld.iri-research.org/ontology/categorisation/#
@@ -89,7 +87,9 @@
property_list.append((key, obj.toPython()))
return property_list
- def edit_category(self, new_label=None, new_description=None, new_other_properties=None):
+ def edit_category(self, new_label=None,
+ new_description=None,
+ new_other_properties=None):
# Did the label change?
if new_label is not None and new_label != self.label:
# Remove the old triple
@@ -141,7 +141,7 @@
class CategoryManager(object):
def load_cat(self, cat_id):
- p = app.config["PERSISTENCE_METHOD"]()
+ p = getattr(persistence,app.config["PERSISTENCE_METHOD"])()
cat_serial = p.load(name=cat_id)
loaded_cat_graph = Graph()
loaded_cat_graph.parse(source=StringIO(cat_serial), format='turtle')
@@ -149,16 +149,16 @@
return cat
def save_cat(self, cat, message=None):
- p = app.config["PERSISTENCE_METHOD"]()
+ p = getattr(persistence,app.config["PERSISTENCE_METHOD"])()
p.save(content=cat.cat_graph.serialize(format='turtle'),
name=cat.cat_id, message=message)
def delete_cat(self, cat_id, message=None):
- p = app.config["PERSISTENCE_METHOD"]()
- p.delete(name=cat_id, message="Deleting category "+cat_id)
+ p = getattr(persistence,app.config["PERSISTENCE_METHOD"])()
+ p.delete(name=cat_id, message=message)
def list_cat(self):
- p = app.config["PERSISTENCE_METHOD"]()
+ p = getattr(persistence,app.config["PERSISTENCE_METHOD"])()
cat_serial_list = p.list()
# print cat_serial_list
cat_list=[]
--- a/src/catedit/persistence.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/persistence.py Fri Nov 28 14:50:37 2014 +0100
@@ -66,9 +66,9 @@
class PersistenceToGithub(Persistence):
def save(self, **kwargs):
- #print kwargs["content"]
+ # print kwargs["content"]
request_data = {"content": b64encode(kwargs["content"]), \
- "message": kwargs["message"]}
+ "message": kwargs["message"]}
try:
filedict = github.get("repos/"
+app.config["REPOSITORY_OWNER"]+"/"
--- a/src/catedit/settings.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/settings.py Fri Nov 28 14:50:37 2014 +0100
@@ -4,6 +4,13 @@
class appSettings(object):
+ # Debug
+
+ DEBUG = True
+ LOGGING = True
+
+ # WTForms settings
+
WTF_CSRF_ENABLED = True
SECRET_KEY = 'totally-secret-key'
@@ -62,3 +69,7 @@
"object_rdflib_class" : URIRef,
},
}
+
+ # PersistenceMethod
+
+ PERSISTENCE_METHOD="PersistenceToGithub"
--- a/src/catedit/templates/cateditor.html Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/templates/cateditor.html Fri Nov 28 14:50:37 2014 +0100
@@ -127,7 +127,11 @@
<strong>{{ config["PROPERTY_LIST"][predicate]["descriptive_label_fr"] }}</strong>
</td>
<td id="object_td{{ property_count }}">
- {{ object }}
+ {% if config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-link" %}
+ <a href="{{ object }}">{{ object }}</a>
+ {% else %}
+ {{ object }}
+ {% endif %}
</td>
<td id="delete_button_td{{ property_count }}">
<input type="button" id="property_delete_button{{ property_count }}" class="btn btn-default property-delete-button" onClick="CatEditScripts.removeProperty({{ property_count }}, 'properties')" value="Supprimer">
--- a/src/catedit/templates/catrecap.html Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/templates/catrecap.html Fri Nov 28 14:50:37 2014 +0100
@@ -20,6 +20,10 @@
$("#info_button_{{cat.cat_id}}").click(function(){
$("#properties_{{cat.cat_id}}").slideToggle();
});
+ $("#delete_cat_{{cat.cat_id}}").hide();
+ $("#delete_button_{{cat.cat_id}}").click(function(){
+ $("#delete_cat_{{cat.cat_id}}").slideToggle();
+ });
{% endfor %}
});
</script>
@@ -79,7 +83,7 @@
<td class="col-md-2 text-right">
<button class="btn btn-default" id="info_button_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus"/></button>
<a href="{{ url_for('cat_editor', cat_id=cat.cat_id)}}" class="btn btn-default"><span class="glyphicon glyphicon glyphicon-pencil"/></a>
- <a href="{{ url_for('cat_recap', delete_cat_id=cat.cat_id)}}" class="btn btn-default"><span class="glyphicon glyphicon-trash"/></a>
+ <button class="btn btn-default" id="delete_button_{{cat.cat_id}}"><span class="glyphicon glyphicon-trash"/></a>
</td>
</tr>
<tr>
@@ -89,7 +93,7 @@
{% if cat.cat_properties|length == 0 %} <dt></dt><dd>Aucune autre propriété</dd>
{% else %}
{% for (predicate, object) in cat.cat_properties %}
- <dt>{{ predicate }}</dt>
+ <dt>{{ config["PROPERTY_LIST"][predicate]["descriptive_label_fr"] }}</dt>
<dd>
{% if config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-category" %}
{% for cat in cat_list %}
@@ -97,6 +101,8 @@
{{ cat.cat_label }}
{% endif %}
{% endfor %}
+ {% elif config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-link" %}
+ <a href="{{ object }}">{{ object }}</a>
{% else %}
{{ object }}
{% endif %}
@@ -105,6 +111,12 @@
{% endif %}
</dl>
</div>
+ <div id="delete_cat_{{cat.cat_id}}">
+ <form method="POST" action="{{ url_for('cat_recap', delete_cat_id=cat.cat_id) }}" class="form-inline align-center">
+ <input type="text" style="width: 90%" name="delete_message" class="form-control" placeholder="Message de suppression">
+ <input type="submit" class="btn btn-default" value="Supprimer">
+ </form>
+ </div>
</td>
</tr>
{% endfor %}
--- a/src/catedit/views.py Wed Nov 26 16:57:48 2014 +0100
+++ b/src/catedit/views.py Fri Nov 28 14:50:37 2014 +0100
@@ -18,7 +18,7 @@
@app.route('/', methods=['GET'])
@app.route('/catrecap', methods=['GET'])
-@app.route('/catrecap/delete/<string:delete_cat_id>', methods=['GET'])
+@app.route('/catrecap/delete/<string:delete_cat_id>', methods=['GET','POST'])
def cat_recap(delete_cat_id=None):
cat_api_instance = CategoryAPI()
# list categories