def post(self, request): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): serializer.save() msg = strings.registerSuccessFullymessage return response(condition=1, message=msg, status=status.HTTP_200_OK) else: return response(condition=0, message=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): serializer = self.serializer_class(data=request.data, context={"user": request.user}) if serializer.is_valid(): serializer.save() msg = strings.agent_create_succesFully return response(condition=1, message=msg, status=status.HTTP_200_OK) else: return response(condition=0, message=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request): msg = { "cities": strings.CITY, "fields": strings.FIELD, "levels": strings.LEVEL, } return response(1, msg, status.HTTP_200_OK)
def patch(self, request): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): student = request.user.student print(student) student.field = serializer.validated_data.get("field") student.level = serializer.validated_data.get("level") student.father_name = serializer.validated_data.get("father_name") student.father_phone_number = serializer.validated_data.get( "father_phone_number") student.save() msg = strings.student_edu_change return response(condition=1, message=msg, status=status.HTTP_200_OK) else: return response(condition=0, message=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request): profile = Profile.objects.create_user(first_name="center", last_name="center", password="******", username="******", city="tehran", user_type="center", phone_number="9129370910") profile.save() center = Center.objects.create(profile=profile) center.save() return response(1, "center create success", status=status.HTTP_200_OK)
def patch(self, request): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): password = serializer.validated_data.get("password") user = request.user if user.check_password(password): newpassword = serializer.validated_data.get("newpassword") user.set_password(newpassword) user.save() msg = strings.password_change return response(condition=1, message=msg, status=status.HTTP_200_OK) else: msg = strings.wrong_password return response(condition=0, message=msg, status=status.HTTP_401_UNAUTHORIZED) else: return response(condition=0, message=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def patch(self, request): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): username = serializer.validated_data.get("username") phone_number = serializer.validated_data.get("phone_number") try: profile = Profile.objects.get(username=username, phone_number=phone_number) profile.set_password(profile.phone_number) profile.save() msg = strings.password_changed_to_phone_number return response(condition=1, message=msg, status=status.HTTP_200_OK) except: msg = strings.user_dosent_exist return response(condition=0, message=msg, status=status.HTTP_401_UNAUTHORIZED) else: return response(condition=0, message=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request): student = request.user.student student.birth_certificate = None student.save() msg = strings.profile_image_delete_success return response(condition=1, message=msg, status=status.HTTP_200_OK)
def get(self, request): student = request.user.student serializer = self.serializer_class(student) msg = serializer.data return response(condition=1, message=msg, status=status.HTTP_200_OK)
def get(self, request): user = request.user profie = self.serializer_class(user) msg = profie.data return response(condition=1, message=msg, status=status.HTTP_200_OK)
def delete(self, request): user = request.user user.image = None user.save() msg = strings.profile_image_delete_success return response(condition=1, message=msg, status=status.HTTP_200_OK)
def get(self, request): return response(1, strings.CITY, status.HTTP_200_OK)