Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
parlapi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Guillot
parlapi
Commits
fc680e70
Commit
fc680e70
authored
Apr 15, 2017
by
Nicolas Joyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sectionnement API
parent
84b64083
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
60 additions
and
40 deletions
+60
-40
parlapi/rest/api.py
parlapi/rest/api.py
+36
-21
parlapi/rest/endpoint.py
parlapi/rest/endpoint.py
+4
-0
parlapi/rest/setup.py
parlapi/rest/setup.py
+1
-1
parlapi/routes.py
parlapi/routes.py
+7
-4
parlapi/setup_app.py
parlapi/setup_app.py
+3
-3
parlapi/static/an.png
parlapi/static/an.png
+0
-0
parlapi/static/sen.png
parlapi/static/sen.png
+0
-0
parlapi/templates/index.html
parlapi/templates/index.html
+9
-11
No files found.
parlapi/rest/api.py
View file @
fc680e70
...
...
@@ -17,7 +17,8 @@ class API(object):
@
property
def
summary
(
self
):
descs
=
{
k
:
{
'desc'
:
v
.
desc
,
'count'
:
v
.
model
.
query
.
count
()}
descs
=
{
k
:
{
'section'
:
v
.
section
,
'stable'
:
v
.
stable
,
'desc'
:
v
.
desc
,
'count'
:
v
.
model
.
query
.
count
()}
for
k
,
v
in
self
.
registry
.
items
()
if
not
v
.
hidden
}
return
collections
.
OrderedDict
(
sorted
(
descs
.
items
()))
...
...
@@ -26,7 +27,8 @@ class API(object):
ep
=
Endpoint
(
self
,
self
.
ma
,
model
,
**
kwargs
)
self
.
registry
[
ep
.
table
]
=
ep
def
get_endpoint_or_404
(
self
,
table
):
def
get_endpoint_or_404
(
self
,
section
,
stable
):
table
=
'{}_{}'
.
format
(
section
,
stable
)
if
table
not
in
self
.
registry
:
abort
(
404
)
return
self
.
registry
[
table
]
...
...
@@ -34,44 +36,57 @@ class API(object):
def
setup_routes
(
self
,
app
,
prefix
=
'/rest/'
):
prefix
=
'/%s/'
%
prefix
.
strip
(
'/'
)
@
app
.
route
(
'%s<table>/'
%
prefix
)
def
api_list
(
table
):
endpoint
=
self
.
get_endpoint_or_404
(
table
)
@
app
.
route
(
'%s<
section>/<s
table>/'
%
prefix
)
def
api_list
(
section
,
s
table
):
endpoint
=
self
.
get_endpoint_or_404
(
section
,
s
table
)
return
endpoint
.
list
()
@
app
.
route
(
'%s<table>/meta'
%
prefix
)
def
api_meta
(
table
):
endpoint
=
self
.
get_endpoint_or_404
(
table
)
@
app
.
route
(
'%s<
section>/<s
table>/meta'
%
prefix
)
def
api_meta
(
section
,
s
table
):
endpoint
=
self
.
get_endpoint_or_404
(
section
,
s
table
)
return
endpoint
.
describe
()
@
app
.
route
(
'%s<table>/<id>'
%
prefix
)
def
api_detail
(
table
,
id
):
endpoint
=
self
.
get_endpoint_or_404
(
table
)
@
app
.
route
(
'%s<
section>/<s
table>/<id>'
%
prefix
)
def
api_detail
(
section
,
s
table
,
id
):
endpoint
=
self
.
get_endpoint_or_404
(
section
,
s
table
)
return
endpoint
.
show
(
id
)
@
app
.
route
(
'%s<table>/<id>/<custom>'
%
prefix
)
def
api_custom
(
table
,
id
,
custom
):
endpoint
=
self
.
get_endpoint_or_404
(
table
)
@
app
.
route
(
'%s<
section>/<s
table>/<id>/<custom>'
%
prefix
)
def
api_custom
(
section
,
s
table
,
id
,
custom
):
endpoint
=
self
.
get_endpoint_or_404
(
section
,
s
table
)
return
endpoint
.
show
(
id
,
custom
)
def
split_table
(
self
,
table
):
return
table
.
split
(
'_'
)[
0
],
table
.
split
(
'_'
,
1
)[
1
]
def
list_url
(
self
,
table
):
return
url_for
(
'api_list'
,
table
=
table
,
_external
=
True
)
section
,
stable
=
self
.
split_table
(
table
)
return
url_for
(
'api_list'
,
section
=
section
,
stable
=
stable
,
_external
=
True
)
def
list_url_field
(
self
,
table
):
return
self
.
ma
.
AbsoluteURLFor
(
'api_list'
,
table
=
table
)
section
,
stable
=
self
.
split_table
(
table
)
return
self
.
ma
.
AbsoluteURLFor
(
'api_list'
,
section
=
section
,
stable
=
stable
)
def
item_url
(
self
,
table
,
id
):
return
url_for
(
'api_detail'
,
table
,
id
)
section
,
stable
=
self
.
split_table
(
table
)
return
url_for
(
'api_detail'
,
section
=
section
,
stable
=
stable
,
id
=
id
)
def
item_url_field
(
self
,
table
,
attr
=
'id'
):
return
self
.
ma
.
AbsoluteURLFor
(
'api_detail'
,
table
=
table
,
id
=
'<%s>'
%
attr
)
section
,
stable
=
self
.
split_table
(
table
)
return
self
.
ma
.
AbsoluteURLFor
(
'api_detail'
,
section
=
section
,
stable
=
stable
,
id
=
'<%s>'
%
attr
)
def
relation_url
(
self
,
table
,
id
,
rel
):
return
url_for
(
'api_custom'
,
table
,
id
,
rel
)
section
,
stable
=
self
.
split_table
(
table
)
return
url_for
(
'api_custom'
,
section
=
section
,
stable
=
stable
,
id
=
id
,
custom
=
rel
)
def
relation_url_field
(
self
,
table
,
rel
):
return
self
.
ma
.
AbsoluteURLFor
(
'api_custom'
,
table
=
table
,
id
=
'<id>'
,
custom
=
rel
)
section
,
stable
=
self
.
split_table
(
table
)
return
self
.
ma
.
AbsoluteURLFor
(
'api_custom'
,
section
=
section
,
stable
=
stable
,
id
=
'<id>'
,
custom
=
rel
)
def
page_url
(
self
,
table
,
page
,
size
,
**
kwargs
):
qs
=
copy
(
kwargs
)
...
...
parlapi/rest/endpoint.py
View file @
fc680e70
...
...
@@ -48,6 +48,10 @@ class Endpoint(object):
self
.
model
=
model
self
.
table
=
model
.
__tablename__
self
.
section
=
self
.
table
.
split
(
'_'
)[
0
]
self
.
stable
=
self
.
table
.
split
(
'_'
,
1
)[
1
]
self
.
desc
=
description
or
self
.
table
self
.
hidden
=
hidden
...
...
parlapi/rest/setup.py
View file @
fc680e70
...
...
@@ -29,7 +29,7 @@ from ..models.an import (
from
..models.parlapi
import
Job
def
setup_a
n_a
pi
(
app
):
def
setup_api
(
app
):
api
=
API
(
app
)
api
.
endpoint
(
...
...
parlapi/routes.py
View file @
fc680e70
...
...
@@ -9,9 +9,8 @@ import humanize
from
.models.parlapi
import
Job
def
setup_routes
(
app
,
rest_apis
,
graphql_api
):
for
chamber
,
rest_api
in
rest_apis
.
items
():
rest_api
.
setup_routes
(
app
,
'/rest/{}/'
.
format
(
chamber
))
def
setup_routes
(
app
,
rest_api
,
graphql_api
):
rest_api
.
setup_routes
(
app
,
'/rest/'
)
graphql_prefix
=
'/graphql/'
graphql_api
.
setup_routes
(
app
,
graphql_prefix
)
...
...
@@ -51,7 +50,11 @@ def setup_routes(app, rest_apis, graphql_api):
return
render_template
(
'index.html'
,
piwik
=
piwik
,
rest_apis
=
{
k
:
v
.
summary
for
k
,
v
in
rest_apis
.
items
()
},
rest_api
=
rest_api
.
summary
,
sections
=
{
'an'
:
u'Assemblée nationale'
,
'parlapi'
:
'ParlAPI'
},
graphql_prefix
=
graphql_prefix
,
jobs
=
Job
.
query
.
all
()
)
parlapi/setup_app.py
View file @
fc680e70
...
...
@@ -23,8 +23,8 @@ def setup_app(name):
migrate
=
Migrate
(
app
,
db
)
# Setup REST API
from
.rest.setup
import
setup_a
n_api
as
setup_an
_rest_api
an_rest_api
=
setup_an
_rest_api
(
app
)
from
.rest.setup
import
setup_a
pi
as
setup
_rest_api
rest_api
=
setup
_rest_api
(
app
)
# Setup GraphQL API
from
.graphql.setup
import
setup_api
as
setup_graphql_api
...
...
@@ -32,7 +32,7 @@ def setup_app(name):
# Setup routes
from
.routes
import
setup_routes
setup_routes
(
app
,
{
'an'
:
an_rest_api
}
,
graphql_api
)
setup_routes
(
app
,
rest_api
,
graphql_api
)
# Enable Markdown
Markdown
(
app
)
...
...
parlapi/static/
chamber-
an.png
→
parlapi/static/an.png
View file @
fc680e70
File moved
parlapi/static/
chamber-
sen.png
→
parlapi/static/sen.png
View file @
fc680e70
File moved
parlapi/templates/index.html
View file @
fc680e70
...
...
@@ -63,17 +63,15 @@
<th>
Taille
</th>
<th>
Point d'entrée API
</th>
</tr>
{% for chamber, rest_api in rest_apis.items() %}
{% for table, item in rest_api.items() %}
<tr>
<td><img
class=
"chamber-icon"
src=
"{{ url_for('static', filename='chamber-' + chamber + '.png') }}"
</
td
>
<td>
{{ item.desc }}
</td>
<td>
{{ item.count }}
</td>
<td>
<a
href=
"/rest/an/{{ table }}"
><code>
/rest/an/{{ table }}
</code></a>
</td>
</tr>
{% endfor %}
{% for table, item in rest_api.items() %}
<tr>
<td><img
class=
"chamber-icon"
src=
"{{ url_for('static', filename='' + item.section + '.png') }}"
alt=
"{{ sections[item.section] }}"
title=
"{{ sections[item.section] }}"
></td>
<td>
{{ item.desc }}
</td>
<td>
{{ item.count }}
</td>
<td>
<a
href=
"/rest/{{ item.section }}/{{ item.stable }}"
><code>
/rest/{{ item.section }}/{{ item.stable }}
</code></a>
</td>
</tr>
{% endfor %}
</table>
</section>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment