Commit 714b362c authored by Florent Chehab's avatar Florent Chehab

Backend API generation ok and makefile added

parent d7d7926d
Pipeline #26701 passed with stages
......@@ -4,3 +4,4 @@ ignore = E501
exclude =
env/*
node_modules/*
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 %}
......@@ -19,3 +19,4 @@ pytest-xdist==1.23.0
flake8
django-debug-toolbar==1.9.1
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