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-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",
name="name",
field=models.CharField(
max_length=100,
unique=True,
validators=[backend_app.validation.validators.TagNameValidator()],
),
),
]
# Generated by Django 2.1.7 on 2019-04-17 19:35
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("backend_app", "0002_auto_20190417_2125")]
operations = [
migrations.RenameField(
model_name="campustaggeditem", old_name="custom_content", new_name="content"
),
migrations.RenameField(
model_name="citytaggeditem", old_name="custom_content", new_name="content"
),
migrations.RenameField(
model_name="countrytaggeditem",
old_name="custom_content",
new_name="content",
),
migrations.RenameField(
model_name="universitytaggeditem",
old_name="custom_content",
new_name="content",
),
]
# Generated by Django 2.1.7 on 2019-04-06 14:36
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("backend_app", "0002_auto_20190324_2123"),
("backend_app", "0002_auto_20190405_2131"),
]
operations = []
# Generated by Django 2.1.7 on 2019-04-07 08:10
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [("backend_app", "0003_merge_20190406_1636")]
operations = [
migrations.RenameField(
model_name="coursefeedback", old_name="work_dose", new_name="working_dose"
),
migrations.RemoveField(model_name="course", name="description"),
migrations.RemoveField(model_name="course", name="has_pending_moderation"),
migrations.RemoveField(model_name="course", name="moderated_by"),
migrations.RemoveField(model_name="course", name="moderated_on"),
migrations.RemoveField(model_name="course", name="obj_moderation_level"),
migrations.RemoveField(model_name="course", name="updated_by"),
migrations.RemoveField(model_name="course", name="updated_on"),
migrations.RemoveField(model_name="coursefeedback", name="departure"),
migrations.RemoveField(model_name="exchange", name="has_pending_moderation"),
migrations.RemoveField(model_name="exchange", name="is_anonymous"),
migrations.RemoveField(model_name="exchange", name="moderated_by"),
migrations.RemoveField(model_name="exchange", name="moderated_on"),
migrations.RemoveField(model_name="exchange", name="obj_moderation_level"),
migrations.RemoveField(model_name="exchange", name="updated_by"),
migrations.RemoveField(model_name="exchange", name="updated_on"),
migrations.RemoveField(model_name="exchangefeedback", name="departure"),
migrations.RemoveField(model_name="exchangefeedback", name="id"),
migrations.AddField(
model_name="course",
name="category",
field=models.CharField(blank=True, max_length=5, null=True),
),
migrations.AddField(
model_name="coursefeedback",
name="course",
field=models.ForeignKey(
default=0,
on_delete=django.db.models.deletion.CASCADE,
to="backend_app.Course",
),
),
migrations.AddField(
model_name="coursefeedback",
name="university",
field=models.ForeignKey(
default=0,
on_delete=django.db.models.deletion.PROTECT,
to="backend_app.University",
),
),
migrations.AddField(
model_name="exchangefeedback",
name="exchange",
field=models.OneToOneField(
default=0,
on_delete=django.db.models.deletion.CASCADE,
primary_key=True,
related_name="feedbacks",
serialize=False,
to="backend_app.Exchange",
),
),
migrations.AddField(
model_name="exchangefeedback",
name="university",
field=models.ForeignKey(
default=0,
on_delete=django.db.models.deletion.PROTECT,
to="backend_app.University",
),
),
migrations.AlterField(
model_name="exchange",
name="semester",
field=models.CharField(
choices=[("a", "autumn"), ("p", "spring")], default="a", max_length=5
),
),
migrations.AlterField(
model_name="exchange",
name="student_major",
field=models.CharField(max_length=20),
),
migrations.AlterField(
model_name="exchange",
name="student_minor",
field=models.CharField(max_length=7),
),
migrations.AlterField(
model_name="exchange",
name="student_option",
field=models.CharField(max_length=7),
),
migrations.AlterField(
model_name="exchange",
name="user",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to=settings.AUTH_USER_MODEL,
),
),
]
# Generated by Django 2.1.7 on 2019-04-21 09:14
import backend_app.fields
import backend_app.utils
import backend_app.validation.validators
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("backend_app", "0003_auto_20190417_2135")]
operations = [
migrations.RemoveField(model_name="userdata", name="config"),
migrations.RemoveField(model_name="userdata", name="other_data"),
migrations.AddField(
model_name="userdata",
name="theme",
field=backend_app.fields.JSONField(
default=backend_app.utils.get_default_theme_settings,
validators=[backend_app.validation.validators.ThemeValidator()],
),
),
]
# Generated by Django 2.1.7 on 2019-04-16 20:00
import backend_app.fields
import backend_app.validation.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("backend_app", "0004_auto_20190407_1010")]
operations = [
migrations.AlterField(
model_name="campus",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="campustaggeditem",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="citytaggeditem",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="countrydri",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="countryscholarship",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="countrytaggeditem",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="university",
name="logo",
field=models.URLField(
blank=True,
default="",
validators=[
backend_app.validation.validators.PathExtensionValidator(
["jpg", "jpeg", "png", "svg"]
)
],
),
),
migrations.AlterField(
model_name="universitydri",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="universityinfo",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="universityscholarship",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="universitysemestersdates",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
migrations.AlterField(
model_name="universitytaggeditem",
name="useful_links",
field=backend_app.fields.JSONField(
default=list,
validators=[backend_app.validation.validators.UsefulLinksValidator()],
),
),
]
# Generated by Django 2.1.7 on 2019-04-23 18:27
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("backend_app", "0004_auto_20190421_1114")]
operations = [
migrations.AlterUniqueTogether(name="recommendation", unique_together=set()),
migrations.RemoveField(model_name="recommendation", name="moderated_by"),
migrations.RemoveField(model_name="recommendation", name="owner"),
migrations.RemoveField(model_name="recommendation", name="parent_list"),
migrations.RemoveField(model_name="recommendation", name="specialty"),
migrations.RemoveField(model_name="recommendation", name="university"),
migrations.RemoveField(model_name="recommendation", name="updated_by"),
migrations.AlterUniqueTogether(
name="recommendationlist", unique_together=set()
),
migrations.RemoveField(model_name="recommendationlist", name="moderated_by"),
migrations.RemoveField(model_name="recommendationlist", name="owner"),
migrations.RemoveField(model_name="recommendationlist", name="updated_by"),
migrations.DeleteModel(name="Recommendation"),
migrations.DeleteModel(name="RecommendationList"),
]
# Generated by Django 2.1.7 on 2019-04-16 20:27
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("backend_app", "0005_auto_20190416_2200")]
operations = [
migrations.RenameField(model_name="tag", old_name="config", new_name="schema")
]
# Generated by Django 2.1.7 on 2019-05-04 15:52
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [("backend_app", "0005_auto_20190423_2027")]
operations = [
migrations.RemoveField(model_name="coursefeedback", name="is_psf_credit"),
migrations.RemoveField(model_name="coursefeedback", name="university"),
migrations.RemoveField(model_name="exchange", name="courses"),
migrations.AddField(
model_name="course",
name="exchange",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="exchange_courses",
to="backend_app.Exchange",
),
),
migrations.AlterField(
model_name="course",
name="link",
field=models.URLField(blank=True, max_length=500, null=True),
),
migrations.AlterField(
model_name="course",
name="nb_credit",
field=models.PositiveIntegerField(default=0),
),
migrations.AlterField(
model_name="course", name="utc_exchange_id", field=models.IntegerField()
),
migrations.AlterField(
model_name="coursefeedback",
name="adequation",
field=models.IntegerField(
default=0,
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
],
),
),
migrations.AlterField(
model_name="coursefeedback",
name="course",
field=models.OneToOneField(
default=0,
on_delete=django.db.models.deletion.CASCADE,
related_name="course_feedback",
to="backend_app.Course",
),
),
migrations.AlterField(
model_name="coursefeedback",
name="language_following_ease",
field=models.IntegerField(
default=0,
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
],
),
),
migrations.AlterField(
model_name="coursefeedback",
name="working_dose",
field=models.IntegerField(
default=0,
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(-5),
],
),
),
]
# Generated by Django 2.1.7 on 2019-05-08 08:39
import backend_app.validation.validators
from django.conf import settings
from django.db import migrations, models