Commit 8a8e8cf6 authored by Florent Chehab's avatar Florent Chehab

Merge branch 'frontend' into 'master'

New Frontend initialize

Closes #11

See merge request chehabfl/outgoing_rex!15
parents f7b3fc08 a157cc69
Pipeline #26686 passed with stages
in 3 minutes and 30 seconds
{
"presets": [
"env",
"react",
"es2015",
"stage-1"
],
"plugins": [
"transform-class-properties"
]
}
\ No newline at end of file
[run]
omit = *migrations*
source = .
omit =
*migrations*
tests/*
source = .
extends: google
[flake8]
# E501 line too long
ignore = E501
exclude = tests/*, env/*
\ No newline at end of file
exclude =
env/*
node_modules/*
......@@ -8,4 +8,5 @@ db.sqlite3
node_modules
.coverage
htmlcov
.vscode
\ No newline at end of file
.vscode
.pytest_cache
......@@ -14,9 +14,7 @@ testing:
- export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
- pip install -r requirements.txt --quiet
- ./manage.py check
- coverage3 run manage.py test
- coverage3 report
- coverage3 html
- pytest -n 4 general/ frontend/ backend/ --cov-report html
artifacts:
paths:
- htmlcov/
......
......@@ -8,7 +8,9 @@
"**/.DS_Store": true,
"**/__pycache__":true,
"**/*.pyc":true,
"htmlcov":true
"htmlcov":false,
"env":true,
".coverage":true
},
"cSpell.language": "en,fr-FR,fr",
"python.linting.flake8Enabled": true
......
default_app_config = 'backend.apps.BackendConfig'
......@@ -47,6 +47,8 @@ from backend.models.user import PreviousDeparture
from backend.models.user import PreviousDepartureFeedback
from backend.models.user import UserData
from backend.models.my_model import PendingModeration
CLASSIC_MODELS = [
Country,
City,
......@@ -59,7 +61,8 @@ CLASSIC_MODELS = [
RecommendationList,
PreviousDeparture,
PreviousDepartureFeedback,
UserData
UserData,
PendingModeration
]
VERSIONNED_MODELS = [
......
......@@ -3,3 +3,6 @@ from django.apps import AppConfig
class BackendConfig(AppConfig):
name = 'backend'
def ready(self):
import backend.signals # noqa: F401
from .load_all import load_all # noqa: F401
from .loading_scripts import LoadAdminUser
from .loading_scripts import LoadCountries
from .loading_scripts import LoadUniversities
def load_all():
admin = LoadAdminUser().get()
LoadCountries(admin).load()
LoadUniversities(admin).load()
from .loadAdminUser import LoadAdminUser # noqa: F401
from .loadCountries import LoadCountries # noqa: F401
from .loadUniversities import LoadUniversities # noqa: F401
from django.contrib.auth.models import User
class LoadAdminUser(object):
def __init__(self):
admins = User.objects.filter(username="admin")
if len(admins) > 0:
self.admin = admins[0]
else:
self.admin = User.objects.create_superuser(
username='admin',
email='null@null.fr',
password='admin'
)
def get(self):
return self.admin
from backend.models.location import Country
import os
import pandas as pd
from .loadGeneric import LoadGeneric
class LoadCountries(LoadGeneric):
def __init__(self, admin):
self.admin = admin
def load(self):
tmp = os.path.join(os.path.realpath(__file__),
'../../assets/country.csv')
country_file_loc = os.path.abspath(tmp)
tmp = os.path.join(os.path.realpath(__file__),
'../../assets/alpha-conv-table.csv')
conv_alpha_file_loc = os.path.abspath(tmp)
country_pd = pd.read_csv(country_file_loc, sep=',', header=0,
dtype=object).fillna('')
# Need to load the information for converting
# Countries alpha-3 code to alpha-2 code
data_conv = pd.read_csv(conv_alpha_file_loc, sep=',',
header=0, na_filter=False)
conv_alpha = {}
for index, row in data_conv.iterrows():
conv_alpha[row["alpha-3"]] = row["alpha-2"]
for index, r in country_pd.iterrows():
Iso_3 = str(r['ISO-alpha3 Code'])
code_alpha_2 = None
if Iso_3 in conv_alpha.keys():
code_alpha_2 = conv_alpha[Iso_3]
else:
print("ignoring country :", Iso_3)
continue
country = Country(
name=r["Country or Area"],
iso_alpha2_code=code_alpha_2,
iso_alpha3_code=Iso_3,
region_name=r["Region Name"],
region_un_code=r["Region Code"],
sub_region_name=r["Sub-region Name"],
sub_region_un_code=r["Sub-region Code"],
intermediate_region_name=r["Intermediate Region Name"],
intermediate_region_un_code=r["Intermediate Region Code"],
)
country.save()
self.add_info(country, self.admin)
from django.utils import timezone
import reversion
class LoadGeneric(object):
@classmethod
def add_info(cls, obj, admin):
with reversion.create_revision():
obj.moderated_by = admin
obj.updated_by = admin
obj.moderated_on = timezone.now()
obj.updated_on = timezone.now()
obj.save()
from backend.models.location import City, Country
from backend.models.university import University, Campus
import os
import pandas as pd
from .loadGeneric import LoadGeneric
class LoadUniversities(LoadGeneric):
def __init__(self, admin):
self.admin = admin
def load(self):
tmp = os.path.join(os.path.realpath(__file__),
'../../assets/destinations_extracted.csv')
destinations_path = os.path.abspath(tmp)
data = pd.read_csv(destinations_path, sep=',', header=0,
dtype=object)
for index, row in data.iterrows():
univ_name, city_name, country_code, lat, lon = row
lat = round(float(lat), 6)
lon = round(float(lon), 6)
country = Country.objects.filter(pk=country_code)[0]
city = City(
name=city_name,
country=country
)
city.save()
self.add_info(city, self.admin)
univ = University(
name=univ_name
)
univ.save()
self.add_info(univ, self.admin)
main_campus = Campus(
is_main_campus=True,
name="Campus - " + univ.name,
city=city,
university=univ,
lat=lat,
lon=lon
)
main_campus.save()
self.add_info(main_campus, self.admin)
# Generated by Django 2.0.3 on 2018-08-24 07:10
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='campus',
name='university',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='univ_campus', to='backend.University'),
),
]
This diff is collapsed.
# Generated by Django 2.0.3 on 2018-08-24 13:51
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),
('contenttypes', '0002_remove_content_type_name'),
('backend', '0003_auto_20180824_1011'),
]
operations = [
migrations.CreateModel(
name='PendingModeration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.CharField(max_length=100)),
('content_object', django.contrib.postgres.fields.jsonb.JSONField()),
('delete', models.NullBooleanField(default=None)),
('approve', models.NullBooleanField(default=None)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
],
),
]
# Generated by Django 2.0.3 on 2018-08-24 13:53
import django.contrib.postgres.fields.jsonb
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0004_pendingmoderation'),
]
operations = [
migrations.AlterField(
model_name='pendingmoderation',
name='content_object',
field=django.contrib.postgres.fields.jsonb.JSONField(default={}),
),
]
# Generated by Django 2.0.3 on 2018-08-24 13:58
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0005_auto_20180824_1553'),
]
operations = [
migrations.RenameField(
model_name='pendingmoderation',
old_name='content_object',
new_name='new_object',
),
]
# Generated by Django 2.0.3 on 2018-08-24 15:41
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0006_auto_20180824_1558'),
]
operations = [
migrations.RenameField(
model_name='pendingmoderation',
old_name='new_object',
new_name='object_to_moderate',
),
]
# Generated by Django 2.0.3 on 2018-08-24 19:28
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('backend', '0007_auto_20180824_1741'),
]
operations = [
migrations.RenameField(
model_name='pendingmoderation',
old_name='object_to_moderate',
new_name='new_object',
),
migrations.RemoveField(
model_name='pendingmoderation',
name='approve',
),
migrations.RemoveField(
model_name='pendingmoderation',
name='delete',
),
migrations.RemoveField(
model_name='university',
name='updated_at',
),
migrations.AddField(
model_name='university',
name='moderated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='moderated', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='university',
name='moderated_on',
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name='university',
name='updated_on',
field=models.DateTimeField(null=True),
),
migrations.AlterField(
model_name='campus',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='campusaccommodation',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='campuscultureandstudentlife',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='campusotherstuff',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='campustransport',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='cityotherstuff',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='cityphoto',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='citytourism',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='citytransport',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryculture',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countrydri',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryhealthinsurance',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryotherinsurance',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryotherstuff',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryphoto',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryscholarship',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countrytourism',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countrytransport',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='countryvisaadministrative',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='university',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated', to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universitycourses',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityculture',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universitydri',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityinfo',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityinsurance',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityotherstuff',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityphoto',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityscholarship',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universitysemestersdates',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='universityspecialoffer',
name='updated_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
]
# Generated by Django 2.0.3 on 2018-08-24 20:18
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('backend', '0008_auto_20180824_2128'),
]
operations = [
migrations.AlterUniqueTogether(
name='pendingmoderation',
unique_together={('content_type', 'object_id')},
),
]
# Generated by Django 2.0.3 on 2018-08-24 20:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0009_auto_20180824_2218'),
]
operations = [
migrations.RenameField(
model_name='pendingmoderation',
old_name='author',
new_name='updated_by',
),
migrations.AddField(
model_name='pendingmoderation',
name='updated_on',
field=models.DateTimeField(null=True),
),
]
# Generated by Django 2.0.3 on 2018-08-25 16:49
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('backend', '0010_auto_20180824_2251'),
]
operations = [
migrations.CreateModel(
name='TestingModeration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('moderated_on', models.DateTimeField(null=True)),
('updated_on', models.DateTimeField(null=True)),
('do_not_touch_this_stuff', models.CharField(max_length=100)),
('moderated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],