src/catedit/resources.py
author Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
Fri, 20 Feb 2015 10:55:54 +0100
changeset 45 1506da593f40
parent 43 6d0e2523e17d
child 62 746d486f7c42
permissions -rw-r--r--
Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
"""
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
     2
resources.py:
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
contains the api that links the views (views.py) to the model (models.py) and
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
its persistence method (persistence.py). As it only trades rdf graphs
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
serializations strings, it isn't bound to one specific view
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
"""
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
from rdflib import Graph
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
from flask.ext.restful import Resource, reqparse
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    11
from flask import session
45
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    12
from catedit import app, cache, github
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
from catedit.models import Category, CategoryManager
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
import catedit.persistence
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
from io import StringIO
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
logger = app.logger
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
cat_parser = reqparse.RequestParser()
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
cat_parser.add_argument('label', type=str)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
cat_parser.add_argument('description', type=str)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
cat_parser.add_argument('property_predicate', type=str, action="append")
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
cat_parser.add_argument('property_object', type=str, action="append")
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
23
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
    25
cat_parser.add_argument('commit_message', type=str)
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
    26
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
class CategoryAPI(Resource):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
        The API to create and edit categories, returns rdf graph serializations
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        when successful
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    """
45
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    33
    def get(self, repository, cat_id=""):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
            API to get the category of id cat_id, or if cat_id is None,
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
            get the list of category
45
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    37
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    38
            The result of this API function goes into the Flask Cache.
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        """
45
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    40
        cache_key = "categoryapi_get_" + repository + "_" + cat_id
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    41
        if cache.get(cache_key) is None:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    42
            rv = None
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    43
            cat_manager_instance = CategoryManager(
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    44
                getattr(
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    45
                    catedit.persistence,
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    46
                    app.config["PERSISTENCE_CONFIG"]["METHOD"]
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    47
                )(repository=repository),
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    48
            )
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    49
            if cat_id != "":
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    50
                cat = cat_manager_instance.load_category(cat_id)
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    51
                if cat is not None:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    52
                    rv = cat.cat_graph.serialize(
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    53
                        format='turtle'
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    54
                    ).decode("utf-8"), 200
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    55
                else:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    56
                    rv = 404
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    57
            else:
45
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    58
                response = []
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    59
                for cat in cat_manager_instance.list_categories():
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    60
                    response.append(
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    61
                        cat.cat_graph.serialize(format='turtle').decode("utf-8")
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    62
                    )
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    63
                rv = response, 200
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    64
            cache.set(cache_key, rv, timeout=3600)
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    65
            return rv
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
        else:
45
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    67
            return cache.get(cache_key)
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
    # update category cat_id
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    70
    def put(self, repository, cat_id=None, cat_data=None):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        """
23
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
    72
            API to edit an existing category
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    73
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    74
            Args are:
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    75
            * repository: the repository where the category cat_id is stored
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    76
            * cat_id : the id of the category to edit
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    77
            * cat_data : the new data of the category, dict of the form:
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    78
            {
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    79
                "label": edited_cat_label,
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    80
                "description": edited_cat_description,
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    81
                "properties": [(predicate1, object1), (predicate2, object2)]
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    82
            }
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    83
            List of predicate is available in config.py, key PROPERTY_LIST
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    84
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    85
            Note: If cat_id is None and persistence support change sets, will
23
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
    86
            submit all changes to category list
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
        cat_manager_instance = CategoryManager(
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
    89
            getattr(
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
    90
                catedit.persistence,
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
    91
                app.config["PERSISTENCE_CONFIG"]["METHOD"]
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
    92
            )(repository=repository),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
        )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
        args = cat_parser.parse_args()
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
    95
        if cat_id is None:
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
    96
            if cat_manager_instance.persistence.session_compliant is True:
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
    97
                logger.debug(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
    98
                    "Submitting - deleted categories are:"
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
    99
                    + str(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   100
                        session.get(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   101
                            "deleted_categories", {}
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   102
                        ).get(repository, {})
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   103
                    ) + " and modified categories are:"
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   104
                    + str(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   105
                        session.get(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   106
                            "modified_categories", {}
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   107
                        ).get(repository, {})
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   108
                    )
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   109
                )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
                cat_manager_instance.save_changes(
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   111
                    deleted_cat_dict=session.get(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   112
                        "deleted_categories", {}
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   113
                    ).get(repository, {}),
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   114
                    modified_cat_dict=session.get(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   115
                        "modified_categories", {}
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   116
                    ).get(repository, {}),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
                    message=args["commit_message"]
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
                )
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   119
                session["deleted_categories"]["local"] = {}
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   120
                session["modified_categories"]["local"] = {}
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   121
                cache.clear()
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   122
                return 204
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        else:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
            # is the edition occuring on an already modified category?
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   125
            if (cat_id in session.get(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   126
                    "modified_categories", {}
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   127
            ).get(repository, {}).keys()):
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   128
                cat_graph = Graph()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   129
                cat_graph.parse(
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   130
                    source=StringIO(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   131
                        session["modified_categories"][repository][cat_id]
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   132
                    ),
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   133
                    format="turtle"
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   134
                )
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   135
                cat = Category(graph=cat_graph)
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
            else:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
                cat = cat_manager_instance.load_category(cat_id)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   139
            cat.edit_category(new_description=cat_data["description"],
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   140
                              new_label=cat_data["label"],
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   141
                              new_other_properties=cat_data["properties"])
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   143
            session["modified_categories"][repository][cat.cat_id] = str(
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   144
                cat.cat_graph.serialize(format="turtle"), "utf-8"
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
            )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
            # Now we must clean the deleted categories list in case the
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
            # modified category was deleted before being edited
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   149
            session["deleted_categories"][repository] = {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   150
                cat_name: cat_content for cat_name, cat_content
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   151
                in session["deleted_categories"][repository].items()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   152
                if cat_name != cat.cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   153
            }
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
            logger.debug("put id: "+cat.cat_id)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
        return 204
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   157
    def post(self, repository, cat_data):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
            API to create a new category
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   160
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   161
            Args are:
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   162
            * repository: the repository where the category cat_id is stored
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   163
            * cat_data : the new data of the category, dict of the form:
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   164
            {
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   165
                "label": edited_cat_label,
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   166
                "description": edited_cat_description,
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   167
                "properties": [(predicate1, object1), (predicate2, object2)]
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   168
            }
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   169
            List of predicate is available in config.py, key PROPERTY_LIST
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
        """
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   171
        cat = Category(
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   172
            label=cat_data["label"],
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   173
            description=cat_data["description"],
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   174
            other_properties=cat_data["properties"]
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   175
        )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   177
        if cat.cat_id not in session["modified_categories"][repository].keys():
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   178
            session["modified_categories"][repository][cat.cat_id] = str(
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
                cat.cat_graph.serialize(format="turtle"), "utf-8"
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   180
            )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
        logger.debug("post id: "+cat.cat_id)
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   183
        return cat.cat_id, \
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   184
               cat.cat_graph.serialize(format='turtle').decode("utf-8"), \
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   185
               201
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   187
    def delete(self, repository, deleted_cat_id):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
            API to delete the category of id cat_id or restore it from the
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
            deletion list
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
        """
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   192
        # if cat_id is already in deleted categories, we restore it
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   193
        if deleted_cat_id in session["deleted_categories"][repository].keys():
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   194
            session["deleted_categories"][repository] = {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   195
                cat_name: cat_content for cat_name, cat_content
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   196
                in session["deleted_categories"][repository].items()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   197
                if cat_name != deleted_cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   198
            }
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
            # warning, not safe if 2 files share the same name (or category id)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
            # but that shouldn't happen
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
        else:
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   202
            session["deleted_categories"] \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   203
                   [repository] \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   204
                   [deleted_cat_id] = "deleted"
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   205
            # Maybe we can store something more useful in there, such as
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   206
            # category content when deleted to restore last edit?
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   207
            # It would be nice to have symetry between modified and
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   208
            # deleted dicts
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   209
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
            # now we must clean the modified categories list in case the
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
            # deleted category was modified before
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   212
            session["modified_categories"][repository] = {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   213
                cat_name: cat_content for cat_name, cat_content
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   214
                in session["modified_categories"][repository].items()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   215
                if cat_name != deleted_cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   216
            }
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   217
            logger.debug(str(
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   218
                {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   219
                    cat_name: cat_content for cat_name, cat_content
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   220
                    in session["modified_categories"][repository].items()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   221
                    if cat_name != deleted_cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   222
                }
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   223
            ))
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
            # Now we also have to clean up categories that reference the
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
            # deleted category
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
            cat_manager_instance = CategoryManager(
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
                getattr(
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   228
                    catedit.persistence,
38
d1bc73ce855a Finished WTForms support for properties + Refactored API so it doesn't handle form parsing anymore + added version.py and edited setup.py, version is now displayed in the footer of every page + reworked config to condense every persistence parameter and logging parameter
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 25
diff changeset
   229
                    app.config["PERSISTENCE_CONFIG"]["METHOD"]
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   230
                )(repository=repository),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
            )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
            cat_list = cat_manager_instance.list_categories()
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
            # first we edit what was already modified before the deletion
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   234
            logger.debug(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   235
                session.get("modified_categories", {}).get(repository, {})
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   236
            )
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   237
            if (
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   238
                    deleted_cat_id in
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   239
                    session["deleted_categories"][repository].keys()
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   240
            ):
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   241
                for element in session.get("modified_categories", {}) \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   242
                                      .get(repository, {}).keys():
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
                    logger.debug(str(element))
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
                    modified_cat_graph = Graph()
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
                    modified_cat_graph.parse(
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   246
                        source=StringIO(
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   247
                            session["modified_categories"][repository][element]
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   248
                        ),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
                        format="turtle"
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
                    )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
                    modified_cat = Category(graph=modified_cat_graph)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
                    if (modified_cat.cat_id !=
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
                            app.config["CATEGORY_NAMESPACE"] + deleted_cat_id):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
                        new_property_list = []
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
                        for (predicate, obj) in modified_cat.properties:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
                            if not (
42
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   257
                                    app.config["PROPERTY_LIST"]
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   258
                                    [predicate]
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   259
                                    ["object_type"]
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   260
                                    == "uriref-category"
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   261
                                    and (
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   262
                                        obj == (
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   263
                                            app.config["CATEGORY_NAMESPACE"]
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   264
                                            + deleted_cat_id
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   265
                                        )
dac9b1248e0f V0.1.4: Implemented github social functions into CatEdit: refactored template and views hierarchy, names, views submodule, created macro to generate category tables + small esthetic changes (buttons to display categories/tables switch state, possibility to hide tables) + views modules have been converted into Flask Blueprints
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   266
                                    )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
                            ):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
                                new_property_list.append((predicate, obj))
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
                        if new_property_list != modified_cat.properties:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
                            logger.debug("Modifying modified category")
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
                            modified_cat.edit_category(
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
                                new_other_properties=new_property_list
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
                            )
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   275
                            session["modified_categories"] \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   276
                                   [repository] \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   277
                                   [modified_cat.cat_id] = str(
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   278
                                modified_cat.cat_graph
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   279
                                            .serialize(format="turtle"),
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   280
                                "utf-8"
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
                            )
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   282
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
                # now we check if an unmodified category reference the deleted
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
                # category
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
                for cat in cat_list:
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   286
                    if (cat.cat_id not in (
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   287
                            list(session["modified_categories"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   288
                                        [repository].keys())
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   289
                            + list(session["deleted_categories"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   290
                                          [repository].keys())
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   291
                    )):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
                        new_property_list = []
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
                        for (predicate, obj) in cat.properties:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
                            if not (
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   295
                                    app.config["PROPERTY_LIST"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   296
                                              [predicate]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   297
                                              ["object_type"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   298
                                    == "uriref-category"
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   299
                                    and (
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   300
                                        obj ==
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   301
                                        app.config["CATEGORY_NAMESPACE"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   302
                                        + deleted_cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   303
                                    )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
                            ):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
                                new_property_list.append((predicate, obj))
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
                        if new_property_list != cat.properties:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
                            logger.debug("Modifying untouched category")
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
                            cat.edit_category(
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
                                new_other_properties=new_property_list
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
                            )
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   312
                            session["modified_categories"] \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   313
                                   [repository] \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   314
                                   [cat.cat_id] = str(
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   315
                                cat.cat_graph.serialize(format="turtle"),
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   316
                                "utf-8"
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
                            )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
        logger.debug("delete id: " + deleted_cat_id)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
        return 204
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   322
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
class CategoryChangesAPI(Resource):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
    """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
        API for getting and deleting category changes, returns a dict when
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
        succesful if category is a modified one, returns only the cat_id if it
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
        is a deleted one
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   329
        All changes and deletions are saved in
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   330
        session["modified_categories"][repository] and
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   331
        session["deleted_categories"][repository] under the format:
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   332
        {changed_cat_id: content_of_changed_cat}
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
    """
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   334
    def get(self, repository, modified_cat_id=None):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
            API to get the pending changes for category cat_id
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
        """
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   338
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
        if modified_cat_id is None:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
            return {
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   341
                "modified_categories": session.get("modified_categories", {})
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   342
                                              .get(repository, {}),
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   343
                "deleted_categories": session.get("deleted_categories", {})
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   344
                                             .get(repository, {})
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   345
            }, 200
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
        else:
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   347
            if modified_cat_id in session.get("modified_categories", {}) \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   348
                                         .get(repository, {}):
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   349
                return {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   350
                    "type": "modified",
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   351
                    "category": {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   352
                        modified_cat_id: session["modified_categories"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   353
                                                [repository]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   354
                                                [modified_cat_id]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   355
                    }
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   356
                }, 200
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   357
            if modified_cat_id in session.get("deleted_categories", {}) \
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   358
                                         .get(repository, {}):
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   359
                return {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   360
                    "type": "deleted",
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   361
                    "category": {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   362
                        modified_cat_id: session["deleted_categories"]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   363
                                                [repository]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   364
                                                [modified_cat_id]
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   365
                    }
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   366
                }, 200
23
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   367
            return {
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   368
                "type": "untouched",
877c3b66313a Removed references to REPOSITORY_NAME + some refactoring of cat_editor in views.py (wtforms)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   369
                "category": modified_cat_id
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   370
            }, 200
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   372
    def delete(self, repository, modified_cat_id=None):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
            API to delete the category cat_id from the changelist or if cat_id
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
            is None, delete the whole changelist
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
        """
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   377
        if modified_cat_id is not None:
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   378
            session["modified_categories"][repository] = {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   379
                cat_name: cat_content for cat_name, cat_content
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   380
                in session["modified_categories"][repository].items()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   381
                if cat_name != modified_cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   382
            }
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   383
            session["deleted_categories"][repository] = {
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   384
                cat_name: cat_content for cat_name, cat_content
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   385
                in session["deleted_categories"][repository].items()
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   386
                if cat_name != modified_cat_id
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   387
            }
21
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   388
        else:
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   389
            session["modified_categories"][repository] = {}
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   390
            session["deleted_categories"][repository] = {}
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
        return 204