Esempio n. 1
0
File: api.py Progetto: marved/tfg
    def create(self, request, *args, **kwargs):
        user_id = request.data.get("userId", None)
        body = request.data.get("body", None)
        university_id = request.data.get("universityId", None)
        subject_id = request.data.get("subjectId", None)
        date = datetime.datetime.now()

        #try:
        user = UserProfile.objects.get(pk=user_id)
        if subject_id != None:
            subject = Subject.objects.get(pk=subject_id)
        else:
            subject = None
        if university_id != None:
            university = University.objects.get(pk=university_id)
        else:
            university = None

        comment = Comment.objects.create(user=user,
                                         body=body.encode("utf-8"),
                                         university=university,
                                         subject=subject,
                                         dateTime=date)
        comment.save()
        #except:
         #   return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)

        return http_200_ok()
Esempio n. 2
0
File: api.py Progetto: marved/tfg
    def partial_update(self, request, *args, **kwargs):
        form = PasswordFormValidator(request.data)
        if form.is_valid():
            new_password = form.cleaned_data['newPassword']
            current_password = form.cleaned_data['currentPassword']

            user_id = kwargs.get("pk", None)
            user = UserProfile.objects.get(pk=user_id)
            if user.check_password(current_password.encode("utf-8")):
                user.set_password(new_password.encode("utf-8"))
                user.save()

        else:
            subjects_id = request.data.get("subjects", None)
            user_id = kwargs.get("pk", None)
            #try:
            user = UserProfile.objects.get(pk=int(user_id))
            for subject_id in subjects_id:
                try:
                    subject = Subject.objects.get(pk=subject_id)
                except:
                    return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
                user.subjects.add(subject)
            user.save()

        return http_200_ok()
Esempio n. 3
0
File: api.py Progetto: marved/tfg
    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)
Esempio n. 4
0
File: api.py Progetto: marved/tfg
 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)
Esempio n. 5
0
File: api.py Progetto: marved/tfg
 def partial_update(self, request, *args, **kwargs):
     description = request.data.get("description", None)
     contacts = request.data.get("contacts", None)
     university_id = kwargs.get("pk", None)
     try:
         university = University.objects.get(pk=int(university_id))
     except:
         return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
     university.description = description.encode("utf-8")
     university.contacts = contacts.encode("utf-8")
     university.save()
     context = {"request": request}
     serializer = UniversitySerializer(university, context=context)
     return http_200_ok()
Esempio n. 6
0
File: api.py Progetto: marved/tfg
 def partial_update(self, request, *args, **kwargs):
     description = request.data.get("description", None)
     validation_subjects = request.data.get("validationSubjects", None)
     credits_ects = request.data.get("creditsEcts", None)
     subject_id = kwargs.get("pk", None)
     try:
         subject = Subject.objects.get(pk=int(subject_id))
     except:
         return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
     subject.description = description.encode("utf-8")
     subject.validation_subjects = validation_subjects.encode("utf-8")
     subject.credits_ects = credits_ects
     subject.save()
     context = {"request": request}
     serializer = SubjectSerializer(subject, context=context)
     return http_200_ok()
Esempio n. 7
0
File: api.py Progetto: marved/tfg
    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)
Esempio n. 8
0
File: api.py Progetto: marved/tfg
 def partial_update(self, request, *args, **kwargs):
     infoCity = request.data.get("infoCity", None)
     description = infoCity.get("description", None)
     lodging = infoCity.get("lodging", None)
     transport = infoCity.get("transport", None)
     prices = infoCity.get("prices", None)
     mobile_phone = infoCity.get("mobilePhone", None)
     weather = infoCity.get("weather", None)
     student_life = infoCity.get("studentLife", None)
     nightlife = infoCity.get("nightlife", None)
     bank_account = infoCity.get("bankAccount", None)
     restaurants = infoCity.get("restaurants", None)
     shopping = infoCity.get("shopping", None)
     culture = infoCity.get("culture", None)
     tourism = infoCity.get("tourism", None)
     information_interest = infoCity.get("informationInterest", None)
     city_id = kwargs.get("pk", None)
     try:
         city = City.objects.get(pk=int(city_id))
     except:
         return http_400_bad_request(INVALID_CREDENTIALS_ERROR_MSG)
     city.description = description.encode("utf-8")
     city.lodging = lodging.encode("utf-8")
     city.transport = transport.encode("utf-8")
     city.prices = prices.encode("utf-8")
     city.mobile_phone = mobile_phone.encode("utf-8")
     city.weather = weather.encode("utf-8")
     city.student_life = student_life.encode("utf-8")
     city.nightlife = nightlife.encode("utf-8")
     city.bank_account = bank_account.encode("utf-8")
     city.restaurants = restaurants.encode("utf-8")
     city.shopping = shopping.encode("utf-8")
     city.culture = culture.encode("utf-8")
     city.tourism = tourism.encode("utf-8")
     city.information_interest = information_interest.encode("utf-8")
     city.save()
     context = {"request": request}
     serializer = CitySerializer(city, context=context)
     return http_200_ok()