Commit 61887e05 authored by Florent Chehab's avatar Florent Chehab

endpoints updated for main campus

parent 39210901
Pipeline #26558 passed with stages
in 3 minutes and 11 seconds
from .university import University # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer, MainCampusViewSet # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from .universityScholarship import UniversityScholarship, UniversityScholarshipSerializer, UniversityScholarshipViewSet # noqa: F401
......
......@@ -46,3 +46,8 @@ class CampusViewSet(BasicModuleViewSet):
queryset = Campus.objects.all().prefetch_related(
'updated_by') # pylint: disable=E1101
serializer_class = CampusSerializer
class MainCampusViewSet(BasicModuleViewSet):
queryset = Campus.objects.filter(is_main_campus=True)
serializer_class = CampusSerializer
from backend.models.university import University
from rest_framework import permissions
from backend.models.university.campus import CampusSerializer
from backend.models.tools import NoDeleteIfNotAdmin
from backend.models.my_model import MyModelSerializer, MyModelViewSet
class UniversitySerializer(MyModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True)
class Meta:
model = University
......@@ -20,5 +18,4 @@ class UniversityViewSet(MyModelViewSet):
permissions.IsAuthenticated,
NoDeleteIfNotAdmin,
)
queryset = University.objects.all()\
.prefetch_related('univ_campus', 'univ_campus__updated_by') # pylint: disable=E1101
queryset = University.objects.all() # pylint: disable=E1101
......@@ -28,7 +28,7 @@ from backend.models.location import CityOtherStuffViewSet
from backend.models.location import CityPhotoViewSet
from backend.models.university import UniversityViewSet
from backend.models.university import CampusViewSet
from backend.models.university import CampusViewSet, MainCampusViewSet
from backend.models.university import UniversityScholarshipViewSet
from backend.models.university import UniversityInfoViewSet
from backend.models.university import UniversitySemestersDatesViewSet
......@@ -74,6 +74,7 @@ if settings.TESTING:
router.register(r'country', CountryViewSet)
router.register(r'city', CityViewSet)
router.register(r'campus', CampusViewSet)
router.register(r'main_campus', MainCampusViewSet)
router.register(r'university', UniversityViewSet)
......
......@@ -40,6 +40,9 @@ contexts = [
}, {
'NAME': 'COUNTRIES',
'name': 'countries'
}, {
'NAME': 'MAIN_CAMPUS',
'name': 'mainCampus'
}
]
......
......@@ -5,7 +5,9 @@ import { Map, TileLayer, Marker, Popup, LayersControl, FeatureGroup, Circle, Lay
// import MarkerClusterGroup from 'react-leaflet-markercluster';
import {
universitiesFetchData,
universitiesInvalidated
universitiesInvalidated,
mainCampusFetchData,
mainCampusInvalidated
} from '../../generated/actions';
......@@ -13,16 +15,21 @@ import {
class UnivMap extends Component {
componentDidMount() {
if (this.props.universities.length == 0 || this.props.invalidated) {
console.log("here mother uc", this.props.universities);
this.props.fetchData('http://127.0.0.1:8000/api/university');
this.props.fetchUniversitiesData('http://127.0.0.1:8000/api/university');
}
if (this.props.mainCampus.length == 0 || this.props.invalidated) {
this.props.fetchMainCampusData('http://127.0.0.1:8000/api/main_campus');
}
}
componentDidUpdate() {
// TODO ajouter expire date
if (this.props.invalidated) {
this.props.fetchData('http://127.0.0.1:8000/api/university');
if (this.props.universitiesInvalidated) {
this.props.fetchUniversitiesData('http://127.0.0.1:8000/api/university');
}
if (this.props.mainCampusInvalidated) {
this.props.fetchMainCampusData('http://127.0.0.1:8000/api/main_campus');
}
}
......@@ -31,23 +38,31 @@ class UnivMap extends Component {
}
render() {
if (this.props.hasError) {
if (this.props.universitiesHasError || this.props.mainCampusHasError) {
return <p>Sorry! There was an error loading the items</p>;
}
if (this.props.isLoading || this.props.invalidated) {
if (this.props.universitiesIsLoading || this.props.universitiesInvalidated) {
return <Loading />;
}
if (this.props.mainCampusIsLoading || this.props.mainCampusInvalidated) {
return <Loading />;
}
let universities = this.props.universities;
let mainCampus = this.props.mainCampus;
console.log(universities, mainCampus)
let univ_to_plot = [];
for (let univ_pk in universities) {
let univ = universities[univ_pk];
if (univ.univ_campus.length > 0) {
univ_to_plot.push({
name: univ.name,
main_campus: univ.univ_campus[0]
})
}
for (let main_campus_pk in mainCampus) {
let campus = mainCampus[main_campus_pk]
let univ = universities[campus.university]
univ_to_plot.push({
name: univ.name,
main_campus: campus
})
}
return (
......@@ -108,17 +123,25 @@ class UnivMap extends Component {
const mapStateToProps = (state) => {
return {
universities: state.universitiesFetched.universities,
fetchedAt: state.universitiesFetched.fetchedAt,
hasError: state.universitiesHasError,
isLoading: state.universitiesIsLoading,
invalidated: state.universitiesInvalidated
universitiesFetchedAt: state.universitiesFetched.fetchedAt,
universitiesHasError: state.universitiesHasError,
universitiesIsLoading: state.universitiesIsLoading,
universitiesInvalidated: state.universitiesInvalidated,
mainCampus: state.mainCampusFetched.mainCampus,
mainCampusFetchedAt: state.mainCampusFetched.fetchedAt,
mainCampusHasError: state.mainCampusHasError,
mainCampusIsLoading: state.mainCampusIsLoading,
mainCampusInvalidated: state.mainCampusInvalidated,
};
};
const mapDispatchToProps = (dispatch) => {
return {
fetchData: (url) => dispatch(universitiesFetchData(url)),
invalidate: () => dispatch(universitiesInvalidated(true))
fetchUniversitiesData: (url) => dispatch(universitiesFetchData(url)),
fetchMainCampusData: (url) => dispatch(mainCampusFetchData(url)),
// invalidateUniversities: (bool) => dispatch(universitiesInvalidated(bool)),
// invalidateMainCampus: (bool) => dispatch(mainCampusInvalidated(bool))
};
};
......
import { combineReducers } from 'redux';
import {
universitiesFetched,
universitiesHasError,
import {
universitiesFetched,
universitiesHasError,
universitiesIsLoading,
universitiesInvalidated,
countriesFetched,
countriesHasError,
countriesFetched,
countriesHasError,
countriesIsLoading,
countriesInvalidated
countriesInvalidated,
mainCampusFetched,
mainCampusHasError,
mainCampusIsLoading,
mainCampusInvalidated,
} from '../generated/reducers';
......@@ -17,10 +23,16 @@ const rootReducer = combineReducers({
universitiesHasError,
universitiesIsLoading,
universitiesInvalidated,
countriesFetched,
countriesHasError,
countriesFetched,
countriesHasError,
countriesIsLoading,
countriesInvalidated
countriesInvalidated,
mainCampusFetched,
mainCampusHasError,
mainCampusIsLoading,
mainCampusInvalidated,
})
export default rootReducer
......
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