Commit 6a5274e8 authored by Florent Chehab's avatar Florent Chehab

feat(taggedItems): reworked, clean and operationnal & twaeked(site...

feat(taggedItems): reworked, clean and operationnal & twaeked(site information): added notification parameter

WARNING:
* Cleaned ALL migrations files as there were to many issues during the cleaning of taggedModels,

Tagged Items:
* Only for university and country now
* Auto creation on university/country creation
* Front operationnal
* Removed tag models and abstract tagged item

Site Information:
* Added a `should_notify` boolean to the model/front

Other:
* Added a default bot user
* Fixed timezone warning in the back
* Clean signals setup
* Fixed proptypes of Fields in the front
* Added HiddenField
* Deleted now useless files

Closes #30 #58
parent ae65342b
Pipeline #42557 passed with stages
in 4 minutes
......@@ -5,13 +5,10 @@ from backend_app.models.abstract.versionedEssentialModule import (
VersionedEssentialModule,
)
from backend_app.models.campus import Campus
from backend_app.models.campusTaggedItem import CampusTaggedItem
from backend_app.models.city import City
from backend_app.models.cityTaggedItem import CityTaggedItem
from backend_app.models.country import Country
from backend_app.models.countryDri import CountryDri
from backend_app.models.countryScholarship import CountryScholarship
from backend_app.models.countryTaggedItem import CountryTaggedItem
from backend_app.models.course import Course
from backend_app.models.courseFeedback import CourseFeedback
from backend_app.models.currency import Currency
......@@ -24,13 +21,12 @@ from backend_app.models.offer import Offer
from backend_app.models.pendingModeration import PendingModeration
from backend_app.models.recommendationList import RecommendationList
from backend_app.models.specialty import Specialty
from backend_app.models.tag import Tag
from backend_app.models.university import University
from backend_app.models.universityDri import UniversityDri
from backend_app.models.universityInfo import UniversityInfo
from backend_app.models.universityScholarship import UniversityScholarship
from backend_app.models.universitySemestersDates import UniversitySemestersDates
from backend_app.models.universityTaggedItem import UniversityTaggedItem
from backend_app.models.taggedItems import UniversityTaggedItem, CountryTaggedItem
from backend_app.models.userData import UserData
from backend_app.models.version import Version
from base_app.models import SiteInformation
......@@ -38,9 +34,7 @@ from base_app.models import SiteInformation
ALL_MODELS = [
SiteInformation,
Campus,
CampusTaggedItem,
City,
CityTaggedItem,
Country,
CountryDri,
CountryScholarship,
......@@ -55,7 +49,6 @@ ALL_MODELS = [
ExchangeFeedback,
RecommendationList,
Specialty,
Tag,
University,
UniversityDri,
UniversityInfo,
......
......@@ -5,6 +5,10 @@ class BackendAppConfig(AppConfig):
name = "backend_app"
def ready(self):
import backend_app.signals.squash_revisions # noqa:F401
import backend_app.signals.auto_creation # noqa:F401
import backend_app.signals.update_nb_version # noqa:F401
from backend_app.signals.auto_creation import enable_auto_create
from backend_app.signals.squash_revisions import enable_squash_revisions
from backend_app.signals.update_nb_version import enable_update_nb_version
enable_auto_create()
enable_squash_revisions()
enable_update_nb_version()
import reversion
from backend_app.load_data.loading_scripts.loadAdminUser import LoadAdminUser
from backend_app.load_data.loading_scripts.loadBaseUsers import LoadBaseUsers
from backend_app.load_data.loading_scripts.loadCountries import LoadCountries
from backend_app.load_data.loading_scripts.loadCurrencies import LoadCurrencies
from backend_app.load_data.loading_scripts.loadGroups import LoadGroups
......@@ -11,7 +11,6 @@ from backend_app.load_data.loading_scripts.loadRecommendationLists import (
from backend_app.load_data.loading_scripts.loadSiteInformation import (
LoadSiteInformation,
)
from backend_app.load_data.loading_scripts.loadTags import LoadTags
from backend_app.load_data.loading_scripts.loadUniversities import LoadUniversities
from backend_app.load_data.loading_scripts.loadUniversityEx import LoadUniversityEx
......@@ -23,11 +22,10 @@ def load_all():
with reversion.create_revision():
LoadGroups()
admin = LoadAdminUser().get()
admin = LoadBaseUsers().get_admin()
LoadCurrencies(admin).load()
LoadCountries(admin).load()
LoadUniversities(admin).load()
LoadTags(admin).load()
LoadLanguages().load()
LoadUniversityEx(admin).load()
LoadRecommendationLists(admin).load()
......
from base_app.models import User
import os
from base_app.models import User
class LoadAdminUser(object):
class LoadBaseUsers(object):
def __init__(self):
"""
Creating admin user by creating a user and setting is_staff is True
......@@ -22,5 +23,18 @@ class LoadAdminUser(object):
username=os.environ["DJANGO_ADMIN_USERNAME"]
)[0]
def get(self) -> User:
self.bot = User.objects.get_or_create(
username="#bot",
defaults=dict(
first_name="#bot",
last_name="",
email="bot@null.fr",
password=User.objects.make_random_password(30),
pseudo="bot",
allow_sharing_personal_info=True,
has_validated_cgu_rgpd=True,
),
)
def get_admin(self) -> User:
return self.admin
import datetime
from django.utils import timezone
from base_app.models import SiteInformation
from base_app.models import User
from .loadGeneric import LoadGeneric
......@@ -14,7 +16,7 @@ class LoadSiteInformation(LoadGeneric):
self.admin = admin
def load(self):
start = datetime.datetime.now()
start = timezone.now()
end = start + datetime.timedelta(days=5)
info = SiteInformation(
start=start,
......
import json
import os
from backend_app.models.tag import Tag
from base_app.models import User
from .loadGeneric import LoadGeneric
class LoadTags(LoadGeneric):
"""
Class to load the tags in the app.
"""
def __init__(self, admin: User):
self.admin = admin
def load(self):
tmp = os.path.join(os.path.realpath(__file__), "../../assets/tags.json")
tags_path = os.path.abspath(tmp)
with open(tags_path) as f:
tags = json.load(f)
for tag_name in tags:
t = Tag(name=tag_name)
t.save()
self.add_info_and_save(t, self.admin)
......@@ -8,12 +8,11 @@ from backend_app.models.currency import Currency
from backend_app.models.exchange import Exchange
from backend_app.models.exchangeFeedback import ExchangeFeedback
from backend_app.models.language import Language
from backend_app.models.tag import Tag
from backend_app.models.taggedItems import UniversityTaggedItem
from backend_app.models.university import University
from backend_app.models.universityDri import UniversityDri
from backend_app.models.universityInfo import UniversityInfo
from backend_app.models.universitySemestersDates import UniversitySemestersDates
from backend_app.models.universityTaggedItem import UniversityTaggedItem
from base_app.models import User
from .loadGeneric import LoadGeneric
......@@ -29,7 +28,6 @@ class LoadUniversityEx(LoadGeneric):
def load(self):
EPFL = University.objects.get(acronym="EPFL")
CHF = Currency.objects.get(pk="CHF")
ACCOMMODATION_TAG = Tag.objects.get(name="accommodation")
SWITZERLAND = Country.objects.get(pk="CH")
univ_dri_1 = UniversityDri(
......@@ -71,11 +69,7 @@ class LoadUniversityEx(LoadGeneric):
self.add_info_and_save(country_scholarship, self.admin)
univ_tag_1 = UniversityTaggedItem(
university=EPFL,
tag=ACCOMMODATION_TAG,
title="C'est compliqué de trouver un logement",
comment="Mon commentaire.",
importance_level="++",
university=EPFL, comment="C'est compliqué de trouver un logement"
)
self.add_info_and_save(univ_tag_1, self.admin)
......
# Generated by Django 2.1.7 on 2019-03-23 14:30
# Generated by Django 2.1.7 on 2019-06-26 21:10
import backend_app.fields
import backend_app.models.abstract.essentialModule
import backend_app.models.university
from django.conf import settings
import backend_app.validation.validators
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("contenttypes", "0002_remove_content_type_name"),
("base_app", "0001_initial"),
]
dependencies = []
operations = [
migrations.CreateModel(
......@@ -48,7 +42,15 @@ class Migration(migrations.Migration):
("nb_versions", models.PositiveIntegerField(default=0)),
("title", models.CharField(blank=True, default="", max_length=150)),
("comment", models.CharField(blank=True, default="", max_length=5000)),
("useful_links", backend_app.fields.JSONField(default=list)),
(
"useful_links",
backend_app.fields.JSONField(
default=list,
validators=[
backend_app.validation.validators.UsefulLinksValidator()
],
),
),
(
"importance_level",
models.CharField(
......@@ -87,58 +89,6 @@ class Migration(migrations.Migration):
),
],
),
migrations.CreateModel(
name="CampusTaggedItem",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("updated_on", models.DateTimeField(null=True)),
("moderated_on", models.DateTimeField(null=True)),
(
"obj_moderation_level",
models.SmallIntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(0),
backend_app.models.abstract.essentialModule.validate_obj_model_lv,
],
),
),
("has_pending_moderation", models.BooleanField(default=False)),
("nb_versions", models.PositiveIntegerField(default=0)),
("title", models.CharField(blank=True, default="", max_length=150)),
("comment", models.CharField(blank=True, default="", max_length=5000)),
("useful_links", backend_app.fields.JSONField(default=list)),
(
"importance_level",
models.CharField(
choices=[
("-", "normal"),
("+", "important"),
("++", "IMPORTANT"),
],
default="-",
max_length=2,
),
),
("custom_content", backend_app.fields.JSONField(default=dict)),
(
"campus",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="campus_tagged_items",
to="backend_app.Campus",
),
),
],
),
migrations.CreateModel(
name="City",
fields=[
......@@ -160,58 +110,6 @@ class Migration(migrations.Migration):
],
options={"abstract": False},
),
migrations.CreateModel(
name="CityTaggedItem",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("updated_on", models.DateTimeField(null=True)),
("moderated_on", models.DateTimeField(null=True)),
(
"obj_moderation_level",
models.SmallIntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(0),
backend_app.models.abstract.essentialModule.validate_obj_model_lv,
],
),
),
("has_pending_moderation", models.BooleanField(default=False)),
("nb_versions", models.PositiveIntegerField(default=0)),
("title", models.CharField(blank=True, default="", max_length=150)),
("comment", models.CharField(blank=True, default="", max_length=5000)),
("useful_links", backend_app.fields.JSONField(default=list)),
(
"importance_level",
models.CharField(
choices=[
("-", "normal"),
("+", "important"),
("++", "IMPORTANT"),
],
default="-",
max_length=2,
),
),
("custom_content", backend_app.fields.JSONField(default=dict)),
(
"city",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="city_tagged_items",
to="backend_app.City",
),
),
],
),
migrations.CreateModel(
name="Country",
fields=[
......@@ -273,7 +171,15 @@ class Migration(migrations.Migration):
("nb_versions", models.PositiveIntegerField(default=0)),
("title", models.CharField(blank=True, default="", max_length=150)),
("comment", models.CharField(blank=True, default="", max_length=5000)),
("useful_links", backend_app.fields.JSONField(default=list)),
(
"useful_links",
backend_app.fields.JSONField(
default=list,
validators=[
backend_app.validation.validators.UsefulLinksValidator()
],
),
),
(
"importance_level",
models.CharField(
......@@ -286,12 +192,6 @@ class Migration(migrations.Migration):
max_length=2,
),
),
(
"countries",
models.ManyToManyField(
related_name="country_dri", to="backend_app.Country"
),
),
],
options={"abstract": False},
),
......@@ -323,7 +223,15 @@ class Migration(migrations.Migration):
("nb_versions", models.PositiveIntegerField(default=0)),
("title", models.CharField(blank=True, default="", max_length=150)),
("comment", models.CharField(blank=True, default="", max_length=5000)),
("useful_links", backend_app.fields.JSONField(default=list)),
(
"useful_links",
backend_app.fields.JSONField(
default=list,
validators=[
backend_app.validation.validators.UsefulLinksValidator()
],
),
),
(
"importance_level",
models.CharField(
......@@ -375,12 +283,6 @@ class Migration(migrations.Migration):
validators=[django.core.validators.MinValueValidator(0)],
),
),
(
"countries",
models.ManyToManyField(
related_name="country_scholarships", to="backend_app.Country"
),
),
],
options={"abstract": False},
),
......@@ -410,31 +312,131 @@ class Migration(migrations.Migration):
),
("has_pending_moderation", models.BooleanField(default=False)),
("nb_versions", models.PositiveIntegerField(default=0)),
("title", models.CharField(blank=True, default="", max_length=150)),
("comment", models.CharField(blank=True, default="", max_length=5000)),
("useful_links", backend_app.fields.JSONField(default=list)),
(
"importance_level",
"tag",
models.CharField(
choices=[
("-", "normal"),
("+", "important"),
("++", "IMPORTANT"),
("immigration", "immigration"),
("administrative", "administrative"),
("culture", "culture"),
("tourism", "tourism"),
("transport", "transport"),
("other", "other"),
],
max_length=20,
),
),
("comment", models.CharField(blank=True, default="", max_length=5000)),
(
"useful_links",
backend_app.fields.JSONField(
default=list,
validators=[
backend_app.validation.validators.UsefulLinksValidator()
],
),
),
],
),
migrations.CreateModel(
name="Course",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("utc_exchange_id", models.IntegerField()),
("course_id", models.IntegerField()),
("code", models.CharField(max_length=10)),
(
"title",
models.CharField(blank=True, default="", max_length=200, null=True),
),
("link", models.URLField(blank=True, max_length=500, null=True)),
("nb_credit", models.PositiveIntegerField(default=0)),
("category", models.CharField(blank=True, max_length=5, null=True)),
("profile", models.CharField(blank=True, max_length=10, null=True)),
("tsh_profile", models.CharField(blank=True, max_length=21, null=True)),
(
"student_login",
models.CharField(blank=True, max_length=8, null=True),
),
],
options={"abstract": False},
),
migrations.CreateModel(
name="CourseFeedback",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("updated_on", models.DateTimeField(null=True)),
("moderated_on", models.DateTimeField(null=True)),
(
"obj_moderation_level",
models.SmallIntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(0),
backend_app.models.abstract.essentialModule.validate_obj_model_lv,
],
),
),
("has_pending_moderation", models.BooleanField(default=False)),
("comment", models.TextField(max_length=1500, null=True)),
(
"adequation",
models.IntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(-5),
django.core.validators.MaxValueValidator(5),
],
),
),
(
"would_recommend",
models.IntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(-5),
django.core.validators.MaxValueValidator(5),
],
),
),
(
"working_dose",
models.IntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(-5),
django.core.validators.MaxValueValidator(5),
],
default="-",
max_length=2,
),
),
("custom_content", backend_app.fields.JSONField(default=dict)),
(
"country",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="country_tagged_items",
to="backend_app.Country",
"following_ease",
models.IntegerField(
default=0,
validators=[
django.core.validators.MinValueValidator(-5),
django.core.validators.MaxValueValidator(5),
],
),
),
],
options={"abstract": False},
),
migrations.CreateModel(
name="Currency",
......@@ -468,6 +470,72 @@ class Migration(migrations.Migration):
],
options={"abstract": False},
),
migrations.CreateModel(
name="Exchange",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("utc_departure_id", models.IntegerField()),
("year", models.PositiveIntegerField(default=2018)),
(
"semester",
models.CharField(
choices=[("a", "autumn"), ("p", "spring")],
default="a",
max_length=5,
),
),
("duration", models.PositiveIntegerField()),
("dual_degree", models.BooleanField()),
("master_obtained", models.BooleanField()),