Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
f7a7f518
Commit
f7a7f518
authored
Aug 29, 2018
by
Florent Chehab
Browse files
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
Changes
18
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.flake8
View file @
f7a7f518
...
...
@@ -5,3 +5,4 @@ exclude =
env/*
node_modules/*
backend/urls.py
backend/admin.py
backend/admin.py
deleted
100644 → 0
View file @
66ca721d
raise
Exception
(
"This file should be automatically generated"
)
\ No newline at end of file
backend/generate/api_config.yml
View file @
f7a7f518
-
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
backend/generate/generate_all.py
View file @
f7a7f518
#####
# 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
)
backend/generate/templates/admin.tpl
0 → 100644
View file @
f7a7f518
{
%
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 %}
backend/migrations/0024_auto_20180829_1840.py
0 → 100644
View file @
f7a7f518
# 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'
,
),
migrations
.
RemoveField
(
model_name
=
'countryculture'
,
name
=
'country'
,
),
migrations
.
RemoveField
(
model_name
=
'countryculture'
,
name
=
'moderated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryculture'
,
name
=
'updated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryhealthinsurance'
,
name
=
'country'
,
),
migrations
.
RemoveField
(
model_name
=
'countryhealthinsurance'
,
name
=
'moderated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryhealthinsurance'
,
name
=
'updated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryotherinsurance'
,
name
=
'country'
,
),
migrations
.
RemoveField
(
model_name
=
'countryotherinsurance'
,
name
=
'moderated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryotherinsurance'
,
name
=
'updated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryotherstuff'
,
name
=
'country'
,
),
migrations
.
RemoveField
(
model_name
=
'countryotherstuff'
,
name
=
'moderated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countryotherstuff'
,
name
=
'updated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countrytourism'
,
name
=
'country'
,
),
migrations
.
RemoveField
(
model_name
=
'countrytourism'
,
name
=
'moderated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countrytourism'
,
name
=
'updated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countrytransport'
,
name
=
'country'
,
),
migrations
.
RemoveField
(
model_name
=
'countrytransport'
,
name
=
'moderated_by'
,
),
migrations
.
RemoveField
(
model_name
=
'countrytransport'
,
name
=
'updated_by'
,
),