src/catedit/api.py
author Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
Mon, 29 Dec 2014 18:01:09 +0100
changeset 14 fc63b1a3d2ef
parent 12 8ca7be41e3ca
child 15 4f08f1a107b3
permissions -rw-r--r--
Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     1
"""
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     2
api.py:
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     3
contains the api that links the views (views.py) to the model (models.py) and
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     4
its persistence method (persistence.py). As it only trades rdf graphs
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     5
serializations strings, it isn't bound to one specific view
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     6
"""
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     7
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     8
from flask.ext.restful import Resource, Api, reqparse
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
     9
from flask import request
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    10
from catedit import app, cache
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    11
from catedit.models import Category, CategoryManager
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    12
import catedit.persistence
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    13
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    14
api = Api(app)
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    15
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    16
logger = app.logger
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    17
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    18
cat_parser = reqparse.RequestParser()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    19
cat_parser.add_argument('label', type=str)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    20
cat_parser.add_argument('description', type=str)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    21
cat_parser.add_argument('commit_message', type=str)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    22
cat_parser.add_argument('property_predicate', type=str, action="append")
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    23
cat_parser.add_argument('property_object', type=str, action="append")
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    24
cat_parser.add_argument('delete_message', type=str)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    25
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    26
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    27
class CategoryAPI(Resource):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    28
    """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    29
        The API to create and edit categories, returns rdf graph serializations
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    30
        when successful
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    31
    """
3
73b18cb88583 Updated property edition + cache to "get" method so it doesn't generate as many requests to Github API
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 2
diff changeset
    32
    @classmethod
4
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
    33
    @cache.memoize(timeout=3600)
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    34
    def get(cls, cat_id=None):
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    35
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    36
            API to get the category of id cat_id, or if cat_id is None,
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    37
            get the list of category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    38
        """
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    39
        cat_manager_instance = CategoryManager(
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    40
                                   getattr(catedit.persistence,
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    41
                                           app.config["PERSISTENCE_METHOD"])()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    42
                                               )
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    43
        if cat_id is not None:
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    44
            cat = cat_manager_instance.load_cat(cat_id)
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    45
            return cat.cat_graph.serialize(format='turtle').decode("utf-8")
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    46
        else:
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
    47
            response = []
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    48
            for cat in cat_manager_instance.list_cat():
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    49
                response.append(cat.cat_graph.serialize(format='turtle')
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    50
                                             .decode("utf-8"))
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    51
            return response
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    52
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    53
    # update category cat_id
3
73b18cb88583 Updated property edition + cache to "get" method so it doesn't generate as many requests to Github API
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 2
diff changeset
    54
    @classmethod
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    55
    def put(cls, cat_id=None):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    56
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    57
            API to edit the category of id cat_id
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    58
            * If None and persistence support change sets, will submit all
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    59
            changes to category list
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    60
        """
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    61
        cat_manager_instance = CategoryManager(
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    62
            getattr(catedit.persistence, app.config["PERSISTENCE_METHOD"])()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    63
        )
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    64
        args = cat_parser.parse_args()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    65
        if (cat_id is None and
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    66
            cat_manager_instance.persistence.session_compliant is True):
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    67
            cat_manager_instance.save_cat(message=args["commit_message"])
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    68
        else:
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    69
            new_property_list = []
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    70
            logger.debug(args["property_predicate"])
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    71
            logger.debug(args["property_object"])
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    72
            if args["property_predicate"] is not None and \
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    73
               args["property_object"] is not None:
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    74
                for property_predicate, property_object in zip(
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    75
                        args["property_predicate"],
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    76
                        args["property_object"]):
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    77
                    if property_object:
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    78
                        property_object_to_append = property_object
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    79
                        # if URIRef category, we must prefix id with namespace
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    80
                        if (app.config["PROPERTY_LIST"]
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    81
                                      [property_predicate]
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    82
                                      ["object_type"]) == "uriref-category":
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    83
                            property_object_to_append = \
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    84
                                app.config["CATEGORY_NAMESPACE"] \
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    85
                                + property_object
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    86
                            logger.debug(property_object_to_append)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    87
                        new_property_list.append((property_predicate,
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    88
                                                  property_object_to_append))
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    89
            logger.debug(new_property_list)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    90
            cat = cat_manager_instance.load_cat(cat_id)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    91
            cat.edit_category(new_description=args["description"],
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    92
                              new_label=args["label"],
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    93
                              new_other_properties=new_property_list)
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    94
            cat_manager_instance.save_cat(cat, message=args["commit_message"])
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    95
            logger.debug("put id: "+cat.cat_id)
4
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
    96
        cache.clear()
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    97
        return 204
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    98
3
73b18cb88583 Updated property edition + cache to "get" method so it doesn't generate as many requests to Github API
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 2
diff changeset
    99
    @classmethod
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   100
    def post(cls):
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   101
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   102
            API to create a new category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   103
        """
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   104
        args = cat_parser.parse_args()
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   105
        property_list = []
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   106
        logger.debug(args["property_predicate"])
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   107
        logger.debug(args["property_object"])
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   108
        for property_predicate, property_object in zip(
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   109
                request.form.getlist('property_predicate'),
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   110
                request.form.getlist('property_object')):
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   111
            if property_object:
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   112
                if (app.config["PROPERTY_LIST"]
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   113
                              [property_predicate]
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   114
                              ["object_type"]) == "uriref-category":
4
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
   115
                    property_list.append((property_predicate,
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   116
                                          app.config["CATEGORY_NAMESPACE"]
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   117
                                          + property_object))
4
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
   118
                else:
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
   119
                    property_list.append((property_predicate,
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
   120
                                          property_object))
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   121
        logger.debug(property_list)
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   122
        cat = Category(label=args["label"],
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   123
                       description=args["description"],
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   124
                       other_properties=property_list)
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   125
        cat_manager_instance = CategoryManager(
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   126
                                   getattr(catedit.persistence,
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   127
                                           app.config["PERSISTENCE_METHOD"])()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   128
                                               )
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   129
        cat_manager_instance.save_cat(cat, message=args["commit_message"])
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   130
        logger.debug("post id: "+cat.cat_id)
4
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
   131
        cache.clear()
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   132
        return cat.cat_graph.serialize(format='turtle').decode("utf-8"), 201
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   133
3
73b18cb88583 Updated property edition + cache to "get" method so it doesn't generate as many requests to Github API
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 2
diff changeset
   134
    @classmethod
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   135
    def delete(cls, cat_id):
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   136
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   137
            API to delete the category of id cat_id
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   138
        """
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   139
        args = cat_parser.parse_args()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   140
        cat_manager_instance = CategoryManager(
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   141
                                   getattr(catedit.persistence,
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   142
                                           app.config["PERSISTENCE_METHOD"])()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   143
                                               )
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   144
        if args["delete_message"] is None:
5
259707477c10 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
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 4
diff changeset
   145
            message = "Deleting category "+cat_id
259707477c10 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
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 4
diff changeset
   146
        else:
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   147
            message = args["delete_message"]
5
259707477c10 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
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 4
diff changeset
   148
        cat_manager_instance.delete_cat(cat_id, message=message)
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   149
        logger.debug("delete id: "+cat_id)
4
88d4d32a864e Fixed cache clearing bug + category creation bug
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 3
diff changeset
   150
        cache.clear()
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   151
        return 204
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   152
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   153
api.add_resource(CategoryAPI,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   154
                 '/category/<string:cat_id>',
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   155
                 '/category',
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   156
                 endpoint='category')