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()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -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)
key = 'enforce_moderation_user_level'
key = "enforce_moderation_user_level"
if key in model_config.keys() and model_config[key] is not None:
if user_level < model_config[key]:
return True
......@@ -40,5 +41,4 @@ def is_moderation_required(model_config, obj_in_db, user, user_level=None):
elif model_moderation_level == 2:
return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"]
else:
raise Exception(
"No other moderation level should be defined...")
raise Exception("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