src/catedit/__init__.py
author ymh <ymh.work@gmail.com>
Thu, 19 Mar 2015 18:00:34 +0100
changeset 49 7809ac45ad21
parent 46 5bd3fb023396
child 72 75170fe4d56b
permissions -rw-r--r--
increment version
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
__init__.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
module main file used to configure the Flask app
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
"""
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
     5
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
     6
from logging import FileHandler, Formatter
26
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
     7
import os
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
     8
import re
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: 32
diff changeset
     9
from catedit.version import CURRENT_VERSION
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
    10
from requests import request
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    11
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 flask import Flask, session, request, url_for
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: 32
diff changeset
    13
from flask_wtf.csrf import CsrfProtect
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
from flask.ext.github import GitHub
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
from flask.ext.cache import Cache
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    16
from flask.ext.restful import Api
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    17
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    18
from catedit.settings import AppSettings
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
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: 32
diff changeset
    20
# Set up app
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
app = Flask(__name__)
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
app.config.from_object(AppSettings)
26
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    23
app_configured = False
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    24
try:
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    25
    from catedit.config import AppConfig
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    26
    app.config.from_object(AppConfig)
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    27
    app_configured = True
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    28
except ImportError:
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    29
    pass
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    30
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    31
if 'CATEDIT_SETTINGS' in os.environ:
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    32
    app.config.from_envvar('CATEDIT_SETTINGS')
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    33
    app_configured = True
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    34
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    35
if not app_configured:
e3affd6625d6 add packaging
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    36
    raise Exception("Catedit not configured")
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
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
    38
cache = Cache(app, config=app.config["CACHE_CONFIG"])
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
    39
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: 32
diff changeset
    40
# CSRF protection
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: 32
diff changeset
    41
CsrfProtect(app)
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: 32
diff changeset
    42
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: 32
diff changeset
    43
# Github
40
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    44
app.config["GITHUB_CLIENT_ID"] = app.config["PERSISTENCE_CONFIG"].get(
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    45
    "GITHUB_CLIENT_ID",
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    46
    "local_persistence"
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    47
)
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    48
app.config["GITHUB_CLIENT_SECRET"] = app.config["PERSISTENCE_CONFIG"].get(
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    49
    "GITHUB_CLIENT_SECRET",
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    50
    "local_persistence"
8c32ea41b391 New version + Reworked login process to suppress unauthenticated request + reworked file persistence + added tests module and API tests + reworked how the list repositories user can access is generated (can now only access repositories that are both in his repository list AND in the config repository list, so there is no need to add every new user to all repositories)
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 38
diff changeset
    51
)
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
github = GitHub(app)
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
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
    54
@github.access_token_getter
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
    55
def token_getter():
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
    56
    """
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
    57
        Utility function for github-flask module to get user token when
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
    58
        making authenticated requests
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
    59
    """
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
    60
    if session.get("user_logged", None):
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
    61
        # logger.debug("I made an authentified request")
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
    62
        return session["user_code"]
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
    63
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
    64
def log_api_rate(r, *args, **kwargs):
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
    65
    """
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
    66
        Utility hook function to link to every github call as a kwarg so the
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
    67
        app logs how many requests can still be made, after the current request
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
    68
    """
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
    69
    app.logger.debug(
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
    70
        str(r.request.method) + " "
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
    71
        + str(r.url) + " - "
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
    72
        + "Remaining requests count: "
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
    73
        + str(r.headers["X-RateLimit-Remaining"]) + "/"
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
    74
        + str(r.headers["X-RateLimit-Limit"])
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
    75
    )
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
    76
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
    77
def save_links(r, *args, **kwargs):
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
    78
    """
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
    79
        Utility hook function that stores the links in the header of
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
    80
        the response in order to use them for further API requests.
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
    81
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
    82
        After that hook, the entry "pagination_links" in session is updated
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
    83
        with last page and current_page, as well as the resource to request
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
    84
        from for each header link
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
    85
    """
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
    86
    session["pagination_links"] = {}
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
    87
    log_api_rate(r, *args, **kwargs)
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
    88
    print("link header: "+r.headers.get("link", "none"))
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
    89
    if r.headers.get("link", None) is not None:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
    90
        session["pagination_links"] = r.links
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
    91
        for (key, item) in session["pagination_links"].items():
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
    92
            resource = item["url"][len(github.BASE_URL):]
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
    93
            item["url"] = resource
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
    94
        if session["pagination_links"].get("next", None) is not None:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
    95
            page_arg = re.search(
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
    96
                "(\?|&)page=(\d+)",
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
    97
                string=session["pagination_links"]["next"]["url"]
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
    98
            )
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
    99
            session["pagination_links"]["current_page"] = int(
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   100
                page_arg.group(2)
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
   101
            )-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
   102
            if session["pagination_links"].get("last", None) is not None:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
   103
                last_page_arg = re.search(
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   104
                    "(\?|&)page=(\d+)",
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
   105
                    string=session["pagination_links"]["last"]["url"]
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
   106
                )
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
   107
                session["pagination_links"]["last_page"] = int(
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   108
                    last_page_arg.group(2)
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
   109
                )
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
   110
            else:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
   111
                # We don't know what is the last page (case: github 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
   112
                # API)
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   113
                session["pagination_links"]["last_page"] = \
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   114
                session["pagination_links"]["current_page"] + 1
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
   115
        elif session["pagination_links"].get("prev", None) is not None:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
   116
            # This means we're at the last page
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
   117
            page_arg = re.search(
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   118
                "(\?|&)page=(\d+)",
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
   119
                string=session["pagination_links"]["prev"]["url"]
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
   120
            )
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
   121
            session["pagination_links"]["current_page"] = int(
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   122
                page_arg.group(2)
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
   123
            )+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
   124
            session["pagination_links"] \
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
   125
                   ["last_page"] = session["pagination_links"]["current_page"]
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
   126
        else:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
   127
            session["pagination_links"]["current_page"] = 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
   128
            session["pagination_links"]["last_page"] = 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
   129
    else:
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
   130
        session.pop("pagination_links", None)
1506da593f40 Caching fix (now works on views.categories submodule) and config (dict CACHE_CONFIG, see Flask-cache doc for expected values) + Pagination for comments (changeset & issues) + Hooks to log API rate consumption and get pagination info
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 42
diff changeset
   131
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: 32
diff changeset
   132
# Api
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   133
api = Api(app)
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   134
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: 32
diff changeset
   135
# Version
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: 32
diff changeset
   136
app.config["CURRENT_VERSION"] = CURRENT_VERSION
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: 32
diff changeset
   137
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: 32
diff changeset
   138
# Views and APIs
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
   139
from catedit.views import home, categories, social
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   140
from catedit.resources import CategoryAPI, CategoryChangesAPI
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
   141
app.register_blueprint(home.module)
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
   142
app.register_blueprint(categories.module)
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
   143
app.register_blueprint(social.module)
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   144
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   145
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   146
api.add_resource(CategoryAPI,
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   147
                 '/category/<string:cat_id>',
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   148
                 '/category',
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   149
                 endpoint='category')
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   150
api.add_resource(CategoryChangesAPI,
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   151
                 '/category-changes/<string:cat_id>',
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   152
                 '/category-changes',
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   153
                 endpoint='category_changes')
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   154
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
   155
# Pagination utility functions for templates
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   156
def url_for_other_page(page, arg_name="page"):
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
   157
    args = request.view_args.copy()
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   158
    args[arg_name] = page
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
   159
    return url_for(request.endpoint, **args)
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
   160
app.jinja_env.globals['url_for_other_page'] = url_for_other_page
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
   161
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   162
def url_for_other_per_page(
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   163
    per_page,
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   164
    page_arg_name="page",
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   165
    per_page_arg_name="per_page"
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   166
):
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
   167
    args = request.view_args.copy()
46
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   168
    args[page_arg_name] = 1
5bd3fb023396 Added pagination to commit list and issue list + changeset page now display categories before and after modifications
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 45
diff changeset
   169
    args[per_page_arg_name] = per_page
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
   170
    return url_for(request.endpoint, **args)
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
   171
app.jinja_env.globals['url_for_other_per_page'] = url_for_other_per_page
20
d47f8f8b3faf correct initialization and import of application + rename api file
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   172
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: 32
diff changeset
   173
# Set up logging
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: 32
diff changeset
   174
if app.config["LOGGING_CONFIG"]["IS_LOGGING"]:
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: 32
diff changeset
   175
    file_handler = FileHandler(filename=app.config["LOGGING_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: 32
diff changeset
   176
                                                  ["LOG_FILE_PATH"])
31
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   177
    file_handler.setFormatter(Formatter(
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   178
        '%(asctime)s %(levelname)s: %(message)s '
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   179
        '[in %(pathname)s:%(lineno)d]',
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   180
        '%Y-%m-%d %H:%M:%S'
511f3b94c616 Fix to logging format + Link to discussion + github logging message format
Nicolas DURAND <nicolas.durand@iri.centrepompidou.fr>
parents: 20
diff changeset
   181
    ))
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
    app.logger.addHandler(file_handler)
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: 32
diff changeset
   183
    app.logger.setLevel(app.config["LOGGING_CONFIG"]["LOGGING_LEVEL"])
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
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: 32
diff changeset
   185
# Session management
11
f2d54d2841f3 start of small refactorisation: python 3.4, remove imports *, logger, apply pylint, remove app.py
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
19
82635fefa88e add github callback uri + secret key
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   187
app.secret_key = app.config["SECRET_KEY"]