Commit f7a7f518 authored by Florent Chehab's avatar Florent Chehab
Browse files

Removed old basic module stuff

Better backend generation (now with admin.py)
parent 66ca721d
...@@ -5,3 +5,4 @@ exclude = ...@@ -5,3 +5,4 @@ exclude =
env/* env/*
node_modules/* node_modules/*
backend/urls.py 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 - model: Country
viewset: CountryViewSet viewset: CountryViewSet
import_location: location import_location: location
...@@ -13,6 +8,35 @@ ...@@ -13,6 +8,35 @@
import_location: location import_location: location
api_end_point: city 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 - model: Currency
viewset: CurrencyViewSet viewset: CurrencyViewSet
import_location: module import_location: module
...@@ -38,77 +62,29 @@ ...@@ -38,77 +62,29 @@
import_location: otherCore import_location: otherCore
api_end_point: other/offer 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 - model: CountryPhoto
viewset: CountryPhotoViewSet viewset: CountryPhotoViewSet
import_location: location import_location: location
api_end_point: country_more/photos api_end_point: country_more/photos
versionned: true
- model: CountryScholarship - model: CountryScholarship
viewset: CountryScholarshipViewSet viewset: CountryScholarshipViewSet
import_location: location import_location: location
api_end_point: country_more/scholarship api_end_point: country_more/scholarship
versionned: true
- model: CountryDri - model: CountryDri
viewset: CountryDriViewSet viewset: CountryDriViewSet
import_location: location import_location: location
api_end_point: country_more/dri api_end_point: country_more/dri
versionned: true
- 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 - model: CityPhoto
viewset: CityPhotoViewSet viewset: CityPhotoViewSet
import_location: location import_location: location
api_end_point: city_more/photos api_end_point: city_more/photos
versionned: true
- model: University - model: University
...@@ -120,8 +96,9 @@ ...@@ -120,8 +96,9 @@
viewset: CampusViewSet viewset: CampusViewSet
import_location: university import_location: university
api_end_point: campus api_end_point: campus
versionned: true
- model: Campus - model: null
viewset: MainCampusViewSet viewset: MainCampusViewSet
import_location: university import_location: university
api_end_point: main_campus api_end_point: main_campus
...@@ -131,79 +108,39 @@ ...@@ -131,79 +108,39 @@
viewset: UniversityScholarshipViewSet viewset: UniversityScholarshipViewSet
import_location: university import_location: university
api_end_point: university_more/scholarship api_end_point: university_more/scholarship
versionned: true
- model: UniversityInfo - model: UniversityInfo
viewset: UniversityInfoViewSet viewset: UniversityInfoViewSet
import_location: university import_location: university
api_end_point: university_more/info api_end_point: university_more/info
versionned: true
- model: UniversitySemestersDates - model: UniversitySemestersDates
viewset: UniversitySemestersDatesViewSet viewset: UniversitySemestersDatesViewSet
import_location: university import_location: university
api_end_point: university_more/semesters_dates api_end_point: university_more/semesters_dates
versionned: true
- 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 - model: UniversityPhoto
viewset: UniversityPhotoViewSet viewset: UniversityPhotoViewSet
import_location: university import_location: university
api_end_point: university_more/photo api_end_point: university_more/photo
versionned: true
- 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 - model: UniversityDri
viewset: UniversityDriViewSet viewset: UniversityDriViewSet
import_location: university import_location: university
api_end_point: university_more/dri api_end_point: university_more/dri
versionned: true
- model: UniversityModules - model: null
viewset: UniversityModulesViewSet viewset: UniversityModulesViewSet
import_location: university import_location: university
api_end_point: university_more/all api_end_point: university_more/all
api_attr: (?P<univ_id>[0-9]+) api_attr: (?P<univ_id>[0-9]+)
api_name: university_details 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 - model: Recommendation
viewset: RecommendationViewSet viewset: RecommendationViewSet
import_location: user import_location: user
...@@ -241,6 +178,7 @@ ...@@ -241,6 +178,7 @@
api_end_point: version api_end_point: version
api_attr: (?P<content_type_id>[0-9]+)/(?P<object_pk>[0-9A-Za-z]+) api_attr: (?P<content_type_id>[0-9]+)/(?P<object_pk>[0-9A-Za-z]+)
api_name: versions-list api_name: versions-list
ignore_in_admin: true
- model: ForTestingModeration - model: ForTestingModeration
viewset: ForTestingModerationViewSet viewset: ForTestingModerationViewSet
...@@ -253,10 +191,4 @@ ...@@ -253,10 +191,4 @@
import_location: my_model import_location: my_model
api_end_point: test/versioning api_end_point: test/versioning
requires_testing: true requires_testing: true
# versionned: true don't put it here, it is manually handled with @register decorator
# 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 # This python file is used to generate js files for redux
import os
from django import template from django import template
import yaml import yaml
from os.path import join, realpath, dirname
############ ############
# Need to do this first so that Django template engine is working # Need to do this first so that Django template engine is working
...@@ -30,37 +30,39 @@ def write_file(file, data): ...@@ -30,37 +30,39 @@ def write_file(file, data):
the_file.write(data) the_file.write(data)
current_dir = os.path.dirname(os.path.realpath(__file__)) def render_and_save(template_path, context, output_path):
templates_dir = current_dir + '/templates/' t = template.Template(read_file(template_path))
saving_dir = os.path.realpath(current_dir + "/../") c = template.Context({'data': context})
output = t.render(c)
# if not os.path.exists(saving_dir): write_file(output_path, output)
# 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) 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}) # API_BASE = "http://127.0.0.1:8000/api/"
output = t.render(c)
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 %}
# Generated by Django 2.0.3 on 2018-08-29 16:40
import backend.models.tools.usefullLinksField
from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('backend', '0023_auto_20180829_1815'),
]
operations = [
migrations.CreateModel(
name='CampusTaggedItem',
fields=[
('moderated_on', models.DateTimeField(null=True)),
('updated_on', models.DateTimeField(null=True)),
('comment', models.TextField(blank=True)),
('usefull_links', backend.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[backend.models.tools.usefullLinksField.validate_usefull_links])),
('custom_content', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)),
('campus', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='city_items', serialize=False, to='backend.Campus')),
('moderated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='backend.Tag')),
('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='CityTaggedItem',
fields=[
('moderated_on', models.DateTimeField(null=True)),
('updated_on', models.DateTimeField(null=True)),
('comment', models.TextField(blank=True)),
('usefull_links', backend.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[backend.models.tools.usefullLinksField.validate_usefull_links])),
('custom_content', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)),
('city', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='city_items', serialize=False, to='backend.City')),
('moderated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='backend.Tag')),
('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='CountryTaggedItem',
fields=[
('moderated_on', models.DateTimeField(null=True)),
('updated_on', models.DateTimeField(null=True)),
('comment', models.TextField(blank=True)),
('usefull_links', backend.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[backend.models.tools.usefullLinksField.validate_usefull_links])),
('custom_content', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)),
('country', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='city_items', serialize=False, to='backend.Country')),
('moderated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='backend.Tag')),
('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='UniversityTaggedItem',
fields=[
('moderated_on', models.DateTimeField(null=True)),
('updated_on', models.DateTimeField(null=True)),
('comment', models.TextField(blank=True)),
('usefull_links', backend.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[backend.models.tools.usefullLinksField.validate_usefull_links])),
('custom_content', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)),
('university', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='city_items', serialize=False, to='backend.University')),
('moderated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='backend.Tag')),
('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
),
migrations.RemoveField(
model_name='campusaccommodation',
name='campus',
),
migrations.RemoveField(
model_name='campusaccommodation',
name='moderated_by',
),
migrations.RemoveField(
model_name='campusaccommodation',
name='updated_by',
),
migrations.RemoveField(
model_name='campuscultureandstudentlife',
name='campus',
),
migrations.RemoveField(
model_name='campuscultureandstudentlife',
name='moderated_by',
),
migrations.RemoveField(
model_name='campuscultureandstudentlife',
name='updated_by',
),
migrations.RemoveField(
model_name='campusotherstuff',
name='campus',
),
migrations.RemoveField(
model_name='campusotherstuff',
name='moderated_by',
),
migrations.RemoveField(
model_name='campusotherstuff',
name='updated_by',
),
migrations.RemoveField(
model_name='campustransport',
name='campus',
),
migrations.RemoveField(
model_name='campustransport',
name='moderated_by',
),
migrations.RemoveField(
model_name='campustransport',
name='updated_by',
),
migrations.RemoveField(
model_name='cityotherstuff',
name='city',
),
migrations.RemoveField(
model_name='cityotherstuff',
name='moderated_by',
),
migrations.RemoveField(
model_name='cityotherstuff',
name='updated_by',
),
migrations.RemoveField(
model_name='citytourism',
name='city',
),
migrations.RemoveField(
model_name='citytourism',
name='moderated_by',
),
migrations.RemoveField(
model_name='citytourism',
name='updated_by',
),
migrations.RemoveField(
model_name='citytransport',
name='city',
),
migrations.RemoveField(
model_name='citytransport',
name='moderated_by',
),
migrations.RemoveField(
model_name='citytransport',
name='updated_by',
),