Пример #1
0
Файл: api.py Проект: 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()
Пример #2
0
Файл: api.py Проект: 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)
Пример #3
0
Файл: api.py Проект: 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()
Пример #4
0
Файл: api.py Проект: 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()
Пример #5
0
Файл: api.py Проект: marved/tfg
 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()
Пример #6
0
Файл: api.py Проект: marved/tfg
    def post(self, request, format=None):
        form = LoginFormValidator(request.data)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            user = authenticate(username=username, password=password)
            if user is None:
                return http_401_not_authorized(INVALID_CREDENTIALS_ERROR_MSG)
            else:
                if user.is_active:
                    login(request, user)
                    context = {"request": request}
                    serializer = UserProfileSerializer(user, context=context)
                    return Response(serializer.data)
                else:
                    return http_401_not_authorized(INVALID_CREDENTIALS_ERROR_MSG)
        else:
            return http_400_bad_request(form.errors)
Пример #7
0
Файл: api.py Проект: 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)
Пример #8
0
Файл: api.py Проект: 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()