src/catedit/models.py
author durandn
Mon, 13 Apr 2015 12:03:48 +0200
changeset 95 0a131f9b92a5
parent 87 e7afb5bd5a85
child 103 ef02353dff20
permissions -rw-r--r--
Properties are now cached globally instead of being stored in the session
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     1
"""
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     2
models.py:
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     3
contains the "principal" objects that will be manipulated by the application:
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     4
* categories
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     5
* helper classes to manage category life cycle
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     6
"""
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
     7
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: 54
diff changeset
     8
from catedit import app
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: 54
diff changeset
     9
from io import StringIO
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: 54
diff changeset
    10
import logging
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: 54
diff changeset
    11
from uuid import uuid4
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: 54
diff changeset
    12
69
524e01a8127a Fix to navbar select css + cleaning up leftover unused imports
durandn
parents: 62
diff changeset
    13
from rdflib import Graph, RDF, RDFS, Literal
47
ddba4624d661 Added cache support for getting issues, commits and comments + reworked workshop page, now displaying latest changes and latest opened issues and links to changeset and issues list + changeset page now displays a change summary
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 44
diff changeset
    14
from rdflib.compare import to_isomorphic, graph_diff
7
b3c03d54e144 Make host configurable from config.py (see settings.py) + changed id generation (using slugified labels instead of GUIDs)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
    15
from slugify import slugify
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: 54
diff changeset
    16
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    17
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 17
diff changeset
    18
logger = logging.getLogger(__name__)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    19
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    20
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    21
class Category(object):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    22
    """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    23
        Category Class:
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    24
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    25
        Init:
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    26
        * label is the rdf label of the category, unique and non-empty
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    27
        * description is the description of the category, unique and non-empty
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    28
        * other_properties is a dictionnary containing every other supported
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    29
        property as defined in the PROPERTY_LIST dict in settings.py
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    30
        * graph is used if we want to create the Category from a turtle
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    31
        rdf graph
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    32
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    33
        Additional info:
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    34
        * cat_id is a generated, hidden id that uniquely identify
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    35
        a given category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    36
    """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    37
    def __init__(self, label=None, description=None,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    38
                 other_properties=None, graph=None):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    39
        if not graph:
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
    40
            # cat_id = .hex - Alternate method of generating ids
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
    41
            cat_id = slugify(label)+"_"+str(uuid4())[:8]
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    42
            self.cat_graph = 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: 54
diff changeset
    43
            self.this_category = app.config["CATEGORY_NAMESPACE"][cat_id]
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    44
            self.cat_graph.add((self.this_category, RDF.ID, Literal(cat_id)))
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    45
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    46
            if label:
44
5ab922a46f13 Restored ancient login flow
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    47
                self.cat_graph.add(
5ab922a46f13 Restored ancient login flow
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    48
                    (self.this_category, RDFS.label, Literal(label))
5ab922a46f13 Restored ancient login flow
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    49
                )
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    50
            if description:
44
5ab922a46f13 Restored ancient login flow
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    51
                self.cat_graph.add(
5ab922a46f13 Restored ancient login flow
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    52
                    (self.this_category, RDF.Description, Literal(description))
5ab922a46f13 Restored ancient login flow
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 43
diff changeset
    53
                )
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    54
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    55
            if other_properties:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    56
                for (predicate, obj) in other_properties:
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: 54
diff changeset
    57
                    self.cat_graph.add((self.this_category, predicate, obj))
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    58
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    59
        else:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    60
            self.cat_graph = 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: 54
diff changeset
    61
            # Warning: not foolproof, if loading a Graph with multiple IDs (should not happen)
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: 54
diff changeset
    62
            self.this_category = next(self.cat_graph.subjects(predicate=RDF.ID))
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    63
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    64
    @property
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    65
    def label(self):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    66
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    67
            Returns category label
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    68
        """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    69
        return_value = self.cat_graph.value(self.this_category, RDFS.label)
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    70
        if return_value is None:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    71
            return None
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    72
        else:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    73
            return return_value.toPython()
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    74
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    75
    @property
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    76
    def description(self):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    77
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    78
            Returns category description
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    79
        """
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    80
        return_value = \
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    81
            self.cat_graph.value(self.this_category, RDF.Description)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    82
        if return_value is None:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    83
            return None
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    84
        else:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    85
            return return_value.toPython()
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    86
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    87
    @property
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    88
    def cat_id(self):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    89
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    90
            Returns category id
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    91
        """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    92
        return self.cat_graph.value(self.this_category, RDF.ID).toPython()
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    93
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    94
    @property
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    95
    def properties(self):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    96
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    97
            Returns category property list
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    98
        """
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: 54
diff changeset
    99
        return [
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: 54
diff changeset
   100
            predicate_object_tuple for predicate_object_tuple in self.cat_graph.predicate_objects() 
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: 54
diff changeset
   101
            if (
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: 54
diff changeset
   102
                predicate_object_tuple[0]!=RDF.ID and 
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: 54
diff changeset
   103
                predicate_object_tuple[0]!=RDFS.label and
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: 54
diff changeset
   104
                predicate_object_tuple[0]!=RDF.Description
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: 54
diff changeset
   105
            )
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: 54
diff changeset
   106
        ]
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: 54
diff changeset
   107
        
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   108
    def edit_category(self, new_label="",
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   109
                      new_description="",
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   110
                      new_other_properties=None):
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 7
diff changeset
   111
        """
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   112
            Edits category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   113
            * new_label is the new label of the category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   114
            * new_description is the new description of the category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   115
            * new_other_property is the new property list of the category
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   116
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   117
            new_other_properties default is None because it can't be [], as
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   118
            that would mean we want to delete all properties
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 7
diff changeset
   119
        """
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   120
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   121
        if (new_label != "") and \
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   122
           (new_label != self.label):
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   123
            self.cat_graph.remove((self.this_category,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   124
                                   RDFS.label,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   125
                                   self.cat_graph.label(self.this_category)))
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   126
            self.cat_graph.add((self.this_category,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   127
                                RDFS.label,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   128
                                Literal(new_label)))
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 7
diff changeset
   129
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   130
        if (new_description != "") and \
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   131
           (new_description != self.description):
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   132
            self.cat_graph.remove((self.this_category,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   133
                                  RDF.Description,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   134
                                  self.cat_graph.value(self.this_category,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   135
                                                       RDF.Description)))
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   136
            self.cat_graph.add((self.this_category,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   137
                               RDF.Description,
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   138
                               Literal(new_description)))
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   139
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   140
        logger.debug("current properties: "
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   141
                     + str(self.properties)
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   142
                     + " new properties: "
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   143
                     + str(new_other_properties))
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   144
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   145
        if new_other_properties is not None and \
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   146
           (new_other_properties != self.properties):
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: 54
diff changeset
   147
            for (predicate, object) in self.cat_graph.predicate_objects():
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: 54
diff changeset
   148
                if predicate not in [RDF.ID, RDF.Description, RDFS.label]:
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: 54
diff changeset
   149
                    self.cat_graph.remove(
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: 54
diff changeset
   150
                        (self.this_category, predicate, None)
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: 54
diff changeset
   151
                    )
7
b3c03d54e144 Make host configurable from config.py (see settings.py) + changed id generation (using slugified labels instead of GUIDs)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
   152
            for (predicate, obj) in new_other_properties:
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: 54
diff changeset
   153
                self.cat_graph.add(
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: 54
diff changeset
   154
                    (self.this_category, predicate, 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: 54
diff changeset
   155
                )
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   156
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   157
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   158
class CategoryManager(object):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   159
    """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   160
        CategoryManager class
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   161
        This class deals with creation and loading of Category objects
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   162
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   163
        * load_category returns a category from its id
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   164
        * list_categories returns all categories
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   165
        * save_changes will take a list of modified categories and a list of
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   166
        deleted categories and save the changes using the persistence method
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   167
        * delete_category will delete a single category from its id
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   168
    """
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
   169
    def __init__(self, persistence_method):
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   170
        """
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   171
            persistence_method is a class that must have 4 methods:
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   172
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   173
            * save
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   174
            * load
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   175
            * delete
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   176
            * list
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   177
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   178
            It must save and return RDF graph serializations.
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   179
            See persistence.py for details
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   180
        """
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   181
        self.persistence = persistence_method
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   182
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   183
    def load_category(self, cat_id):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   184
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   185
            Loads a category from its id
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   186
        """
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   187
        cat_serial = self.persistence.load(name=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
   188
        cat = None
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
   189
        if cat_serial != "":
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
   190
            loaded_cat_graph = Graph()
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
   191
            loaded_cat_graph.parse(source=StringIO(cat_serial), format='turtle')
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
   192
            cat = Category(graph=loaded_cat_graph)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   193
        return cat
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   194
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   195
    def save_changes(self,
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
   196
                     deleted_cat_dict=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
   197
                     modified_cat_dict=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
   198
                     message=""):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   199
        """
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   200
            Saves all changes to categories
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   201
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   202
            * deleted_cat_list must be a list of dict describing deleted
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   203
            categories, each dict of the format :
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   204
            {"name": category_id}
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   205
            * modified_cat_list must be a list of dict describing modified
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   206
            categories, each dict of the format :
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   207
            {"name": category_id, "content": category turtle serialization}
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   208
            * message is used as commit message when applicable (github)
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   209
        """
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
   210
        if modified_cat_dict 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
   211
            modified_cat_dict = {}
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 deleted_cat_dict 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
   213
            deleted_cat_dict = {}
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   214
        logger.debug("Calling persistance save method - deleted list is "
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
                     + str(deleted_cat_dict)
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   216
                     + " and modified list is "
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
   217
                     + str(modified_cat_dict))
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   218
        self.persistence.save(deletion_dict=deleted_cat_dict,
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   219
                              modification_dict=modified_cat_dict,
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   220
                              message=message)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   221
43
6d0e2523e17d Pep8/Pylint small changes
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 40
diff changeset
   222
    def delete_category(self, deleted_cat_id):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   223
        """
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   224
            Deletes a category from its id
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   225
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   226
            * message serves as commit message if github is used as a
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   227
            persistence method
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   228
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   229
            NOTE: This will not auto-update existing categories to delete
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   230
            references to deleted category. This is handled in the api as such
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   231
            operations apply to the intermediary persistence (changeset)
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   232
        """
54
b9279505109f message should be more explicit + increment version
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
   233
        self.persistence.delete(name=deleted_cat_id, message="Category deleted")
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   234
        # Now we must clean up the categories that reference the deleted cat
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   235
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 15
diff changeset
   236
    def list_categories(self):
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   237
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   238
            Lists all categories available
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   239
        """
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   240
        cat_serial_list = self.persistence.list()
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   241
        # logger.debug(cat_serial_list)
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 7
diff changeset
   242
        cat_list = []
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   243
        for cat_serial in cat_serial_list:
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   244
            loaded_cat_graph = Graph()
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   245
            loaded_cat_graph.parse(
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   246
                source=StringIO(cat_serial),
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   247
                format='turtle'
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   248
            )
12
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   249
            cat = Category(graph=loaded_cat_graph)
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
   250
            cat_list.append(cat)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   251
        return cat_list