-
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.
- Loading branch information
0 parents
commit 7f0d7fa
Showing
22 changed files
with
1,196 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CD | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
python -m build | ||
twine upload dist/* |
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,55 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9 | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install .[dev] | ||
- name: Run Ruff | ||
run: ruff check . | ||
- name: Run Ruff Format | ||
run: ruff format --check . | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: [3.7, 3.8, 3.9, "3.10"] | ||
django-version: [3.2, 4.0, 4.1, 4.2] | ||
exclude: | ||
# Django 4.0+ requires Python 3.8+ | ||
- python-version: 3.7 | ||
django-version: 4.0 | ||
- python-version: 3.7 | ||
django-version: 4.1 | ||
- python-version: 3.7 | ||
django-version: 4.2 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install "Django==${{ matrix.django-version }}.*" | ||
python -m pip install selenium webdriver-manager | ||
- name: Run Tests | ||
run: | | ||
python -m unittest discover django_modal_actions/tests |
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,14 @@ | ||
*.pyc | ||
__pycache__ | ||
.DS_Store | ||
.coverage | ||
.tox/ | ||
*.db | ||
*sqlite | ||
.venv | ||
.idea | ||
.env | ||
build/* | ||
dist/* | ||
*.egg-info | ||
.DS_Store |
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,5 @@ | ||
## Version 0.1.0 (September 02, 2024) | ||
|
||
--- | ||
|
||
Initial release! |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024, Michael Gendy | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
include LICENSE | ||
include README.md | ||
recursive-include django_modal_actions/static * | ||
recursive-include django_modal_actions/templates * |
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,101 @@ | ||
# Django Modal Actions | ||
|
||
Django Modal Actions is a reusable Django app that provides a convenient way to add modal-based actions to your Django admin interface. It allows you to create custom actions that open in a modal dialog, enhancing the user experience and functionality of your Django admin. | ||
|
||
## Features | ||
|
||
- Easy integration with Django admin | ||
- Support for both list-view and object-view actions | ||
- Customizable modal forms | ||
- AJAX-based form submission | ||
|
||
## Requirements | ||
|
||
- Python (>= 3.7) | ||
- Django (>= 3.2) | ||
|
||
## Installation | ||
|
||
1. Install the package using pip: | ||
|
||
``` | ||
pip install django-modal-actions | ||
``` | ||
|
||
2. Add `'django_modal_actions'` to your `INSTALLED_APPS` setting: | ||
|
||
```python | ||
INSTALLED_APPS = [ | ||
... | ||
'django_modal_actions', | ||
... | ||
] | ||
``` | ||
|
||
## Usage | ||
|
||
1. In your `admin.py`, import the necessary components: | ||
|
||
```python | ||
from django.contrib import admin | ||
from django_modal_actions import ModalActionMixin, modal_action | ||
``` | ||
|
||
2. Create a custom admin class that inherits from `ModalActionMixin` and your base admin class: | ||
|
||
```python | ||
@admin.register(YourModel) | ||
class YourModelAdmin(ModalActionMixin, admin.ModelAdmin): | ||
modal_actions = ["your_object_action"] | ||
list_modal_actions = ["your_list_action"] | ||
|
||
@modal_action(modal_header="Object Action") | ||
def your_object_action(self, request, obj, form_data=None): | ||
# Your object action logic here | ||
return "Action completed successfully" | ||
|
||
@modal_action(modal_header="List Action") | ||
def your_list_action(self, request, queryset, form_data=None): | ||
# Your list action logic here | ||
return f"Action completed on {queryset.count()} items" | ||
``` | ||
|
||
3. If you need a custom form for your action, create a form class: | ||
|
||
```python | ||
from django import forms | ||
|
||
class CustomForm(forms.Form): | ||
name = forms.CharField(label="Name", required=True) | ||
|
||
def clean_name(self): | ||
name = self.cleaned_data["name"] | ||
if name == "bad": | ||
raise forms.ValidationError("Name cannot be 'bad'") | ||
return name | ||
``` | ||
|
||
Then, use it in your action: | ||
|
||
```python | ||
@modal_action(modal_header="Action with Form", form_class=CustomForm) | ||
def your_action_with_form(self, request, obj, form_data=None): | ||
# Your action logic here | ||
return f"Action completed with name: {form_data['name']}" | ||
``` | ||
|
||
## Testing | ||
|
||
To run the tests, execute: | ||
|
||
``` | ||
python -m unittest discover django_modal_actions/tests | ||
``` | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please feel free to submit a Pull Request. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. |
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,6 @@ | ||
from .mixins import ModalActionMixin, modal_action | ||
|
||
__all__ = ["ModalActionMixin", "modal_action"] | ||
|
||
|
||
default_app_config = "django_modal_actions.apps.DjangoModalActionsConfig" |
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,9 @@ | ||
import os | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class DjangoModalActionsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "django_modal_actions" | ||
path = os.path.dirname(os.path.abspath(__file__)) |
Oops, something went wrong.