Skip to content

Commit

Permalink
Merge pull request #74 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
csae8092 authored Mar 1, 2024
2 parents d02181b + 1bb889b commit 377c400
Show file tree
Hide file tree
Showing 23 changed files with 1,844 additions and 33 deletions.
87 changes: 86 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,89 @@ media/uploads/*.rdf
media/uploads/*.ttl
.secret
.env
.docker
.docker
.coverage

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
node_modules
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,4 @@ hansi.*
media/relations.gexf
edges.csv
nodes.csv
node_modules/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ maybe in future also with PMB CRUD included

## set up new instance

in order to avoid errors on a new instance you'll need to set an environment variable `PMB_NEW=whatever`. After you run the inital `python manage.py migrate` you should `unset PMB_NEW`
in order to avoid errors on a new instance you'll need to set an environment variable `PMB_NEW=whatever`. After you run the inital `python manage.py migrate` you should `unset PMB_NEW`


## vite

* bundling js-code (used for network-vis) is not part of the docker-setup
* for development make sure the vite-dev-server is running `pnpm run vite`
* for building new bundle, run `pn run build`
47 changes: 47 additions & 0 deletions dumper/templates/dumper/network.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends "base.html" %}
{% load static %}
{% load django_vite %}

{% block title %}Vite{% endblock %}
{% block scripts %}
{% vite_hmr_client %}
{% vite_asset 'js/main.js' %}
{% endblock scripts %}

{% block content %}
<div class="container pt-4">
<h1 class="display-3 text-center">Netzwerk aller Verbindungen</h1>
<div class="d-flex justify-content-center">
<div class="alert alert-warning d-flex align-items-center" role="alert">
<div>
Hierbei handelt es sich nur um ein Proof of Concept
</div>
</div>
</div>

<div class="d-flex justify-content-center" id="spinner">
<div class="spinner-border" role="status">
<span class="visually-hidden">Lade die Netzwerkdaten...</span>
</div>
</div>
<div class="row">
<div class="col-2" >
<div class="p2" style="visibility: hidden;" id="legend">
<ul>
{% for x in model_list %}
<li>
<i class="{{ x.icon }}"></i> {{ x.name }}
</li>
{% endfor %}
</ul>
</div>
</div>
<div class="col-10">
<div id="app"></div>

</div>
</div>


</div>
{% endblock %}
5 changes: 5 additions & 0 deletions dumper/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ def test_09_imprint(self):
url = reverse("dumper:export")
response = client.get(url)
self.assertEqual(response.status_code, 200)

def test_10_network(self):
url = reverse("dumper:network")
response = client.get(url)
self.assertEqual(response.status_code, 200)
1 change: 1 addition & 0 deletions dumper/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
urlpatterns = [
path("", views.HomePageView.as_view(), name="home"),
path("about/", views.AboutView.as_view(), name="about"),
path("network/", views.NetworkView.as_view(), name="network"),
path("export/", views.ExportView.as_view(), name="export"),
path("imprint/", views.ImprintView.as_view(), name="imprint"),
path("login/", views.user_login, name="user_login"),
Expand Down
23 changes: 23 additions & 0 deletions dumper/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any
from django.apps import apps
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
Expand Down Expand Up @@ -26,6 +28,27 @@ class ExportView(TemplateView):
template_name = "dumper/export.html"


class NetworkView(TemplateView):
template_name = "dumper/network.html"

def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
MODELS = list(apps.all_models["apis_entities"].values())
model_list = []
for x in MODELS:
try:
item = {
"color": x.get_color(),
"icon": x.get_icon(),
"name": x._meta.verbose_name,
}
except AttributeError:
continue
model_list.append(item)
context["model_list"] = model_list
return context


class ImprintView(TemplateView):
template_name = "dumper/imprint.html"

Expand Down
89 changes: 89 additions & 0 deletions issue__162_tagebuchurifix.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "bbbbf1e8",
"metadata": {},
"outputs": [],
"source": [
"from tqdm import tqdm"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1233b691",
"metadata": {},
"outputs": [],
"source": [
"uris = Uri.objects.filter(uri__icontains=\"schnitzler-tagebuch.acdh.oeaw.ac.at/entity/\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17196a40",
"metadata": {},
"outputs": [],
"source": [
"uris.count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e9d83d5",
"metadata": {},
"outputs": [],
"source": [
"for x in tqdm(uris, total=uris.count()):\n",
" new_uri = f'{x.uri.replace(\"/entity\", \"\")}.html'\n",
" x.uri = new_uri\n",
" try:\n",
" x.save()\n",
" except Exception as e:\n",
" print(x, e)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b37ca48",
"metadata": {},
"outputs": [],
"source": [
"Uri.objects.filter(uri__icontains=\"schnitzler-tagebuch.acdh.oeaw.ac.at/entity/\").count()"
]
},
{
"cell_type": "markdown",
"id": "e19d4223",
"metadata": {},
"source": [
"### run on production 2024-02-29"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Django Shell-Plus",
"language": "python",
"name": "django_extensions"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "vite-project",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^5.1.4"
},
"dependencies": {
"@cosmograph/cosmograph": "^1.3.1",
"d3": "^7.8.5"
}
}
8 changes: 8 additions & 0 deletions pmb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# SECURITY WARNING: don't run with debug turned on in production!
if os.environ.get("DEBUG"):
DEBUG = True
VITE_DEV = True
else:
DEBUG = False
VITE_DEV = False

ALLOWED_HOSTS = ["*"]
FIXTURE_DIRS = [os.path.join(BASE_DIR, "fixtures")]
Expand Down Expand Up @@ -46,6 +48,7 @@
"crispy_bootstrap5",
"django_tables2",
"django_filters",
"django_vite",
"apis_core.apis_entities",
"apis_core.apis_metainfo",
"apis_core.apis_relations",
Expand Down Expand Up @@ -139,6 +142,7 @@

STATICFILES_DIRS = [
BASE_DIR / "static",
BASE_DIR / "static" / "vite",
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
Expand Down Expand Up @@ -298,3 +302,7 @@
],
},
}

DJANGO_VITE = {
"default": {"dev_mode": VITE_DEV, "manifest_path": "static/vite/manifest.info"}
}
29 changes: 20 additions & 9 deletions pmb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
from apis_core.apis_entities import resolver_views


urlpatterns = [
path("apis/", include("apis_core.urls", namespace="apis")),
path("normdata/", include("normdata.urls", namespace="normdata")),
path("admin/", admin.site.urls),
path("arche/", include("archemd.urls", namespace="archemd")),
path("uri/", resolver_views.uri_resolver, name="uri-resolver"),
path("entity/<int:pk>/", resolver_views.entity_resolver, name="entity-resolver"),
path("", include("dumper.urls", namespace="dumper")),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = (
[
path("apis/", include("apis_core.urls", namespace="apis")),
path("normdata/", include("normdata.urls", namespace="normdata")),
path("admin/", admin.site.urls),
path("arche/", include("archemd.urls", namespace="archemd")),
path("uri/", resolver_views.uri_resolver, name="uri-resolver"),
path(
"entity/<int:pk>/", resolver_views.entity_resolver, name="entity-resolver"
),
path("", include("dumper.urls", namespace="dumper")),
]
# + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
# + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
)

if settings.DEBUG:
urlpatterns = urlpatterns + static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)
Loading

0 comments on commit 377c400

Please sign in to comment.