Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 31 additions & 58 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,60 @@ name: CI/CD

on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
branches: ["master", "main"]
push:
branches:
- main
branches: ["master", "main"]
release:
types:
- published
types: [published]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: "3.11"
enable-cache: true

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Set up Python
run: uv python install 3.13

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
run: uv sync --all-extras

- name: Black with tox
run: tox -e black

- name: Isort with tox
run: tox -e isort
- name: Ruff with tox
run: uv run tox -e ruff

- name: Pylint with tox
run: tox -e pylint
run: uv run tox -e pylint

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
dj-version: [django42, django50]
python-version: ["3.12", "3.13"]
dj-version: [django52, django60]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
run: uv sync --all-extras

- name: Test with tox
run: |
PY_VERSION=${{ matrix.python-version }} &&
tox -e py${PY_VERSION//.}-${{ matrix.dj-version }}
uv run tox -e py${PY_VERSION//.}-${{ matrix.dj-version }}

release:
name: Release
Expand All @@ -93,34 +73,27 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: "3.11"
enable-cache: true

- name: Set up Python
run: uv python install 3.13

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
node-version: 22

- name: Install dependencies
run: |
npm ci
run: npm install

- name: Build JS/CSS deps
run: |
npm run build
run: npm run build

- name: Build Package
run: poetry build
run: uv build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
5 changes: 3 additions & 2 deletions django_admin_shellx/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib

from django.apps import AppConfig


Expand All @@ -7,7 +9,6 @@ class DjangoAdminShellX(AppConfig):

def ready(self):
try:
# pylint: disable=unused-import, import-outside-toplevel
import django_admin_shellx.signals
importlib.import_module("django_admin_shellx.signals")
except ImportError:
pass
14 changes: 6 additions & 8 deletions django_admin_shellx/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from django.apps import apps
from django.conf import settings
from django.contrib.admin.models import CHANGE, LogEntry
from django.contrib.contenttypes.models import ContentType

from .models import TerminalCommand

Expand Down Expand Up @@ -73,8 +72,8 @@ def run_command(self):
self.child_pid = proc.pid
proc.wait()

# Subprocess has finished, close the websocket
# happens when process exits, either via user exiting using exit() or by error
# Subprocess has finished, close the websocket when the process
# exits, either by using exit() or by failing.
self.subprocess = None
self.child_pid = None
if self.connected:
Expand All @@ -83,7 +82,7 @@ def run_command(self):

def connect(self):

if not "user" in self.scope:
if "user" not in self.scope:
self.close(4401)
return

Expand Down Expand Up @@ -192,13 +191,12 @@ def save_command_history(self, command):
tc.save()

# Create a log entry for the command
LogEntry.objects.log_action(
LogEntry.objects.log_actions(
user_id=self.user.id,
content_type_id=ContentType.objects.get_for_model(tc).pk,
object_id=tc.id,
object_repr=str(tc),
queryset=TerminalCommand.objects.filter(pk=tc.pk),
action_flag=CHANGE,
change_message={"changed": {"name": "action", "object": tc.command}},
single_object=True,
)

def receive(self, text_data=None, bytes_data=None):
Expand Down
4 changes: 2 additions & 2 deletions django_admin_shellx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class TerminalView(LoginRequiredMixin, UserPassesTestMixin, TemplateView):

def test_func(self):
super_user_required = getattr(
settings, "DJANGO_ADMIN_SHELLX_SUPERUSER_ONLY", True
Expand Down Expand Up @@ -108,7 +107,8 @@ def toggle_favorite(request, pk):
color = "text-yellow-400" if instance.favorite else ""
return HttpResponse(
format_html( # pyright: ignore [reportArgumentType]
"<div class='tooltip' data-tip='Favorite Command'><i class='fa fa-star {}'></i></div>",
"<div class='tooltip' data-tip='Favorite Command'>"
"<i class='fa fa-star {}'></i></div>",
mark_safe(color),
)
)
Expand Down
18 changes: 15 additions & 3 deletions django_admin_shellx_custom_admin/admin.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
from django.contrib import admin
from django.urls import reverse
from django.contrib.admin import autodiscover
from django.urls import NoReverseMatch, reverse


class CustomAdminSite(admin.AdminSite): # pylint: disable=too-few-public-methods
class CustomAdminSite(admin.AdminSite):
def get_urls(self):
# Ensure admin modules are registered before URL patterns are built.
autodiscover()
return super().get_urls()

def get_app_list(self, request, app_label=None):
app_list = super().get_app_list(request, app_label)

for app in app_list:
if app["app_label"] == "django_admin_shellx":
try:
terminal_url = reverse(
"admin:django_admin_shellx_terminalcommand_terminal"
)
except NoReverseMatch:
break

app["models"].insert(
0,
{
"name": "Terminal",
"object_name": "Terminal",
"admin_url": f"{reverse('admin:django_admin_shellx_terminalcommand_changelist')}terminal/",
"admin_url": terminal_url,
"view_only": True,
},
)
Expand Down
1 change: 0 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import absolute_import, unicode_literals

import os
import sys
Expand Down
Loading
Loading