Commit b92d223e authored by Florent Chehab's avatar Florent Chehab

Merge branch 'connect_back_front' into 'master'

Connect back front

See merge request chehabfl/outgoing_rex!36
parents a938e15d 6ff038f3
...@@ -6,3 +6,4 @@ exclude = ...@@ -6,3 +6,4 @@ exclude =
node_modules/* node_modules/*
backend/urls.py backend/urls.py
backend/admin.py backend/admin.py
backend/permissions/__list_user_post_permission.py
\ No newline at end of file
...@@ -13,4 +13,5 @@ htmlcov ...@@ -13,4 +13,5 @@ htmlcov
/backend/urls.py /backend/urls.py
/backend/admin.py /backend/admin.py
database.db database.db
database.db-journal database.db-journal
\ No newline at end of file backend/permissions/__list_user_post_permission.py
...@@ -5,4 +5,6 @@ class BackendConfig(AppConfig): ...@@ -5,4 +5,6 @@ class BackendConfig(AppConfig):
name = 'backend' name = 'backend'
def ready(self): 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
from backend.fields.jSONField import JSONField from backend.fields import JSONField
from rest_framework import serializers from rest_framework import serializers
field_mapping = serializers.ModelSerializer.serializer_field_mapping field_mapping = serializers.ModelSerializer.serializer_field_mapping
......
from .jSONField import JSONField # noqa: F401
...@@ -43,6 +43,11 @@ template_path = join(templates_dir, 'urls.tpl') ...@@ -43,6 +43,11 @@ template_path = join(templates_dir, 'urls.tpl')
output_path = join(saving_dir, 'urls.py') output_path = join(saving_dir, 'urls.py')
render_and_save(template_path, api_config, output_path) 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 # Render admin.py
data = [] data = []
for obj in api_config: for obj in api_config:
......
{% 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 %}
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
from django.conf.urls import url, include from django.conf.urls import url, include
from django.conf import settings from django.conf import settings
from rest_framework import routers from rest_framework import routers
from django.urls import path
from . import views
ALL_MODELS = [] ALL_MODELS = []
ALL_VIEWSETS = [] ALL_VIEWSETS = []
...@@ -51,6 +53,7 @@ router.register( ...@@ -51,6 +53,7 @@ router.register(
){% endif %}{% endfor %} ){% endif %}{% endfor %}
urlpatterns += [url(r'^api/', include(router.urls))] urlpatterns += [url(r'^api/', include(router.urls))]
urlpatterns.append(path('api/serverModerationStatus/', views.app_moderation_status))
for model in ALL_MODELS: for model in ALL_MODELS:
for key in model.model_config: for key in model.model_config:
......
...@@ -7,5 +7,49 @@ ...@@ -7,5 +7,49 @@
"required": true "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
...@@ -3,11 +3,15 @@ from .loading_scripts import LoadCurrencies ...@@ -3,11 +3,15 @@ from .loading_scripts import LoadCurrencies
from .loading_scripts import LoadCountries from .loading_scripts import LoadCountries
from .loading_scripts import LoadUniversities from .loading_scripts import LoadUniversities
from .loading_scripts import LoadTags from .loading_scripts import LoadTags
from .loading_scripts import LoadUniversityEx
import reversion
def load_all(): def load_all():
admin = LoadAdminUser().get() with reversion.create_revision():
LoadCurrencies(admin).load() admin = LoadAdminUser().get()
LoadCountries(admin).load() LoadCurrencies(admin).load()
LoadUniversities(admin).load() LoadCountries(admin).load()
LoadTags(admin).load() LoadUniversities(admin).load()
LoadTags(admin).load()
LoadUniversityEx(admin).load()
...@@ -3,3 +3,4 @@ from .loadCountries import LoadCountries # noqa: F401 ...@@ -3,3 +3,4 @@ from .loadCountries import LoadCountries # noqa: F401
from .loadUniversities import LoadUniversities # noqa: F401 from .loadUniversities import LoadUniversities # noqa: F401
from .loadTags import LoadTags # noqa: F401 from .loadTags import LoadTags # noqa: F401
from .loadCurrencies import LoadCurrencies # noqa: F401 from .loadCurrencies import LoadCurrencies # noqa: F401
from .loadUniversityEx import LoadUniversityEx # noqa: F401
...@@ -49,4 +49,4 @@ class LoadCountries(LoadGeneric): ...@@ -49,4 +49,4 @@ class LoadCountries(LoadGeneric):
intermediate_region_un_code=r["Intermediate Region Code"], intermediate_region_un_code=r["Intermediate Region Code"],
) )
country.save() country.save()
self.add_info(country, self.admin) self.add_info_and_save(country, self.admin)
...@@ -26,4 +26,4 @@ class LoadCurrencies(LoadGeneric): ...@@ -26,4 +26,4 @@ class LoadCurrencies(LoadGeneric):
one_EUR_in_this_currency=Decimal(r[2]) one_EUR_in_this_currency=Decimal(r[2])
) )
currency.save() currency.save()
self.add_info(currency, self.admin) self.add_info_and_save(currency, self.admin)
...@@ -5,7 +5,7 @@ import reversion ...@@ -5,7 +5,7 @@ import reversion
class LoadGeneric(object): class LoadGeneric(object):
@classmethod @classmethod
def add_info(cls, obj, admin): def add_info_and_save(cls, obj, admin):
with reversion.create_revision(): with reversion.create_revision():
obj.moderated_by = admin obj.moderated_by = admin
obj.updated_by = admin obj.updated_by = admin
......
...@@ -20,4 +20,4 @@ class LoadTags(LoadGeneric): ...@@ -20,4 +20,4 @@ class LoadTags(LoadGeneric):
for tag in tags: for tag in tags:
t = Tag(name=tag['name'], config=tag['config']) t = Tag(name=tag['name'], config=tag['config'])
t.save() t.save()
self.add_info(t, self.admin) self.add_info_and_save(t, self.admin)
...@@ -33,7 +33,7 @@ class LoadUniversities(LoadGeneric): ...@@ -33,7 +33,7 @@ class LoadUniversities(LoadGeneric):
country=country country=country
) )
city.save() city.save()
self.add_info(city, self.admin) self.add_info_and_save(city, self.admin)
univ = University.objects.update_or_create( univ = University.objects.update_or_create(
utc_id=utc_id, utc_id=utc_id,
...@@ -44,7 +44,7 @@ class LoadUniversities(LoadGeneric): ...@@ -44,7 +44,7 @@ class LoadUniversities(LoadGeneric):
"logo": logo "logo": logo
} }
)[0] )[0]
self.add_info(univ, self.admin) self.add_info_and_save(univ, self.admin)
main_campus = Campus( main_campus = Campus(
is_main_campus=True, is_main_campus=True,
...@@ -55,4 +55,4 @@ class LoadUniversities(LoadGeneric): ...@@ -55,4 +55,4 @@ class LoadUniversities(LoadGeneric):
lon=lon lon=lon
) )
main_campus.save() main_campus.save()
self.add_info(main_campus, self.admin) self.add_info_and_save(main_campus, self.admin)
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)
This diff is collapsed.
# 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