Commit f7a7f518 authored by Florent Chehab's avatar Florent Chehab

Removed old basic module stuff

Better backend generation (now with admin.py)
parent 66ca721d
Pipeline #26724 failed with stages
in 3 minutes and 15 seconds
......@@ -5,3 +5,4 @@ exclude =
env/*
node_modules/*
backend/urls.py
backend/admin.py
raise Exception("This file should be automatically generated")
\ No newline at end of file
- model: Tag
viewset: TagViewSet
import_location: module
api_end_point: tag
- model: Country
viewset: CountryViewSet
import_location: location
......@@ -13,6 +8,35 @@
import_location: location
api_end_point: city
- model: Tag
viewset: TagViewSet
import_location: module
api_end_point: tag
- model: UniversityTaggedItem
viewset: UniversityTaggedItemViewSet
import_location: university
api_end_point: university_more_tmp
versionned: true
- model: CampusTaggedItem
viewset: CampusTaggedItemViewSet
import_location: university
api_end_point: campus_more_tmp
versionned: true
- model: CountryTaggedItem
viewset: CountryTaggedItemViewSet
import_location: location
api_end_point: country_more_tmp
versionned: true
- model: CityTaggedItem
viewset: CityTaggedItemViewSet
import_location: location
api_end_point: city_more_tmp
versionned: true
- model: Currency
viewset: CurrencyViewSet
import_location: module
......@@ -38,77 +62,29 @@
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
versionned: true
- model: CountryScholarship
viewset: CountryScholarshipViewSet
import_location: location
api_end_point: country_more/scholarship
versionned: true
- 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
versionned: true
- model: CityPhoto
viewset: CityPhotoViewSet
import_location: location
api_end_point: city_more/photos
versionned: true
- model: University
......@@ -120,8 +96,9 @@
viewset: CampusViewSet
import_location: university
api_end_point: campus
versionned: true
- model: Campus
- model: null
viewset: MainCampusViewSet
import_location: university
api_end_point: main_campus
......@@ -131,79 +108,39 @@
viewset: UniversityScholarshipViewSet
import_location: university
api_end_point: university_more/scholarship
versionned: true
- model: UniversityInfo
viewset: UniversityInfoViewSet
import_location: university
api_end_point: university_more/info
versionned: true
- 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
versionned: true
- 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
versionned: true
- model: UniversityDri
viewset: UniversityDriViewSet
import_location: university
api_end_point: university_more/dri
versionned: true
- model: UniversityModules
- model: null
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
......@@ -241,6 +178,7 @@
api_end_point: version
api_attr: (?P<content_type_id>[0-9]+)/(?P<object_pk>[0-9A-Za-z]+)
api_name: versions-list
ignore_in_admin: true
- model: ForTestingModeration
viewset: ForTestingModerationViewSet
......@@ -253,10 +191,4 @@
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
# versionned: true don't put it here, it is manually handled with @register decorator
#####
# This python file is used to generate js files for redux
import os
from django import template
import yaml
from os.path import join, realpath, dirname
############
# Need to do this first so that Django template engine is working
......@@ -30,37 +30,39 @@ def write_file(file, data):
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()
def render_and_save(template_path, context, output_path):
t = template.Template(read_file(template_path))
c = template.Context({'data': context})
output = t.render(c)
write_file(output_path, output)
# for c in contexts:
# c['NAME'] = convert(c['name'])
# # print(contexts)
current_dir = dirname(realpath(__file__))
templates_dir = current_dir + '/templates/'
saving_dir = realpath(current_dir + "/../")
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)
# API_BASE = "http://127.0.0.1:8000/api/"
write_file(os.path.join(saving_dir, filename + '.py'), output)
api_config = yaml.load(read_file(join(current_dir, 'api_config.yml')))
# Render urls.py
template_path = join(templates_dir, 'urls.tpl')
output_path = join(saving_dir, 'urls.py')
render_and_save(template_path, api_config, output_path)
# Render admin.py
data = []
for obj in api_config:
if 'model' in obj and obj['model']:
if 'requires_testing' in obj and 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']:
continue
if 'versionned' not in obj:
obj['versionned'] = False
data.append(obj)
template_path = join(templates_dir, 'admin.tpl')
output_path = join(saving_dir, 'admin.py')
render_and_save(template_path, data, output_path)
{% 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.contrib import admin
from reversion_compare.admin import CompareVersionAdmin
{% spaceless %}
{% for model in data %}
from backend.models.{{model.import_location}} import {{model.model}}
{% endfor %}
{% endspaceless %}
CLASSIC_MODELS = [
{% for model in data %}{% if not model.versionned %}
{{model.model}},
{% endif %}{% endfor %}
]
VERSIONNED_MODELS = [
{% for model in data %}{% if model.versionned %}
{{model.model}},
{% endif %}{% endfor %}
]
for model in CLASSIC_MODELS:
admin.site.register(model)
try:
model.get_serializer()
raise Exception("CLASSIX MODEL SHOULDN'T have this method")
except AttributeError:
pass
for model in VERSIONNED_MODELS:
admin.site.register(model, CompareVersionAdmin)
if (model.get_serializer().Meta.model != model):
raise Exception(
"Get_serializer configuration incorrect in", str(model))
{% endautoescape %}
This diff is collapsed.
from .country import Country, CountrySerializer, CountryViewSet # noqa: F401
from .city import City, CitySerializer, CityViewSet # noqa: F401
from .countryBasicModules import CountryCulture, CountryCultureViewSet # noqa: F401
from .countryBasicModules import CountryVisaAdministrative, CountryVisaAdministrativeViewSet # noqa: F401
from .countryBasicModules import CountryHealthInsurance, CountryHealthInsuranceViewSet # noqa: F401
from .countryBasicModules import CountryOtherInsurance, CountryOtherInsuranceViewSet # noqa: F401
from .countryBasicModules import CountryTransport, CountryTransportViewSet # noqa: F401
from .countryBasicModules import CountryTourism, CountryTourismViewSet # noqa: F401
from .countryBasicModules import CountryOtherStuff, CountryOtherStuffViewSet # noqa: F401
from .countryPhoto import CountryPhoto, CountryPhotoViewSet # noqa: F401
from .countryScholarship import CountryScholarship, CountryScholarshipViewSet # noqa: F401
from .countryDri import CountryDri, CountryDriViewSet # noqa: F401
from .countryTaggedItem import CountryTaggedItem, CountryTaggedItemSerializer, CountryTaggedItemViewSet # noqa: F401
from .cityBasicModules import CityTransport, CityTransportViewSet # noqa: F401
from .cityBasicModules import CityOtherStuff, CityOtherStuffViewSet # noqa: F401
from .cityBasicModules import CityTourism, CityTourismViewSet # noqa: F401
from .city import City, CitySerializer, CityViewSet # noqa: F401
from .cityPhoto import CityPhoto, CityPhotoViewSet # noqa: F401
from .cityTaggedItem import CityTaggedItem, CityTaggedItemSerializer, CityTaggedItemViewSet # noqa: F401
......@@ -13,11 +13,6 @@ class City(MyModel):
country = models.ForeignKey(Country, on_delete=models.PROTECT)
"""
API RELATED STUFF BELLOW
"""
class CitySerializer(MyModelSerializer):
country_url = serializers.SerializerMethodField()
......
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
####################
# CityTransport
###################
class CityTransport(BasicModule):
city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_transport', primary_key=True)
@classmethod
def get_serializer(cls):
return CityTransportSerializer
class CityTransportSerializer(BasicModuleSerializer):
class Meta:
model = CityTransport
fields = '__all__'
class CityTransportViewSet(BasicModuleViewSet):
queryset = CityTransport.objects.all() # pylint: disable=E1101
serializer_class = CityTransportSerializer
#####################
#####################
####################
# CityTourism
###################
class CityTourism(BasicModule):
city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_tourism', primary_key=True)
@classmethod
def get_serializer(cls):
return CityTourismSerializer
class CityTourismSerializer(BasicModuleSerializer):
class Meta:
model = CityTourism
fields = '__all__'
class CityTourismViewSet(BasicModuleViewSet):
queryset = CityTourism.objects.all() # pylint: disable=E1101
serializer_class = CityTourismSerializer
#####################
#####################
####################
# CityOtherStuff
###################
class CityOtherStuff(BasicModule):
city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CityOtherStuffSerializer
class CityOtherStuffSerializer(BasicModuleSerializer):
class Meta:
model = CityOtherStuff
fields = '__all__'
class CityOtherStuffViewSet(BasicModuleViewSet):
queryset = CityOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CityOtherStuffSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
from backend.models.module import Tag
class CityTaggedItem(BasicModule):
city = models.OneToOneField(
City, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
@classmethod
def get_serializer(cls):
return CityTaggedItemSerializer
class Meta:
unique_together = ('city', 'tag')
class CityTaggedItemSerializer(BasicModuleSerializer):
class Meta:
model = CityTaggedItem
fields = '__all__'
class CityTaggedItemViewSet(BasicModuleViewSet):
queryset = CityTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CityTaggedItemSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import Country
####################
# CountryVisaAdministrative
###################
class CountryVisaAdministrative(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_visa_administrative', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryVisaAdministrativeSerializer
class CountryVisaAdministrativeSerializer(BasicModuleSerializer):
class Meta:
model = CountryVisaAdministrative
fields = '__all__'
class CountryVisaAdministrativeViewSet(BasicModuleViewSet):
queryset = CountryVisaAdministrative.objects.all() # pylint: disable=E1101
serializer_class = CountryVisaAdministrativeSerializer
#####################
#####################
####################
# CountryHealthInsurance
###################
class CountryHealthInsurance(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_health_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryHealthInsuranceSerializer
class CountryHealthInsuranceSerializer(BasicModuleSerializer):
class Meta:
model = CountryHealthInsurance
fields = '__all__'
class CountryHealthInsuranceViewSet(BasicModuleViewSet):
queryset = CountryHealthInsurance.objects.all() # pylint: disable=E1101
serializer_class = CountryHealthInsuranceSerializer
#####################
#####################
####################
# Other Insurance
###################
class CountryOtherInsurance(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_other_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryOtherInsuranceSerializer
class CountryOtherInsuranceSerializer(BasicModuleSerializer):
class Meta:
model = CountryOtherInsurance
fields = '__all__'
class CountryOtherInsuranceViewSet(BasicModuleViewSet):
queryset = CountryOtherInsurance.objects.all() # pylint: disable=E1101
serializer_class = CountryOtherInsuranceSerializer
#####################
#####################
####################
# CountryCulture
###################
class CountryCulture(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_culture', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryCultureSerializer
class CountryCultureSerializer(BasicModuleSerializer):
class Meta:
model = CountryCulture
fields = '__all__'
class CountryCultureViewSet(BasicModuleViewSet):
queryset = CountryCulture.objects.all() # pylint: disable=E1101
serializer_class = CountryCultureSerializer
#####################
#####################
####################
# CountryTransport
###################
class CountryTransport(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_transport', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryTransportSerializer
class CountryTransportSerializer(BasicModuleSerializer):
class Meta:
model = CountryTransport
fields = '__all__'
class CountryTransportViewSet(BasicModuleViewSet):
queryset = CountryTransport.objects.all() # pylint: disable=E1101
serializer_class = CountryTransportSerializer
#####################
#####################
####################
# CountryTourism
###################
class CountryTourism(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_tourism', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryTourismSerializer
class CountryTourismSerializer(BasicModuleSerializer):
class Meta:
model = CountryTourism
fields = '__all__'
class CountryTourismViewSet(BasicModuleViewSet):
queryset = CountryTourism.objects.all() # pylint: disable=E1101
serializer_class = CountryTourismSerializer
#####################
#####################
####################
# CountryOtherStuff
###################
class CountryOtherStuff(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryOtherStuffSerializer
class CountryOtherStuffSerializer(BasicModuleSerializer):
class Meta:
model = CountryOtherStuff
fields = '__all__'
class CountryOtherStuffViewSet(BasicModuleViewSet):
queryset = CountryOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CountryOtherStuffSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet