From 32264d8b62d1f54327c7165c18e1b14b97c32336 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Tue, 7 Nov 2023 12:28:45 +0100 Subject: [PATCH] default usage of datamodel --- defcdb/templates/defcdb/base.html | 2 +- django_spaghetti/__init__.py | 20 ---- .../templates/django_spaghetti/meatball.html | 21 ---- .../templates/django_spaghetti/plate.html | 45 --------- django_spaghetti/urls.py | 8 -- django_spaghetti/views.py | 97 ------------------- orea/urls.py | 1 - requirements.txt | 1 + webpage/templates/webpage/data_model.html | 12 +++ webpage/urls.py | 7 ++ 10 files changed, 21 insertions(+), 193 deletions(-) delete mode 100644 django_spaghetti/__init__.py delete mode 100644 django_spaghetti/templates/django_spaghetti/meatball.html delete mode 100644 django_spaghetti/templates/django_spaghetti/plate.html delete mode 100644 django_spaghetti/urls.py delete mode 100644 django_spaghetti/views.py create mode 100644 webpage/templates/webpage/data_model.html diff --git a/defcdb/templates/defcdb/base.html b/defcdb/templates/defcdb/base.html index 9957e43..2e86139 100644 --- a/defcdb/templates/defcdb/base.html +++ b/defcdb/templates/defcdb/base.html @@ -346,7 +346,7 @@ Building the defc app
  • - Data Model + Data Model
  • diff --git a/django_spaghetti/__init__.py b/django_spaghetti/__init__.py deleted file mode 100644 index a57fd35..0000000 --- a/django_spaghetti/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -__version_info__ = { - "major": 0, - "minor": 2, - "micro": 0, - "releaselevel": "final", - "serial": 0, -} - - -def get_version(release_level=True): - """ - Return the formatted version information - """ - vers = ["%(major)i.%(minor)i.%(micro)i" % __version_info__] - if release_level and __version_info__["releaselevel"] != "final": - vers.append("%(releaselevel)s%(serial)i" % __version_info__) - return "".join(vers) - - -__version__ = get_version() diff --git a/django_spaghetti/templates/django_spaghetti/meatball.html b/django_spaghetti/templates/django_spaghetti/meatball.html deleted file mode 100644 index f5d8abb..0000000 --- a/django_spaghetti/templates/django_spaghetti/meatball.html +++ /dev/null @@ -1,21 +0,0 @@ -
    -
    - Model: {{ model.model }}
    - App: {{ model.app_label }} -
    -
    - {{ model.doc }} -
    -{% if fields %} - Fields: - -{% endif %} -
    \ No newline at end of file diff --git a/django_spaghetti/templates/django_spaghetti/plate.html b/django_spaghetti/templates/django_spaghetti/plate.html deleted file mode 100644 index 61845cb..0000000 --- a/django_spaghetti/templates/django_spaghetti/plate.html +++ /dev/null @@ -1,45 +0,0 @@ -{% load staticfiles %} -{% block scriptHeader %} - - -{% endblock %} - -

    The application's Data Model

    -

    back

    -
    - - diff --git a/django_spaghetti/urls.py b/django_spaghetti/urls.py deleted file mode 100644 index cc22588..0000000 --- a/django_spaghetti/urls.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.urls import path -from django_spaghetti.views import plate - - -app_name = "django_spaghetti" -urlpatterns = [ - path(r"", plate, name="plate"), -] diff --git a/django_spaghetti/views.py b/django_spaghetti/views.py deleted file mode 100644 index 7cfcb94..0000000 --- a/django_spaghetti/views.py +++ /dev/null @@ -1,97 +0,0 @@ -from django.contrib.contenttypes.models import ContentType -from django.shortcuts import render - -from django.conf import settings -from django.db.models.fields import related -from django.template.loader import get_template -from django.template import Context -import json - -graph_settings = getattr(settings, "SPAGHETTI_SAUCE", {}) -apps = graph_settings.get("apps", []) - - -def plate(request): - excludes = [ - "%s__%s" % (app, model) - for app, models in graph_settings.get("exclude", {}).items() - for model in models - ] - models = ContentType.objects.filter(app_label__in=apps) - nodes = [] - edges = [] - for model in models: - if model.model_class() == None: - continue - - model.doc = model.model_class().__doc__ - _id = "%s__%s" % (model.app_label, model.model) - if _id in excludes: - continue - label = "%s" % (model.model) - fields = [f for f in model.model_class()._meta.fields] - many = [f for f in model.model_class()._meta.many_to_many] - if graph_settings.get("show_fields", True): - label += "\n%s\n" % ("-" * len(model.model)) - label += "\n".join([str(f.name) for f in fields]) - edge_color = {"inherit": "from"} - - for f in fields + many: - if f.rel is not None: - m = f.rel.to._meta - if m.app_label != model.app_label: - edge_color = {"inherit": "both"} - edge = { - "from": _id, - "to": "%s__%s" % (m.app_label, m.model_name), - "color": edge_color, - } - - if str(f.name).endswith("_ptr"): - # fields that end in _ptr are pointing to a parent object - edge.update( - { - "arrows": { - "to": {"scaleFactor": 0.75} - }, # needed to draw from-to - "font": {"align": "middle"}, - "label": "is a", - "dashes": True, - } - ) - elif type(f) == related.ForeignKey: - edge.update({"arrows": {"to": {"scaleFactor": 0.75}}}) - elif type(f) == related.OneToOneField: - edge.update({"font": {"align": "middle"}, "label": "|"}) - elif type(f) == related.ManyToManyField: - edge.update( - { - "color": {"color": "gray"}, - "arrows": { - "to": {"scaleFactor": 1}, - "from": {"scaleFactor": 1}, - }, - } - ) - - edges.append(edge) - - nodes.append( - { - "id": _id, - "label": label, - "shape": "box", - "group": model.app_label, - "title": get_template("django_spaghetti/meatball.html").render( - Context( - { - "model": model, - "fields": fields, - } - ) - ), - } - ) - - data = {"meatballs": json.dumps(nodes), "spaghetti": json.dumps(edges)} - return render(request, "django_spaghetti/plate.html", data) diff --git a/orea/urls.py b/orea/urls.py index 3d66368..56796ec 100644 --- a/orea/urls.py +++ b/orea/urls.py @@ -150,5 +150,4 @@ path("publicrecords/", include("publicrecords.urls", namespace="publicrecords")), path("3Dmodels/", include("threedmodels.urls", namespace="3Dmodels")), path("browsing/", include("browsing.urls", namespace="browsing")), - path("datamodel/", include("django_spaghetti.urls", namespace="datamodel")), ] diff --git a/requirements.txt b/requirements.txt index da54e00..c9fda6a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ django-crispy-forms django-filter django-haystack django-reversion +django-spaghetti-and-meatballs==0.4.2 django-tables2 djangorestframework Jinja2 diff --git a/webpage/templates/webpage/data_model.html b/webpage/templates/webpage/data_model.html new file mode 100644 index 0000000..c7e78d8 --- /dev/null +++ b/webpage/templates/webpage/data_model.html @@ -0,0 +1,12 @@ +{% extends "defcdb/base.html" %} +{% load static %} +{% block title %} Datenmodell {% endblock %} +{% block content %} +
    + + {% include 'django_spaghetti/plate.html' %} +{% endblock %} \ No newline at end of file diff --git a/webpage/urls.py b/webpage/urls.py index 0ca6367..c6053bc 100644 --- a/webpage/urls.py +++ b/webpage/urls.py @@ -2,11 +2,18 @@ from django.urls import path from . import views +from django_spaghetti.views import Plate + app_name = "webpage" urlpatterns = [ path("", views.homepage, name="homepage"), + path( + "data-model/", + Plate.as_view(plate_template_name="webpage/data_model.html"), + name="data_model", + ), path("about/", views.about, name="about"), path("imprint/", views.imprint, name="imprint"), path(