-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add type annotations and restructure
- re-init project with cookiecutter - add type annotations - upgrade docs - remove form_button, use django-form-button instead
- Loading branch information
Showing
18 changed files
with
153 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
name: Upload Python Package | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
- release | ||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: python -m build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.x" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: python -m build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include LICENSE | ||
include README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,67 @@ | ||
# django-form-action | ||
|
||
Django action/button with an intermediate page to parse data from a form | ||
Django action with an intermediate page to parse data from a form | ||
|
||
## Installation | ||
|
||
Just install the pakage from PyPI | ||
You can install the package via pip: | ||
|
||
``` | ||
pip install django-form-action | ||
``` | ||
|
||
## Demo | ||
|
||
![Step 1](docs/step1.png) | ||
![Step 2](docs/step2.png) | ||
![Step 3](docs/step3.png) | ||
|
||
## Usage | ||
|
||
Django admin action with form | ||
![Demo Form Action](https://raw.githubusercontent.com/sandbox-pokhara/django-form-action/master/demo/form-action.gif) | ||
Example usage showing an action in UserAdmin which has an intermediate form that parses data on how to perform that action. | ||
|
||
```python | ||
from typing import Any | ||
|
||
from django.contrib import admin | ||
from django.contrib import messages | ||
from django.contrib.auth.admin import UserAdmin | ||
from django.contrib.auth.models import User | ||
from django.db.models import QuerySet | ||
from django.forms import CharField | ||
from django.forms import Form | ||
from django.http import HttpRequest | ||
|
||
from dummyapp.models import Fruit | ||
from form_action import form_action | ||
|
||
|
||
class MyForm(Form): | ||
message = CharField() | ||
|
||
|
||
@form_action(MyForm, description="Do some task") | ||
def my_action(modeladmin, request, queryset, form): | ||
msg = form.cleaned_data["message"] | ||
messages.add_message(request, messages.INFO, f"Got message: {msg}") | ||
|
||
from django_form_action import form_action | ||
|
||
@admin.register(Fruit) | ||
class MyModelAdmin(admin.ModelAdmin): | ||
actions = [my_action] | ||
``` | ||
|
||
Or use it as an extra button with form | ||
![Demo Extra Button](https://raw.githubusercontent.com/sandbox-pokhara/django-form-action/master/demo/extra-button.gif) | ||
admin.site.unregister(User) | ||
|
||
```python | ||
from django.contrib import admin | ||
from django.forms import CharField | ||
from django.forms import Form | ||
from django.http.response import HttpResponse | ||
|
||
from dummyapp.models import Fruit | ||
from form_action.decorators import extra_button | ||
from form_action.mixins import ExtraButtonMixin | ||
class ChangeFirstName(Form): | ||
first_name = CharField() | ||
|
||
|
||
class MyForm(Form): | ||
message = CharField() | ||
@form_action(ChangeFirstName, "Change selected users' first name") | ||
def change_first_name( | ||
modeladmin: Any, | ||
request: HttpRequest, | ||
queryset: QuerySet[User], | ||
form: ChangeFirstName, | ||
): | ||
queryset.update(first_name=form.cleaned_data["first_name"]) | ||
messages.add_message( | ||
request, | ||
messages.INFO, | ||
"Successfully changed the first name of selected users.", | ||
) | ||
|
||
|
||
@extra_button("Test Button", MyForm) | ||
def test(request, form): | ||
msg = form.cleaned_data["message"] | ||
return HttpResponse(f"Got message: {msg}") | ||
@admin.register(User) | ||
class CustomUserAdmin(UserAdmin): | ||
actions = [change_first_name] | ||
|
||
``` | ||
|
||
@admin.register(Fruit) | ||
class MyModelAdmin(ExtraButtonMixin, admin.ModelAdmin): | ||
extra_buttons = [test] | ||
## License | ||
|
||
``` | ||
This project is licensed under the terms of the MIT license. |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django_form_action.decorators import form_action | ||
|
||
__version__ = "2.0.0" | ||
__all__ = ["form_action"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.