-
-
Notifications
You must be signed in to change notification settings - Fork 26
Make Graphviz optional, use MermaidJS in admin frontend #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
374ec1a
0dea1ba
8d118ad
d1696a8
b86b6ac
864826a
f84cf3c
b2fcced
c9c2ab3
9bebc8a
f881193
d93b177
6ed5112
1b22c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,8 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
|
|
||
| PyPi: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # See https://pre-commit.com for more information | ||
| # See https://pre-commit.com/hooks.html for more hooks | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v6.0.0 | ||
| hooks: | ||
| - id: trailing-whitespace | ||
| - id: check-merge-conflict | ||
| - id: check-ast | ||
| - id: check-toml | ||
| - id: check-yaml | ||
| - id: debug-statements | ||
| - id: end-of-file-fixer | ||
| - id: name-tests-test | ||
| args: ['--pytest-test-first'] | ||
| exclude: ^tests/(testapp/|manage.py$) | ||
| - id: no-commit-to-branch | ||
| args: [--branch, main] | ||
| - repo: https://github.com/asottile/pyupgrade | ||
| rev: v3.21.1 | ||
| hooks: | ||
| - id: pyupgrade | ||
| - repo: https://github.com/adamchainz/django-upgrade | ||
| rev: 1.29.1 | ||
| hooks: | ||
| - id: django-upgrade | ||
| - repo: https://github.com/hukkin/mdformat | ||
| rev: 1.0.0 | ||
| hooks: | ||
| - id: mdformat | ||
| additional_dependencies: | ||
| - mdformat-ruff | ||
| - mdformat-footnote | ||
| - mdformat-gfm | ||
| - mdformat-gfm-alerts | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: v0.14.4 | ||
| hooks: | ||
| - id: ruff-check | ||
| args: [--fix, --exit-non-zero-on-fix] | ||
| - id: ruff-format | ||
| - repo: https://github.com/google/yamlfmt | ||
| rev: v0.20.0 | ||
| hooks: | ||
| - id: yamlfmt | ||
| - repo: https://github.com/djlint/djLint | ||
| rev: v1.36.4 | ||
| hooks: | ||
| - id: djlint-reformat-django | ||
| ci: | ||
| autoupdate_schedule: weekly | ||
| skip: | ||
| - no-commit-to-branch |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,9 @@ | ||||||||||||||||||||
| from django.contrib import admin, messages | ||||||||||||||||||||
| from django.contrib.auth import get_permission_codename | ||||||||||||||||||||
| from django.db import transaction | ||||||||||||||||||||
| from django.forms.widgets import Media, MediaAsset, Script | ||||||||||||||||||||
| from django.utils.html import format_html | ||||||||||||||||||||
| from django.utils.safestring import mark_safe | ||||||||||||||||||||
| from django.utils.translation import gettext_lazy as t | ||||||||||||||||||||
|
|
||||||||||||||||||||
| from . import forms, models | ||||||||||||||||||||
|
|
@@ -19,13 +21,13 @@ def rerun(modeladmin, request, queryset): | |||||||||||||||||||
| if succeeded: | ||||||||||||||||||||
| messages.warning( | ||||||||||||||||||||
| request, | ||||||||||||||||||||
| "Only failed tasks can be retried. %s tasks have been skipped" % succeeded, | ||||||||||||||||||||
| f"Only failed tasks can be retried. {succeeded} tasks have been skipped", | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| counter = 0 | ||||||||||||||||||||
| for obj in queryset.not_succeeded().iterator(): | ||||||||||||||||||||
| obj.enqueue() | ||||||||||||||||||||
| counter += 1 | ||||||||||||||||||||
| messages.success(request, "%s tasks have been successfully queued" % counter) | ||||||||||||||||||||
| messages.success(request, f"{counter} tasks have been successfully queued") | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @admin.action( | ||||||||||||||||||||
|
|
@@ -37,8 +39,7 @@ def cancel(modeladmin, request, queryset): | |||||||||||||||||||
| if not_scheduled: | ||||||||||||||||||||
| messages.warning( | ||||||||||||||||||||
| request, | ||||||||||||||||||||
| "Only scheduled tasks can be canceled. %s tasks have been skipped" | ||||||||||||||||||||
| % not_scheduled, | ||||||||||||||||||||
| f"Only scheduled tasks can be canceled. {not_scheduled} tasks have been skipped", | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| queryset.scheduled().cancel(request.user) | ||||||||||||||||||||
| messages.success(request, "Tasks have been successfully canceled") | ||||||||||||||||||||
|
|
@@ -135,6 +136,14 @@ class TaskInlineAdmin(admin.TabularInline): | |||||||||||||||||||
| classes = ["collapse"] | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class CSS(MediaAsset): | ||||||||||||||||||||
| element_template = "<style{attributes}>{path}</style>" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @property | ||||||||||||||||||||
| def path(self): | ||||||||||||||||||||
| return mark_safe(self._path) # noqa: S308 | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class WorkflowAdmin(VersionAdmin): | ||||||||||||||||||||
| list_filter = ( | ||||||||||||||||||||
| "modified", | ||||||||||||||||||||
|
|
@@ -147,13 +156,40 @@ def get_inlines(self, *args, **kwargs): | |||||||||||||||||||
|
|
||||||||||||||||||||
| def get_readonly_fields(self, *args, **kwargs): | ||||||||||||||||||||
| return [ | ||||||||||||||||||||
| "get_instance_graph_svg", | ||||||||||||||||||||
| "display_workflow_diagram", | ||||||||||||||||||||
| *super().get_readonly_fields(*args, **kwargs), | ||||||||||||||||||||
| "modified", | ||||||||||||||||||||
| "created", | ||||||||||||||||||||
| ] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @admin.display(description="Workflow Diagram") | ||||||||||||||||||||
| def display_workflow_diagram(self, obj): | ||||||||||||||||||||
| """Display workflow diagram using MermaidJS for client-side rendering.""" | ||||||||||||||||||||
| if obj.pk: | ||||||||||||||||||||
| return mark_safe( # noqa: S308 | ||||||||||||||||||||
| f"""<pre class="mermaid" style="width: 100%; display: block">{obj.get_instance_graph_mermaid()}</pre>""" | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| return "" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @transaction.atomic() | ||||||||||||||||||||
| def save_model(self, request, obj, form, change): | ||||||||||||||||||||
| super().save_model(request, obj, form, change) | ||||||||||||||||||||
| form.start_next_tasks(request.user) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @property | ||||||||||||||||||||
| def media(self): | ||||||||||||||||||||
| return super().media + Media( | ||||||||||||||||||||
| js=[ | ||||||||||||||||||||
| Script( | ||||||||||||||||||||
| "https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.esm.min.mjs", | ||||||||||||||||||||
| type="module", | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
||||||||||||||||||||
| ) | |
| ), | |
| Script( | |
| """ | |
| import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.esm.min.mjs'; | |
| mermaid.initialize({ startOnLoad: true }); | |
| """, | |
| type="module", | |
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in extras specification: 'graphiz' should be 'graphviz' to match the optional dependency name defined in pyproject.toml.