Commit 42992788 authored by Florent Chehab's avatar Florent Chehab

Backend completely reorganized to limit cyclic imports

parent c776e24f
Pipeline #27073 passed with stages
in 2 minutes and 27 seconds
from backend.models.location import Country
from backend.models.country import Country
import os
import pandas as pd
from .loadGeneric import LoadGeneric
......
from backend.models.location import Currency
from backend.models.currency import Currency
import os
import csv
from .loadGeneric import LoadGeneric
......
from backend.models.location import City, Country
from backend.models.university import University, Campus
from backend.models.country import Country
from backend.models.city import City
from backend.models.university import University
from backend.models.campus import Campus
import os
import pandas as pd
......
# Generated by Django 2.0.3 on 2018-09-09 13:47
import backend.models.tools.jSONField
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0002_auto_20180909_1455'),
]
operations = [
migrations.AddField(
model_name='campustaggeditem',
name='comment',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='campustaggeditem',
name='importance_level',
field=models.CharField(choices=[('-', 'normal'), ('+', 'important'), ('++', 'IMPORTANT')], default='-', max_length=2),
),
migrations.AddField(
model_name='campustaggeditem',
name='usefull_links',
field=backend.models.tools.jSONField.JSONField(default=list),
),
migrations.AddField(
model_name='citytaggeditem',
name='comment',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='citytaggeditem',
name='importance_level',
field=models.CharField(choices=[('-', 'normal'), ('+', 'important'), ('++', 'IMPORTANT')], default='-', max_length=2),
),
migrations.AddField(
model_name='citytaggeditem',
name='usefull_links',
field=backend.models.tools.jSONField.JSONField(default=list),
),
migrations.AddField(
model_name='countrytaggeditem',
name='comment',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='countrytaggeditem',
name='importance_level',
field=models.CharField(choices=[('-', 'normal'), ('+', 'important'), ('++', 'IMPORTANT')], default='-', max_length=2),
),
migrations.AddField(
model_name='countrytaggeditem',
name='usefull_links',
field=backend.models.tools.jSONField.JSONField(default=list),
),
migrations.AddField(
model_name='universitytaggeditem',
name='comment',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='universitytaggeditem',
name='importance_level',
field=models.CharField(choices=[('-', 'normal'), ('+', 'important'), ('++', 'IMPORTANT')], default='-', max_length=2),
),
migrations.AddField(
model_name='universitytaggeditem',
name='usefull_links',
field=backend.models.tools.jSONField.JSONField(default=list),
),
]
from .basicModule import BasicModule, BasicModuleSerializer, BasicModuleViewSet # noqa: F401
from django.db import models
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from backend.models.tools import JSONField
from backend.models.tag.tagged_item_validation import validate_content_against_config
from backend.models.tag.tags_config import USEFULL_LINKS_CONFIG
from backend.validators.tag import validate_content_against_config
from backend.validators.tag.tags_config import USEFULL_LINKS_CONFIG
IMPORTANCE_LEVEL = (
('-', 'normal'),
......
from .campus import Campus, CampusViewSet, CampusSerializer, MainCampusViewSet # noqa: F401
from .campusTaggedItem import CampusTaggedItem, CampusTaggedItemSerializer, CampusTaggedItemViewSet # noqa: F401
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.city import City
from backend.models.university import University
from django.core.validators import MinValueValidator, MaxValueValidator
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.university import Campus
from backend.models.campus import Campus
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from .city import City, CitySerializer, CityViewSet # noqa: F401
from .cityTaggedItem import CityTaggedItem, CityTaggedItemSerializer, CityTaggedItemViewSet # noqa: F401
from django.db import models
from backend.models.location import Country
from backend.models.country import Country
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.location import City
from backend.models.city import City
from backend.utils import get_model_config, get_viewset_permissions
......
from .currency import Currency, CurrencyViewSet, CurrencySerializer # noqa: F401
from .country import Country, CountrySerializer, CountryViewSet # noqa: F401
from .countryScholarship import CountryScholarship, CountryScholarshipViewSet # noqa: F401
from .countryDri import CountryDri, CountryDriViewSet # noqa: F401
from .countryTaggedItem import CountryTaggedItem, CountryTaggedItemSerializer, CountryTaggedItemViewSet # noqa: F401
from .city import City, CitySerializer, CityViewSet # noqa: F401
from .cityTaggedItem import CityTaggedItem, CityTaggedItemSerializer, CityTaggedItemViewSet # noqa: F401
from django.db import models
from backend.models.location import Country
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
from backend.models.country import Country
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.utils import get_model_config, get_viewset_permissions
class CountryDri(DriRestrictedModule):
class CountryDri(BasicModule):
model_config = get_model_config("CountryDri")
country = models.ManyToManyField(
Country, related_name="country_dri")
......@@ -14,14 +14,14 @@ class CountryDri(DriRestrictedModule):
return CountryDriSerializer
class CountryDriSerializer(DriRestrictedModuleSerializer):
class CountryDriSerializer(BasicModuleSerializer):
class Meta:
model = CountryDri
fields = '__all__'
class CountryDriViewSet(DriRestrictedModuleViewSet):
class CountryDriViewSet(BasicModuleViewSet):
permission_classes = get_viewset_permissions("CountryDriViewSet")
queryset = CountryDri.objects.all() # pylint: disable=E1101
serializer_class = CountryDriSerializer
from django.db import models
from backend.models.location import Country
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.models.country import Country
from backend.models.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.location import Country
from backend.models.country import Country
from backend.utils import get_model_config, get_viewset_permissions
......
from .currency import Currency, CurrencyViewSet, CurrencySerializer # noqa: F401
from .basicModule import BasicModule, BasicModuleSerializer, BasicModuleViewSet # noqa: F401
from .scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet # noqa: F401
from .driRestrictedModule import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet # noqa: F401
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
class DriRestrictedModule(BasicModule):
class Meta:
abstract = True
class DriRestrictedModuleSerializer(BasicModuleSerializer):
class Meta:
model = DriRestrictedModule
class DriRestrictedModuleViewSet(BasicModuleViewSet):
serializer_class = DriRestrictedModuleSerializer
from .scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet # noqa: F401
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import Currency
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.currency import Currency
from rest_framework import serializers
from django.core.validators import MinValueValidator
......
from .tag import Tag, TagSerializer, TagViewSet # noqa: F401
from .taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet # noqa: F401
from .tagged_item_validation import validate_content_against_config # noqa: F401
from django.db import models
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from .tag import Tag
from .tagged_item_validation import tagged_item_validation
from backend.validators.tag import tagged_item_validation
from backend.models.tools import JSONField
class TaggedItem(MyModelVersionned):
class TaggedItem(BasicModule):
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
custom_content = JSONField(default=dict)
......@@ -13,13 +13,13 @@ class TaggedItem(MyModelVersionned):
abstract = True
class TaggedItemSerializer(MyModelVersionnedSerializer):
class TaggedItemSerializer(BasicModuleSerializer):
def my_validate(self, attrs):
tagged_item_validation(attrs)
return attrs
class TaggedItemViewSet(MyModelVersionnedViewSet):
class TaggedItemViewSet(BasicModuleViewSet):
def extend_queryset(self):
return self.mymodel_queryset.prefetch_related('tag')
......@@ -6,6 +6,3 @@ from .universityInfo import UniversityInfo, UniversityInfoSerializer, University
from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesSerializer, UniversitySemestersDatesViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
from .universityTaggedItem import UniversityTaggedItem, UniversityTaggedItemSerializer, UniversityTaggedItemViewSet # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer, MainCampusViewSet # noqa: F401
from .campusTaggedItem import CampusTaggedItem, CampusTaggedItemSerializer, CampusTaggedItemViewSet # noqa: F401
......@@ -3,7 +3,7 @@ from backend.models.my_model import MyModel
from backend.utils import get_model_config
from django.core.exceptions import ValidationError
from rest_framework.validators import ValidationError as RFValidationError
from backend.models.tag.validators.url import validate_extension
from backend.validators.tag.url import validate_extension
from django.conf import settings
from backend.models.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
......
from django.db import models
from backend.models.university import University
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.utils import get_model_config, get_viewset_permissions
class UniversityDri(DriRestrictedModule):
class UniversityDri(BasicModule):
model_config = get_model_config("UniversityDri")
university = models.ManyToManyField(
University, related_name="university_dri")
......@@ -14,14 +14,14 @@ class UniversityDri(DriRestrictedModule):
return UniversityDriSerializer
class UniversityDriSerializer(DriRestrictedModuleSerializer):
class UniversityDriSerializer(BasicModuleSerializer):
class Meta:
model = UniversityDri
fields = '__all__'
class UniversityDriViewSet(DriRestrictedModuleViewSet):
class UniversityDriViewSet(BasicModuleViewSet):
permission_classes = get_viewset_permissions("UniversityDriViewSet")
queryset = UniversityDri.objects.all() # pylint: disable=E1101
serializer_class = UniversityDriSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from backend.models.location import Currency
from backend.models.currency import Currency
from django.core.validators import MinValueValidator
from backend.utils import get_model_config, get_viewset_permissions
......
from backend.models.university import University
from backend.models.university.campus import CampusSerializer
from backend.models.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer
from backend.models.my_model import MyModelSerializer, MyModelViewSet
......
from django.db import models
from backend.models.university import University
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.models.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from rest_framework import serializers
from backend.utils import get_model_config, get_viewset_permissions
......
from django.test import TestCase
from backend.models.module.scholarship import ScholarshipSerializer
from backend.models.scholarship import ScholarshipSerializer
import pytest
from rest_framework.validators import ValidationError
......@@ -8,15 +8,15 @@ class ScholarshipTestCase(TestCase):
def test_scholarhip_validation(self):
ser = ScholarshipSerializer()
attrs = {
'usefull_links': [],
'comment': ''
}
with pytest.raises(ValidationError):
attrs = {
'amount_max': 100,
'amount_min': 200
}
attrs['amount_min'] = 200
attrs['amount_max'] = 100
ser.my_validate(attrs)
attrs = {
'amount_max': 200,
'amount_min': 100
}
attrs['amount_min'] = 100
attrs['amount_max'] = 200
ser.my_validate(attrs)
......@@ -11,7 +11,10 @@ class SemesterDatesTestCase(TestCase):
def test_validation(self):
def build(l):
return {sem: val for sem, val in zip(semesters, l)}
tmp = {sem: val for sem, val in zip(semesters, l)}
tmp['comment'] = ""
tmp['usefull_links'] = []
return tmp
def _test_attrs_error(attrs):
with pytest.raises(ValidationError):
......
......@@ -2,7 +2,7 @@ from django.test import TestCase
import pytest
from rest_framework.validators import ValidationError as RFValidationError
from django.core.validators import ValidationError as DJValidationError
from backend.models.tag.validators.url import validate_extension, validate_url
from backend.validators.tag.url import validate_extension, validate_url
class ValidationUrlTestCase(TestCase):
......
from .url import validate_url # noqa: F401
from .text import validate_text # noqa: F401
from .tagged_item_validation import validate_content_against_config # noqa: F401
from .checks import check_required
from .validators import validate_url, validate_text
from .url import validate_url
from .text import validate_text
from rest_framework.validators import ValidationError
from .tags_config import PHOTOS_TAG_GONFIG
from .tags_config import PHOTOS_TAG_CONFIG
from .tags_config import USEFULL_LINKS_CONFIG
......@@ -29,7 +30,7 @@ def validate_content_against_config(config, content):
elif field_type == 'text':
validate_text(field_config, field_submitted)
elif field_type == 'photos':
validate_content_against_config({"photos": PHOTOS_TAG_GONFIG}, {
validate_content_against_config({"photos": PHOTOS_TAG_CONFIG}, {
"photos": field_submitted})
elif field_type == 'usefull_links':
validate_content_against_config({"ul": USEFULL_LINKS_CONFIG}, {
......
from .photos import PHOTOS_TAG_GONFIG # noqa: F401
from .photos import PHOTOS_TAG_CONFIG # noqa: F401
from .usefull_links import USEFULL_LINKS_CONFIG # noqa: F401
from django.conf import settings
PHOTOS_TAG_GONFIG = {
PHOTOS_TAG_CONFIG = {
"type": "array",
"required": True,
"content": {
......
......@@ -38,13 +38,13 @@
- model: Country
viewset: CountryViewSet
import_location: location
import_location: country
api_end_point: countries
viewset_permission: IsStaffOrReadOnly
- model: City
viewset: CityViewSet
import_location: location
import_location: city
api_end_point: cities
moderation_level: 2
......@@ -56,7 +56,7 @@
- model: Campus
viewset: CampusViewSet
import_location: university
import_location: campus
api_end_point: campuses
versionned: true
moderation_level: 2
......@@ -80,7 +80,7 @@
- model: Currency
viewset: CurrencyViewSet
import_location: location
import_location: currency
api_end_point: currencies
moderation_level: 2
viewset_permission: IsStaffOrReadOnly
......@@ -116,19 +116,19 @@
- model: CountryTaggedItem
viewset: CountryTaggedItemViewSet
import_location: location
import_location: country
api_end_point: countriesTaggedItems
versionned: true
- model: CountryScholarship
viewset: CountryScholarshipViewSet
import_location: location
import_location: country
api_end_point: countriesScholarships
versionned: true
- model: CountryDri
viewset: CountryDriViewSet
import_location: location
import_location: country
api_end_point: countriesDri
viewset_permission: IsDriOrReadOnly
versionned: true
......@@ -137,7 +137,7 @@
- model: CityTaggedItem
viewset: CityTaggedItemViewSet
import_location: location
import_location: city
api_end_point: citiesTaggedItems
versionned: true
......@@ -185,13 +185,13 @@
- model: CampusTaggedItem
viewset: CampusTaggedItemViewSet
import_location: university
import_location: campus
api_end_point: campusesTaggedItems
versionned: true
- model: null
viewset: MainCampusViewSet
import_location: university
import_location: campus
api_end_point: mainCampuses
read_only: true
......
......@@ -34,6 +34,7 @@ INSTALLED_APPS = [
'rest_framework.authtoken',
'backend',
'frontend',
'django_extensions',
'debug_toolbar',
]
......
......@@ -19,4 +19,5 @@ pytest-xdist==1.23.0
flake8
django-debug-toolbar==1.9.1
pandas
pyyaml
\ No newline at end of file
pyyaml
django-extensions==2.1.2
\ No newline at end of file
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