semvec/pypi-packages huggingface dataset:
django-admin-wizard 0.6.0
Django Admin dialogs and actions with intermediate forms
License: MIT
Keywords: django, admin, wizard, actions

django-admin-wizard
===================


django-admin-wizard is a Django app providing helpers for django admin actions
with intermediate forms.

[![Build Status](https://github.com/just-work/django-admin-wizard/workflows/build/badge.svg?branch=master&event=push)](https://github.com/just-work/django-admin-wizard/actions?query=event%3Apush+branch%3Amaster+workflow%3Abuild)
[![codecov](https://codecov.io/gh/just-work/django-admin-wizard/branch/master/graph/badge.svg)](https://codecov.io/gh/just-work/django-admin-wizard)
[![PyPI version](https://badge.fury.io/py/django-admin-wizard.svg)](https://badge.fury.io/py/django-admin-wizard)

Description
-----------

Do you know "delete selected" action in Django-admin? This package provides 
helpers for creating such actions with intermediate forms in two lines of code.
Also, you may add a link from django admin change page to a custom form view to
perform some form-supplied action on single object.

Installation
------------

```shell script
pip install django-admin-wizard
```

Working example is in `testproject.testapp`.

1. Add application to installed apps in django settings:
    ```python
    INSTALLED_APPS.append('admin_wizard')
    ```
2. And an action to your admin:
    ```python
    from django.contrib import admin
    from admin_wizard.admin import UpdateAction
    
    from testproject.testapp import forms, models
   
   
    @admin.register(models.MyModel)
    class MyModelAdmin(admin.ModelAdmin):
        actions = [UpdateAction(form_class=forms.RenameForm)]
    ```
3. Add custom view to your admin:
    ```python
    from django.contrib import admin
    from django.urls import path
    from admin_wizard.admin import UpdateDialog
    
    from testproject.testapp import forms, models
   
   
    @admin.register(models.MyModel)
    class MyModelAdmin(admin.ModelAdmin):
   
        def get_urls(self):
            urls = [
                path('<int:pk>/rename/',
                     UpdateDialog.as_view(model_admin=self,
                                          model=models.MyModel,
                                          form_class=forms.RenameForm),
                     name='rename')
            ]
            return urls + super().get_urls()

    ```
4. Add a link to custom dialog in admin change page:
    ```python
    from django.contrib import admin
    from django.urls import reverse
    
    from testproject.testapp import models
   
  
    @admin.register(models.MyModel)
    class MyModelAdmin(admin.ModelAdmin):
       readonly_fields = ('update_obj_url',)
   
       def update_obj_url(self, obj):
           # FIXME: it's XSS, don't copy-paste
           url = reverse('admin:rename', kwargs=dict(pk=obj.pk))
           return f'<a href="{url}">Rename...</a>'
       update_obj_url.short_description = 'rename'
    ```

Now you have "rename" action in changelist and "rename" link in change view.
Enjoy :)
django-admin-smoke 0.6.0
Smoke tests library for Django Admin
License: MIT
Keywords: django, admin, smoke, tests

Django-admin-smoke
==================

Django-Admin-Smoke is a Django app providing smoke tests for django-admin.

![build](https://github.com/just-work/django-admin-smoke/workflows/build/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/just-work/django-admin-smoke/branch/master/graph/badge.svg)](https://codecov.io/gh/just-work/django-admin-smoke)
[![PyPI version](https://badge.fury.io/py/django-admin-smoke.svg)](https://badge.fury.io/py/django-admin-smoke)

Installation
------------

```shell script
pip install django-admin-smoke
```

Usage
-----

Full example located at `testproject.testapp.tests`

```python

from admin_smoke.tests import AdminTests, AdminBaseTestCase
from testproject.testapp import admin, models


class ProjectAdminTestCase(AdminTests, AdminBaseTestCase):
    model_admin = admin.ProjectAdmin  # ModelAdmin to test
    model = models.Project  # Django model to test against
    object_name = 'project'  # self.project is an edited object in this testcase
    excluded_fields = ['client']  #  fields excluded from presence check

    def setUp(self):
        super().setUp()
        # We need existing object to test editing and deleting
        self.project = models.Project.objects.create(name='first')
        # All inlines for tested model admin should be non-empty, so we fill
        # all related models.
        self.task = models.Task.objects.create(name='first',
                                               project=self.project)

    def transform_to_new(self, data: dict) -> dict:
        # Creating a new object is tested with following algorithm:
        # 1. Open "edit" page for existing object
        # 2. Clear PK value in form data
        # 3. Clear PK values for all related objects in admin inlines
        # 4. Clear FK values pointing to existing object in admin inlines
        # 5. POST resulting data to "add" page
        # This algorithm need some help with unique fields and other constraints
        # and restrictions, so there is a hook for making newly created object
        # valid.

        data = data.copy()
        # Project.name is unique, making new value
        data['name'] += 'new'
        # Manually reset PK/FK values in admin inlines
        self.reset_inline_data(
            data,        # form data
            'task_set',  # name of inline prefix - it's FK's related_name 
            'project'    # name of edited object FK field (FK.name)
        )
        # Task.name is also unique, it should be changed properly
        data['task_set-0-name'] += '_new'
        return data

    def prepare_deletion(self):
        # To delete an object with FK's with models.PROTECT behavior we need
        # a hook to delete it manually before POST delete confirmation.
        self.task.delete()
```

Happy testing and non-smoky admins :)