Commit a49d5f70 authored by Florent Chehab's avatar Florent Chehab

API to regroup info added and minor tweaks

parent b67fda5d
This diff is collapsed.
# Generated by Django 2.0.3 on 2018-09-10 13:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0001_squashed_0006_auto_20180910_1508'),
]
operations = [
migrations.AlterField(
model_name='countryscholarship',
name='country',
field=models.ManyToManyField(related_name='country_scholarhips', to='backend.Country'),
),
migrations.AlterField(
model_name='countrytaggeditem',
name='country',
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='country_tagged_items', serialize=False, to='backend.Country'),
),
]
# Generated by Django 2.0.3 on 2018-09-10 13:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0002_auto_20180910_1528'),
]
operations = [
migrations.AlterField(
model_name='countryscholarship',
name='country',
field=models.ManyToManyField(related_name='country_scholarships', to='backend.Country'),
),
]
# Generated by Django 2.0.3 on 2018-09-10 13:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0003_auto_20180910_1529'),
]
operations = [
migrations.AlterField(
model_name='campustaggeditem',
name='campus',
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='campus_tagged_items', serialize=False, to='backend.Campus'),
),
migrations.AlterField(
model_name='citytaggeditem',
name='city',
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='city_tagged_items', serialize=False, to='backend.City'),
),
]
# Generated by Django 2.0.3 on 2018-09-10 13:04
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0004_auto_20180910_1016'),
]
operations = [
migrations.AlterField(
model_name='campus',
name='university',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='university_campuses', to='backend.University'),
),
migrations.RemoveField(
model_name='universityscholarship',
name='university',
),
migrations.AddField(
model_name='universityscholarship',
name='university',
field=models.ManyToManyField(related_name='university_scholarships', to='backend.University'),
),
]
# Generated by Django 2.0.3 on 2018-09-10 13:08
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0005_auto_20180910_1504'),
]
operations = [
migrations.AlterField(
model_name='universitytaggeditem',
name='university',
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='university_tagged_items', serialize=False, to='backend.University'),
),
]
......@@ -12,7 +12,7 @@ class MyModelViewSet(DictModeViewSet):
Extended default rest framework behavior
to prefetch some table and enhance performances
"""
self.mymodel_queryset = self.queryset.prefetch_related(
self.my_model_queryset = self.queryset.prefetch_related(
'moderated_by', 'updated_by', 'pending_moderation')
return self.extend_queryset()
......@@ -20,4 +20,4 @@ class MyModelViewSet(DictModeViewSet):
"""
Function to extend get_queryset when subclassing
"""
return self.mymodel_queryset
return self.my_model_queryset
......@@ -22,4 +22,4 @@ class TaggedItemSerializer(BasicModuleSerializer):
class TaggedItemViewSet(BasicModuleViewSet):
def extend_queryset(self):
return self.mymodel_queryset.prefetch_related('tag')
return self.my_model_queryset.prefetch_related('tag')
from .campus import Campus, CampusViewSet, CampusSerializer, MainCampusViewSet # noqa: F401
from .campusTaggedItem import CampusTaggedItem, CampusTaggedItemSerializer, CampusTaggedItemViewSet # noqa: F401
from .campusModulesAPI import CampusModulesViewSet # noqa: F401
......@@ -14,7 +14,7 @@ class Campus(BasicModule):
comment = models.TextField(null=True, blank=True)
city = models.ForeignKey(City, on_delete=models.PROTECT, null=False)
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univ_campus")
University, on_delete=models.PROTECT, null=False, related_name="university_campuses")
lat = models.DecimalField(
max_digits=10,
......
from backend.models.campus import Campus
from backend.models.campus import CampusTaggedItemSerializer
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
class CampusModulesSerializer(MyModelSerializer):
campus_tagged_items = CampusTaggedItemSerializer(
many=True, read_only=True)
class Meta:
model = Campus
fields = '__all__'
class CampusModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("CampusModulesViewSet")
serializer_class = CampusModulesSerializer
queryset = Campus.objects.all()
def extend_queryset(self):
campus_id = self.kwargs['campus_id']
return self.my_model_queryset.filter(pk=campus_id).prefetch_related(
'campus_tagged_items'
) # pylint: disable=E1101
......@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class CampusTaggedItem(TaggedItem):
model_config = get_model_config("CampusTaggedItem")
campus = models.OneToOneField(
Campus, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
Campus, on_delete=models.PROTECT, related_name='campus_tagged_items', primary_key=True)
@classmethod
def get_serializer(cls):
......
from .city import City, CitySerializer, CityViewSet # noqa: F401
from .cityTaggedItem import CityTaggedItem, CityTaggedItemSerializer, CityTaggedItemViewSet # noqa: F401
from .cityModulesAPI import CityModulesViewSet # noqa: F401
from backend.models.city import City
from backend.models.city import CityTaggedItemSerializer
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
class CityModulesSerializer(MyModelSerializer):
city_tagged_items = CityTaggedItemSerializer(
many=True, read_only=True)
class Meta:
model = City
fields = '__all__'
class CityModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("CityModulesViewSet")
serializer_class = CityModulesSerializer
queryset = City.objects.all()
def extend_queryset(self):
city_id = self.kwargs['city_id']
return self.my_model_queryset.filter(pk=city_id).prefetch_related(
'city_tagged_items'
) # pylint: disable=E1101
......@@ -8,7 +8,7 @@ class CityTaggedItem(TaggedItem):
model_config = get_model_config("CityTaggedItem")
city = models.OneToOneField(
City, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
City, on_delete=models.PROTECT, related_name='city_tagged_items', primary_key=True)
@classmethod
def get_serializer(cls):
......
from .country import Country, CountrySerializer, CountryViewSet # noqa: F401
from .countryScholarship import CountryScholarship, CountryScholarshipViewSet # noqa: F401
from .countryDri import CountryDri, CountryDriViewSet # noqa: F401
from .countryScholarship import CountryScholarship, CountryScholarshipSerializer, CountryScholarshipViewSet # noqa: F401
from .countryDri import CountryDri, CountryDriSerializer, CountryDriViewSet # noqa: F401
from .countryTaggedItem import CountryTaggedItem, CountryTaggedItemSerializer, CountryTaggedItemViewSet # noqa: F401
from .countryModulesAPI import CountryModulesViewSet # noqa: F401
from backend.models.country import Country
from backend.models.country import CountryDriSerializer
from backend.models.country import CountryScholarshipSerializer
from backend.models.country import CountryTaggedItemSerializer
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
class CountryModulesSerializer(MyModelSerializer):
country_scholarships = CountryScholarshipSerializer(
many=True, read_only=True)
country_tagged_items = CountryTaggedItemSerializer(
many=True, read_only=True)
country_dri = CountryDriSerializer(many=True, read_only=True)
class Meta:
model = Country
fields = '__all__'
class CountryModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("CountryModulesViewSet")
serializer_class = CountryModulesSerializer
queryset = Country.objects.all()
def extend_queryset(self):
country_id = self.kwargs['country_id']
return self.my_model_queryset.filter(pk=country_id).prefetch_related(
'country_dri',
'country_scholarships',
'country_tagged_items'
) # pylint: disable=E1101
......@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class CountryScholarship(Scholarship):
model_config = get_model_config("CountryScholarship")
country = models.ManyToManyField(
Country, related_name="country_scholarhip")
Country, related_name="country_scholarships")
@classmethod
def get_serializer(cls):
......
......@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class CountryTaggedItem(TaggedItem):
model_config = get_model_config("CountryTaggedItem")
country = models.OneToOneField(
Country, on_delete=models.PROTECT, related_name='country_items', primary_key=True)
Country, on_delete=models.PROTECT, related_name='country_tagged_items', primary_key=True)
@classmethod
def get_serializer(cls):
......
......@@ -4,5 +4,5 @@ from .universityScholarship import UniversityScholarship, UniversityScholarshipS
from .universityDri import UniversityDri, UniversityDriSerializer, UniversityDriViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoSerializer, UniversityInfoViewSet # noqa: F401
from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesSerializer, UniversitySemestersDatesViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
from .universityTaggedItem import UniversityTaggedItem, UniversityTaggedItemSerializer, UniversityTaggedItemViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
......@@ -2,13 +2,25 @@ from backend.models.university import University
from backend.models.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer
from backend.models.university import UniversityInfoSerializer
from backend.models.university import UniversityScholarshipSerializer
from backend.models.university import UniversitySemestersDatesSerializer
from backend.models.university import UniversityTaggedItemSerializer
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
class UniversityModulesSerializer(MyModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True)
university_campuses = CampusSerializer(many=True, read_only=True)
university_scholarships = UniversityScholarshipSerializer(
many=True, read_only=True)
university_tagged_items = UniversityTaggedItemSerializer(
many=True, read_only=True)
university_dri = UniversityDriSerializer(many=True, read_only=True)
university_info = UniversityInfoSerializer(read_only=True)
university_semesters_dates = UniversitySemestersDatesSerializer(
read_only=True)
class Meta:
model = University
......@@ -18,9 +30,15 @@ class UniversityModulesSerializer(MyModelSerializer):
class UniversityModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("UniversityModulesViewSet")
serializer_class = UniversityModulesSerializer
queryset = University.objects.all()
def get_queryset(self):
def extend_queryset(self):
univ_id = self.kwargs['univ_id']
return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri') # pylint: disable=E1101
# queryset = get_queryset()
return self.my_model_queryset.filter(pk=univ_id).prefetch_related(
'university_campuses',
'university_dri',
'university_info',
'university_scholarships',
'university_semesters_dates',
'university_tagged_items'
) # pylint: disable=E1101
......@@ -6,8 +6,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class UniversityScholarship(Scholarship):
model_config = get_model_config("UniversityScholarship")
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
university = models.ManyToManyField(University, related_name="university_scholarships")
@classmethod
def get_serializer(cls):
......
......@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem):
model_config = get_model_config("UniversityTaggedItem")
university = models.OneToOneField(
University, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
University, on_delete=models.PROTECT, related_name='university_tagged_items', primary_key=True)
@classmethod
def get_serializer(cls):
......
......@@ -177,10 +177,34 @@
- model: null
viewset: UniversityModulesViewSet
import_location: university
api_end_point: universitiesAll
api_end_point: universityAll
api_attr: (?P<univ_id>[0-9]+)
api_name: university_details
read_only: true
- model: null
viewset: CountryModulesViewSet
import_location: country
api_end_point: countryAll
api_attr: (?P<country_id>[a-zA-Z]+)
api_name: country_details
read_only: true
- model: null
viewset: CityModulesViewSet
import_location: city
api_end_point: cityAll
api_attr: (?P<city_id>[0-9]+)
api_name: city_details
read_only: true
- model: null
viewset: CampusModulesViewSet
import_location: campus
api_end_point: campusAll
api_attr: (?P<campus_id>[0-9]+)
api_name: campus_details
read_only: true
- model: CampusTaggedItem
......
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