Commit a6808d81 authored by Florent Chehab's avatar Florent Chehab

Merge branch 'backend_generation' into 'master'

Backend generation

See merge request chehabfl/outgoing_rex!21
parents 6b656ae7 714b362c
Pipeline #26706 canceled with stages
in 7 seconds
......@@ -4,3 +4,4 @@ ignore = E501
exclude =
env/*
node_modules/*
backend/urls.py
......@@ -10,3 +10,4 @@ node_modules
htmlcov
.vscode
.pytest_cache
/backend/urls.py
......@@ -12,9 +12,9 @@ testing:
script:
- export ENV=development
- export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
- pip install -r requirements.txt --quiet
- ./manage.py check
- pytest -n 4 general/ frontend/ backend/ --cov-report html
- make install_backend
- make check_backend
- make test_backend_server
artifacts:
paths:
- htmlcov/
......@@ -39,9 +39,7 @@ pages:
script:
- mkdir .public
- mv htmlcov/ .public/coverage
- cd docs/UML
- make all
- cd ../../
- make docs
- mv docs/ .public/docs
- mv .public public
artifacts:
......
# You need to have source the env before using the makefile
.PHONY: docs
install_backend:
pip install -r requirements.txt --quiet
generate_backend:
python ./backend/generate/generate_all.py
test_backend: generate_backend
pytest
test_backend_server:
pytest -n 4 general/ frontend/ backend/ --cov-report html
check_backend: generate_backend
./manage.py check
run_backend: generate_backend
./manage.py runserver
docs:
cd docs/UML && $(MAKE) all
docs_clean:
cd docs/UML && $(MAKE) clean
- model: Country
viewset: CountryViewSet
import_location: location
api_end_point: country
- model: City
viewset: CityViewSet
import_location: location
api_end_point: city
- model: Currency
viewset: CurrencyViewSet
import_location: module
api_end_point: currency
- model: Department
viewset: DepartmentViewSet
import_location: otherCore
api_end_point: other/department
- model: Specialty
viewset: SpecialtyViewSet
import_location: otherCore
api_end_point: other/specialty
- model: Semester
viewset: SemesterViewSet
import_location: otherCore
api_end_point: other/semester
- model: Offer
viewset: OfferViewSet
import_location: otherCore
api_end_point: other/offer
- model: CountryCulture
viewset: CountryCultureViewSet
import_location: location
api_end_point: country_more/culture
- model: CountryHealthInsurance
viewset: CountryHealthInsuranceViewSet
import_location: location
api_end_point: country_more/health_insurance
- model: CountryOtherInsurance
viewset: CountryOtherInsuranceViewSet
import_location: location
api_end_point: country_more/other_insurance
- model: CountryTransport
viewset: CountryTransportViewSet
import_location: location
api_end_point: country_more/transport
- model: CountryTourism
viewset: CountryTourismViewSet
import_location: location
api_end_point: country_more/tourism
- model: CountryOtherStuff
viewset: CountryOtherStuffViewSet
import_location: location
api_end_point: country_more/other_stuff
- model: CountryVisaAdministrative
viewset: CountryVisaAdministrativeViewSet
import_location: location
api_end_point: country_more/visa_administrative
- model: CountryPhoto
viewset: CountryPhotoViewSet
import_location: location
api_end_point: country_more/photos
- model: CountryScholarship
viewset: CountryScholarshipViewSet
import_location: location
api_end_point: country_more/scholarship
- model: CountryDri
viewset: CountryDriViewSet
import_location: location
api_end_point: country_more/dri
- model: CityTransport
viewset: CityTransportViewSet
import_location: location
api_end_point: city_more/transport
- model: CityTourism
viewset: CityTourismViewSet
import_location: location
api_end_point: city_more/tourism
- model: CityOtherStuff
viewset: CityOtherStuffViewSet
import_location: location
api_end_point: city_more/other_stuff
- model: CityPhoto
viewset: CityPhotoViewSet
import_location: location
api_end_point: city_more/photos
- model: University
viewset: UniversityViewSet
import_location: university
api_end_point: university
- model: Campus
viewset: CampusViewSet
import_location: university
api_end_point: campus
- model: Campus
viewset: MainCampusViewSet
import_location: university
api_end_point: main_campus
read_only: true
- model: UniversityScholarship
viewset: UniversityScholarshipViewSet
import_location: university
api_end_point: university_more/scholarship
- model: UniversityInfo
viewset: UniversityInfoViewSet
import_location: university
api_end_point: university_more/info
- model: UniversitySemestersDates
viewset: UniversitySemestersDatesViewSet
import_location: university
api_end_point: university_more/semesters_dates
- model: UniversityInsurance
viewset: UniversityInsuranceViewSet
import_location: university
api_end_point: university_more/insurance
- model: UniversityCourses
viewset: UniversityCoursesViewSet
import_location: university
api_end_point: university_more/courses
- model: UniversityCulture
viewset: UniversityCultureViewSet
import_location: university
api_end_point: university_more/culture
- model: UniversityPhoto
viewset: UniversityPhotoViewSet
import_location: university
api_end_point: university_more/photo
- model: UniversityOtherStuff
viewset: UniversityOtherStuffViewSet
import_location: university
api_end_point: university_more/other_stuff
- model: UniversitySpecialOffer
viewset: UniversitySpecialOfferViewSet
import_location: university
api_end_point: university_more/special_offer
- model: UniversityDri
viewset: UniversityDriViewSet
import_location: university
api_end_point: university_more/dri
- model: UniversityModules
viewset: UniversityModulesViewSet
import_location: university
api_end_point: university_more/all
api_attr: (?P<univ_id>[0-9]+)
api_name: university_details
- model: CampusTransport
viewset: CampusTransportViewSet
import_location: university
api_end_point: campus_more/transport
- model: CampusAccommodation
viewset: CampusAccommodationViewSet
import_location: university
api_end_point: campus_more/accomodation
- model: CampusCultureAndStudentLife
viewset: CampusCultureAndStudentLifeViewSet
import_location: university
api_end_point: campus_more/culture_and_sl
- model: CampusOtherStuff
viewset: CampusOtherStuffViewSet
import_location: university
api_end_point: campus_more/other_tuff
- model: Recommendation
viewset: RecommendationViewSet
import_location: user
api_end_point: user/recommendation
- model: RecommendationList
viewset: RecommendationListViewSet
import_location: user
api_end_point: user/recommendations_list
- model: PreviousDeparture
viewset: PreviousDepartureViewSet
import_location: user
api_end_point: university_more/previous_departure
- model: PreviousDepartureFeedback
viewset: PreviousDepartureFeedbackViewSet
import_location: user
api_end_point: university_more/previous_departure_feedback
- model: UserData
viewset: UserDataViewSet
import_location: user
api_end_point: user/data
api_name: user-data-detail
- model: PendingModeration
viewset: PendingModerationViewSet
import_location: my_model
api_end_point: pending_moderation
- model: Version
viewset: VersionViewSet
import_location: my_model
api_end_point: version
api_attr: (?P<content_type_id>[0-9]+)/(?P<object_pk>[0-9A-Za-z]+)
api_name: versions-list
- model: ForTestingModeration
viewset: ForTestingModerationViewSet
import_location: my_model
api_end_point: test/moderation
requires_testing: true
- model: ForTestingVersioning
viewset: ForTestingVersioningViewSet
import_location: my_model
api_end_point: test/versioning
requires_testing: true
# requires_testing
# viewset
# import_location
# api_end_point
# api_attr
\ No newline at end of file
#####
# This python file is used to generate js files for redux
import os
from django import template
import yaml
############
# Need to do this first so that Django template engine is working
import django
from django.conf import settings
settings.configure(TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['.'], # if you want the templates from a file
'APP_DIRS': False, # we have no apps
},
])
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)
current_dir = os.path.dirname(os.path.realpath(__file__))
templates_dir = current_dir + '/templates/'
saving_dir = os.path.realpath(current_dir + "/../")
# if not os.path.exists(saving_dir):
# os.makedirs(saving_dir)
templates = [
'urls',
]
# API_BASE = "http://127.0.0.1:8000/api/"
contexts = yaml.load(read_file(os.path.join(current_dir, 'api_config.yml')))
# 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()
# 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')))
c = template.Context({'data': contexts})
output = t.render(c)
write_file(os.path.join(saving_dir, filename + '.py'), output)
{% autoescape off %}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
# WITH /backend/generate/generate_all.py
# MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED
# THIS WARNING DOESN'T APPLY TO .tpl FILES...
from django.conf.urls import url, include
from django.conf import settings
from rest_framework import routers
{% spaceless %}
{% for model in data %}{% if 'requires_testing' not in model or not model.requires_testing %}
from backend.models.{{model.import_location}} import {{model.viewset}}
{% endif %}{% endfor %}
{% endspaceless %}
from rest_framework.documentation import include_docs_urls
urlpatterns = [
url(r'^api-docs/', include_docs_urls(title='Outgoing API'))
]
router = routers.DefaultRouter()
if settings.TESTING:
{% for model in data %}{% if 'requires_testing' in model or model.requires_testing %}
from backend.models.{{model.import_location}} import {{model.viewset}}
router.register(
r'{{model.api_end_point}}{% if 'api_attr' in model %}/{{model.api_attr}}{% endif %}',
{{model.viewset}}{%if 'api_name' in model%},"{{model.api_name}}"{% endif %}
){% endif %}{% endfor %}
{% for model in data %}{% if 'requires_testing' not in model or not model.requires_testing %}
router.register(
r'{{model.api_end_point}}{% if 'api_attr' in model %}/{{model.api_attr}}{% endif %}',
{{model.viewset}}{%if 'api_name' in model%},"{{model.api_name}}"{% endif %}
){% endif %}{% endfor %}
urlpatterns += [url(r'^api/', include(router.urls))]
{% endautoescape %}
from django.conf.urls import url, include
from django.conf import settings
from rest_framework import routers
from backend.models.location import CountryViewSet
from backend.models.location import CityViewSet
from backend.models.module import CurrencyViewSet
from backend.models.otherCore import DepartmentViewSet
from backend.models.otherCore import OfferViewSet
from backend.models.otherCore import SemesterViewSet
from backend.models.otherCore import SpecialtyViewSet
from backend.models.location import CountryCultureViewSet
from backend.models.location import CountryHealthInsuranceViewSet
from backend.models.location import CountryOtherInsuranceViewSet
from backend.models.location import CountryTransportViewSet
from backend.models.location import CountryTourismViewSet
from backend.models.location import CountryOtherStuffViewSet
from backend.models.location import CountryVisaAdministrativeViewSet
from backend.models.location import CountryPhotoViewSet
from backend.models.location import CountryScholarshipViewSet
from backend.models.location import CountryDriViewSet
from backend.models.location import CityTransportViewSet
from backend.models.location import CityTourismViewSet
from backend.models.location import CityOtherStuffViewSet
from backend.models.location import CityPhotoViewSet
from backend.models.university import UniversityViewSet
from backend.models.university import CampusViewSet, MainCampusViewSet
from backend.models.university import UniversityScholarshipViewSet
from backend.models.university import UniversityInfoViewSet
from backend.models.university import UniversitySemestersDatesViewSet
from backend.models.university import UniversityInsuranceViewSet
from backend.models.university import UniversityCoursesViewSet
from backend.models.university import UniversityCultureViewSet
from backend.models.university import UniversityOtherStuffViewSet
from backend.models.university import UniversitySpecialOfferViewSet
from backend.models.university import UniversityPhotoViewSet
from backend.models.university import UniversityDriViewSet
from backend.models.university import UniversityModulesViewSet
from backend.models.university import CampusTransportViewSet
from backend.models.university import CampusAccommodationViewSet
from backend.models.university import CampusCultureAndStudentLifeViewSet
from backend.models.university import CampusOtherStuffViewSet
from backend.models.user import RecommendationViewSet
from backend.models.user import RecommendationListViewSet
from backend.models.user import PreviousDepartureViewSet
from backend.models.user import PreviousDepartureFeedbackViewSet
from backend.models.user import UserDataViewSet
from backend.models.my_model import PendingModerationViewSet
from backend.models.my_model import VersionViewSet
from rest_framework.documentation import include_docs_urls
urlpatterns = [
# url(r'^$', views.home, name='home'),
url(r'^api-docs/', include_docs_urls(title='Outgoing API'))
]
router = routers.DefaultRouter()
if settings.TESTING:
from backend.models.my_model import ForTestingModerationViewSet
from backend.models.my_model import ForTestingVersioningViewSet
router.register(r'test/moderation', ForTestingModerationViewSet)
router.register(r'test/versioning', ForTestingVersioningViewSet)
router.register(r'country', CountryViewSet)
router.register(r'city', CityViewSet)
router.register(r'campus', CampusViewSet)
router.register(r'main_campus', MainCampusViewSet)
router.register(r'university', UniversityViewSet)
router.register(r'country_more/culture', CountryCultureViewSet)
router.register(r'country_more/health_insurance',
CountryHealthInsuranceViewSet)
router.register(r'country_more/other_insurance', CountryOtherInsuranceViewSet)
router.register(r'country_more/transport', CountryTransportViewSet)
router.register(r'country_more/tourism', CountryTourismViewSet)
router.register(r'country_more/other_stuff', CountryOtherStuffViewSet)
router.register(r'country_more/visa_administrative',
CountryVisaAdministrativeViewSet)
router.register(r'country_more/photos', CountryPhotoViewSet)
router.register(r'country_more/scholarship', CountryScholarshipViewSet)
router.register(r'country_more/dri', CountryDriViewSet)
router.register(r'city_more/transport', CityTransportViewSet)
router.register(r'city_more/tourism', CityTourismViewSet)
router.register(r'city_more/other_stuff', CityOtherStuffViewSet)
router.register(r'city_more/photos', CityPhotoViewSet)
router.register(
r'university_more/all/(?P<univ_id>[0-9]+)', UniversityModulesViewSet, "university_details")
router.register(r'university_more/scholarship', UniversityScholarshipViewSet)
router.register(r'university_more/info', UniversityInfoViewSet)
router.register(r'university_more/insurance', UniversityInsuranceViewSet)
router.register(r'university_more/semesters_dates',
UniversitySemestersDatesViewSet)
router.register(r'university_more/courses', UniversityCoursesViewSet)
router.register(r'university_more/culture', UniversityCultureViewSet)
router.register(r'university_more/other_stuff', UniversityOtherStuffViewSet)
router.register(r'university_more/photos', UniversityPhotoViewSet)
router.register(r'university_more/special_offer',
UniversitySpecialOfferViewSet)
router.register(r'university_more/dri', UniversityDriViewSet)
router.register(r'campus_more/culture_and_sl',
CampusCultureAndStudentLifeViewSet)
router.register(r'campus_more/accomodation', CampusAccommodationViewSet)
router.register(r'campus_more/transport', CampusTransportViewSet)
router.register(r'campus_more/other_tuff', CampusOtherStuffViewSet)
router.register(r'other/currency', CurrencyViewSet)
router.register(r'other/semester', SemesterViewSet)
router.register(r'other/department', DepartmentViewSet)
router.register(r'other/specialty', SpecialtyViewSet)
router.register(r'other/offer', OfferViewSet)
router.register(r'university_more/previous_departure',
PreviousDepartureViewSet)
router.register(r'university_more/previous_departure_feedback',
PreviousDepartureFeedbackViewSet)
router.register(r'user/recommendation', RecommendationViewSet)
router.register(r'user/recommendations_list', RecommendationListViewSet)
router.register(r'user/data', UserDataViewSet, "user_data-detail")
router.register(r'pending_moderation', PendingModerationViewSet)
router.register(
r'version/(?P<content_type_id>[0-9]+)/(?P<object_pk>[0-9A-Za-z]+)', VersionViewSet, "versions-list")
urlpatterns += [url(r'^api/', include(router.urls))]
......@@ -18,4 +18,5 @@ pytest-cov==2.5.1
pytest-xdist==1.23.0
flake8
django-debug-toolbar==1.9.1
pandas
\ No newline at end of file
pandas
pyyaml
\ No newline at end of file
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