Commit 4c32f310 authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'clean_generation' into 'master'

File generation cleaned

See merge request chehabfl/outgoing_rex!26
parents a97d8933 30f954e1
Pipeline #26857 passed with stages
in 2 minutes and 52 seconds
...@@ -5,10 +5,10 @@ install_backend: ...@@ -5,10 +5,10 @@ install_backend:
pip install -r requirements.txt --quiet pip install -r requirements.txt --quiet
generate_backend: generate_backend:
export PYTHONPATH=$$PWD ; python ./backend/generate/generate_all.py export PYTHONPATH=$$PWD ; python ./backend/generate/generate_backend_files.py
generate_frontend: generate_frontend:
python ./frontend/generate/generate_frontend_files.py export PYTHONPATH=$$PWD ; python ./frontend/generate/generate_frontend_files.py
test_backend: generate_backend test_backend: generate_backend
pytest pytest
......
##### #####
# 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 django import template
from os.path import join, realpath, dirname from os.path import join, realpath, dirname
from general.api import get_api_config from general.api import get_api_config
...@@ -20,21 +20,15 @@ django.setup() ...@@ -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): 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}) c = template.Context({'data': context})
output = t.render(c) output = t.render(c)
write_file(output_path, output)
with open(output_path, 'w') as f:
f.write(output)
current_dir = dirname(realpath(__file__)) current_dir = dirname(realpath(__file__))
...@@ -42,8 +36,6 @@ templates_dir = current_dir + '/templates/' ...@@ -42,8 +36,6 @@ templates_dir = current_dir + '/templates/'
saving_dir = realpath(current_dir + "/../") saving_dir = realpath(current_dir + "/../")
# API_BASE = "http://127.0.0.1:8000/api/"
api_config = get_api_config() api_config = get_api_config()
# Render urls.py # Render urls.py
...@@ -55,12 +47,10 @@ render_and_save(template_path, api_config, output_path) ...@@ -55,12 +47,10 @@ render_and_save(template_path, api_config, output_path)
data = [] data = []
for obj in api_config: for obj in api_config:
if 'model' in obj and obj['model']: 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 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 continue
if 'versionned' not in obj:
obj['versionned'] = False
data.append(obj) data.append(obj)
template_path = join(templates_dir, 'admin.tpl') template_path = join(templates_dir, 'admin.tpl')
......
{% autoescape off %} {% autoescape off %}
# WARNING # WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED # 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 # MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED
# THIS WARNING DOESN'T APPLY TO .tpl FILES... # THIS WARNING DOESN'T APPLY TO .tpl FILES...
......
{% autoescape off %} {% autoescape off %}
# WARNING # WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED # 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 # MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED
# THIS WARNING DOESN'T APPLY TO .tpl FILES... # THIS WARNING DOESN'T APPLY TO .tpl FILES...
......
##### #####
# This python file is used to generate js files for redux # This python file is used to generate js files for redux
import os from os import makedirs
from os.path import join from os.path import join, dirname, realpath, exists
from django import template from django import template
import re import re
import yaml import yaml
...@@ -23,12 +23,12 @@ django.setup() ...@@ -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/' 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): if not exists(saving_dir):
os.makedirs(saving_dir) makedirs(saving_dir)
templates = [ templates = [
'action-types', 'action-types',
...@@ -38,7 +38,7 @@ templates = [ ...@@ -38,7 +38,7 @@ templates = [
] ]
API_BASE = "/api/" API_BASE = "/api/"
with open(join(current_dir, '../../backend/generate/api_config.yml'), 'r') as f: with open(join(current_dir, '../../general/api/api_config.yml'), 'r') as f:
data = f.read() data = f.read()
api_config = yaml.load(data) api_config = yaml.load(data)
...@@ -54,16 +54,6 @@ for api in api_config: ...@@ -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): def convert(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', 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() return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper()
...@@ -72,13 +62,17 @@ def convert(name): ...@@ -72,13 +62,17 @@ def convert(name):
for c in contexts: for c in contexts:
c['NAME'] = convert(c['name']) c['NAME'] = convert(c['name'])
# print(contexts)
for filename in templates: for filename in templates:
t = template.Template( template_path = join(templates_dir, filename + '.tpl')
read_file(os.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}) c = template.Context({'data': contexts})
output = t.render(c) 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)
...@@ -20,7 +20,7 @@ export const {{obj.NAME}}_EL_INVALIDATED = '{{obj.NAME}}_EL_INVALIDATED'; ...@@ -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_IS_LOADING = '{{obj.NAME}}_IS_LOADING';
export const {{obj.NAME}}_EL_FETCH_DATA_SUCCESS = '{{obj.NAME}}_FETCH_DATA_SUCCESS'; 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_IS_SAVING = '{{obj.NAME}}_IS_POSTING';
export const {{obj.NAME}}_EL_SAVING_DATA_SUCCESS = '{{obj.NAME}}_POST_DATA_SUCCESS'; export const {{obj.NAME}}_EL_SAVING_DATA_SUCCESS = '{{obj.NAME}}_POST_DATA_SUCCESS';
{% endif %} {% endif %}
......
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
{{obj.NAME}}_EL_IS_LOADING, {{obj.NAME}}_EL_IS_LOADING,
{{obj.NAME}}_EL_FETCH_DATA_SUCCESS, {{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_IS_SAVING,
{{obj.NAME}}_EL_SAVING_DATA_SUCCESS, {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
{% endif %} {% endif %}
...@@ -186,7 +186,7 @@ export function {{obj.name}}ElFetchData(pk) { ...@@ -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) { export function {{obj.name}}ElIsSaving(bool) {
return { return {
......
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
{{obj.name}}ElIsLoading, {{obj.name}}ElIsLoading,
{{obj.name}}ElFetched, {{obj.name}}ElFetched,
{% if 'read_only' not in obj or not obj.read_only %} {% if not obj.read_only %}
{{obj.name}}ElIsSaving, {{obj.name}}ElIsSaving,
{{obj.name}}ElSaved, {{obj.name}}ElSaved,
{% endif %} {% endif %}
...@@ -40,7 +40,7 @@ export const {{obj.name}}ElReducers = combineReducers({ ...@@ -40,7 +40,7 @@ export const {{obj.name}}ElReducers = combineReducers({
isLoading: {{obj.name}}ElIsLoading, isLoading: {{obj.name}}ElIsLoading,
fetched: {{obj.name}}ElFetched, fetched: {{obj.name}}ElFetched,
{% if 'read_only' not in obj or not obj.read_only %} {% if not obj.read_only %}
isSaving: {{obj.name}}ElIsSaving, isSaving: {{obj.name}}ElIsSaving,
isSaved: {{obj.name}}ElSaved, isSaved: {{obj.name}}ElSaved,
{% endif %} {% endif %}
......
...@@ -16,7 +16,7 @@ import { ...@@ -16,7 +16,7 @@ import {
{{obj.NAME}}_EL_IS_LOADING, {{obj.NAME}}_EL_IS_LOADING,
{{obj.NAME}}_EL_FETCH_DATA_SUCCESS, {{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_IS_SAVING,
{{obj.NAME}}_EL_SAVING_DATA_SUCCESS, {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
{% endif %} {% endif %}
...@@ -114,7 +114,7 @@ export function {{obj.name}}ElFetched(state = { data: Object(), fetchedAt: null ...@@ -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 // Handling POST and PUT
......
...@@ -11,7 +11,9 @@ def get_api_config(): ...@@ -11,7 +11,9 @@ def get_api_config():
DEFAULT_SETTINGS = { DEFAULT_SETTINGS = {
"ignore_in_admin": False, "ignore_in_admin": False,
"requires_testing": False, "requires_testing": False,
"moderation_level": 2 "moderation_level": 2,
"versionned": False,
"read_only": False
} }
for obj in api_config: for obj in api_config:
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
"description": "[![build](/../badges/master/build.svg)](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [![coverage](/../badges/master/coverage.svg)](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)", "description": "[![build](/../badges/master/build.svg)](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [![coverage](/../badges/master/coverage.svg)](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)",
"main": "manage.py", "main": "manage.py",
"scripts": { "scripts": {
"gen": "python ./frontend/generate/generate_frontend_files.py", "dev": "make generate_frontend && webpack --mode development ./frontend/src/index.js --output ./frontend/static/frontend/main.js",
"dev": "npm run gen && 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",
"build": "npm run gen && webpack --mode production ./frontend/src/index.js --output ./frontend/static/frontend/main.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment