Make host configurable from config.py (see settings.py) + changed id generation (using slugified labels instead of GUIDs)
--- a/src/catedit/main.py Fri Nov 28 14:53:11 2014 +0100
+++ b/src/catedit/main.py Fri Nov 28 17:32:22 2014 +0100
@@ -5,4 +5,4 @@
from views import *
if __name__ == '__main__':
- app.run(host='0.0.0.0')
+ app.run(host=app.config["HOST"])
--- a/src/catedit/models.py Fri Nov 28 14:53:11 2014 +0100
+++ b/src/catedit/models.py Fri Nov 28 17:32:22 2014 +0100
@@ -4,6 +4,7 @@
from uuid import uuid4
from StringIO import StringIO
from app import *
+from slugify import slugify
import persistence
"""
@@ -21,7 +22,8 @@
def __init__(self, label=None, description=None,
other_properties=None, graph=None):
if not(graph):
- cat_id = uuid4().hex
+ #cat_id = uuid4().hex
+ cat_id="category_id_"+slugify(label)
self.cat_graph = Graph()
self.this_category = URIRef(app.config["ONTOLOGY_NAMESPACE"]+cat_id)
self.cat_graph.add((self.this_category, RDF.ID, Literal(cat_id)))
@@ -114,13 +116,21 @@
# Did the properties change?
if new_other_properties is not None or self.properties is not None:
+ print "before suppressing properties: "
+ print self.properties
+ print "will replace with: "
+ print new_other_properties
for key in app.config["PROPERTY_LIST"]:
self.cat_graph.remove((self.this_category,
app.config["PROPERTY_LIST"]
[key]
["rdflib_class"],
None))
- for (predicate,obj) in new_other_properties:
+ print "now properties are: "
+ print self.properties
+ print "making new properties: "
+ print new_other_properties
+ for (predicate, obj) in new_other_properties:
self.cat_graph.add((self.this_category,
app.config["PROPERTY_LIST"]
[predicate]
@@ -153,9 +163,21 @@
p.save(content=cat.cat_graph.serialize(format='turtle'),
name=cat.cat_id, message=message)
- def delete_cat(self, cat_id, message=None):
+ def delete_cat(self, deleted_cat_id, message=None):
+ cat_list=self.list_cat()
+ for cat in cat_list:
+ if cat.cat_id != app.config["ONTOLOGY_NAMESPACE"]+deleted_cat_id:
+ new_property_list_for_cat=[]
+ for (predicate, obj) in cat.properties:
+ if not ((app.config["PROPERTY_LIST"]
+ [predicate]
+ ["object_type"] == "uriref-category") and
+ (obj == app.config["ONTOLOGY_NAMESPACE"]+deleted_cat_id)):
+ new_property_list_for_cat.append((predicate, obj))
+ cat.edit_category(new_other_properties=new_property_list_for_cat)
+ self.save_cat(cat, message=message+", cleaning up other properties")
p = getattr(persistence,app.config["PERSISTENCE_METHOD"])()
- p.delete(name=cat_id, message=message)
+ p.delete(name=deleted_cat_id, message=message)
def list_cat(self):
p = getattr(persistence,app.config["PERSISTENCE_METHOD"])()
--- a/src/catedit/settings.py Fri Nov 28 14:53:11 2014 +0100
+++ b/src/catedit/settings.py Fri Nov 28 17:32:22 2014 +0100
@@ -4,8 +4,9 @@
class appSettings(object):
- # Debug
+ # Debug and running settings
+ HOST = "0.0.0.0"
DEBUG = True
LOGGING = True
--- a/virtualenv/requirements.txt Fri Nov 28 14:53:11 2014 +0100
+++ b/virtualenv/requirements.txt Fri Nov 28 17:32:22 2014 +0100
@@ -4,4 +4,5 @@
flask-wtf
Github-Flask
flask-cache
+python-slugify
pep8