Commit 7a7776d9 authored by Florent Chehab's avatar Florent Chehab

back ready

parent de3c1897
......@@ -33,8 +33,10 @@ from backend_app.models.universitySemestersDates import UniversitySemestersDates
from backend_app.models.universityTaggedItem import UniversityTaggedItem
from backend_app.models.userData import UserData
from backend_app.models.version import Version
from base_app.models import SiteInformation
ALL_MODELS = [
SiteInformation,
Campus,
CampusTaggedItem,
City,
......
......@@ -5,12 +5,15 @@ 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
from backend_app.load_data.loading_scripts.loadLanguages import LoadLanguages
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
from backend_app.load_data.loading_scripts.loadRecommendationLists import (
LoadRecommendationLists,
)
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
def load_all():
......@@ -28,3 +31,4 @@ def load_all():
LoadLanguages().load()
LoadUniversityEx(admin).load()
LoadRecommendationLists(admin).load()
LoadSiteInformation(admin).load()
import datetime
from base_app.models import SiteInformation
from base_app.models import User
from .loadGeneric import LoadGeneric
class LoadSiteInformation(LoadGeneric):
"""
Load currencies in the app
"""
def __init__(self, admin: User):
self.admin = admin
def load(self):
start = datetime.datetime.now()
end = start + datetime.timedelta(days=5)
info = SiteInformation(
start=start,
end=end,
variant="success",
message="Le site vient d'être créé !",
)
self.add_info_and_save(info, self.admin)
......@@ -52,7 +52,7 @@ from backend_app.serializers import (
CourseSerializer,
)
from backend_app.settings.defaults import OBJ_MODERATION_PERMISSIONS
from base_app.models import UserViewset, User
from base_app.models import UserViewset, User, SiteInformationViewSet
class CourseViewSet(BaseModelViewSet):
......@@ -108,6 +108,7 @@ class ExchangeViewSet(BaseModelViewSet):
ALL_API_VIEWSETS = [
SiteInformationViewSet,
UserViewset,
CampusViewSet,
MainCampusViewSet,
......
# Generated by Django 2.1.7 on 2019-06-23 15:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("base_app", "0003_auto_20190616_1754")]
operations = [
migrations.CreateModel(
name="SiteInformation",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("start", models.DateTimeField()),
("end", models.DateTimeField(null=True)),
("message", models.TextField(max_length=500)),
(
"variant",
models.CharField(
choices=[
("info", "info"),
("success", "success"),
("warning", "warning"),
("error", "error"),
],
default="info",
max_length=10,
),
),
],
options={"abstract": False},
)
]
from datetime import datetime
from typing import List
from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q
from django.utils.functional import cached_property
from rest_framework.response import Response
from backend_app.models.abstract.base import BaseModelSerializer
from backend_app.models.abstract.base import BaseModelSerializer, BaseModel
from backend_app.models.abstract.base import BaseModelViewSet
from backend_app.permissions.app_permissions import IsOwner, ReadOnly
from backend_app.utils import get_user_level, OBJ_MODERATION_PERMISSIONS
......@@ -122,3 +124,51 @@ class UserViewset(BaseModelViewSet):
permission_classes = (IsOwner | ReadOnly,)
serializer_class = UserSerializer
end_point_route = "users"
SITE_INFORMATION_VARIANTS = (
("info", "info"),
("success", "success"),
("warning", "warning"),
("error", "error"),
)
class SiteInformation(BaseModel):
start = models.DateTimeField(null=False)
end = models.DateTimeField(null=True)
message = models.TextField(max_length=500)
variant = models.CharField(
max_length=10,
choices=SITE_INFORMATION_VARIANTS,
default="info",
null=False,
blank=False,
)
class SiteInformationSerializer(BaseModelSerializer):
class Meta:
model = SiteInformation
fields = BaseModelSerializer.Meta.fields + (
"start",
"end",
"message",
"variant",
)
class SiteInformationViewSet(BaseModelViewSet):
permission_classes = (ReadOnly,)
serializer_class = SiteInformationSerializer
end_point_route = "information"
def get_queryset(self):
get = self.request.GET
if "now" in get.keys():
now = datetime.now()
return SiteInformation.objects.filter(
Q(start__lte=now) & (Q(end__isnull=True) | Q(end__gte=now))
)
else:
return SiteInformation.objects.all()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment