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 django.db import models
from backend_app.models.university import University 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 from backend_app.utils import get_model_config, get_viewset_permissions
class UniversityDri(BasicModule): class UniversityDri(BasicModule):
model_config = get_model_config("UniversityDri") model_config = get_model_config("UniversityDri")
universities = models.ManyToManyField( universities = models.ManyToManyField(University, related_name="university_dri")
University, related_name="university_dri")
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -19,7 +22,7 @@ class UniversityDriSerializer(BasicModuleSerializer): ...@@ -19,7 +22,7 @@ class UniversityDriSerializer(BasicModuleSerializer):
class Meta: class Meta:
model = UniversityDri model = UniversityDri
fields = '__all__' fields = "__all__"
class UniversityDriViewSet(BasicModuleViewSet): class UniversityDriViewSet(BasicModuleViewSet):
...@@ -30,5 +33,5 @@ class UniversityDriViewSet(BasicModuleViewSet): ...@@ -30,5 +33,5 @@ class UniversityDriViewSet(BasicModuleViewSet):
BYPASS_DICT_MODE = True BYPASS_DICT_MODE = True
def extend_queryset(self): 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() return self.my_model_queryset.filter(universities__pk=univ_id).distinct()
from django.db import models 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.university import University
from backend_app.models.currency import Currency from backend_app.models.currency import Currency
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
...@@ -10,24 +14,22 @@ class UniversityInfo(BasicModule): ...@@ -10,24 +14,22 @@ class UniversityInfo(BasicModule):
model_config = get_model_config("UniversityInfo") model_config = get_model_config("UniversityInfo")
university = models.OneToOneField( 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( cost_exchange = models.DecimalField(
decimal_places=2, decimal_places=2, max_digits=20, validators=[MinValueValidator(0)], null=True
max_digits=20,
validators=[MinValueValidator(0)],
null=True
) )
cost_double_degree = models.DecimalField( cost_double_degree = models.DecimalField(
decimal_places=2, decimal_places=2, max_digits=20, validators=[MinValueValidator(0)], null=True
max_digits=20,
validators=[MinValueValidator(0)],
null=True
) )
costs_currency = models.ForeignKey( costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT, null=True)
Currency, on_delete=models.PROTECT, null=True)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -35,10 +37,9 @@ class UniversityInfo(BasicModule): ...@@ -35,10 +37,9 @@ class UniversityInfo(BasicModule):
class UniversityInfoSerializer(BasicModuleSerializer): class UniversityInfoSerializer(BasicModuleSerializer):
class Meta: class Meta:
model = UniversityInfo model = UniversityInfo
fields = '__all__' fields = "__all__"
class UniversityInfoViewSet(BasicModuleViewSet): class UniversityInfoViewSet(BasicModuleViewSet):
......
from django.db import models from django.db import models
from backend_app.models.university import University 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 from backend_app.utils import get_model_config, get_viewset_permissions
class UniversityScholarship(Scholarship): class UniversityScholarship(Scholarship):
model_config = get_model_config("UniversityScholarship") model_config = get_model_config("UniversityScholarship")
universities = models.ManyToManyField( universities = models.ManyToManyField(
University, related_name="university_scholarships") University, related_name="university_scholarships"
)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -19,17 +24,16 @@ class UniversityScholarshipSerializer(ScholarshipSerializer): ...@@ -19,17 +24,16 @@ class UniversityScholarshipSerializer(ScholarshipSerializer):
class Meta: class Meta:
model = UniversityScholarship model = UniversityScholarship
fields = '__all__' fields = "__all__"
class UniversityScholarshipViewSet(ScholarshipViewSet): class UniversityScholarshipViewSet(ScholarshipViewSet):
permission_classes = get_viewset_permissions( permission_classes = get_viewset_permissions("UniversityScholarshipViewSet")
"UniversityScholarshipViewSet")
queryset = UniversityScholarship.objects.all() # pylint: disable=E1101 queryset = UniversityScholarship.objects.all() # pylint: disable=E1101
serializer_class = UniversityScholarshipSerializer serializer_class = UniversityScholarshipSerializer
BYPASS_DICT_MODE = True BYPASS_DICT_MODE = True
def extend_queryset(self): 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() return self.my_model_queryset.filter(universities__pk=univ_id).distinct()
from django.db import models 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.university import University
from rest_framework import serializers from rest_framework import serializers
from backend_app.utils import get_model_config, get_viewset_permissions 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 ...@@ -7,14 +11,20 @@ from backend_app.utils import get_model_config, get_viewset_permissions
def semester_error(semester_name): def semester_error(semester_name):
raise serializers.ValidationError( raise serializers.ValidationError(
"Inconsistent {} semester dates".format(semester_name)) "Inconsistent {} semester dates".format(semester_name)
)
class UniversitySemestersDates(BasicModule): class UniversitySemestersDates(BasicModule):
model_config = get_model_config("UniversitySemestersDates") model_config = get_model_config("UniversitySemestersDates")
university = models.OneToOneField( 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_begin = models.DateField(null=True, blank=True)
spring_end = models.DateField(null=True, blank=True) spring_end = models.DateField(null=True, blank=True)
...@@ -27,34 +37,32 @@ class UniversitySemestersDates(BasicModule): ...@@ -27,34 +37,32 @@ class UniversitySemestersDates(BasicModule):
class UniversitySemestersDatesSerializer(BasicModuleSerializer): class UniversitySemestersDatesSerializer(BasicModuleSerializer):
def my_validate(self, attrs): def my_validate(self, attrs):
attrs = super(UniversitySemestersDatesSerializer, attrs = super(UniversitySemestersDatesSerializer, self).my_validate(attrs)
self).my_validate(attrs)
s_b, s_e = attrs['spring_begin'], attrs['spring_end'] s_b, s_e = attrs["spring_begin"], attrs["spring_end"]
a_b, a_e = attrs['autumn_begin'], attrs['autumn_end'] a_b, a_e = attrs["autumn_begin"], attrs["autumn_end"]
def test(begin, end, name): def test(begin, end, name):
ok = (begin is None and end is None) or ( 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: if not ok:
semester_error(name) semester_error(name)
if begin is not None and (begin > end): if begin is not None and (begin > end):
semester_error(name) semester_error(name)
test(s_b, s_e, 'spring') test(s_b, s_e, "spring")
test(a_b, a_e, 'autumn') test(a_b, a_e, "autumn")
return attrs return attrs
class Meta: class Meta:
model = UniversitySemestersDates model = UniversitySemestersDates
fields = '__all__' fields = "__all__"
class UniversitySemestersDatesViewSet(BasicModuleViewSet): class UniversitySemestersDatesViewSet(BasicModuleViewSet):
permission_classes = get_viewset_permissions( permission_classes = get_viewset_permissions("UniversitySemestersDatesViewSet")
"UniversitySemestersDatesViewSet")
queryset = UniversitySemestersDates.objects.all() # pylint: disable=E1101 queryset = UniversitySemestersDates.objects.all() # pylint: disable=E1101
serializer_class = UniversitySemestersDatesSerializer serializer_class = UniversitySemestersDatesSerializer
from django.db import models 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.models.university import University
from backend_app.utils import get_model_config, get_viewset_permissions 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 ...@@ -7,20 +11,21 @@ from backend_app.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem): class UniversityTaggedItem(TaggedItem):
model_config = get_model_config("UniversityTaggedItem") model_config = get_model_config("UniversityTaggedItem")
university = models.ForeignKey( university = models.ForeignKey(
University, on_delete=models.PROTECT, related_name='university_tagged_items') University, on_delete=models.PROTECT, related_name="university_tagged_items"
)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
return UniversityTaggedItemSerializer return UniversityTaggedItemSerializer
class Meta: class Meta:
unique_together = ('university', 'tag', 'importance_level') unique_together = ("university", "tag", "importance_level")
class UniversityTaggedItemSerializer(TaggedItemSerializer): class UniversityTaggedItemSerializer(TaggedItemSerializer):
class Meta: class Meta:
model = UniversityTaggedItem model = UniversityTaggedItem
fields = '__all__' fields = "__all__"
class UniversityTaggedItemViewSet(TaggedItemViewSet): class UniversityTaggedItemViewSet(TaggedItemViewSet):
...@@ -31,5 +36,5 @@ class UniversityTaggedItemViewSet(TaggedItemViewSet): ...@@ -31,5 +36,5 @@ class UniversityTaggedItemViewSet(TaggedItemViewSet):
BYPASS_DICT_MODE = True BYPASS_DICT_MODE = True
def extend_queryset(self): 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() return self.my_model_queryset.filter(university__pk=univ_id).distinct()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -12,13 +12,14 @@ from shared import OBJ_MODERATION_PERMISSIONS ...@@ -12,13 +12,14 @@ from shared import OBJ_MODERATION_PERMISSIONS
###################################### ######################################
###################################### ######################################
def is_moderation_required(model_config, obj_in_db, user, user_level=None): 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: if user_level is None:
user_level = get_user_level(user) user_level = get_user_level(user)
key = 'enforce_moderation_user_level' key = "enforce_moderation_user_level"
if key in model_config.keys() and model_config[key] is not None: if key in model_config.keys() and model_config[key] is not None:
if user_level < model_config[key]: if user_level < model_config[key]:
return True return True
...@@ -40,5 +41,4 @@ def is_moderation_required(model_config, obj_in_db, user, user_level=None): ...@@ -40,5 +41,4 @@ def is_moderation_required(model_config, obj_in_db, user, user_level=None):
elif model_moderation_level == 2: elif model_moderation_level == 2:
return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"] return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"]
else: else:
raise Exception( raise Exception("No other moderation level should be defined...")
"No other moderation level should be defined...")
This diff is collapsed.
This diff is collapsed.
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