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

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-24 20:23
import backend_app.fields
import backend_app.models.abstract.essentialModule
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("backend_app", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="Course",
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)),
("course_id", models.IntegerField()),
("code", models.CharField(max_length=10)),
(
"title",
models.CharField(blank=True, default="", max_length=200, null=True),
),
("link", models.CharField(blank=True, max_length=500, null=True)),
("nb_credit", models.PositiveIntegerField()),
(
"description",
models.TextField(blank=True, max_length=2000, 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),
),
(
"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,
),
),
],
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(
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
]
),
),
(
"work_dose",
models.IntegerField(
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
]
),
),
(
"language_following_ease",
models.IntegerField(
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
]
),
),
("is_psf_credit", models.BooleanField()),
],
options={"abstract": False},
),
migrations.CreateModel(
name="Exchange",
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)),
("utc_departure_id", models.IntegerField()),
("year", models.PositiveIntegerField(default=2018)),
(
"semester",
models.CharField(
choices=[("a", "autumn"), ("p", "spring")],
default="a",
max_length=2,
),
),
("duration", models.PositiveIntegerField()),
("dual_degree", models.BooleanField()),
("master_obtained", models.BooleanField()),
("student_major", models.CharField(max_length=40)),
("student_minor", models.CharField(max_length=40)),
("student_option", models.CharField(max_length=40)),
("utc_allow_courses", models.BooleanField()),
("utc_allow_login", models.BooleanField()),
("is_anonymous", models.BooleanField()),
("courses", backend_app.fields.JSONField(null=True)),
(
"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,
),
),
(
"user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
(
"utc_univ_id",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="backend_app.University",
),
),
],
options={"abstract": False},
),
migrations.CreateModel(
name="ExchangeFeedback",
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)),
("general_comment", models.TextField(max_length=1500, null=True)),
(
"academical_level_appreciation",
models.IntegerField(
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
]
),
),
(
"foreign_student_welcome",
models.PositiveIntegerField(
validators=[django.core.validators.MaxValueValidator(10)]
),
),
(
"cultural_interest",
models.PositiveIntegerField(
validators=[django.core.validators.MaxValueValidator(10)]
),
),
(
"departure",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to="backend_app.Exchange",
),
),
(
"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,
),
),
],
options={"abstract": False},
),
migrations.RemoveField(model_name="previousdeparture", name="moderated_by"),
migrations.RemoveField(model_name="previousdeparture", name="specialty"),
migrations.RemoveField(model_name="previousdeparture", name="university"),
migrations.RemoveField(model_name="previousdeparture", name="updated_by"),
migrations.RemoveField(model_name="previousdeparture", name="user"),
migrations.RemoveField(
model_name="previousdeparturefeedback", name="departure"
),
migrations.RemoveField(
model_name="previousdeparturefeedback", name="moderated_by"
),
migrations.RemoveField(model_name="previousdeparturefeedback", name="owner"),
migrations.RemoveField(
model_name="previousdeparturefeedback", name="updated_by"
),
migrations.DeleteModel(name="PreviousDeparture"),
migrations.DeleteModel(name="PreviousDepartureFeedback"),
migrations.AddField(
model_name="coursefeedback",
name="departure",
field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to="backend_app.Exchange"
),
),
migrations.AddField(
model_name="coursefeedback",
name="moderated_by",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AddField(
model_name="coursefeedback",
name="updated_by",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AddField(
model_name="course",
name="utc_exchange_id",
field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to="backend_app.Exchange"
),
),
]
# Generated by Django 2.1.7 on 2019-04-05 19:31
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("backend_app", "0001_initial")]
operations = [
migrations.RemoveField(model_name="userdata", name="contact_info"),
migrations.RemoveField(model_name="userdata", name="contact_info_is_public"),
]
# Generated by Django 2.1.7 on 2019-04-17 19:25
import backend_app.validation.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("backend_app", "0001_squashed_0006_auto_20190416_2227")]
operations = [
migrations.RemoveField(model_name="tag", name="schema"),
migrations.AlterField(
model_name="tag",