Fixing Django 4 compatibility, removing auto_updates refs

This commit is contained in:
Sebastien Laithier 2022-08-17 16:32:40 +02:00
parent d6e8f370e9
commit f449d2cb4e
5 changed files with 33 additions and 59 deletions

View File

@ -44,7 +44,6 @@
<th class='text-center'>Hostname</th>
<th class='text-center'>Updates #</th>
<th class='text-center'>Uptime</th>
<th class='text-center'>Auto-update</th>
</tr>
</thead>
<tbody>
@ -56,7 +55,6 @@
<td><a href="{% url 'packages-by-host' stat.server.hostname %}">{{ stat.server.hostname }}</b></td>
<td class='status-{{ stat.updates_status }} text-center'>{{ stat.updates }}</td>
<td class='status-{{ stat.uptime_status }} text-center'>{{ stat.uptime }}</td>
<td class='status-{{ stat.auto_updates_status }} text-center'>{{ stat.get_auto_updates_display }}</td>
</tr>
{% endfor %}
</tbody>
@ -106,34 +104,10 @@ jQuery.fn.dataTableExt.oSort['num-none-desc'] = function(x,y) {
else return ((parseInt(x) < parseInt(y)) ? 1 : ((parseInt(x) > parseInt(y)) ? -1 : 0));
};
// sort auto-updates status: Ok < Unkown < Error < N/A
// Error < Unkown < Ok < N/A
jQuery.fn.dataTableExt.oSort['auto-updates-asc'] = function(x,y) {
if (x == y) return 0;
else if (x == 'N/A') return 1;
else if (y == 'N/A') return -1;
else if (x == 'Ok') return -1;
else if (y == 'Ok') return 1;
else if (x == 'Error') return 1;
else if (y == 'Error') return -1;
};
jQuery.fn.dataTableExt.oSort['auto-updates-desc'] = function(x,y) {
if (x == y) return 0;
else if (x == 'N/A') return 1;
else if (y == 'N/A') return -1;
else if (x == 'Ok') return 1;
else if (y == 'Ok') return -1;
else if (x == 'Error') return -1;
else if (y == 'Error') return 1;
};
$(document).ready(function() {
$('#server-list').DataTable({
"paging": false,
"order": [[ 1, "asc" ]],
"aoColumns": [
null, null, null, null, {"sType": "num-none"}, {"sType": "num-none"}, {"sType": "auto-updates"}
]
});
});
</script>

View File

@ -1,4 +1,5 @@
from django.conf.urls import url, include
from django.conf.urls import include
from django.urls import re_path
from django.contrib import admin
from django.conf import settings
from django.contrib.auth import views as auth_views
@ -7,84 +8,84 @@ from . import views
urlpatterns = [
# home
url(r'^/?$',
re_path(r'^/?$',
views.index,
name='index'),
# server list
url(r'^server-list/?$',
re_path(r'^server-list/?$',
views.server_list,
name='server-list'),
url(r'^server-list/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
re_path(r'^server-list/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
views.server_list,
name='server-list-by-date'),
url(r'^server-list/(?P<group>[a-z0-9\-_]*)/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
re_path(r'^server-list/(?P<group>[a-z0-9\-_]*)/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
views.server_list,
name='server-list-by-group'),
url(r'^server-list/team/(?P<team>[a-z]*)/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
re_path(r'^server-list/team/(?P<team>[a-z]*)/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
views.server_list,
name='server-list-by-team'),
# package list
url(r'^packages/?$',
re_path(r'^packages/?$',
views.packages_list,
name='packages-list'),
url(r'^packages/package/(?P<package>[a-z0-9\.\-_]*)/?$',
re_path(r'^packages/package/(?P<package>[a-z0-9\.\-_]*)/?$',
views.packages,
name='packages-by-package'),
url(r'^packages/host/(?P<hostname>[a-z0-9\.\-_]*)/?$',
re_path(r'^packages/host/(?P<hostname>[a-z0-9\.\-_]*)/?$',
views.packages,
name='packages-by-host'),
# os statistics
url(r'^os-statistics/?$',
re_path(r'^os-statistics/?$',
views.os_statistics,
name='os-statistics'),
# history graphs
url(r'^history/(?P<obj>updates|uptime|os)/?$',
re_path(r'^history/(?P<obj>updates|uptime|os)/?$',
views.history,
name='history'),
url(r'^history/(?P<obj>updates|uptime|os)/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/?$',
re_path(r'^history/(?P<obj>updates|uptime|os)/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/?$',
views.history,
name='history'),
# manage statuses
url(r'^manage/?$',
re_path(r'^manage/?$',
views.manage,
name='manage'),
url(r'^manage/purge/?$',
re_path(r'^manage/purge/?$',
views.purge_all,
name='purge_all'),
url(r'^manage/purge/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
re_path(r'^manage/purge/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
views.purge_statuses_by_date,
name='purge_statuses_by_date'),
url(r'^manage/import/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
re_path(r'^manage/import/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
views.import_csv,
name='import'),
url(r'^manage/update-groups/?$',
re_path(r'^manage/update-groups/?$',
views.update_groups,
name='update_groups'),
# manage packages
url(r'^manage-packages/?$',
re_path(r'^manage-packages/?$',
views.manage_packages,
name='manage-packages'),
url(r'^manage-packages/purge/?$',
re_path(r'^manage-packages/purge/?$',
views.purge_packages,
name='purge_packages'),
url(r'^manage-packages/import/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
re_path(r'^manage-packages/import/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/?$',
views.import_csv_packages,
name='import-packages'),
# user
url(r'^login/?$', auth_views.LoginView.as_view(), name='login'),
url(r'^logout/?$', auth_views.LogoutView.as_view(), name='logout'),
re_path(r'^login/?$', auth_views.LoginView.as_view(), name='login'),
re_path(r'^logout/?$', auth_views.LogoutView.as_view(), name='logout'),
]
# debug toolbar
if settings.DEBUG and settings.DEBUG_TOOLBAR:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
re_path(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns

View File

@ -379,8 +379,7 @@ def purge_packages(request):
@login_required
def import_csv(request, year, month, day):
# Reminder: the imported file must be in this format:
# myserver.fr;Ubuntu;16;28;12;UNK
# | | | | | |- 5: auto updates status
# myserver.fr;Ubuntu;16;28;12
# | | | | |----- 4: uptime in days
# | | | |-------- 3: number of available updates
# | | |----------- 2: OS major version (string). Must match with OS model data
@ -417,7 +416,6 @@ def import_csv(request, year, month, day):
row_os_version = row[2]
row_updates = row[3] if row[3] else None
row_uptime = row[4] if row[4] else None
row_auto_updates = row[5] if row[5] else None
# get OS
cache_key_os = "os_%s_%s" % (row_os_distribution, row_os_version)
@ -453,7 +451,6 @@ def import_csv(request, year, month, day):
)
current_st.updates = row_updates
current_st.uptime = row_uptime
current_st.auto_updates = row_auto_updates
try:
current_st.save()
except IntegrityError:

View File

@ -9,6 +9,7 @@ SECRET_KEY = 'long random key'
#DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', ]
CSRF_TRUSTED_ORIGINS ['127.0.0.1']
# for debug_toolbar
INTERNAL_IPS = ['127.0.0.1', ]

View File

@ -5,18 +5,19 @@ The `urlpatterns` list routes URLs to views. For more information please see:
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
2. Add a URL to urlpatterns: re_path(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
2. Add a URL to urlpatterns: re_path(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
2. Add a URL to urlpatterns: re_path(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.conf.urls import include
from django.urls import re_path
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('dashboard.urls')),
re_path(r'^admin/', admin.site.urls),
re_path(r'^', include('dashboard.urls')),
]