src/catedit/resources.py
author durandn
Wed, 08 Apr 2015 11:27:26 +0200
changeset 63 9494a2d66aea
parent 62 746d486f7c42
child 72 75170fe4d56b
permissions -rw-r--r--
Small changes to navbar ("Page d'Accueil" -> "Accueil")
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
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
     9
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
    10
from catedit.models import Category, CategoryManager
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
import catedit.persistence
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
from io import StringIO
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
    14
from flask import session
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
    15
from rdflib import Graph, URIRef, Literal
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
    16
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
    17
from flask.ext.restful import Resource, reqparse
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
    18
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
    19
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
logger = app.logger
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
cat_parser = reqparse.RequestParser()
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
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
    24
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
    25
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
    26
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
    27
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
    28
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
    29
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
class CategoryAPI(Resource):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        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
    34
        when successful
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    """
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
    36
    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
    37
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
            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
    39
            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
    40
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
            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
    42
        """
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
    43
        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
    44
        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
    45
            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
    46
            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
    47
                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
    48
                    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
    49
                    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
    50
                )(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
    51
            )
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
            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
    53
                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
    54
                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
    55
                    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
    56
                        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
    57
                    ).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
    58
                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
    59
                    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
    60
            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
    61
                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
    62
                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
    63
                    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
    64
                        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
    65
                    )
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
    66
                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
    67
            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
    68
            return rv
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        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
    70
            return cache.get(cache_key)
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    # 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
    73
    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
    74
        """
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
    75
            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
    76
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
            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
    78
            * 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
    79
            * 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
    80
            * 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
    81
            {
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
                "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
    83
                "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
    84
                "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
    85
            }
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
    86
            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
    87
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
    88
            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
    89
            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
    90
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        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
    92
            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
    93
                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
    94
                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
    95
            )(repository=repository),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
        )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
        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
    98
        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
    99
            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
   100
                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
   101
                    "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
   102
                    + 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
   103
                        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
   104
                            "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
   105
                        ).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
   106
                    ) + " 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
   107
                    + 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
   108
                        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
   109
                            "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
   110
                        ).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
   111
                    )
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
                )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
                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
   114
                    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
   115
                        "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
   116
                    ).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
   117
                    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
   118
                        "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
   119
                    ).get(repository, {}),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
                    message=args["commit_message"]
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
                )
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
   122
                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
   123
                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
   124
                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
   125
                return 204
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
        else:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
            # 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
   128
            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
   129
                    "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
   130
            ).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
   131
                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
   132
                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
   133
                    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
   134
                        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
   135
                    ),
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
   136
                    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
   137
                )
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
   138
                cat = Category(graph=cat_graph)
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
            else:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
                cat = cat_manager_instance.load_category(cat_id)
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   141
            
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   142
            new_property_list=[]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   143
            for (predicate, obj) in cat_data["properties"]:
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   144
                if session["properties"][repository][predicate]["object_type"] == "uriref-category":
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   145
                    new_property_list.append(
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   146
                        (URIRef(session["properties"][repository][predicate]["rdflib_class"]), app.config["CATEGORY_NAMESPACE"][obj])
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   147
                    )
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   148
                elif session["properties"][repository][predicate]["object_type"] == "uriref-link":
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   149
                    new_property_list.append(
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   150
                        (URIRef(session["properties"][repository][predicate]["rdflib_class"]), URIRef(obj))
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   151
                    )
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   152
                else:
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   153
                    new_property_list.append(
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   154
                        (URIRef(session["properties"][repository][predicate]["rdflib_class"]), Literal(obj))
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   155
                    )
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
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
            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
   158
                              new_label=cat_data["label"],
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   159
                              new_other_properties=new_property_list)
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
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
   161
            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
   162
                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
   163
            )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
            # 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
   166
            # 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
   167
            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
   168
                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
   169
                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
   170
                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
   171
            }
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
            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
   173
        return 204
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
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
   175
    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
   176
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
            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
   178
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
   179
            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
   180
            * 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
   181
            * 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
   182
            {
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
   183
                "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
   184
                "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
   185
                "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
   186
            }
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
   187
            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
   188
        """
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   189
        property_list = []
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   190
        for (predicate, obj) in cat_data["properties"]:
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   191
            if session["properties"][repository][predicate]["object_type"] == "uriref-category":
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   192
                property_list.append(
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   193
                    (URIRef(session["properties"][repository][predicate]["rdflib_class"]), app.config["CATEGORY_NAMESPACE"][obj])
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   194
                )
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   195
            elif session["properties"][repository][predicate]["object_type"] == "uriref-link":
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   196
                property_list.append(
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   197
                    (URIRef(session["properties"][repository][predicate]["rdflib_class"]), URIRef(obj))
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   198
                )
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   199
            else:
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   200
                property_list.append(
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   201
                    (URIRef(session["properties"][repository][predicate]["rdflib_class"]), Literal(obj))
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   202
                )
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   203
        
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
   204
        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
   205
            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
   206
            description=cat_data["description"],
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   207
            other_properties=property_list
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
   208
        )
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   209
        
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   210
        
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   211
        
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
        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
   213
            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
   214
                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
   215
            )
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
        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
   218
        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
   219
               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
   220
               201
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
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
   222
    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
   223
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
            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
   225
            deletion list
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
        """
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
   227
        # 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
   228
        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
   229
            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
   230
                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
   231
                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
   232
                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
   233
            }
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
            # 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
   235
            # but that shouldn't happen
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
        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
   237
            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
   238
                   [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
   239
                   [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
   240
            # 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
   241
            # 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
   242
            # 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
   243
            # 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
   244
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
            # 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
   246
            # 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
   247
            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
   248
                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
   249
                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
   250
                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
   251
            }
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
   252
            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
   253
                {
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
   254
                    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
   255
                    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
   256
                    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
   257
                }
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
   258
            ))
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
            # 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
   260
            # deleted category
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
            cat_manager_instance = CategoryManager(
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
                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
   263
                    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
   264
                    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
   265
                )(repository=repository),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
            )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
            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
   268
            # 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
   269
            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
   270
                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
   271
            )
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
   272
            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
   273
                    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
   274
                    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
   275
            ):
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
   276
                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
   277
                                      .get(repository, {}).keys():
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
                    logger.debug(str(element))
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
                    modified_cat_graph = Graph()
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
                    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
   281
                        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
   282
                            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
   283
                        ),
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
                        format="turtle"
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
                    )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
                    modified_cat = Category(graph=modified_cat_graph)
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   287
                    if (modified_cat.cat_id != app.config["CATEGORY_NAMESPACE"][deleted_cat_id]):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
                        new_property_list = []
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
                        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
   290
                            if not (
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   291
                                    session["properties"]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   292
                                           [repository]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   293
                                           [predicate.toPython()]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   294
                                           ["object_type"]
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
   295
                                    == "uriref-category"
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   296
                                    and (obj == app.config["CATEGORY_NAMESPACE"][deleted_cat_id])
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
                            ):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
                                new_property_list.append((predicate, obj))
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
                        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
   301
                            logger.debug("Modifying modified category")
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
                            modified_cat.edit_category(
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
                                new_other_properties=new_property_list
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
                            )
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
   305
                            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
   306
                                   [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
   307
                                   [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
   308
                                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
   309
                                            .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
   310
                                "utf-8"
20
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
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
                # 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
   314
                # category
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
                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
   316
                    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
   317
                            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
   318
                                        [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
   319
                            + 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
   320
                                          [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
   321
                    )):
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
                        new_property_list = []
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
                        for (predicate, obj) in cat.properties:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
                            if not (
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   325
                                    session["properties"]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   326
                                           [repository]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   327
                                           [predicate.toPython()]
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   328
                                           ["object_type"]
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
                                    == "uriref-category"
62
746d486f7c42 Added support for custom properties per repository + added doc in the readme for this (config.py PROPERTY_LIST entry has changed a bit)
durandn
parents: 45
diff changeset
   330
                                    and (obj == app.config["CATEGORY_NAMESPACE"][deleted_cat_id])
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
                            ):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
                                new_property_list.append((predicate, obj))
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
                        if new_property_list != cat.properties:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
                            logger.debug("Modifying untouched category")
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
                            cat.edit_category(
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
                                new_other_properties=new_property_list
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
                            )
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
   339
                            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
   340
                                   [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
   341
                                   [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
   342
                                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
   343
                                "utf-8"
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
                            )
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
        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
   347
        return 204
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
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
   349
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
class CategoryChangesAPI(Resource):
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
    """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
        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
   353
        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
   354
        is a deleted one
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
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
   356
        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
   357
        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
   358
        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
   359
        {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
   360
    """
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
   361
    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
   362
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
            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
   364
        """
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
   365
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
        if modified_cat_id is None:
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
            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
   368
                "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
   369
                                              .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
   370
                "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
   371
                                             .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
   372
            }, 200
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
        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
   374
            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
   375
                                         .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
   376
                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
   377
                    "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
   378
                    "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
   379
                        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
   380
                                                [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
   381
                                                [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
                    }
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
   383
                }, 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
   384
            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
   385
                                         .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
   386
                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
   387
                    "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
   388
                    "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
   389
                        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
   390
                                                [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
   391
                                                [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
   392
                    }
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
   393
                }, 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
   394
            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
   395
                "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
   396
                "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
   397
            }, 200
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
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
   399
    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
   400
        """
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
            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
   402
            is None, delete the whole changelist
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
        """
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
   404
        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
   405
            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
   406
                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
   407
                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
   408
                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
   409
            }
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
   410
            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
   411
                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
   412
                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
   413
                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
   414
            }
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
   415
        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
   416
            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
   417
            session["deleted_categories"][repository] = {}
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
        return 204