class UpdateAccountInfo(LoginRequiredMixin, View): """ View for update information about account of user """ def post(self, request, *args, **kwargs): if request.is_ajax(): result = dict() status = 200 try: if request.FILES: coordinates_x1 = int(request.POST.get('coordinates[x1]')) coordinates_y1 = int(request.POST.get('coordinates[y1]')) coordinates_x2 = int(request.POST.get('coordinates[x2]')) coordinates_y2 = int(request.POST.get('coordinates[y2]')) field = 'account_user_info-picture' value = request.FILES[field] new = {field: value} account_info = AccountUserInfo.objects.get(account=self.request.user) account_info.picture = value account_info.full_clean() account_info.save() picture_file = Image.open(account_info.picture.path) cropped_picture = picture_file.crop([coordinates_x1, coordinates_y1, coordinates_x2, coordinates_y2]) cropped_picture.save(account_info.picture.path) result['new_image_url'] = account_info.picture.url else: field = self.request.POST['field'] value = self.request.POST['value'] if field == 'datetimepicker_for_birthday_account': correct_field = 'birthday' else: correct_field = field.replace('account_user_info-', '') new = {correct_field: value} account_info = AccountUserInfo.objects.filter(account=self.request.user) AccountUserInfo(**new).full_clean(exclude=['account']) account_info.update(**new) account_info = AccountUserInfo.objects.get(account=self.request.user) result['new_value_progresbar_filling_account_info'] = account_info.filling_account_info() except BaseException as errors: result = dict(errors) status = 400 return JsonResponse(data=result, status=status)