Commit 04c716cf authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'update_back_linting' into 'master'

Update back linting and fix documentation job failing on master

Closes #44

See merge request !44
parents 3a3bbbd2 955238be
Pipeline #34792 passed with stages
in 2 minutes and 57 seconds
from django.db import models
from backend_app.models.university import University
from backend_app.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend_app.models.abstract.basic_module import (
BasicModule,
BasicModuleSerializer,
BasicModuleViewSet,
)
from backend_app.utils import get_model_config, get_viewset_permissions
class UniversityDri(BasicModule):
model_config = get_model_config("UniversityDri")
universities = models.ManyToManyField(
University, related_name="university_dri")
universities = models.ManyToManyField(University, related_name="university_dri")
@classmethod
def get_serializer(cls):
......@@ -19,7 +22,7 @@ class UniversityDriSerializer(BasicModuleSerializer):
class Meta:
model = UniversityDri
fields = '__all__'
fields = "__all__"
class UniversityDriViewSet(BasicModuleViewSet):
......@@ -30,5 +33,5 @@ class UniversityDriViewSet(BasicModuleViewSet):
BYPASS_DICT_MODE = True
def extend_queryset(self):
univ_id = self.kwargs['univ_id']
univ_id = self.kwargs["univ_id"]
return self.my_model_queryset.filter(universities__pk=univ_id).distinct()
from django.db import models
from backend_app.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend_app.models.abstract.basic_module import (
BasicModule,
BasicModuleSerializer,
BasicModuleViewSet,
)
from backend_app.models.university import University
from backend_app.models.currency import Currency
from django.core.validators import MinValueValidator
......@@ -10,24 +14,22 @@ class UniversityInfo(BasicModule):
model_config = get_model_config("UniversityInfo")
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_info', primary_key=True, null=False)
University,
on_delete=models.CASCADE,
related_name="university_info",
primary_key=True,
null=False,
)
cost_exchange = models.DecimalField(
decimal_places=2,
max_digits=20,
validators=[MinValueValidator(0)],
null=True
decimal_places=2, max_digits=20, validators=[MinValueValidator(0)], null=True
)
cost_double_degree = models.DecimalField(
decimal_places=2,
max_digits=20,
validators=[MinValueValidator(0)],
null=True
decimal_places=2, max_digits=20, validators=[MinValueValidator(0)], null=True
)
costs_currency = models.ForeignKey(
Currency, on_delete=models.PROTECT, null=True)
costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT, null=True)
@classmethod
def get_serializer(cls):
......@@ -35,10 +37,9 @@ class UniversityInfo(BasicModule):
class UniversityInfoSerializer(BasicModuleSerializer):
class Meta:
model = UniversityInfo
fields = '__all__'
fields = "__all__"
class UniversityInfoViewSet(BasicModuleViewSet):
......
from django.db import models
from backend_app.models.university import University
from backend_app.models.abstract.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend_app.models.abstract.scholarship import (
Scholarship,
ScholarshipSerializer,
ScholarshipViewSet,
)
from backend_app.utils import get_model_config, get_viewset_permissions
class UniversityScholarship(Scholarship):
model_config = get_model_config("UniversityScholarship")
universities = models.ManyToManyField(
University, related_name="university_scholarships")
University, related_name="university_scholarships"
)
@classmethod
def get_serializer(cls):
......@@ -19,17 +24,16 @@ class UniversityScholarshipSerializer(ScholarshipSerializer):
class Meta:
model = UniversityScholarship
fields = '__all__'
fields = "__all__"
class UniversityScholarshipViewSet(ScholarshipViewSet):
permission_classes = get_viewset_permissions(
"UniversityScholarshipViewSet")
permission_classes = get_viewset_permissions("UniversityScholarshipViewSet")
queryset = UniversityScholarship.objects.all() # pylint: disable=E1101
serializer_class = UniversityScholarshipSerializer
BYPASS_DICT_MODE = True
def extend_queryset(self):
univ_id = self.kwargs['univ_id']
univ_id = self.kwargs["univ_id"]
return self.my_model_queryset.filter(universities__pk=univ_id).distinct()
from django.db import models
from backend_app.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend_app.models.abstract.basic_module import (
BasicModule,
BasicModuleSerializer,
BasicModuleViewSet,
)
from backend_app.models.university import University
from rest_framework import serializers
from backend_app.utils import get_model_config, get_viewset_permissions
......@@ -7,14 +11,20 @@ from backend_app.utils import get_model_config, get_viewset_permissions
def semester_error(semester_name):
raise serializers.ValidationError(
"Inconsistent {} semester dates".format(semester_name))
"Inconsistent {} semester dates".format(semester_name)
)
class UniversitySemestersDates(BasicModule):
model_config = get_model_config("UniversitySemestersDates")
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_semesters_dates', primary_key=True, null=False)
University,
on_delete=models.CASCADE,
related_name="university_semesters_dates",
primary_key=True,
null=False,
)
spring_begin = models.DateField(null=True, blank=True)
spring_end = models.DateField(null=True, blank=True)
......@@ -27,34 +37,32 @@ class UniversitySemestersDates(BasicModule):
class UniversitySemestersDatesSerializer(BasicModuleSerializer):
def my_validate(self, attrs):
attrs = super(UniversitySemestersDatesSerializer,
self).my_validate(attrs)
attrs = super(UniversitySemestersDatesSerializer, self).my_validate(attrs)
s_b, s_e = attrs['spring_begin'], attrs['spring_end']
a_b, a_e = attrs['autumn_begin'], attrs['autumn_end']
s_b, s_e = attrs["spring_begin"], attrs["spring_end"]
a_b, a_e = attrs["autumn_begin"], attrs["autumn_end"]
def test(begin, end, name):
ok = (begin is None and end is None) or (
begin is not None and end is not None)
begin is not None and end is not None
)
if not ok:
semester_error(name)
if begin is not None and (begin > end):
semester_error(name)
test(s_b, s_e, 'spring')
test(a_b, a_e, 'autumn')
test(s_b, s_e, "spring")
test(a_b, a_e, "autumn")
return attrs
class Meta:
model = UniversitySemestersDates
fields = '__all__'
fields = "__all__"
class UniversitySemestersDatesViewSet(BasicModuleViewSet):
permission_classes = get_viewset_permissions(
"UniversitySemestersDatesViewSet")
permission_classes = get_viewset_permissions("UniversitySemestersDatesViewSet")
queryset = UniversitySemestersDates.objects.all() # pylint: disable=E1101
serializer_class = UniversitySemestersDatesSerializer
from django.db import models
from backend_app.models.abstract.taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend_app.models.abstract.taggedItem import (
TaggedItem,
TaggedItemSerializer,
TaggedItemViewSet,
)
from backend_app.models.university import University
from backend_app.utils import get_model_config, get_viewset_permissions
......@@ -7,20 +11,21 @@ from backend_app.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem):
model_config = get_model_config("UniversityTaggedItem")
university = models.ForeignKey(
University, on_delete=models.PROTECT, related_name='university_tagged_items')
University, on_delete=models.PROTECT, related_name="university_tagged_items"
)
@classmethod
def get_serializer(cls):
return UniversityTaggedItemSerializer
class Meta:
unique_together = ('university', 'tag', 'importance_level')
unique_together = ("university", "tag", "importance_level")
class UniversityTaggedItemSerializer(TaggedItemSerializer):
class Meta:
model = UniversityTaggedItem
fields = '__all__'
fields = "__all__"
class UniversityTaggedItemViewSet(TaggedItemViewSet):
......@@ -31,5 +36,5 @@ class UniversityTaggedItemViewSet(TaggedItemViewSet):
BYPASS_DICT_MODE = True
def extend_queryset(self):
univ_id = self.kwargs['univ_id']
univ_id = self.kwargs["univ_id"]
return self.my_model_queryset.filter(university__pk=univ_id).distinct()
from .userRestrictedModule import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet # noqa: F401
from .previousDeparture import PreviousDeparture, PreviousDepartureViewSet # noqa: F401
from .previousDepartureFeedback import PreviousDepartureFeedback, PreviousDepartureFeedbackViewSet # noqa: F401
from .recommendationList import RecommendationList, RecommendationListSerializer, RecommendationListViewSet # noqa: F401
from .recommendation import Recommendation, RecommendationSerializer, RecommendationViewSet # noqa: F401
from .userData import UserData, UserDataViewSet # noqa: F401
from .userRestrictedModule import (
UserRestrictedModule,
UserRestrictedModuleSerializer,
UserRestrictedModuleViewSet,
)
from .previousDeparture import PreviousDeparture, PreviousDepartureViewSet
from .previousDepartureFeedback import (
PreviousDepartureFeedback,
PreviousDepartureFeedbackViewSet,
)
from .recommendationList import (
RecommendationList,
RecommendationListSerializer,
RecommendationListViewSet,
)
from .recommendation import (
Recommendation,
RecommendationSerializer,
RecommendationViewSet,
)
from .userData import UserData, UserDataViewSet
__all__ = [
"UserRestrictedModule",
"UserRestrictedModuleSerializer",
"UserRestrictedModuleViewSet",
"PreviousDeparture",
"PreviousDepartureViewSet",
"PreviousDepartureFeedback",
"PreviousDepartureFeedbackViewSet",
"RecommendationList",
"RecommendationListSerializer",
"RecommendationListViewSet",
"Recommendation",
"RecommendationSerializer",
"RecommendationViewSet",
"UserData",
"UserDataViewSet",
]
......@@ -4,7 +4,11 @@ from backend_app.models.other_core.semester import Semester
from backend_app.models.university import University
from django.contrib.auth.models import User
from backend_app.fields import JSONField
from backend_app.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend_app.models.abstract.my_model import (
MyModel,
MyModelSerializer,
MyModelViewSet,
)
from backend_app.utils import get_model_config, get_viewset_permissions
......@@ -25,10 +29,9 @@ class PreviousDeparture(MyModel):
class PreviousDepartureSerializer(MyModelSerializer):
class Meta:
model = PreviousDeparture
fields = '__all__'
fields = "__all__"
class PreviousDepartureViewSet(MyModelViewSet):
......
from django.db import models
from django.core.validators import MaxValueValidator
from backend_app.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
from backend_app.models.user import (
UserRestrictedModule,
UserRestrictedModuleSerializer,
UserRestrictedModuleViewSet,
)
from backend_app.models.user import PreviousDeparture
from backend_app.fields import JSONField
from backend_app.utils import get_model_config, get_viewset_permissions
......@@ -9,28 +13,23 @@ from backend_app.utils import get_model_config, get_viewset_permissions
class PreviousDepartureFeedback(UserRestrictedModule):
model_config = get_model_config("Country")
departure = models.OneToOneField(
PreviousDeparture, on_delete=models.CASCADE)
departure = models.OneToOneField(PreviousDeparture, on_delete=models.CASCADE)
courses_and_courses_feedback = JSONField(default=dict)
adequation_comment = models.CharField(default='', blank=True, max_length=5000)
integration_comment = models.CharField(default='', blank=True, max_length=5000)
adequation_grate = models.PositiveIntegerField(
validators=[MaxValueValidator(20)])
integration_grade = models.PositiveIntegerField(
validators=[MaxValueValidator(20)])
adequation_comment = models.CharField(default="", blank=True, max_length=5000)
integration_comment = models.CharField(default="", blank=True, max_length=5000)
adequation_grate = models.PositiveIntegerField(validators=[MaxValueValidator(20)])
integration_grade = models.PositiveIntegerField(validators=[MaxValueValidator(20)])
# TODO check on save that courses are coherent with Previous Departure
class PreviousDepartureFeedbackSerializer(UserRestrictedModuleSerializer):
class Meta:
model = PreviousDepartureFeedback
fields = '__all__'
fields = "__all__"
class PreviousDepartureFeedbackViewSet(UserRestrictedModuleViewSet):
permission_classes = get_viewset_permissions(
"PreviousDepartureFeedbackViewSet")
permission_classes = get_viewset_permissions("PreviousDepartureFeedbackViewSet")
queryset = PreviousDepartureFeedback.objects.all() # pylint: disable=E1101
serializer_class = PreviousDepartureFeedbackSerializer
......@@ -2,7 +2,11 @@ from django.db import models
from django.core.validators import MaxValueValidator
from backend_app.models.university import University
from backend_app.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
from backend_app.models.user import (
UserRestrictedModule,
UserRestrictedModuleSerializer,
UserRestrictedModuleViewSet,
)
from backend_app.models.other_core import Specialty
from backend_app.models.user import RecommendationList
......@@ -13,22 +17,22 @@ class Recommendation(UserRestrictedModule):
model_config = get_model_config("Recommendation")
university = models.ForeignKey(University, on_delete=models.PROTECT)
parent_list = models.ForeignKey(
RecommendationList, on_delete=models.PROTECT, related_name='recommendations')
RecommendationList, on_delete=models.PROTECT, related_name="recommendations"
)
specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT)
order_in_list = models.PositiveIntegerField()
comment = models.CharField(default='', blank=True, max_length=5000)
grade = models.PositiveIntegerField(
null=True, validators=[MaxValueValidator(20)])
comment = models.CharField(default="", blank=True, max_length=5000)
grade = models.PositiveIntegerField(null=True, validators=[MaxValueValidator(20)])
class Meta:
unique_together = ('order_in_list', 'parent_list')
unique_together = ("order_in_list", "parent_list")
class RecommendationSerializer(UserRestrictedModuleSerializer):
class Meta:
model = Recommendation
fields = '__all__'
fields = "__all__"
class RecommendationViewSet(UserRestrictedModuleViewSet):
......
from django.db import models
from backend_app.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
from backend_app.models.user import (
UserRestrictedModule,
UserRestrictedModuleSerializer,
UserRestrictedModuleViewSet,
)
from backend_app.utils import get_model_config, get_viewset_permissions
......@@ -9,14 +13,13 @@ class RecommendationList(UserRestrictedModule):
title = models.CharField(max_length=200)
class Meta:
unique_together = ('title', 'owner')
unique_together = ("title", "owner")
class RecommendationListSerializer(UserRestrictedModuleSerializer):
class Meta:
model = RecommendationList
fields = '__all__'
fields = "__all__"
class RecommendationListViewSet(UserRestrictedModuleViewSet):
......
......@@ -2,22 +2,26 @@ from django.db import models
from rest_framework import serializers
from backend_app.models.university import University
from backend_app.fields import JSONField
from backend_app.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend_app.models.abstract.my_model import (
MyModel,
MyModelSerializer,
MyModelViewSet,
)
from django.contrib.auth.models import User
from backend_app.utils import get_viewset_permissions, get_model_config, get_user_level
from backend_app.permissions.__list_user_post_permission import list_user_post_permission
from backend_app.permissions.__list_user_post_permission import (
list_user_post_permission,
)
class UserData(MyModel):
model_config = get_model_config("UserData")
owner = models.OneToOneField(
User, on_delete=models.CASCADE, primary_key=True)
owner = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
contact_info = JSONField(default=dict)
contact_info_is_public = models.BooleanField(default=False)
config = JSONField(default=dict)
black_list = models.ManyToManyField(
University, related_name='+', blank=True)
black_list = models.ManyToManyField(University, related_name="+", blank=True)
other_data = JSONField(default=dict)
......@@ -33,7 +37,7 @@ class UserDataSerializer(MyModelSerializer):
return list_user_post_permission(obj.owner)
def my_pre_save(self):
self.override_validated_data({'owner': self.user})
self.override_validated_data({"owner": self.user})
# we try to recover the correct instance
query = UserData.objects.filter(owner=self.user)
......@@ -42,7 +46,7 @@ class UserDataSerializer(MyModelSerializer):
class Meta:
model = UserData
fields = '__all__'
fields = "__all__"
class UserDataViewSet(MyModelViewSet):
......@@ -52,7 +56,10 @@ class UserDataViewSet(MyModelViewSet):
def get_queryset(self):
def get_for_querier():
return UserData.objects.filter(owner=self.request.user) # pylint: disable=E1101
return UserData.objects.filter(
owner=self.request.user
) # pylint: disable=E1101
queryset = get_for_querier()
if len(queryset) == 0:
UserData.objects.update_or_create(owner=self.request.user)
......
from django.db import models
from rest_framework import serializers
from django.contrib.auth.models import User
from backend_app.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend_app.models.abstract.my_model import (
MyModel,
MyModelSerializer,
MyModelViewSet,
)
class UserRestrictedModule(MyModel):
"""
TODO move to abstract folder ?
"""
# RGPD made easy with CASCADE
owner = models.ForeignKey(User, on_delete=models.CASCADE)
......@@ -23,12 +28,12 @@ class UserRestrictedModule(MyModel):
class UserRestrictedModuleSerializer(MyModelSerializer):
owner = serializers.HiddenField(
default=serializers.CurrentUserDefault(),
default=serializers.CurrentUserDefault()
) # TODO check that this works
class Meta:
model = UserRestrictedModule
fields = '__all__'
fields = "__all__"
class UserRestrictedModuleViewSet(MyModelViewSet):
......
from .noDeleteIfNotStaff import NoDeleteIfNotStaff # noqa: F401
from .isOwner import IsOwner # noqa: F401
from .noDelete import NoDelete # noqa: F401
from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401
from .readOnly import ReadOnly # noqa: F401
from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401
from .isDriOrNoPost import IsDriOrNoPost # noqa: F401
from .noPostIfNotStaff import NoPostIfNotStaff # noqa: F401
from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS # noqa: F401
from .__is_moderation_required import is_moderation_required # noqa: F401
from .noDeleteIfNotStaff import NoDeleteIfNotStaff
from .isOwner import IsOwner
from .noDelete import NoDelete
from .isStaffOrReadOnly import IsStaffOrReadOnly
from .readOnly import ReadOnly
from .isDriOrReadOnly import IsDriOrReadOnly
from .isDriOrNoPost import IsDriOrNoPost
from .noPostIfNotStaff import NoPostIfNotStaff
from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS
from .__is_moderation_required import is_moderation_required
__all__ = [
"NoDeleteIfNotStaff",
"IsOwner",
"NoDelete",
"IsStaffOrReadOnly",
"ReadOnly",
"IsDriOrReadOnly",
"IsDriOrNoPost",
"NoPostIfNotStaff",
"DEFAULT_VIEWSET_PERMISSIONS",
"is_moderation_required",
]
......@@ -12,13 +12,14 @@ from shared import OBJ_MODERATION_PERMISSIONS
######################################
######################################
def is_moderation_required(model_config, obj_in_db, user, user_level=None):
model_moderation_level = model_config['moderation_level']
model_moderation_level = model_config["moderation_level"]
if user_level is None:
user_level = get_user_level(user)