Skip to content
GitLab
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
b92d223e
Commit
b92d223e
authored
Sep 16, 2018
by
Florent Chehab
Browse files
Merge branch 'connect_back_front' into 'master'
Connect back front See merge request chehabfl/outgoing_rex!36
parents
a938e15d
6ff038f3
Pipeline
#27364
passed with stages
in 3 minutes and 1 second
Changes
187
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
.flake8
View file @
b92d223e
...
...
@@ -6,3 +6,4 @@ exclude =
node_modules/*
backend/urls.py
backend/admin.py
backend/permissions/__list_user_post_permission.py
\ No newline at end of file
.gitignore
View file @
b92d223e
...
...
@@ -13,4 +13,5 @@ htmlcov
/backend/urls.py
/backend/admin.py
database.db
database.db-journal
\ No newline at end of file
database.db-journal
backend/permissions/__list_user_post_permission.py
backend/apps.py
View file @
b92d223e
...
...
@@ -5,4 +5,6 @@ class BackendConfig(AppConfig):
name
=
'backend'
def
ready
(
self
):
import
backend.signals
# noqa: F401
import
backend.signals.__create_user_modules_post_create
# noqa: F401
import
backend.signals.__squash_revision_by_user
# noqa: F401
import
backend.signals.__create_univ_modules_post_save
# noqa: F401
backend/custom/mySerializerWithJSON.py
View file @
b92d223e
from
backend.fields
.jSONField
import
JSONField
from
backend.fields
import
JSONField
from
rest_framework
import
serializers
field_mapping
=
serializers
.
ModelSerializer
.
serializer_field_mapping
...
...
backend/fields
/jSONField
.py
→
backend/fields.py
View file @
b92d223e
File moved
backend/fields/__init__.py
deleted
100644 → 0
View file @
a938e15d
from
.jSONField
import
JSONField
# noqa: F401
backend/generate/generate_backend_files.py
View file @
b92d223e
...
...
@@ -43,6 +43,11 @@ template_path = join(templates_dir, 'urls.tpl')
output_path
=
join
(
saving_dir
,
'urls.py'
)
render_and_save
(
template_path
,
api_config
,
output_path
)
# render list_user_post_permission.py
template_path
=
join
(
templates_dir
,
'list_user_post_permission.tpl'
)
output_path
=
join
(
saving_dir
,
'./permissions/__list_user_post_permission.py'
)
render_and_save
(
template_path
,
api_config
,
output_path
)
# Render admin.py
data
=
[]
for
obj
in
api_config
:
...
...
backend/generate/templates/list_user_post_permission.tpl
0 → 100644
View file @
b92d223e
{
%
autoescape
off
%
}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
# WITH /backend/generate/generate_backend_files.py
# MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED
# THIS WARNING DOESN'T APPLY TO .tpl FILES...
from django.conf import settings
ALL_VIEWSETS = {}
{% for model in data %}{% if not model.requires_testing %}{% if model.viewset != 'UserDataViewSet' %}
from backend.models.{
{
model
.
import_location
}
} import {
{
model
.
viewset
}
}
ALL_VIEWSETS["{
{
model
.
viewset
}
}"] = {
{
model
.
viewset
}
}
{% endif %}{% endif %}{% endfor %}
if settings.TESTING:
{% for model in data %}{% if model.requires_testing %}
from backend.models.{
{
model
.
import_location
}
} import {
{
model
.
viewset
}
}
ALL_VIEWSETS["{
{
model
.
viewset
}
}"] = {
{
model
.
viewset
}
}
{% endif %}{% endfor %}
class Request(object):
def __init__(self, user, method):
self.user = user
self.method = method
def list_user_post_permission(user):
viewsets_user_can_post = []
request = Request(user, 'POST')
for viewset_name in ALL_VIEWSETS:
viewset = ALL_VIEWSETS[viewset_name]
user_can_post = True
for permission_class in viewset.permission_classes:
if not permission_class.has_permission(None, request, None):
user_can_post = False
break
if user_can_post:
name = viewset_name.split('ViewSet')[0]
name = name[0].lower() + name[1:]
viewsets_user_can_post.append(name)
return viewsets_user_can_post
{% endautoescape %}
backend/generate/templates/urls.tpl
View file @
b92d223e
...
...
@@ -8,6 +8,8 @@
from django.conf.urls import url, include
from django.conf import settings
from rest_framework import routers
from django.urls import path
from . import views
ALL_MODELS = []
ALL_VIEWSETS = []
...
...
@@ -51,6 +53,7 @@ router.register(
){% endif %}{% endfor %}
urlpatterns += [url(r'^api/', include(router.urls))]
urlpatterns.append(path('api/serverModerationStatus/', views.app_moderation_status))
for model in ALL_MODELS:
for key in model.model_config:
...
...
backend/load_data/assets/tags.json
View file @
b92d223e
...
...
@@ -7,5 +7,49 @@
"required"
:
true
}
}
},
{
"name"
:
"insurance"
,
"config"
:
{}
},
{
"name"
:
"transport"
,
"config"
:
{}
},
{
"name"
:
"accommodation"
,
"config"
:
{}
},
{
"name"
:
"student_life"
,
"config"
:
{}
},
{
"name"
:
"everyday_life"
,
"config"
:
{}
},
{
"name"
:
"other"
,
"config"
:
{}
},
{
"name"
:
"administrative"
,
"config"
:
{}
},
{
"name"
:
"culture"
,
"config"
:
{}
},
{
"name"
:
"tourism"
,
"config"
:
{}
},
{
"name"
:
"shared_comment"
,
"config"
:
{}
},
{
"name"
:
"specific_partnership"
,
"config"
:
{}
}
]
\ No newline at end of file
backend/load_data/load_all.py
View file @
b92d223e
...
...
@@ -3,11 +3,15 @@ from .loading_scripts import LoadCurrencies
from
.loading_scripts
import
LoadCountries
from
.loading_scripts
import
LoadUniversities
from
.loading_scripts
import
LoadTags
from
.loading_scripts
import
LoadUniversityEx
import
reversion
def
load_all
():
admin
=
LoadAdminUser
().
get
()
LoadCurrencies
(
admin
).
load
()
LoadCountries
(
admin
).
load
()
LoadUniversities
(
admin
).
load
()
LoadTags
(
admin
).
load
()
with
reversion
.
create_revision
():
admin
=
LoadAdminUser
().
get
()
LoadCurrencies
(
admin
).
load
()
LoadCountries
(
admin
).
load
()
LoadUniversities
(
admin
).
load
()
LoadTags
(
admin
).
load
()
LoadUniversityEx
(
admin
).
load
()
backend/load_data/loading_scripts/__init__.py
View file @
b92d223e
...
...
@@ -3,3 +3,4 @@ from .loadCountries import LoadCountries # noqa: F401
from
.loadUniversities
import
LoadUniversities
# noqa: F401
from
.loadTags
import
LoadTags
# noqa: F401
from
.loadCurrencies
import
LoadCurrencies
# noqa: F401
from
.loadUniversityEx
import
LoadUniversityEx
# noqa: F401
backend/load_data/loading_scripts/loadCountries.py
View file @
b92d223e
...
...
@@ -49,4 +49,4 @@ class LoadCountries(LoadGeneric):
intermediate_region_un_code
=
r
[
"Intermediate Region Code"
],
)
country
.
save
()
self
.
add_info
(
country
,
self
.
admin
)
self
.
add_info
_and_save
(
country
,
self
.
admin
)
backend/load_data/loading_scripts/loadCurrencies.py
View file @
b92d223e
...
...
@@ -26,4 +26,4 @@ class LoadCurrencies(LoadGeneric):
one_EUR_in_this_currency
=
Decimal
(
r
[
2
])
)
currency
.
save
()
self
.
add_info
(
currency
,
self
.
admin
)
self
.
add_info
_and_save
(
currency
,
self
.
admin
)
backend/load_data/loading_scripts/loadGeneric.py
View file @
b92d223e
...
...
@@ -5,7 +5,7 @@ import reversion
class
LoadGeneric
(
object
):
@
classmethod
def
add_info
(
cls
,
obj
,
admin
):
def
add_info
_and_save
(
cls
,
obj
,
admin
):
with
reversion
.
create_revision
():
obj
.
moderated_by
=
admin
obj
.
updated_by
=
admin
...
...
backend/load_data/loading_scripts/loadTags.py
View file @
b92d223e
...
...
@@ -20,4 +20,4 @@ class LoadTags(LoadGeneric):
for
tag
in
tags
:
t
=
Tag
(
name
=
tag
[
'name'
],
config
=
tag
[
'config'
])
t
.
save
()
self
.
add_info
(
t
,
self
.
admin
)
self
.
add_info
_and_save
(
t
,
self
.
admin
)
backend/load_data/loading_scripts/loadUniversities.py
View file @
b92d223e
...
...
@@ -33,7 +33,7 @@ class LoadUniversities(LoadGeneric):
country
=
country
)
city
.
save
()
self
.
add_info
(
city
,
self
.
admin
)
self
.
add_info
_and_save
(
city
,
self
.
admin
)
univ
=
University
.
objects
.
update_or_create
(
utc_id
=
utc_id
,
...
...
@@ -44,7 +44,7 @@ class LoadUniversities(LoadGeneric):
"logo"
:
logo
}
)[
0
]
self
.
add_info
(
univ
,
self
.
admin
)
self
.
add_info
_and_save
(
univ
,
self
.
admin
)
main_campus
=
Campus
(
is_main_campus
=
True
,
...
...
@@ -55,4 +55,4 @@ class LoadUniversities(LoadGeneric):
lon
=
lon
)
main_campus
.
save
()
self
.
add_info
(
main_campus
,
self
.
admin
)
self
.
add_info
_and_save
(
main_campus
,
self
.
admin
)
backend/load_data/loading_scripts/loadUniversityEx.py
0 → 100644
View file @
b92d223e
from
.loadGeneric
import
LoadGeneric
from
backend.models.university
import
University
from
backend.models.university
import
UniversityDri
from
backend.models.university
import
UniversityInfo
from
backend.models.university
import
UniversitySemestersDates
from
backend.models.university
import
UniversityScholarship
from
backend.models.university
import
UniversityTaggedItem
from
backend.models.currency
import
Currency
from
backend.models.tag
import
Tag
from
datetime
import
datetime
class
LoadUniversityEx
(
LoadGeneric
):
def
__init__
(
self
,
admin
):
self
.
admin
=
admin
def
load
(
self
):
EPFL
=
University
.
objects
.
get
(
acronym
=
'EPFL'
)
CHF
=
Currency
.
objects
.
get
(
pk
=
'CHF'
)
ACCOMMODATION_TAG
=
Tag
.
objects
.
get
(
name
=
'accommodation'
)
univ_dri_1
=
UniversityDri
(
comment
=
"Attention les cours de master sont 100% en anglais"
)
univ_dri_1
.
save
()
univ_dri_1
.
universities
.
add
(
EPFL
)
self
.
add_info_and_save
(
univ_dri_1
,
self
.
admin
)
univ_info
=
UniversityInfo
.
objects
.
get
(
university
=
EPFL
)
univ_info
.
cost_exchange
=
0
univ_info
.
costs_currency
=
CHF
self
.
add_info_and_save
(
univ_info
,
self
.
admin
)
usd
=
UniversitySemestersDates
.
objects
.
get
(
university
=
EPFL
)
usd
.
autumn_begin
=
datetime
.
strptime
(
"17/09/2018"
,
'%d/%m/%Y'
)
usd
.
autumn_end
=
datetime
.
strptime
(
"29/01/2019"
,
'%d/%m/%Y'
)
self
.
add_info_and_save
(
usd
,
self
.
admin
)
univ_scholarship_1
=
UniversityScholarship
(
type
=
"Swiss European..."
,
currency
=
CHF
,
frequency
=
's'
,
amount_min
=
2200
,
amount_max
=
2200
,
comment
=
"Il n'y a rien à faire pour l'obtenir"
)
univ_scholarship_1
.
save
()
univ_scholarship_1
.
universities
.
add
(
EPFL
)
self
.
add_info_and_save
(
univ_scholarship_1
,
self
.
admin
)
univ_tag_1
=
UniversityTaggedItem
(
university
=
EPFL
,
tag
=
ACCOMMODATION_TAG
,
title
=
"C'est compliqué de trouver un logement"
,
comment
=
"Mon commentaire."
,
importance_level
=
'++'
)
self
.
add_info_and_save
(
univ_tag_1
,
self
.
admin
)
backend/migrations/0001_initial.py
View file @
b92d223e
This diff is collapsed.
Click to expand it.
backend/migrations/0002_auto_20180916_1555.py
0 → 100644
View file @
b92d223e
# Generated by Django 2.0.3 on 2018-09-16 13:55
import
backend.models.university.university
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'backend'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'campus'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'campus'
,
name
=
'name'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
200
),
),
migrations
.
AlterField
(
model_name
=
'campus'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'campustaggeditem'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'campustaggeditem'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'city'
,
name
=
'area'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
200
),
),
migrations
.
AlterField
(
model_name
=
'city'
,
name
=
'local_name'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
200
),
),
migrations
.
AlterField
(
model_name
=
'citytaggeditem'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'citytaggeditem'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'country'
,
name
=
'intermediate_region_name'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
200
),
),
migrations
.
AlterField
(
model_name
=
'country'
,
name
=
'intermediate_region_un_code'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
3
),
),
migrations
.
AlterField
(
model_name
=
'country'
,
name
=
'iso_alpha3_code'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
3
,
unique
=
True
),
),
migrations
.
AlterField
(
model_name
=
'country'
,
name
=
'sub_region_name'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
200
),
),
migrations
.
AlterField
(
model_name
=
'country'
,
name
=
'sub_region_un_code'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
3
),
),
migrations
.
AlterField
(
model_name
=
'countrydri'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'countrydri'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'countryscholarship'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'countryscholarship'
,
name
=
'other_advantages'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'countryscholarship'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'countrytaggeditem'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'countrytaggeditem'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'currency'
,
name
=
'symbol'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
30
),
),
migrations
.
AlterField
(
model_name
=
'previousdeparturefeedback'
,
name
=
'adequation_comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'previousdeparturefeedback'
,
name
=
'integration_comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'recommendation'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'university'
,
name
=
'acronym'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
20
),
),
migrations
.
AlterField
(
model_name
=
'university'
,
name
=
'logo'
,
field
=
models
.
URLField
(
blank
=
True
,
default
=
''
,
validators
=
[
backend
.
models
.
university
.
university
.
validate_extension_django
]),
),
migrations
.
AlterField
(
model_name
=
'university'
,
name
=
'website'
,
field
=
models
.
URLField
(
blank
=
True
,
default
=
''
,
max_length
=
300
),
),
migrations
.
AlterField
(
model_name
=
'universitydri'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'universitydri'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'universityinfo'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'universityinfo'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'universityscholarship'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'universityscholarship'
,
name
=
'other_advantages'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'universityscholarship'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'universitysemestersdates'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'universitysemestersdates'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
migrations
.
AlterField
(
model_name
=
'universitytaggeditem'
,
name
=
'comment'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
5000
),
),
migrations
.
AlterField
(
model_name
=
'universitytaggeditem'
,
name
=
'title'
,
field
=
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
150
),
),
]
Prev
1
2
3
4
5
…
10
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment