Skip to content
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

Open the django admin doc model on double click #17

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions assets/components/Network.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ export default {
this.visData.edges = mountVisData(this, 'edges');
this.network = new Network(container, this.visData, this.options);

this.network.on( 'doubleClick', function(properties) {
var adm_slug = properties.nodes.toString();
if (adm_slug.indexOf('Abstract') !== -1) {return} //the abstract property should be inside properties
var n = adm_slug.lastIndexOf(".");
adm_slug = adm_slug.substring(n+1).replace("/", ".");
window.open("/admin/doc/models/" + adm_slug, '_blank');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being hard-coded means it should at least be documented in the README that it must be that path.

Ideally some use of reverse(..) would occur so that it isnt hard-coded.

fwiw, the double click isnt working for me. I havent worked out why yet.

});

this.events.forEach(eventName =>
this.network.on(eventName, props => this.$emit(translateEvent(eventName), props))
);
Expand Down
21 changes: 21 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', "tests.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
33 changes: 30 additions & 3 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import environ
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

env = environ.Env()


DEBUG = True
DATABASES = {"default": env.db(default="sqlite://:memory:")}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
ROOT_URLCONF = "tests.urls"
SECRET_KEY = "not-for-production"
INSTALLED_APPS = [
Expand All @@ -19,14 +25,35 @@
"tests.installed",
"tests.proxy",
"schema_graph",
'django.contrib.admindocs',
'django.contrib.admin',
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
TEMPLATES = (
{"BACKEND": "django.template.backends.django.DjangoTemplates", "APP_DIRS": True},
{"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
)
STATIC_URL = "/static/"
15 changes: 12 additions & 3 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from django.contrib import admin
from schema_graph.views import Schema


try:
# Django 2+:
from django.urls import path
from django.urls import path, include

urlpatterns = [path("", Schema.as_view())]
urlpatterns = [
path('admin/doc/', include('django.contrib.admindocs.urls')),
path('admin/', admin.site.urls),
path("", Schema.as_view())
]
except ImportError:
# Django < 2:
from django.conf.urls import url

urlpatterns = [url(r"^$", Schema.as_view())]
urlpatterns = [
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url('^admin/', admin.site.urls),
url(r"^$", Schema.as_view())
]