Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julien Jerphanion
Rex Dri
Commits
4c32f310
Commit
4c32f310
authored
Sep 02, 2018
by
Florent Chehab
Browse files
Merge branch 'clean_generation' into 'master'
File generation cleaned See merge request chehabfl/outgoing_rex!26
parents
a97d8933
30f954e1
Changes
11
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
4c32f310
...
...
@@ -5,10 +5,10 @@ install_backend:
pip
install
-r
requirements.txt
--quiet
generate_backend
:
export
PYTHONPATH
=
$$
PWD
;
python ./backend/generate/generate_
all
.py
export
PYTHONPATH
=
$$
PWD
;
python ./backend/generate/generate_
backend_files
.py
generate_frontend
:
python ./frontend/generate/generate_frontend_files.py
export
PYTHONPATH
=
$$
PWD
;
python ./frontend/generate/generate_frontend_files.py
test_backend
:
generate_backend
pytest
...
...
backend/generate/generate_
all
.py
→
backend/generate/generate_
backend_files
.py
View file @
4c32f310
#####
# This python file is used to generate
js files for redux
# This python file is used to generate
some backend files
from
django
import
template
from
os.path
import
join
,
realpath
,
dirname
from
general.api
import
get_api_config
...
...
@@ -20,21 +20,15 @@ django.setup()
##########
def
read_file
(
file
):
with
open
(
file
,
"r"
)
as
myfile
:
return
myfile
.
read
()
def
write_file
(
file
,
data
):
with
open
(
file
,
'w'
)
as
the_file
:
the_file
.
write
(
data
)
def
render_and_save
(
template_path
,
context
,
output_path
):
t
=
template
.
Template
(
read_file
(
template_path
))
with
open
(
template_path
,
'r'
)
as
f
:
t
=
f
.
read
()
t
=
template
.
Template
(
t
)
c
=
template
.
Context
({
'data'
:
context
})
output
=
t
.
render
(
c
)
write_file
(
output_path
,
output
)
with
open
(
output_path
,
'w'
)
as
f
:
f
.
write
(
output
)
current_dir
=
dirname
(
realpath
(
__file__
))
...
...
@@ -42,8 +36,6 @@ templates_dir = current_dir + '/templates/'
saving_dir
=
realpath
(
current_dir
+
"/../"
)
# API_BASE = "http://127.0.0.1:8000/api/"
api_config
=
get_api_config
()
# Render urls.py
...
...
@@ -55,12 +47,10 @@ render_and_save(template_path, api_config, output_path)
data
=
[]
for
obj
in
api_config
:
if
'model'
in
obj
and
obj
[
'model'
]:
if
'requires_testing'
in
obj
and
obj
[
'requires_testing'
]:
if
obj
[
'requires_testing'
]:
continue
# we don't want testing models to be register in admin
if
'ignore_in_admin'
in
obj
and
obj
[
'ignore_in_admin'
]:
if
obj
[
'ignore_in_admin'
]:
continue
if
'versionned'
not
in
obj
:
obj
[
'versionned'
]
=
False
data
.
append
(
obj
)
template_path
=
join
(
templates_dir
,
'admin.tpl'
)
...
...
backend/generate/templates/admin.tpl
View file @
4c32f310
{
%
autoescape
off
%
}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
# WITH /backend/generate/generate_
all
.py
# WITH /backend/generate/generate_
backend_files
.py
# MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED
# THIS WARNING DOESN'T APPLY TO .tpl FILES...
...
...
backend/generate/templates/urls.tpl
View file @
4c32f310
{
%
autoescape
off
%
}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
# WITH /backend/generate/generate_
all
.py
# WITH /backend/generate/generate_
backend_files
.py
# MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED
# THIS WARNING DOESN'T APPLY TO .tpl FILES...
...
...
frontend/generate/generate_frontend_files.py
View file @
4c32f310
#####
# This python file is used to generate js files for redux
import
o
s
from
os.path
import
join
from
os
import
makedir
s
from
os.path
import
join
,
dirname
,
realpath
,
exists
from
django
import
template
import
re
import
yaml
...
...
@@ -23,12 +23,12 @@ django.setup()
##########
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
current_dir
=
dirname
(
realpath
(
__file__
))
templates_dir
=
current_dir
+
'/templates/'
saving_dir
=
os
.
path
.
realpath
(
current_dir
+
"/../src/generated/"
)
saving_dir
=
realpath
(
current_dir
+
"/../src/generated/"
)
if
not
os
.
path
.
exists
(
saving_dir
):
os
.
makedirs
(
saving_dir
)
if
not
exists
(
saving_dir
):
makedirs
(
saving_dir
)
templates
=
[
'action-types'
,
...
...
@@ -38,7 +38,7 @@ templates = [
]
API_BASE
=
"/api/"
with
open
(
join
(
current_dir
,
'../../
backend/
genera
te
/api_config.yml'
),
'r'
)
as
f
:
with
open
(
join
(
current_dir
,
'../../genera
l/api
/api_config.yml'
),
'r'
)
as
f
:
data
=
f
.
read
()
api_config
=
yaml
.
load
(
data
)
...
...
@@ -54,16 +54,6 @@ for api in api_config:
})
def
read_file
(
file
):
with
open
(
file
,
"r"
)
as
myfile
:
return
myfile
.
read
()
def
write_file
(
file
,
data
):
with
open
(
file
,
'w'
)
as
the_file
:
the_file
.
write
(
data
)
def
convert
(
name
):
s1
=
re
.
sub
(
'(.)([A-Z][a-z]+)'
,
r
'\1_\2'
,
name
)
return
re
.
sub
(
'([a-z0-9])([A-Z])'
,
r
'\1_\2'
,
s1
).
upper
()
...
...
@@ -72,13 +62,17 @@ def convert(name):
for
c
in
contexts
:
c
[
'NAME'
]
=
convert
(
c
[
'name'
])
# print(contexts)
for
filename
in
templates
:
t
=
template
.
Template
(
read_file
(
os
.
path
.
join
(
templates_dir
,
filename
+
'.tpl'
)))
template_path
=
join
(
templates_dir
,
filename
+
'.tpl'
)
with
open
(
template_path
,
"r"
)
as
f
:
t
=
f
.
read
()
t
=
template
.
Template
(
t
)
c
=
template
.
Context
({
'data'
:
contexts
})
output
=
t
.
render
(
c
)
write_file
(
os
.
path
.
join
(
saving_dir
,
filename
+
'.js'
),
output
)
output_path
=
join
(
saving_dir
,
filename
+
'.js'
)
with
open
(
output_path
,
'w'
)
as
f
:
f
.
write
(
output
)
frontend/generate/templates/action-types.tpl
View file @
4c32f310
...
...
@@ -20,7 +20,7 @@ export const {{obj.NAME}}_EL_INVALIDATED = '{{obj.NAME}}_EL_INVALIDATED';
export const {
{
obj
.
NAME
}
}_EL_IS_LOADING = '{
{
obj
.
NAME
}
}_IS_LOADING';
export const {
{
obj
.
NAME
}
}_EL_FETCH_DATA_SUCCESS = '{
{
obj
.
NAME
}
}_FETCH_DATA_SUCCESS';
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
export const {
{
obj
.
NAME
}
}_EL_IS_SAVING = '{
{
obj
.
NAME
}
}_IS_POSTING';
export const {
{
obj
.
NAME
}
}_EL_SAVING_DATA_SUCCESS = '{
{
obj
.
NAME
}
}_POST_DATA_SUCCESS';
{% endif %}
...
...
frontend/generate/templates/actions.tpl
View file @
4c32f310
...
...
@@ -18,7 +18,7 @@ import {
{
{
obj
.
NAME
}
}_EL_IS_LOADING,
{
{
obj
.
NAME
}
}_EL_FETCH_DATA_SUCCESS,
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
{
{
obj
.
NAME
}
}_EL_IS_SAVING,
{
{
obj
.
NAME
}
}_EL_SAVING_DATA_SUCCESS,
{% endif %}
...
...
@@ -186,7 +186,7 @@ export function {{obj.name}}ElFetchData(pk) {
}
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
export function {
{
obj
.
name
}
}ElIsSaving(bool) {
return {
...
...
frontend/generate/templates/combinedReducers.tpl
View file @
4c32f310
...
...
@@ -18,7 +18,7 @@ import {
{
{
obj
.
name
}
}ElIsLoading,
{
{
obj
.
name
}
}ElFetched,
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
{
{
obj
.
name
}
}ElIsSaving,
{
{
obj
.
name
}
}ElSaved,
{% endif %}
...
...
@@ -40,7 +40,7 @@ export const {{obj.name}}ElReducers = combineReducers({
isLoading: {
{
obj
.
name
}
}ElIsLoading,
fetched: {
{
obj
.
name
}
}ElFetched,
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
isSaving: {
{
obj
.
name
}
}ElIsSaving,
isSaved: {
{
obj
.
name
}
}ElSaved,
{% endif %}
...
...
frontend/generate/templates/reducers.tpl
View file @
4c32f310
...
...
@@ -16,7 +16,7 @@ import {
{
{
obj
.
NAME
}
}_EL_IS_LOADING,
{
{
obj
.
NAME
}
}_EL_FETCH_DATA_SUCCESS,
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
{
{
obj
.
NAME
}
}_EL_IS_SAVING,
{
{
obj
.
NAME
}
}_EL_SAVING_DATA_SUCCESS,
{% endif %}
...
...
@@ -114,7 +114,7 @@ export function {{obj.name}}ElFetched(state = { data: Object(), fetchedAt: null
}
{% if
'read_only' not in obj or
not obj.read_only %}
{% if not obj.read_only %}
// Handling POST and PUT
...
...
general/api/get_api_config.py
View file @
4c32f310
...
...
@@ -11,7 +11,9 @@ def get_api_config():
DEFAULT_SETTINGS
=
{
"ignore_in_admin"
:
False
,
"requires_testing"
:
False
,
"moderation_level"
:
2
"moderation_level"
:
2
,
"versionned"
:
False
,
"read_only"
:
False
}
for
obj
in
api_config
:
...
...
package.json
View file @
4c32f310
...
...
@@ -4,9 +4,8 @@
"description"
:
"[](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [](https://opensource.org/licenses/BSD-2-Clause)"
,
"main"
:
"manage.py"
,
"scripts"
:
{
"gen"
:
"python ./frontend/generate/generate_frontend_files.py"
,
"dev"
:
"npm run gen && webpack --mode development ./frontend/src/index.js --output ./frontend/static/frontend/main.js"
,
"build"
:
"npm run gen && webpack --mode production ./frontend/src/index.js --output ./frontend/static/frontend/main.js"
,
"dev"
:
"make generate_frontend && webpack --mode development ./frontend/src/index.js --output ./frontend/static/frontend/main.js"
,
"build"
:
"make generate_frontend && webpack --mode production ./frontend/src/index.js --output ./frontend/static/frontend/main.js"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"repository"
:
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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