How to use the restless.exceptions.BadRequest function in restless

To help you get started, we’ve selected a few restless examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github toastdriven / restless / tests / test_serializers.py View on Github external
def test_deserialize_invalid(self):
        with self.assertRaises(BadRequest):
            self.serializer.deserialize('not valid!')
github dbca-wa / oim-cms / organisation / api.py View on Github external
def update(self, guid):
        """Update view to handle changes to a DepartmentUser object.
        This view also handles marking users as 'Inactive' or 'Deleted'
        within AD.
        """
        try:
            user = DepartmentUser.objects.get(ad_guid=guid)
        except DepartmentUser.DoesNotExist:
            try:
                user = DepartmentUser.objects.get(email__iexact=guid.lower())
            except DepartmentUser.DoesNotExist:
                raise BadRequest('Object not found')

        LOGGER.info('Updating user guid/email {}'.format(guid))

        try:
            if 'EmailAddress' in self.data and self.data['EmailAddress']:
                user.email = self.data['EmailAddress'].lower()
            elif 'email' in self.data and self.data['email']:
                user.email = self.data['email'].lower()
            if 'DisplayName' in self.data and self.data['DisplayName']:
                user.name = self.data['DisplayName']
            elif 'name' in self.data and self.data['name']:
                user.name = self.data['name']
            if 'SamAccountName' in self.data and self.data['SamAccountName']:
                user.username = self.data['SamAccountName']
            elif 'username' in self.data and self.data['username']:
                user.username = self.data['username']
github toastdriven / restless / restless / serializers.py View on Github external
``deserialize_detail``.

        Has no built-in smarts, simply loads the JSON.

        :param body: The body of the current request
        :type body: string

        :returns: The deserialized data
        :rtype: ``list`` or ``dict``
        """
        try:
            if isinstance(body, bytes):
                return json.loads(body.decode('utf-8'))
            return json.loads(body)
        except ValueError:
            raise BadRequest('Request body is not valid JSON')
github okfn-brasil / open-jus / justa / backend / justa / core / views.py View on Github external
def create(self):
        form = CourtOrderForm(self.data)
        if not form.is_valid():
            raise BadRequest(form.errors)

        return form.save()
github dbca-wa / oim-cms / organisation / api.py View on Github external
def create(self):
        """Call this endpoint from on-prem AD or from Azure AD.
        Match either AD-object key values or Departmentuser field names.
        """
        user = DepartmentUser()
        # Check for essential request params.
        if 'EmailAddress' not in self.data and 'email' not in self.data:
            raise BadRequest('Missing email parameter value')
        if 'DisplayName' not in self.data and 'name' not in self.data:
            raise BadRequest('Missing name parameter value')
        if 'SamAccountName' not in self.data and 'username' not in self.data:
            raise BadRequest('Missing account name parameter value')

        # Make an assumption that EmailAddress or email is passed in.
        if 'EmailAddress' in self.data:
            LOGGER.info('Creating user {}'.format(self.data['EmailAddress'].lower()))
        else:
            LOGGER.info('Creating user {}'.format(self.data['email'].lower()))

        # Required: email, name and sAMAccountName.
        if 'EmailAddress' in self.data:
            user.email = self.data['EmailAddress'].lower()
        elif 'email' in self.data:
            user.email = self.data['email'].lower()
        if 'DisplayName' in self.data:
            user.name = self.data['DisplayName']
github dbca-wa / oim-cms / organisation / api.py View on Github external
def create(self):
        """Call this endpoint from on-prem AD or from Azure AD.
        Match either AD-object key values or Departmentuser field names.
        """
        user = DepartmentUser()
        # Check for essential request params.
        if 'EmailAddress' not in self.data and 'email' not in self.data:
            raise BadRequest('Missing email parameter value')
        if 'DisplayName' not in self.data and 'name' not in self.data:
            raise BadRequest('Missing name parameter value')
        if 'SamAccountName' not in self.data and 'username' not in self.data:
            raise BadRequest('Missing account name parameter value')

        # Make an assumption that EmailAddress or email is passed in.
        if 'EmailAddress' in self.data:
            LOGGER.info('Creating user {}'.format(self.data['EmailAddress'].lower()))
        else:
            LOGGER.info('Creating user {}'.format(self.data['email'].lower()))

        # Required: email, name and sAMAccountName.
        if 'EmailAddress' in self.data:
            user.email = self.data['EmailAddress'].lower()
        elif 'email' in self.data:
            user.email = self.data['email'].lower()
github dbca-wa / oim-cms / organisation / api.py View on Github external
def create(self):
        """Call this endpoint from on-prem AD or from Azure AD.
        Match either AD-object key values or Departmentuser field names.
        """
        user = DepartmentUser()
        # Check for essential request params.
        if 'EmailAddress' not in self.data and 'email' not in self.data:
            raise BadRequest('Missing email parameter value')
        if 'DisplayName' not in self.data and 'name' not in self.data:
            raise BadRequest('Missing name parameter value')
        if 'SamAccountName' not in self.data and 'username' not in self.data:
            raise BadRequest('Missing account name parameter value')

        # Make an assumption that EmailAddress or email is passed in.
        if 'EmailAddress' in self.data:
            LOGGER.info('Creating user {}'.format(self.data['EmailAddress'].lower()))
        else:
            LOGGER.info('Creating user {}'.format(self.data['email'].lower()))

        # Required: email, name and sAMAccountName.
        if 'EmailAddress' in self.data:
            user.email = self.data['EmailAddress'].lower()
        elif 'email' in self.data:
            user.email = self.data['email'].lower()
        if 'DisplayName' in self.data:
            user.name = self.data['DisplayName']
        elif 'name' in self.data:
            user.name = self.data['name']