Unverified Commit c947cc1e authored by Maxime Emschwiller's avatar Maxime Emschwiller Committed by Florent Chehab
Browse files

refacto(backend) : delete old campus and city models

parent a023e005
...@@ -4,8 +4,6 @@ from reversion_compare.admin import CompareVersionAdmin ...@@ -4,8 +4,6 @@ from reversion_compare.admin import CompareVersionAdmin
from backend_app.models.abstract.versionedEssentialModule import ( from backend_app.models.abstract.versionedEssentialModule import (
VersionedEssentialModule, VersionedEssentialModule,
) )
from backend_app.models.campus import Campus
from backend_app.models.city import City
from backend_app.models.country import Country from backend_app.models.country import Country
from backend_app.models.countryDri import CountryDri from backend_app.models.countryDri import CountryDri
from backend_app.models.countryScholarship import CountryScholarship from backend_app.models.countryScholarship import CountryScholarship
...@@ -33,8 +31,6 @@ from base_app.models import SiteInformation ...@@ -33,8 +31,6 @@ from base_app.models import SiteInformation
ALL_MODELS = [ ALL_MODELS = [
SiteInformation, SiteInformation,
Campus,
City,
Country, Country,
CountryDri, CountryDri,
CountryScholarship, CountryScholarship,
......
# Generated by Django 2.1.7 on 2020-05-03 13:14
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("backend_app", "0002_auto_20200417_1430")]
operations = [
migrations.AlterUniqueTogether(name="campus", unique_together=set()),
migrations.RemoveField(model_name="campus", name="city"),
migrations.RemoveField(model_name="campus", name="university"),
migrations.RemoveField(model_name="city", name="country"),
migrations.DeleteModel(name="Campus"),
migrations.DeleteModel(name="City"),
]
from django.core.validators import MinValueValidator, MaxValueValidator
from django.db import models
from backend_app.models.abstract.base import (
BaseModel,
BaseModelSerializer,
BaseModelViewSet,
)
from backend_app.models.city import City
from backend_app.models.university import University
from backend_app.permissions.app_permissions import ReadOnly
class Campus(BaseModel):
is_main_campus = models.BooleanField(null=False)
name = models.CharField(max_length=200, default="", blank=True)
city = models.ForeignKey(City, on_delete=models.PROTECT, null=False)
university = models.ForeignKey(
University,
on_delete=models.PROTECT,
null=False,
related_name="university_campuses",
)
lat = models.DecimalField(
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-85.05112878), MaxValueValidator(85.05112878)],
)
lon = models.DecimalField(
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-180), MaxValueValidator(180)],
)
def location(self):
return {"lat": self.lat, "lon": self.lon}
class Meta:
unique_together = ("is_main_campus", "university")
def save(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
def delete(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
class CampusSerializer(BaseModelSerializer):
class Meta:
model = Campus
fields = BaseModelSerializer.Meta.fields + (
"is_main_campus",
"name",
"city",
"university",
"lat",
"lon",
)
class CampusViewSet(BaseModelViewSet):
permission_classes = (ReadOnly,)
queryset = Campus.objects.all() # pylint: disable=E1101
serializer_class = CampusSerializer
end_point_route = "campuses-deprecated"
class MainCampusViewSet(BaseModelViewSet):
queryset = Campus.objects.filter(is_main_campus=True)
serializer_class = CampusSerializer
permission_classes = (ReadOnly,)
end_point_route = "mainCampuses"
from django.db import models
from backend_app.models.abstract.base import (
BaseModel,
BaseModelSerializer,
BaseModelViewSet,
)
from backend_app.models.country import Country
from backend_app.permissions.app_permissions import ReadOnly
class City(BaseModel):
name = models.CharField(max_length=200)
local_name = models.CharField(max_length=200, default="", blank=True)
# We add an area to distinguish similarly named cities
# in a country
area = models.CharField(max_length=200, default="", blank=True)
country = models.ForeignKey(Country, on_delete=models.PROTECT)
def save(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
def delete(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
class CitySerializer(BaseModelSerializer):
class Meta:
model = City
fields = BaseModelSerializer.Meta.fields + (
"name",
"local_name",
"area",
"country",
)
class CityViewSet(BaseModelViewSet):
queryset = City.objects.all() # pylint: disable=E1101
serializer_class = CitySerializer
permission_classes = (ReadOnly,)
end_point_route = "cities-deprecated"
...@@ -8,8 +8,6 @@ from rest_framework.viewsets import ViewSet ...@@ -8,8 +8,6 @@ from rest_framework.viewsets import ViewSet
from backend_app.checks import check_viewsets from backend_app.checks import check_viewsets
from backend_app.models.abstract.base import BaseModelViewSet from backend_app.models.abstract.base import BaseModelViewSet
from backend_app.models.abstract.essentialModule import EssentialModuleViewSet from backend_app.models.abstract.essentialModule import EssentialModuleViewSet
from backend_app.models.campus import CampusViewSet, MainCampusViewSet
from backend_app.models.city import CityViewSet
from backend_app.models.country import CountryViewSet from backend_app.models.country import CountryViewSet
from backend_app.models.countryDri import CountryDriViewSet from backend_app.models.countryDri import CountryDriViewSet
from backend_app.models.countryScholarship import CountryScholarshipViewSet from backend_app.models.countryScholarship import CountryScholarshipViewSet
...@@ -121,9 +119,6 @@ class ExchangeViewSet(BaseModelViewSet): ...@@ -121,9 +119,6 @@ class ExchangeViewSet(BaseModelViewSet):
ALL_API_VIEWSETS = [ ALL_API_VIEWSETS = [
SiteInformationViewSet, SiteInformationViewSet,
UserViewset, UserViewset,
CampusViewSet,
MainCampusViewSet,
CityViewSet,
CountryViewSet, CountryViewSet,
CountryDriViewSet, CountryDriViewSet,
CountryScholarshipViewSet, CountryScholarshipViewSet,
......
...@@ -25,7 +25,6 @@ import PageAboutUnlinkedPartners from "../pages/PageAboutUnlinkedPartners"; ...@@ -25,7 +25,6 @@ import PageAboutUnlinkedPartners from "../pages/PageAboutUnlinkedPartners";
import PageLogout from "../pages/PageLogout"; import PageLogout from "../pages/PageLogout";
import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper"; import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
import UniversityService from "../../services/data/UniversityService"; import UniversityService from "../../services/data/UniversityService";
// import CityService from "../../services/data/CityService";
import CountryService from "../../services/data/CountryService"; import CountryService from "../../services/data/CountryService";
import CurrencyService from "../../services/data/CurrencyService"; import CurrencyService from "../../services/data/CurrencyService";
import LanguageService from "../../services/data/LanguageService"; import LanguageService from "../../services/data/LanguageService";
...@@ -34,15 +33,12 @@ import useOnBeforeComponentMount from "../../hooks/useOnBeforeComponentMount"; ...@@ -34,15 +33,12 @@ import useOnBeforeComponentMount from "../../hooks/useOnBeforeComponentMount";
const SERVICES_TO_INITIALIZE = [ const SERVICES_TO_INITIALIZE = [
UniversityService, UniversityService,
// CityService,
CountryService, CountryService,
CurrencyService, CurrencyService,
LanguageService, LanguageService,
FilterService FilterService
]; ];
// import PageFiles from "../pages/PageFiles";
/** /**
* Main entry * Main entry
*/ */
...@@ -104,9 +100,7 @@ App.propTypes = {}; ...@@ -104,9 +100,7 @@ App.propTypes = {};
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("countries", "all"), new NetWrapParam("countries", "all"),
//new NetWrapParam("cities", "all"),
new NetWrapParam("universities", "all"), new NetWrapParam("universities", "all"),
//new NetWrapParam("mainCampuses", "all"),
new NetWrapParam("currencies", "all"), new NetWrapParam("currencies", "all"),
new NetWrapParam("languages", "all"), new NetWrapParam("languages", "all"),
new NetWrapParam("serverModerationStatus", "all") // not needed for server moderation status new NetWrapParam("serverModerationStatus", "all") // not needed for server moderation status
......
...@@ -11,12 +11,12 @@ function UnivInfoProvider({ univId, children }) { ...@@ -11,12 +11,12 @@ function UnivInfoProvider({ univId, children }) {
const univIdParsed = parseInt(univId, 10); const univIdParsed = parseInt(univId, 10);
const univ = UniversityService.getUniversityById(univIdParsed); const univ = UniversityService.getUniversityById(univIdParsed);
const country = CountryService.getCountryForCountryId(univ.country) const country = CountryService.getCountryForCountryId(univ.country)
const city = univ.city const {city} = univ.city
const countryId = country.id; const countryId = country.id;
return ( return (
<UnivContext.Provider <UnivContext.Provider
value ={{ value={{
univId: univIdParsed, univId: univIdParsed,
countryId, countryId,
univ, univ,
......
// import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap";
// import { getLatestApiReadData } from "../../hooks/useGlobalState";
// class CityService {
// /**
// * Stores the cities by its id
// * @type {Map<number, object>}
// * @private
// */
// _citiesById = new Map();
// /**
// * Must be called once before accessing other methods.
// */
// initialize() {
// const cities = this.getCities();
// this._citiesById = arrayOfInstancesToMap(cities);
// }
// /**
// * Get the city object for a city id
// *
// * @param {number} cityId
// * @returns {Object}
// */
// getCityForCityId(cityId) {
// return this._citiesById.get(cityId);
// }
// getCities() {
// return getLatestApiReadData("cities-all");
// }
// }
// export default new CityService();
// import CityService from "./CityService";
// import CountryService from "./CountryService";
import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap"; import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap";
import { getLatestApiReadData } from "../../hooks/useGlobalState"; import { getLatestApiReadData } from "../../hooks/useGlobalState";
......
Supports Markdown
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