Skip to content

Commit

Permalink
Merge pull request #1884 from OpenEnergyPlatform/enhancement-oep-djan…
Browse files Browse the repository at this point in the history
…go-5-migration

Migrate oeplatform to django 5
  • Loading branch information
jh-RLI authored Nov 19, 2024
2 parents 1b8fbc2 + 388970d commit 888d987
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 189 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var/
*.egg-info/
.installed.cfg
*.egg
/oep-django-5
oep-django-5/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -79,8 +81,12 @@ venv*/
0_env/
/envs
/node_env
.env*
/fuseki
apache*
/oep-django-5


.DS_Store

# Deployment files
Expand Down
103 changes: 51 additions & 52 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from django.conf.urls import url
from django.urls import path
from django.urls import path, re_path

from api import actions, views

pgsql_qualifier = r"[\w\d_]+"
equal_qualifier = r"[\w\d\s\'\=]"
structures = r"table|sequence"
urlpatterns = [
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/$",
views.Table.as_view(),
name="api_table",
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/sequences/(?P<sequence>[\w\d_\s]+)/$", # noqa
views.Sequence.as_view(),
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/meta/$", # noqa
views.Metadata.as_view(),
name="api_table_meta",
Expand All @@ -33,173 +32,173 @@
views.MovePublish.as_view(),
name="move_publish",
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/columns/(?P<column>[\w\d_\s]+)?$", # noqa
views.Column.as_view(),
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/id/(?P<id>[\d]+)/column/(?P<column>[\w\d_\s]+)/$", # noqa
views.Fields.as_view(),
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/indexes/(?P<index>[\w\d_\s]+)$", # noqa
views.Index.as_view(),
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/rows/(?P<row_id>[\d]+)?$", # noqa
views.Rows.as_view(),
name="api_rows",
),
url(
re_path(
r"^v0/schema/(?P<schema>[\w\d_\s]+)/tables/(?P<table>[\w\d_\s]+)/rows/new?$", # noqa
views.Rows.as_view(),
{"action": "new"},
name="api_rows_new",
),
url(
re_path(
r"^v0/advanced/search",
views.create_ajax_handler(
actions.data_search, allow_cors=True, requires_cursor=True
),
),
url(
re_path(
r"^v0/advanced/insert",
views.create_ajax_handler(actions.data_insert, requires_cursor=True),
name="api_insert",
),
url(
re_path(
r"^v0/advanced/delete",
views.create_ajax_handler(actions.data_delete, requires_cursor=True),
),
url(
re_path(
r"^v0/advanced/update",
views.create_ajax_handler(actions.data_update, requires_cursor=True),
),
url(r"^v0/advanced/info", views.create_ajax_handler(actions.data_info)),
url(
re_path(r"^v0/advanced/info", views.create_ajax_handler(actions.data_info)),
re_path(
r"^v0/advanced/has_schema", views.create_ajax_handler(actions.has_schema)
), # noqa
url(r"^v0/advanced/has_table", views.create_ajax_handler(actions.has_table)),
url(
re_path(r"^v0/advanced/has_table", views.create_ajax_handler(actions.has_table)),
re_path(
r"^v0/advanced/has_sequence", views.create_ajax_handler(actions.has_sequence)
), # noqa
url(r"^v0/advanced/has_type", views.create_ajax_handler(actions.has_type)),
url(
re_path(r"^v0/advanced/has_type", views.create_ajax_handler(actions.has_type)),
re_path(
r"^v0/advanced/get_schema_names",
views.create_ajax_handler(actions.get_schema_names),
),
url(
re_path(
r"^v0/advanced/get_table_names",
views.create_ajax_handler(actions.get_table_names),
),
url(
re_path(
r"^v0/advanced/get_view_names",
views.create_ajax_handler(actions.get_view_names),
),
url(
re_path(
r"^v0/advanced/get_view_definition",
views.create_ajax_handler(actions.get_view_definition),
),
url(
re_path(
r"^v0/advanced/get_columns", views.create_ajax_handler(actions.get_columns)
), # noqa
url(
re_path(
r"^v0/advanced/get_pk_constraint",
views.create_ajax_handler(actions.get_pk_constraint),
),
url(
re_path(
r"^v0/advanced/get_foreign_keys",
views.create_ajax_handler(actions.get_foreign_keys),
),
url(
re_path(
r"^v0/advanced/get_indexes", views.create_ajax_handler(actions.get_indexes)
), # noqa
url(
re_path(
r"^v0/advanced/get_unique_constraints",
views.create_ajax_handler(actions.get_unique_constraints),
),
url(
re_path(
r"^v0/advanced/connection/open",
views.create_ajax_handler(actions.open_raw_connection),
name="api_con_open",
),
url(
re_path(
r"^v0/advanced/connection/close$",
views.create_ajax_handler(actions.close_raw_connection),
name="api_con_close",
),
url(
re_path(
r"^v0/advanced/connection/commit",
views.create_ajax_handler(actions.commit_raw_connection),
name="api_con_commit",
),
url(
re_path(
r"^v0/advanced/connection/rollback",
views.create_ajax_handler(actions.rollback_raw_connection),
),
url(r"^v0/advanced/connection/close_all", views.CloseAll.as_view()),
url(
re_path(r"^v0/advanced/connection/close_all", views.CloseAll.as_view()),
re_path(
r"^v0/advanced/cursor/open", views.create_ajax_handler(actions.open_cursor)
), # noqa
url(
re_path(
r"^v0/advanced/cursor/close", views.create_ajax_handler(actions.close_cursor)
), # noqa
url(
re_path(
r"^v0/advanced/cursor/fetch_one", views.create_ajax_handler(actions.fetchone)
), # noqa
url(
re_path(
r"^v0/advanced/cursor/fetch_many",
views.FetchView.as_view(),
dict(fetchtype="all"),
),
url(
re_path(
r"^v0/advanced/cursor/fetch_all",
views.FetchView.as_view(),
dict(fetchtype="all"),
),
url(
re_path(
r"^v0/advanced/set_isolation_level",
views.create_ajax_handler(actions.set_isolation_level),
),
url(
re_path(
r"^v0/advanced/get_isolation_level",
views.create_ajax_handler(actions.get_isolation_level),
),
url(
re_path(
r"^v0/advanced/do_begin_twophase",
views.create_ajax_handler(actions.do_begin_twophase),
),
url(
re_path(
r"^v0/advanced/do_prepare_twophase",
views.create_ajax_handler(actions.do_prepare_twophase),
),
url(
re_path(
r"^v0/advanced/do_rollback_twophase",
views.create_ajax_handler(actions.do_rollback_twophase),
),
url(
re_path(
r"^v0/advanced/do_commit_twophase",
views.create_ajax_handler(actions.do_commit_twophase),
),
url(
re_path(
r"^v0/advanced/do_recover_twophase",
views.create_ajax_handler(actions.do_recover_twophase),
),
url(r"usrprop/", views.get_users),
url(r"grpprop/", views.get_groups),
url("oeo-search", views.oeo_search),
url("oevkg-query", views.oevkg_search),
url(
path("usrprop/", views.get_users),
path("grpprop/", views.get_groups),
path("oeo-search", views.oeo_search),
path("oevkg-query", views.oevkg_search),
re_path(
r"^v0/factsheet/frameworks/?$",
views.EnergyframeworkFactsheetListAPIView.as_view(),
name="list-framework-factsheets",
),
url(
re_path(
r"^v0/factsheet/models/?$",
views.EnergymodelFactsheetListAPIView.as_view(),
name="list-model-factsheets",
),
url(
re_path(
r"^v0/datasets/list_all/scenario/?$",
views.ScenarioDataTablesListAPIView.as_view(),
name="list-scenario-datasets",
Expand Down
8 changes: 6 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
StreamingHttpResponse,
)
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
from omi.dialects.oep.compiler import JSONCompiler
from omi.structure import OEPMetadata
Expand Down Expand Up @@ -278,7 +279,7 @@ def __create_sequence(self, request, schema, sequence, jsn):

class Metadata(APIView):
@api_exception
@never_cache
@method_decorator(never_cache)
def get(self, request, schema, table):
metadata = actions.get_table_metadata(schema, table)
return JsonResponse(metadata)
Expand Down Expand Up @@ -331,6 +332,7 @@ class Table(APIView):
objects = None

@api_exception
@method_decorator(never_cache)
def get(self, request, schema, table):
"""
Returns a dictionary that describes the DDL-make-up of this table.
Expand Down Expand Up @@ -756,7 +758,7 @@ def put(self, request):

class Column(APIView):
@api_exception
@never_cache
@method_decorator(never_cache)
def get(self, request, schema, table, column=None):
schema, table = actions.get_table_name(schema, table, restrict_schemas=False)
response = actions.describe_columns(schema, table)
Expand Down Expand Up @@ -787,6 +789,7 @@ def put(self, request, schema, table, column):


class Fields(APIView):
@method_decorator(never_cache)
def get(self, request, schema, table, id, column=None):
schema, table = actions.get_table_name(schema, table, restrict_schemas=False)
if (
Expand Down Expand Up @@ -858,6 +861,7 @@ def check_embargo(schema, table):

class Rows(APIView):
@api_exception
@method_decorator(never_cache)
def get(self, request, schema, table, row_id=None):
if check_embargo(schema, table):
return JsonResponse(
Expand Down
19 changes: 15 additions & 4 deletions base/templates/base/base-full.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,21 @@
</div>
{% if user.is_authenticated %} {# This should stay here - later the above if becomes obsolete #}

<div class="btn profile-bar">
<a class="btn-profile" href="/user/profile/{{ user.pk }}/settings">{% fa5_icon 'user' 'fas' %} {{ user }}</a>
<a class="btn-logout" href="/user/logout/?next=/">{% fa5_icon 'arrow-right' 'fas' %} Logout</a>
</div>
<div class="d-flex align-items-center gap-3">
<!-- Profile Link -->
<a class="btn btn-link text-white p-0" href="/user/profile/{{ user.pk }}/settings">
{% fa5_icon 'user' 'fas' %} {{ user }}
</a>

<!-- Logout Form -->
<form method="post" action="{% url 'logout' %}" class="m-0">
{% csrf_token %}
<input type="hidden" name="next" value="/">
<button type="submit" class="btn btn-danger btn-sm">
{% fa5_icon 'arrow-right' 'fas' %} Logout
</button>
</form>
</div>

{% else %}
<a class="btn btn-info" style="float: right;margin:5px"
Expand Down
19 changes: 15 additions & 4 deletions base/templates/base/base-profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,21 @@
</div>
{% if user.is_authenticated %} {# This should stay here - later the above if becomes obsolete #}

<div class="btn profile-bar">
<a class="btn-profile" href="/user/profile/{{ user.pk }}/settings">{% fa5_icon 'user' 'fas' %} {{ user }}</a>
<a class="btn-logout" href="/user/logout/?next=/">{% fa5_icon 'arrow-right' 'fas' %} Logout</a>
</div>
<div class="d-flex align-items-center gap-3">
<!-- Profile Link -->
<a class="btn btn-link text-white p-0" href="/user/profile/{{ user.pk }}/settings">
{% fa5_icon 'user' 'fas' %} {{ user }}
</a>

<!-- Logout Form -->
<form method="post" action="{% url 'logout' %}" class="m-0">
{% csrf_token %}
<input type="hidden" name="next" value="/">
<button type="submit" class="btn btn-danger btn-sm">
{% fa5_icon 'arrow-right' 'fas' %} Logout
</button>
</form>
</div>

{% else %}
<a class="btn btn-info" style="float: right;margin:5px"
Expand Down
19 changes: 15 additions & 4 deletions base/templates/base/base-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,21 @@
</div>
{% if user.is_authenticated %} {# This should stay here - later the above if becomes obsolete #}

<div class="btn profile-bar">
<a class="btn-profile" href="/user/profile/{{ user.pk }}/settings">{% fa5_icon 'user' 'fas' %} {{ user }}</a>
<a class="btn-logout" href="/user/logout/?next=/">{% fa5_icon 'arrow-right' 'fas' %} Logout</a>
</div>
<div class="d-flex align-items-center gap-3">
<!-- Profile Link -->
<a class="btn btn-link text-white p-0" href="/user/profile/{{ user.pk }}/settings">
{% fa5_icon 'user' 'fas' %} {{ user }}
</a>

<!-- Logout Form -->
<form method="post" action="{% url 'logout' %}" class="m-0">
{% csrf_token %}
<input type="hidden" name="next" value="/">
<button type="submit" class="btn btn-danger btn-sm">
{% fa5_icon 'arrow-right' 'fas' %} Logout
</button>
</form>
</div>

{% else %}
<a class="btn btn-info" style="float: right;margin:5px"
Expand Down
Loading

0 comments on commit 888d987

Please sign in to comment.