Commit 5f370671 by François C.

Add first step of monitoring stuff

parent 055d4c07
Pipeline #2569 failed with stage
in 1 minute 18 seconds
from django.db import models
from outils.common_imports import *
import glob
class ThirdPartyAdmin(models.Model):
"""Class to manage third party and view logs"""
@staticmethod
def get_django_logs():
content = []
for file in glob.glob("log/*.log"):
with open(file) as f:
content.append({'key' :file, 'value': f.readlines()})
return content
\ No newline at end of file
var load_content = async function(url, call_back) {
openModal();
try {
let res = await fetch(url);
content = await res.json()
closeModal();
return content;
} catch (main_error) {
return {error: main_error}
}
};
var tabsStructure = {
tabs : [],
parentElt : null,
structure: null,
init: async function(params) {
let data = params.data || [];
this.parentElt = params.parentElt || document.querySelector('body');
data.forEach((item, idx) => {
let tab = {
label: item.key,
content: item.value,
idx: idx
};
this.tabs.push(tab);
});
},
tab_format_content: function(content, idx=0) {
let html_content = "";
if (Array.isArray(content) == true) {
content.forEach((elt) => {
html_content += this.tab_format_content(elt) + "<br/>";
});
} else if (typeof content === "string") {
html_content += content.replace("\n", "<br/>");
} else {
html_content += JSON.stringify(content) + "<br/>";
}
return html_content;
},
draw: async function() {
if (this.tabs.length > 0) {
//generate dom structure according https://codepen.io/dhs/pen/zYErrW (Pure CSS tabs without Javascript)
this.structure = document.createElement("ul");
this.structure.classList.add("tabs");
this.tabs.forEach((tab) => {
let li = document.createElement("li"),
input = document.createElement("input"),
label = document.createElement("label"),
div = document.createElement("div");
li.classList.add("tab", "elt" + tab.idx);
input.setAttribute("type", "radio");
input.setAttribute("name", "tabs");
input.setAttribute("id", "tab-" + tab.idx);
if (tab.idx == 0) input.setAttribute("checked", "checked")
label.setAttribute("for", "tab-" + tab.idx);
label.innerText = tab.label;
div.classList.add("content");
div.setAttribute("id", "tab-content-" + tab.idx);
div.innerHTML = this.tab_format_content(tab.content);
li.append(input);
li.append(label);
li.append(div);
this.structure.append(li);
this.parentElt.append(this.structure);
});
}
}
};
var createTabs = async function(params) {
let result = null,
p = params || {};
try {
let tabs = Object.create(tabsStructure);
await tabs.init(p);
await tabs.draw();
result = tabs;
} catch (e) {
alert("Les onglets n'ont pas pu être créés");
console.log(e);
}
return result;
}
$('#back_to_admin_index').on('click', function() {
const to_remove = window.location.href.split('/').pop();
const new_url = window.location.href.replace(to_remove, "");
window.location.href = new_url;
});
\ No newline at end of file
// Chargement des données et traitement
load_content('/administration/retrieve_django_logs').then(rep => {
if (typeof rep.content !== "undefined") {
const params = {
parentElt: document.querySelector('[class="page_body"]'),
data: rep.content
};
let tabs = createTabs(params);
} else {
alert("La récupération des fichiers n'a pas aboutie");
}
});
\ No newline at end of file
$(document).ready(function() {
if (coop_is_connected()) {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
$(".page_content").show();
let location = window.location.href.replace(/\/$/, '');
$('.management_type_button').on('click', function() {
if (this.id == 'manage_django_logs') {
window.location.assign(location + "/django_logs");
} else if (this.id == 'manage_odoo_logs') {
window.location.assign(location + "/odoo_logs");
}
});
} else {
$(".page_content").hide();
}
});
\ No newline at end of file
"""."""
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^django_logs$', views.django_logs, name='index'),
url(r'^odoo_logs$', views.odoo_logs, name='index'),
url(r'^retrieve_django_logs$', views.retrieve_django_logs, name='index'),
]
\ No newline at end of file
"""Admin views."""
from outils.common_imports import *
from outils.for_view_imports import *
from administration.models import ThirdPartyAdmin
from members.models import CagetteUser
def index(request):
"""Main third-party admin page."""
template = loader.get_template('admin/index.html')
context = {
'title': 'Admin'
}
if CagetteUser.are_credentials_ok(request):
context['is_connected'] = True
if CagetteUser.isAllowedToAdmin(request):
context['is_admin'] = True
return HttpResponse(template.render(context, request))
def django_logs(request):
""" Administration des créneaux des membres """
template = loader.get_template('admin/django_logs.html')
context = {
'title': 'Logs Django',
}
return HttpResponse(template.render(context, request))
def odoo_logs(request):
""" Administration des créneaux des membres """
template = loader.get_template('admin/odoo_logs.html')
context = {
'title': 'Logs Odoo',
}
return HttpResponse(template.render(context, request))
def retrieve_django_logs(request):
if CagetteUser.are_credentials_ok(request) and CagetteUser.isAllowedToAdmin(request):
response = JsonResponse({'content': ThirdPartyAdmin.get_django_logs()})
else:
response = JsonResponse({}, status=403)
return response
\ No newline at end of file
$(document).ready(function() {
if (coop_is_connected()) {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
$(".page_content").show();
} else {
$(".page_content").hide();
}
});
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block additionnal_css %}
<link rel="stylesheet" href="{% static 'css/diasg_tabs.css' %}">
<link rel="stylesheet" href="{% static 'css/admin_common.css' %}">
{% endblock %}
{% block content %}
<div id="admin_connexion_button">
{% include "common/conn_admin.html" %}
</div>
<div class="page_body">
<div id="back_to_admin_index">
<button type="button" class="btn--danger"><i class="fas fa-arrow-left"></i>&nbsp; Retour</button>
</div>
</div>
<script src='{% static "js/all_common.js" %}?v=1651853225'></script>
<script src='{% static "js/admin_common.js" %}?v=1651853225'></script>
<script src='{% static "js/django_logs.js" %}?v=1651853225'></script>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block additionnal_css %}
<link rel="stylesheet" href="{% static 'css/admin/bdm_index.css' %}">
{% endblock %}
{% block content %}
<div id="admin_connexion_button">
{% include "common/conn_admin.html" %}
</div>
<div class="page_body">
<div id="content_main" class="page_content">
<div class="header txtcenter">
<h1>Administration</h1>
</div>
<div>
{% if is_connected %}
{% if is_admin %}
<div class="management_type_buttons txtcenter">
<button type="button" class="btn--primary management_type_button" id="manage_django_logs">
Logs Django
<span class="management_type_button_icons"><i class="fas fa-arrow-right"></i></span>
</button><br>
<button type="button" class="btn--primary management_type_button" id="manage_odoo_logs">
Logs Odoo
<span class="management_type_button_icons"><i class="fas fa-arrow-right"></i></span>
</button><br>
</div>
{% else %}
Vous n'avez pas les droits suffisants pour accéder au contenu.
{% endif %}
{% else %}
Authentification obligatoire, avec droits admin
{% endif %}
</div>
</div>
</div>
<script src="{% static "js/all_common.js" %}?v=1651853225"></script>
<script src="{% static "js/master_admin.js" %}?v=1651853225"></script>
{% endblock %}
{% extends "base.html" %}
{% load static %}
{% block additionnal_css %}
{% endblock %}
{% block additionnal_scripts %}
{% endblock %}
{% block content %}
<div class="page_body">
<div id="back_to_admin_index">
<button type="button" class="btn--danger"><i class="fas fa-arrow-left"></i>&nbsp; Retour</button>
</div>
<div class="login_area">
{% include "common/conn_admin.html" %}
</div>
</div>
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block additionnal_css %}
<link rel="stylesheet" href="{% static 'css/datatables/jquery.dataTables.css' %}">
<link rel="stylesheet" href="{% static 'css/products.css' %}">
{% endblock %}
{% block additionnal_scripts %}
<script type="text/javascript" src="{% static 'js/datatables/jquery.dataTables.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/datatables/dataTables.plugins.js' %}"></script>
<script type="text/javascript" src="{% static 'js/admin/labels.js' %}?v=1651853225"></script>
<script type="text/javascript" src="{% static 'js/notify.min.js' %}?v=1651853225"></script>
{% endblock %}
{% block content %}
<div class="page_body">
<div class="login_area">
{% include "common/conn_admin.html" %}
</div>
<div class="header txtcenter">
<h1>Etiquettes des produits</h1>
</div>
<div class="page_content">
<div class="main">
<table id="products_table" class="display" cellspacing="0" ></table>
</div>
</div>
</div>
<script src="{% static "js/all_common.js" %}?v=1651853225"></script>
<script src="{% static "js/common.js" %}?v=1651853225"></script>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment