semvec/pypi-packages huggingface dataset:
django-presentable-exception 0.0.1
Presentable Exceptions for Django Restframework Projects
License: Apache2
Requires Python: >=3

Presentable Exceptions
======================

This is a module for django restframework, in which modules can specifiy exceptions in an
extra file with an key an description. At some place in the code, they can be fetched by 
the package and key and bubble up to the view. Here a mixin detects them and creates a 
proper response for an fat-client, which can show them then to to user - thus the exceptions
are presentable.

Getting started
---------------

Say, you have a module, like `auth_api` which is registered in `INSTALLED_APPS` in the Django
`settings.py`. Create a new file `auth_api/presentable_exceptions.py` with this content

```python
presentable_exceptions = {
    'client': [
        ('not-enough-data-to-delete-user', 'You did not provide enough data, that we can delete the user {username}')
    ],
    'server': [
        ('backend-connection-lost', 'We lost the connection to the backend'),
    ]
}
```

This file can be in every module and consists of two parts: The exceptions, that are the clients 
fault and the exceptions that are our fault. The first will cause a 4xx error, the latter a 5xx.

Say, you have now an View somewhere, like that:

```python
class MeView(WithPresentableException, APIView):

    def get(self, request):
        data = some_function_with_a_deep_call_stack()
        return Response(data)
```

This will call multiple function and somewhere there is the function `boom()` called:

```python
def boom():
    raise PresentableException.of('auth_api', 'backend-connection-lost')


def some_function_with_a_deep_call_stack():
    # ...
    boom()
    # ...
```

This `PresentableException` will be an `PresentableServerException` and bubble up into 
the Mixing `WithPresentableException` specified in the view above, which generates 
a proper response (with a 5xx code in this case).
find-class 0.0.1
Finds a python-thing, like a class, a function or a variable by string and loads it
License: Apache2
Requires Python: >=3

find_class
==========

This little package finds and loads a class by fully qualified string.

Let's assume there is a file in `package/sub/animal.py` with 

```python
class Animal:  
    def say_somthing(self):
        return 'wau'

def a_little_function():
    return 'wuff'

a_tone = 'wiiiiii'
```

Then, you can use `find_class` to get from a string to the python-thing:

```python
a = find_class('package.sub.animal.Animal')().say_something()
b = find_class('package.sub.animal.a_little_function')()
c = find_class('package.sub.animal.a_tone')

assert a == 'wau'
assert b == 'wuff'
assert c == 'wiiiiii'
```
exception-safe 0.0.3
Catch all exceptions and return None
License: Apache2
Requires Python: >=3

Safe
====

This is quite a simple package. It catches all exceptions within a given 
callable and returns None, if they occur and the return-value of the 
callable if not.

```python

def boom():
    raise Exception()
    return 1

def non_boom():
    return 2

a = safe(lambda: boom())
b = safe(lambda: non_boom())

assert a == None
assert b == 2
```
django-save-deep 0.0.2
Safes a complete tree of django models - from bottom to top.
License: Apache2
Requires Python: >=3

save_deep
=========

This package first saves all the children of the given oject and then the object itself. 
It solves the error:
`ValueError: save() prohibited to prevent data loss due to unsaved related object '<<foreign_object>>'.`

Note: it does not work (yet) with circular dependencies

Example
-------

Say you have this this model

```python

class Company(models.Model):
    name = models.CharField(max_length=256)

class Employee(models.Model):
    username = models.CharField(max_length=256)
    company = models.ForeignKey(Company, on_delete=models.CASCADE)
```

If you try to do

```python
Employee(username='tom', company=Company(name='some-name')).save()
```

you get

```
ValueError: save() prohibited to prevent data loss due to unsaved related object '<<foreign_object>>'.
```

But if you use save_deep, the company is saved first, then the employee

```python
employee = save_deep(Employee(username='tom', company=Company(name='some-name')))
```

This works with a deeply nested object-tree and with updates (and update/create-mixes) as well as long 
as there are no circular dependencies.