src/catedit/persistence.py
author durandn
Mon, 13 Apr 2015 18:13:14 +0200
changeset 98 4a493776539a
parent 87 e7afb5bd5a85
child 103 ef02353dff20
permissions -rw-r--r--
cleaned up last small code from before using wtforms
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
persistence.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 what we need to make a (category) objects (see models.py) persist
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
beyond application scope and load them from outside sources
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
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
For now we can save, load and 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
     7
* to/from a file (using a turtle rdf graph serialization for 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
     8
* to/from a github repository (using a turtle rdf graph serialization
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
     9
for 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
    10
"""
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    11
from abc import ABCMeta, abstractmethod
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: 42
diff changeset
    12
from catedit import github, app, log_api_rate
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
    13
from base64 import b64decode
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
    14
from flask.ext.github import GitHubError
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    15
import os
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    16
import json
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    17
14
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 13
diff changeset
    18
logger = app.logger
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
    19
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
    20
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    21
class Persistence:
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
        Meta-class for all persistence classes
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
    """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    25
    __metaclass__ = ABCMeta
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    26
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    27
    @abstractmethod
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: 13
diff changeset
    28
    def session_compliant(self):
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: 13
diff changeset
    29
        """
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: 13
diff changeset
    30
            Abstract - Can this persistence submit a changeset?
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: 13
diff changeset
    31
        """
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: 13
diff changeset
    32
        return
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: 13
diff changeset
    33
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: 13
diff changeset
    34
    @abstractmethod
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    35
    def save(self, **kwargs):
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
    36
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    37
            Abstract - Saves object
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    38
        """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    39
        return
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    40
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    41
    @abstractmethod
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    42
    def delete(self, **kwargs):
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
    43
        """
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    44
            Abstract - Deletes object
8ca7be41e3ca Pylint + pep8 + adapted code to Python 3 + added support for authentication when persistence is set to PersistenceToFile + cleaning up settings.py/config.py.tmpl and updated readme
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 11
diff changeset
    45
        """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    46
        return
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    47
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    48
    @abstractmethod
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    49
    def load(self, **kwargs):
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
    50
        """
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
    51
            Abstract - Loads object
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
    52
        """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    53
        return
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
    @abstractmethod
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    56
    def list(self, **kwargs):
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
    57
        """
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
    58
            Abstract - Lists objects
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
    59
        """
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    60
        return
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    61
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    62
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    63
class PersistenceToFile(Persistence):
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
    64
    """
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
    65
        Persistence Class for saving to a local file (see config.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
    66
        for tweaking)
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
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
        Expected kwargs for saving to/loading from a file are:
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
    69
        * name : name of the file to write in/read from
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
    70
        * content : desired content of the file when writing
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
    71
    """
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: 39
diff changeset
    72
    def __init__(self, **kwargs):
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: 39
diff changeset
    73
        pass
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: 39
diff changeset
    74
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: 13
diff changeset
    75
    @property
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: 13
diff changeset
    76
    def session_compliant(self):
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: 13
diff changeset
    77
        """
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: 13
diff changeset
    78
            Not session compliant: each modification is submitted
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: 13
diff changeset
    79
        """
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: 39
diff changeset
    80
        return True
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: 13
diff changeset
    81
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
    82
    def save(self, **kwargs):
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
    83
        """
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
    84
            Saves to a file
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: 39
diff changeset
    85
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: 39
diff changeset
    86
            Expected args:
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: 39
diff changeset
    87
            * deletion_dict
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: 39
diff changeset
    88
            * modification_dict
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
        """
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: 39
diff changeset
    90
        modification_dict = kwargs["modification_dict"]
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: 39
diff changeset
    91
        deletion_dict = kwargs["deletion_dict"]
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: 39
diff changeset
    92
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: 39
diff changeset
    93
        for (file_name, file_content) in modification_dict.items():
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: 39
diff changeset
    94
            path_to_save = app.config["PERSISTENCE_CONFIG"] \
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: 39
diff changeset
    95
                                     ["FILE_SAVE_DIRECTORY"] \
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: 39
diff changeset
    96
                           + file_name
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: 39
diff changeset
    97
            print(path_to_save)
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: 39
diff changeset
    98
            file_to_save = open(path_to_save, 'wb')
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: 39
diff changeset
    99
            file_to_save.write(bytes(file_content, "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: 39
diff changeset
   100
            file_to_save.close()
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: 39
diff changeset
   101
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: 39
diff changeset
   102
        for file_name in deletion_dict.keys():
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: 39
diff changeset
   103
            path_to_delete = app.config["PERSISTENCE_CONFIG"] \
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: 39
diff changeset
   104
                                       ["FILE_SAVE_DIRECTORY"] \
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: 39
diff changeset
   105
                             + file_name
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: 39
diff changeset
   106
            os.remove(path_to_delete)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   107
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   108
    def load(self, **kwargs):
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
   109
        """
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
   110
            Loads from a file
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
   111
        """
39
67d2ddbebf7e Quick fix previous commit (syntax error)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   112
        path_to_load = app.config["PERSISTENCE_CONFIG"]["FILE_SAVE_DIRECTORY"] \
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: 31
diff changeset
   113
                       + kwargs["name"]
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: 39
diff changeset
   114
        try:
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: 39
diff changeset
   115
            file_to_load = open(path_to_load, 'rb')
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: 39
diff changeset
   116
            file_content = str(file_to_load.read(), "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: 39
diff changeset
   117
            print(file_content)
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: 39
diff changeset
   118
            file_to_load.close()
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: 39
diff changeset
   119
        except FileNotFoundError:
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: 39
diff changeset
   120
            file_content=""
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   121
        return file_content
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   122
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   123
    def delete(self, **kwargs):
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
   124
        """
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
   125
            Deletes a file
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
   126
        """
39
67d2ddbebf7e Quick fix previous commit (syntax error)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
   127
        path_to_delete = app.config["PERSISTENCE_CONFIG"] \
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: 31
diff changeset
   128
                                   ["FILE_SAVE_DIRECTORY"] + kwargs["name"]
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   129
        os.remove(path_to_delete)
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   130
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   131
    # IDEA: return { file_name: file_content } type dict
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   132
    def list(self, **kwargs):
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
   133
        """
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
   134
            Lists all files in file directory (as set in config.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
   135
        """
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
   136
        file_content_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: 31
diff changeset
   137
        for file_name in os.listdir(app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   138
                                              ["FILE_SAVE_DIRECTORY"]):
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 8
diff changeset
   139
            if not file_name or file_name[0] == ".":
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 8
diff changeset
   140
                continue
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: 39
diff changeset
   141
            path_to_load = app.config["PERSISTENCE_CONFIG"] \
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: 39
diff changeset
   142
                                     ["FILE_SAVE_DIRECTORY"] + file_name
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: 39
diff changeset
   143
            file_to_load = open(path_to_load, 'rb')
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: 39
diff changeset
   144
            file_content = str(file_to_load.read(), "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: 39
diff changeset
   145
            file_to_load.close()
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   146
            file_content_list.append(file_content)
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: 13
diff changeset
   147
        # logger.debug(file_content_list)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   148
        return file_content_list
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   149
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
   150
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   151
class PersistenceToGithub(Persistence):
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
   152
    """
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
   153
        Persistence Class for saving to/loading from a Github repository (see
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
   154
        config.py for tweaks)
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
   155
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
   156
        Expected kwargs for saving to/loading from a Github repository are:
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
   157
        * name : name of the file to write in/read from
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
   158
        * content : desired content of the file when writing
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
        * message : when saving or deleting, commit message to be saved
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
        to Github
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
    """
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
   162
    def __init__(self, **kwargs):
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
   163
        self.repository = kwargs.get("repository", "")
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
   164
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: 13
diff changeset
   165
    @property
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: 13
diff changeset
   166
    def session_compliant(self):
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: 13
diff changeset
   167
        """
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: 13
diff changeset
   168
            Not session compliant: each modification is comitted
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: 13
diff changeset
   169
        """
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: 13
diff changeset
   170
        return True
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 13
diff changeset
   171
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   172
    def save(self, **kwargs):
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: 13
diff changeset
   173
        """
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: 13
diff changeset
   174
            Saves all the recorded files in the session dict to a Github
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: 13
diff changeset
   175
            repository
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: 13
diff changeset
   176
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: 13
diff changeset
   177
            Expected kwargs is:
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: 13
diff changeset
   178
            * message: the commit message to document the changes
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
   179
            * deletion_dict : a dict where the keys are the name of the files
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   180
            to delete, from the category repository (defined 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
   181
            config["CATEGORIES_PATH"]), currently value is a fixed
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
   182
            string
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
   183
                {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
   184
            * modification_dict: a dict where they keys are the name of the
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
   185
            files that changed and the values are the contents of said files
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
   186
                {name_of_the_file: content_of_the_file}
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: 13
diff changeset
   187
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: 13
diff changeset
   188
            IMPORTANT: To save to a file Github, we have to use Git
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: 13
diff changeset
   189
            internal mechanics:
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: 13
diff changeset
   190
            1) Get the current reference for master branch
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: 13
diff changeset
   191
            2) Get the latest commit on that reference
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: 13
diff changeset
   192
            3) Get the tree associated to this commit
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: 13
diff changeset
   193
            4) Create a new tree using the old tree and the session dict that
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: 13
diff changeset
   194
            contains all the changes (keys are "modified_categories" 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: 13
diff changeset
   195
            "deleted_categories")
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: 13
diff changeset
   196
                4-1) This requires creating new blobs for new files
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: 13
diff changeset
   197
            5) Create a new commit referencing the previous commit as parent
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: 13
diff changeset
   198
            and the new tree we just created
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: 13
diff changeset
   199
            6) Update the master branch reference so it points on this new
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: 13
diff changeset
   200
            commit
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: 13
diff changeset
   201
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: 13
diff changeset
   202
            About point 4):
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: 13
diff changeset
   203
            We have 3 list of elements: files already in repo, modified files,
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: 13
diff changeset
   204
            and deleted_files
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: 13
diff changeset
   205
            First, we loop on the files already in repo: this allows us to
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: 13
diff changeset
   206
            update it (if it's in both original file list and modified files
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: 13
diff changeset
   207
            list) or delete it (if it's in both original file list and deleted
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: 13
diff changeset
   208
            files 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: 13
diff changeset
   209
            Then, we loop on the modified files list. If it isn't in the
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: 13
diff changeset
   210
            original file list, then it's a new file and we append it to the
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: 13
diff changeset
   211
            tree
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: 13
diff changeset
   212
        """
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: 13
diff changeset
   213
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
   214
        deletion_dict = kwargs["deletion_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
   215
        modification_dict = kwargs["modification_dict"]
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   216
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: 13
diff changeset
   217
        # point 1
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
   218
        try:
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
   219
            ref_master = github.get(
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
   220
                "repos/"
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: 31
diff changeset
   221
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
                + self.repository
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: 42
diff changeset
   223
                + "/git/refs/heads/master",
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: 42
diff changeset
   224
                hooks=dict(response=log_api_rate)
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
   225
            )
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   226
            #TODO: vérifier encoding - logger.debug(str(ref_master))
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
   227
        except GitHubError as ghe:
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: 39
diff changeset
   228
            logger.error("GitHubError trying to get the reference "
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   229
                         + "to the master branch")
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: 39
diff changeset
   230
            logger.error(
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
   231
                "Endpoint: "
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
   232
                + "repos/"
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: 31
diff changeset
   233
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   234
                + self.repository
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
   235
                + "/git/refs/heads/master"
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
   236
            )
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: 39
diff changeset
   237
            logger.error(ghe.response.text)
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   238
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: 13
diff changeset
   239
        # point 2
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
   240
        try:
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
   241
            last_commit_master = github.get(
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
   242
                "repos/"
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: 31
diff changeset
   243
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   244
                + self.repository
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
   245
                + "/git/commits/"
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: 42
diff changeset
   246
                + ref_master["object"]["sha"],
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: 42
diff changeset
   247
                hooks=dict(response=log_api_rate)
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
   248
            )
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   249
            #TODO: vérifier encoding - logger.debug(str(last_commit_master))
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
   250
        except GitHubError as ghe:
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: 39
diff changeset
   251
            logger.error("GitHubError trying to get the commit associated "
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   252
                         + "to the latest reference to the master branch")
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: 39
diff changeset
   253
            logger.error(ghe.response.text)
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: 13
diff changeset
   254
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   255
        # Point 3
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
   256
        try:
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
   257
            last_commit_tree = github.get(
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
   258
                "repos/"
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: 31
diff changeset
   259
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   260
                + self.repository
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
   261
                + "/git/trees/"
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
   262
                + last_commit_master["tree"]["sha"]
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: 42
diff changeset
   263
                + "?recursive=1",
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: 42
diff changeset
   264
                hooks=dict(response=log_api_rate)
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
            )
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   266
            #TODO: vérifier encoding - logger.debug(str(last_commit_tree))
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
   267
        except GitHubError as ghe:
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: 39
diff changeset
   268
            logger.error("GitHubError trying to get the tree from the commit "
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   269
                         + "associated to the latest reference to the master "
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   270
                         + "branch")
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: 39
diff changeset
   271
            logger.error(ghe.response.text)
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: 13
diff changeset
   272
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   273
        # Point 4
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: 13
diff changeset
   274
        new_tree_data = {"tree": []}
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   275
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   276
        # First we loop over the existing elements to spot which are modified
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   277
        # and which are untouched and create new blobs when needed
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: 13
diff changeset
   278
        for element in last_commit_tree["tree"]:
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: 13
diff changeset
   279
            if element["type"] == "blob":
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: 13
diff changeset
   280
                # test if element is in deleted categories, if it is,
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: 13
diff changeset
   281
                # no point doing anything, the file won't be in the new tree
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   282
                if not(
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   283
                    element["path"] in [
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: 31
diff changeset
   284
                        (app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   285
                                   ["CATEGORIES_PATH"] + cat_name)
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   286
                        for cat_name in deletion_dict.keys()
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   287
                    ]
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   288
                ):
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: 13
diff changeset
   289
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: 13
diff changeset
   290
                    # the element is either modified or untouched so in both
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: 13
diff changeset
   291
                    # case we'll need a blob sha
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: 13
diff changeset
   292
                    blob_sha = ""
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: 13
diff changeset
   293
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: 13
diff changeset
   294
                    # test if element is in modified categories
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   295
                    if (
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   296
                        element["path"] in [
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: 31
diff changeset
   297
                            (app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   298
                                       ["CATEGORIES_PATH"] + cat_name)
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
   299
                            for cat_name in modification_dict.keys()
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   300
                        ]
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   301
                    ):
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: 13
diff changeset
   302
                        # find element in modified categories
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
   303
                        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
   304
                                in modification_dict.items():
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: 13
diff changeset
   305
                            if element["path"] == (
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: 31
diff changeset
   306
                                app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   307
                                          ["CATEGORIES_PATH"] + cat_name
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   308
                            ):
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   309
                                # 4-1 for modified files, creating a new blob
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: 13
diff changeset
   310
                                new_blob_data = {
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
   311
                                    "content": cat_content,
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   312
                                    "encoding": "utf-8"
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   313
                                }
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
   314
                                try:
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
   315
                                    new_blob = github.post(
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
   316
                                        "repos/"
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: 31
diff changeset
   317
                                        + app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   318
                                                    ["REPOSITORY_OWNER"] + "/"
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
   319
                                        + self.repository
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
   320
                                        + "/git/blobs",
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: 42
diff changeset
   321
                                        data=new_blob_data,
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: 42
diff changeset
   322
                                        hooks=dict(response=log_api_rate)
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
   323
                                    )
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
   324
                                    blob_sha = new_blob["sha"]
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
   325
                                    break
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
   326
                                except GitHubError as ghe:
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: 39
diff changeset
   327
                                    logger.error(
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   328
                                        "GitHubError trying to post a new"
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   329
                                        + "blob with following data: "
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
   330
                                        + str(new_blob_data)
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
   331
                                    )
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: 39
diff changeset
   332
                                    logger.error(ghe.response.text)
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
   333
                                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
   334
                                    github.get("rate_limit")["resources"]
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
   335
                                ))
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: 13
diff changeset
   336
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   337
                    # this means element is an untouched file so we just get
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   338
                    # its sha
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: 13
diff changeset
   339
                    else:
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 13
diff changeset
   340
                        blob_sha = element["sha"]
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: 13
diff changeset
   341
                    new_tree_data["tree"].append({"path": element["path"],
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: 13
diff changeset
   342
                                                  "mode": element["mode"],
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: 13
diff changeset
   343
                                                  "type": "blob",
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   344
                                                  "sha": blob_sha})
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   345
        #TODO: vérifier encoding - logger.debug(str(new_tree_data["tree"]))
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   346
        # Now we loop over modified categories to find the ones that don't
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   347
        # exist yet in the last commit tree in order to create blobs for them
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
   348
        for (cat_name, cat_content) in modification_dict.items():
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: 31
diff changeset
   349
            logger.debug(app.config["PERSISTENCE_CONFIG"]
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: 42
diff changeset
   350
                                   ["CATEGORIES_PATH"]
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   351
                         + cat_name
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: 13
diff changeset
   352
                         + " should not be in "
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   353
                         + str([elt["path"] for
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   354
                                elt in last_commit_tree["tree"]]))
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: 31
diff changeset
   355
            if (app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   356
                          ["CATEGORIES_PATH"] + cat_name not in
22
0ba28595fd4d Refactoring: change lists are now dicts + template inheritance for app pages + added debug messages with remaining github request count after each github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 21
diff changeset
   357
                    [elt["path"] for elt in last_commit_tree["tree"]]):
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: 13
diff changeset
   358
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   359
                # 4-1 for added files, creating a new blob
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
   360
                new_blob_data = {"content": cat_content,
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   361
                                 "encoding": "utf-8"}
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
   362
                try:
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
   363
                    new_blob = github.post(
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
   364
                        "repos/"
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: 31
diff changeset
   365
                        + app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   366
                                    ["REPOSITORY_OWNER"] + "/"
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
   367
                        + self.repository
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
   368
                        + "/git/blobs",
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: 42
diff changeset
   369
                        data=new_blob_data,
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: 42
diff changeset
   370
                        hooks=dict(response=log_api_rate)
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
   371
                    )
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   372
                except GitHubError as ghe:
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: 39
diff changeset
   373
                    logger.error(
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   374
                        "GitHubError trying to post a new blob with following"
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   375
                        + "data: "
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
   376
                        + str(new_blob_data)
b1b002c5ff60 Added support for multiple repositories + Started work on template inheritance (only created empty base template so far)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   377
                    )
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: 39
diff changeset
   378
                    logger.error(ghe.response.text)
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: 42
diff changeset
   379
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: 13
diff changeset
   380
                new_tree_data["tree"].append({
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: 31
diff changeset
   381
                    "path": app.config["PERSISTENCE_CONFIG"]
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: 31
diff changeset
   382
                                      ["CATEGORIES_PATH"] + cat_name,
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   383
                    "mode": "100644",
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   384
                    "type": "blob",
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   385
                    "sha": new_blob["sha"]
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   386
                })
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   387
        #TODO: vérifier encoding - logger.debug(str(new_tree_data))
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: 13
diff changeset
   388
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: 13
diff changeset
   389
        # Finally, we post the new tree
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
   390
        try:
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
   391
            new_tree_response = github.post(
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
   392
                "repos/"
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: 31
diff changeset
   393
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   394
                + self.repository
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
   395
                + "/git/trees",
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
   396
                data=new_tree_data
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: 42
diff changeset
   397
            ),
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: 42
diff changeset
   398
            hooks=dict(response=log_api_rate)
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
        except GitHubError as ghe:
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: 39
diff changeset
   400
            logger.error(
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
   401
                "GitHubError trying to post a new tree with following data: "
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
   402
                + str(new_tree_data)
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
   403
            )
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: 39
diff changeset
   404
            logger.error(ghe.response.text)
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   405
        #TODO: vérifier encoding - logger.debug(str(new_tree_response[0]["sha"]))
56
ae469e83026f Fixed errors when submitting (Github api sends tuples for commit parents now) + Fixed error when editing (session entry for modified and deleted categories didn't initialize properly) + added back links to workshop page on discussion list and changeset list
durandn
parents: 53
diff changeset
   406
        
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   407
        # Point 5
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: 13
diff changeset
   408
        new_commit_data = {"message": kwargs["message"],
fc63b1a3d2ef Added support for making multiple changes in a single commit, using the flask dict "session" (keys used are "modified_categories" and "deleted_categories") + Added a view for editing categories that allows the user to see what he has added, deleted or edited + Made it so an unauthenticated user should not generate any Github api request (you have to be logged to see the categories now).
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 13
diff changeset
   409
                           "parents": [last_commit_master["sha"]],
56
ae469e83026f Fixed errors when submitting (Github api sends tuples for commit parents now) + Fixed error when editing (session entry for modified and deleted categories didn't initialize properly) + added back links to workshop page on discussion list and changeset list
durandn
parents: 53
diff changeset
   410
                           "tree": new_tree_response[0]["sha"]}
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   411
        #TODO: vérifier encoding - logger.debug(str(new_commit_data))
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
   412
        try:
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
   413
            new_commit = github.post(
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
   414
                "repos/"
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: 31
diff changeset
   415
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   416
                + self.repository
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
   417
                + "/git/commits",
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
   418
                data=new_commit_data
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: 42
diff changeset
   419
            ),
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: 42
diff changeset
   420
            hooks=dict(response=log_api_rate)
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   421
            #TODO: vérifier encoding - logger.debug(str(new_commit))
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
   422
        except GitHubError as ghe:
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: 39
diff changeset
   423
            logger.error(
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
   424
                "GitHubError trying to post a new commit with following data: "
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
   425
                + str(new_commit_data)
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
   426
            )
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: 39
diff changeset
   427
            logger.error(ghe.response.text)
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: 13
diff changeset
   428
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   429
        # Point 6
56
ae469e83026f Fixed errors when submitting (Github api sends tuples for commit parents now) + Fixed error when editing (session entry for modified and deleted categories didn't initialize properly) + added back links to workshop page on discussion list and changeset list
durandn
parents: 53
diff changeset
   430
        new_head_data = {"sha": new_commit[0]["sha"], "force": "true"}
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   431
        #TODO: vérifier encoding - logger.debug(str(new_head_data))
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
   432
        try:
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
   433
            new_head = github.patch(
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
   434
                "repos/"
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: 31
diff changeset
   435
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   436
                + self.repository
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
   437
                + "/git/refs/heads/master",
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: 42
diff changeset
   438
                data=json.dumps(new_head_data),
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: 42
diff changeset
   439
                hooks=dict(response=log_api_rate)
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
   440
            )
87
e7afb5bd5a85 clean log + session["tasks"] error
durandn
parents: 56
diff changeset
   441
            #TODO: vérifier encoding - logger.debug(str(new_head))
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
   442
        except GitHubError as ghe:
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: 39
diff changeset
   443
            logger.error(
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   444
                "GitHubError trying to edit the head to the master branch"
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 22
diff changeset
   445
                + "with the following data: "
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
   446
                + str(new_head_data)
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
   447
            )
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: 39
diff changeset
   448
            logger.error(ghe.response.text)
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: 42
diff changeset
   449
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
   450
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   451
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   452
    def load(self, **kwargs):
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
   453
        """
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
   454
            Loads from a Github repository
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
   455
        """
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: 39
diff changeset
   456
        file_content=""
1
83d266c0c832 Initial commit (this time I'll push) + added checks if the authenticated user has write access to categories repo + added try except blocks around github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 0
diff changeset
   457
        try:
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
   458
            filedict = github.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
   459
                "repos/"
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
   460
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   461
                + self.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
   462
                + "/contents/"
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
   463
                + app.config["PERSISTENCE_CONFIG"]["CATEGORIES_PATH"]
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: 42
diff changeset
   464
                + kwargs["name"],
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: 42
diff changeset
   465
                hooks=dict(response=log_api_rate)
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
   466
            )
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
   467
            file_content = str(b64decode(filedict["content"]), "utf-8")
13
ea5f985156b1 Fix to github error handling
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   468
        except GitHubError as ghe:
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: 39
diff changeset
   469
            logger.error("Github Error trying to get file: "+kwargs["name"])
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: 39
diff changeset
   470
            logger.error("Github sent an error, if 404, either you may not "
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: 39
diff changeset
   471
                         + "have access to the repository or the file doesn't "
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: 39
diff changeset
   472
                         + "exist ")
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: 39
diff changeset
   473
            logger.error(ghe.response.text)
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: 42
diff changeset
   474
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   475
        return file_content
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   476
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   477
    def delete(self, **kwargs):
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
   478
        """
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
   479
            Deletes from a Github repository
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   480
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   481
            Expected kwargs are:
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   482
            * name : the name of the file to delete
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   483
            * message : the commit message for the deletion
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
   484
        """
17
2db9202ad7cf Refactoring (removing references to session in models.py and persistence.py)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 16
diff changeset
   485
        pass
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   486
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   487
    def list(self, **kwargs):
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
   488
        """
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
   489
            Lists all files in the github repository (as set in config.py)
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: 42
diff changeset
   490
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: 42
diff changeset
   491
            Process is as follows:
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: 42
diff changeset
   492
            1) Get the current reference for master branch
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: 42
diff changeset
   493
            2) Get the latest commit on that reference
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: 42
diff changeset
   494
            3) Get the tree associated to this commit
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: 42
diff changeset
   495
            4) From the tree extract all the filenames
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: 42
diff changeset
   496
            5) For each file name, get the content
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
   497
        """
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: 42
diff changeset
   498
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
   499
        filenames_list = []
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: 42
diff changeset
   500
        # point 1
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   501
        try:
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: 42
diff changeset
   502
            ref_master = github.get(
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: 42
diff changeset
   503
                "repos/"
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: 42
diff changeset
   504
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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: 42
diff changeset
   505
                + self.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: 42
diff changeset
   506
                + "/git/refs/heads/master",
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: 42
diff changeset
   507
                hooks=dict(response=log_api_rate)
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: 42
diff changeset
   508
            )
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: 42
diff changeset
   509
        except GitHubError as ghe:
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: 42
diff changeset
   510
            logger.error("GitHubError trying to get the reference "
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: 42
diff changeset
   511
                         + "to the master branch")
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: 42
diff changeset
   512
            logger.error(
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: 42
diff changeset
   513
                "Endpoint: "
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: 42
diff changeset
   514
                + "repos/"
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: 42
diff changeset
   515
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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: 42
diff changeset
   516
                + self.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: 42
diff changeset
   517
                + "/git/refs/heads/master"
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: 42
diff changeset
   518
            )
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: 42
diff changeset
   519
            logger.error(ghe.response.text)
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: 42
diff changeset
   520
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: 42
diff changeset
   521
        # point 2
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: 42
diff changeset
   522
        try:
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: 42
diff changeset
   523
            last_commit_master = github.get(
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
   524
                "repos/"
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
   525
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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
   526
                + self.repository
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: 42
diff changeset
   527
                + "/git/commits/"
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: 42
diff changeset
   528
                + ref_master["object"]["sha"],
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: 42
diff changeset
   529
                hooks=dict(response=log_api_rate)
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
   530
            )
13
ea5f985156b1 Fix to github error handling
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   531
        except GitHubError as ghe:
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: 42
diff changeset
   532
            logger.error("GitHubError trying to get the commit associated "
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: 42
diff changeset
   533
                         + "to the latest reference to the master branch")
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: 39
diff changeset
   534
            logger.error(ghe.response.text)
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
   535
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: 42
diff changeset
   536
        # Point 3
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: 42
diff changeset
   537
        try:
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: 42
diff changeset
   538
            last_commit_tree = github.get(
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: 42
diff changeset
   539
                "repos/"
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: 42
diff changeset
   540
                + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
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: 42
diff changeset
   541
                + self.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: 42
diff changeset
   542
                + "/git/trees/"
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: 42
diff changeset
   543
                + last_commit_master["tree"]["sha"]
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: 42
diff changeset
   544
                + "?recursive=1",
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: 42
diff changeset
   545
                hooks=dict(response=log_api_rate)
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: 42
diff changeset
   546
            )
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: 42
diff changeset
   547
        except GitHubError as ghe:
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: 42
diff changeset
   548
            logger.error("GitHubError trying to get the tree from the commit "
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: 42
diff changeset
   549
                         + "associated to the latest reference to the master "
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: 42
diff changeset
   550
                         + "branch")
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: 42
diff changeset
   551
            logger.error(ghe.response.text)
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: 42
diff changeset
   552
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: 42
diff changeset
   553
        # Point 4
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: 42
diff changeset
   554
        filenames_list = [
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: 42
diff changeset
   555
            elt["path"]
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: 42
diff changeset
   556
            for elt in last_commit_tree["tree"]
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: 42
diff changeset
   557
            if elt["type"] == "blob" and elt["path"].startswith(
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: 42
diff changeset
   558
                app.config["PERSISTENCE_CONFIG"]["CATEGORIES_PATH"]
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: 42
diff changeset
   559
            )
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: 42
diff changeset
   560
        ]
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: 42
diff changeset
   561
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: 42
diff changeset
   562
        # Point 5
8
d02faa4a2eb2 pep8-fication + cleaning comments so the only comments lefts are to be replaced by logs into a file
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 5
diff changeset
   563
        file_content_list = []
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   564
        for filename in filenames_list:
1
83d266c0c832 Initial commit (this time I'll push) + added checks if the authenticated user has write access to categories repo + added try except blocks around github api request
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 0
diff changeset
   565
            try:
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
   566
                filedict = github.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
   567
                    "repos/"
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: 42
diff changeset
   568
                    + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"]
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: 42
diff changeset
   569
                    + "/" + self.repository
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
   570
                    + "/contents/"
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: 42
diff changeset
   571
                    + filename,
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: 42
diff changeset
   572
                    hooks=dict(response=log_api_rate)
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
   573
                )
53
0acc8b2adcb9 fixed error when creating discussion + adjusted readme on homepage to reflect discussion interface changes
durandn
parents: 45
diff changeset
   574
                file_content_list.append(str(b64decode(filedict["content"]),"utf-8"))
13
ea5f985156b1 Fix to github error handling
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 12
diff changeset
   575
            except GitHubError as ghe:
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: 39
diff changeset
   576
                logger.error("Github Error trying to get file: "+filename)
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: 39
diff changeset
   577
                logger.error(ghe.response.text)
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: 42
diff changeset
   578
15
4f08f1a107b3 Cleaning the code (pep8, pylint)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 14
diff changeset
   579
        # logger.debug(file_content_list)
0
54f4e0f9d636 Initial commit
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents:
diff changeset
   580
        return file_content_list