...
 
Commits (2)
......@@ -12,9 +12,6 @@ from backend_app.load_data.loading_scripts.loadSiteInformation import (
LoadSiteInformation,
)
from backend_app.load_data.loading_scripts.loadUniversities import LoadUniversities
from backend_app.load_data.loading_scripts.loadUniversitiesProd import (
LoadUniversitiesProd,
)
from backend_app.load_data.loading_scripts.loadUniversityEx import LoadUniversityEx
......@@ -48,6 +45,6 @@ def load_prod():
LoadCountries(admin).load()
LoadLanguages().load()
LoadSiteInformation(admin).load()
LoadUniversitiesProd(admin).load()
# LoadUniversitiesProd().load()
# LoadUniversityEx(admin).load()
# LoadRecommendationLists(admin).load()
......@@ -37,7 +37,9 @@ class LoadUniversitiesProd(LoadGeneric):
lon = round(float(row["lon"]), 6)
country = Country.objects.get(pk=row["code_iso"])
city = City.objects.update_or_create(name=row["ville"].title(), country=country)[0]
city = City.objects.update_or_create(
name=row["ville"].title(), country=country
)[0]
self.add_info_and_save(city, self.admin)
univ = University.objects.update_or_create(
......
......@@ -18,6 +18,7 @@ import getActions from "../../redux/api/getActions";
import {compose} from "recompose";
import uuid from "uuid/v4";
import {UniversityHelper} from "../../redux/api/helpers";
import {getMostNRecentSemesters} from "../../utils/compareSemesters";
/**
* Class that handle all the filter manipulation with caching
......@@ -158,6 +159,15 @@ class FilterHandler {
return FilterHandler._semesterOptions;
}
static _defaultSemesters = undefined;
get defaultSemesters() {
if (typeof FilterHandler._defaultSemesters === "undefined") {
FilterHandler._defaultSemesters = getMostNRecentSemesters(this.semesterOptions.map(el => el.value), 4);
}
return FilterHandler._defaultSemesters;
}
getCountryCodeForUniversity(univId) {
const id = parseInt(univId);
return this.universityIdsCountries.get(id).id;
......@@ -249,6 +259,8 @@ class Filter extends CustomComponentForAPI {
static hasSelection = false;
static nbSelection = 0;
static hasBeenChanged = false;
static univHandler = undefined;
static values = {
......@@ -280,9 +292,18 @@ class Filter extends CustomComponentForAPI {
Filter.hasSelection = Object.values(Filter.values).some(arr => arr.length !== 0);
Filter.nbSelection = selectedUniversities.length;
this.props.saveSelection(Filter.hasSelection ? selectedUniversities : null);
Filter.hasBeenChanged = true;
this.forceUpdate();
}
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (Filter.univHandler){ // make sure it has been initilized
const mostRecentSemesters = this.univHandler.defaultSemesters;
if (!Filter.hasBeenChanged) this.updateSelectedUniversities("semesters", mostRecentSemesters);
}
}
getEndMessage() {
if (!Filter.hasSelection) return "(Aucun filtre est actif)";
......@@ -295,7 +316,8 @@ class Filter extends CustomComponentForAPI {
customRender() {
const countriesOptions = this.univHandler.countriesOptions,
majorMinorOptions = this.univHandler.majorMinorOptions,
semestersOptions = this.univHandler.semesterOptions;
semestersOptions = this.univHandler.semesterOptions,
mostRecentSemesters = this.univHandler.defaultSemesters;
const {classes} = this.props;
......@@ -339,6 +361,7 @@ class Filter extends CustomComponentForAPI {
options={semestersOptions}
onChange={(selection) => this.updateSelectedUniversities("semesters", selection)}
cacheId={Filter.DOWNSHIFT_SEMESTERS_ID}
value={[...mostRecentSemesters].reverse()}
/>
</div>
<div className={classes.input}>
......@@ -348,6 +371,9 @@ class Filter extends CustomComponentForAPI {
onChange={(selection) => this.updateSelectedUniversities("majorMinors", selection)}
cacheId={Filter.DOWNSHIFT_MAJORS_ID}
/>
<Typography variant={"caption"}>
Attention, en filtrant par filière, seuls les échanges déjà effectués sont pris en compte.
</Typography>
</div>
</ExpansionPanelDetails>
</ExpansionPanel>
......
......@@ -15,3 +15,17 @@ export default function compareSemesters(year1, period1, year2, period2) {
return year1 - year2;
}
}
/**
*
* @param {Array.<String>} listOfSemesters
* @param {number} n
* @return {Array.<String>}
*/
export function getMostNRecentSemesters(listOfSemesters, n) {
const nToUse = Math.min(n, listOfSemesters.length);
const semesters = listOfSemesters.map(str => ({semester: str[0], year: str.slice(1, 5)}));
semesters.sort((a, b) => -compareSemesters(a.year, a.semester, b.year, b.semester));
return semesters.slice(0, nToUse).map(({semester, year}) => `${semester}${year}`);
}
\ No newline at end of file
import compareSemester from "../../src/utils/compareSemesters";
import compareSemester, {getMostNRecentSemesters} from "../../src/utils/compareSemesters";
test("Compare same", () => {
expect(compareSemester(2019, "a", 2019, "a")).toBeCloseTo(0);
......@@ -15,3 +15,17 @@ test("Compare different year same semester", () => {
test("Both different", () => {
expect(compareSemester(2018, "p", 2019, "a")).toBeLessThan(0);
});
test("Extract the correct list of semester", () => {
const listOfSemester = ["A2019", "A2014", "A2013", "A2012", "A2011",
"P2014", "P2009", "A2010", "A2009", "A2008", "P2012",
"P2011", "P2010", "P2015", "P2013", "A2018"];
const mostRecents = getMostNRecentSemesters(listOfSemester, 5);
expect(mostRecents[0]).toBe("A2019");
expect(mostRecents[1]).toBe("A2018");
expect(mostRecents[2]).toBe("P2015");
expect(mostRecents[3]).toBe("A2014");
expect(mostRecents[4]).toBe("P2014");
});
\ No newline at end of file