Exemple #1
0
    def create(self, request, *args, **kwargs):
        country_name = request.data.get("name", None)
        country, created = Country.objects.get_or_create(name=country_name)
        context = {"request": request}
        serializer = CountrySerializer(country, context=context)
        if created:
            return http_201_created(serializer.data)

        return http_200_ok(serializer.data)
Exemple #2
0
 def create(self, request, *args, **kwargs):
     city_name = request.data.get("name", None)
     country = request.data.get("country", None)
     country_id = country.get("pk", None)
     try:
         country = Country.objects.get(pk=int(country_id))
     except:
         return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
     city, created = City.objects.get_or_create(name=city_name, country=country)
     context = {"request": request}
     serializer = CitySerializer(city, context=context)
     if created:
         return http_201_created(serializer.data)
     return http_200_ok(serializer.data)
Exemple #3
0
 def create(self, request, *args, **kwargs):
     subjects_name = request.data.get("names", None)
     university_id = request.data.get("university", None)
     user = request.data.get("user", None)
     user_id = user.get("pk", None)
     #try:
     user = UserProfile.objects.get(pk=user_id)
     for subject_name in subjects_name:
         try:
             university = University.objects.get(pk=int(university_id))
         except:
             return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
         if subject_name != "" and subject_name != None:
             subject, created = Subject.objects.get_or_create(name=subject_name, university=university)
             user.subjects.add(subject)
     user.save()
     return http_201_created()
Exemple #4
0
    def create(self, request, *args, **kwargs):
        university_name = request.data.get("name", None)
        city = request.data.get("city", None)
        city_id = city.get("pk", None)
        try:
            city = City.objects.get(pk=int(city_id))
        except:
            return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
        university, created = University.objects.get_or_create(name=university_name, city=city)
        if created:
            latLng = getLatLngData(university.name, university.city.name)
            university.latitude = latLng['lat']
            university.longitude = latLng['lng']
            university.save()

        context = {"request": request}
        serializer = UniversitySerializer(university, context=context)
        if created:
            return http_201_created(serializer.data)
        return http_200_ok(serializer.data)