Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mng-dev-ai committed Sep 2, 2024
0 parents commit 7f0d7fa
Show file tree
Hide file tree
Showing 22 changed files with 1,196 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/CD.yml
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/*
55 changes: 55 additions & 0 deletions .github/workflows/CI.yml
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
14 changes: 14 additions & 0 deletions .gitignore
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Version 0.1.0 (September 02, 2024)

---

Initial release!
21 changes: 21 additions & 0 deletions LICENCE
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.
4 changes: 4 additions & 0 deletions MANIFEST.in
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 *
101 changes: 101 additions & 0 deletions README.md
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.
6 changes: 6 additions & 0 deletions django_modal_actions/__init__.py
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"
9 changes: 9 additions & 0 deletions django_modal_actions/apps.py
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__))
Loading

0 comments on commit 7f0d7fa

Please sign in to comment.