Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4e7bd19
Add field to prevent multiple notifications
tboulogne Oct 18, 2020
c58bf62
Check previous send
tboulogne Oct 18, 2020
225c4ea
fix type
tboulogne Oct 18, 2020
14a376a
update fields
tboulogne Oct 18, 2020
f943cc2
save notification send confirm
tboulogne Oct 18, 2020
f746ec6
add returnt obj to create_or_update_entity
tboulogne Oct 18, 2020
ce18743
add login_required to permission wrapper
tboulogne Oct 18, 2020
51bf232
Pretiffy request_data display
tboulogne Oct 18, 2020
ace6530
- upgrade to bootstrap 4
tboulogne Oct 18, 2020
f8d5f23
remove border
tboulogne Oct 18, 2020
eaadf4c
add APP_ERROR_NOTIFICATION_ONCE and APP_ERROR_TICKET_ONCE
tboulogne Oct 19, 2020
4321131
fix migrations
tboulogne Oct 19, 2020
5d10afd
Set default to NONE
tboulogne Oct 19, 2020
50a9bb7
change notification_send to notification_sent
tboulogne Oct 20, 2020
0d12fe8
linting in model
tboulogne Oct 20, 2020
68aafcd
Merge branch 'master' of https://github.com/sonus21/error-tracker int…
tboulogne Oct 22, 2020
6c68807
Merge branch 'sonus21-master'
tboulogne Oct 22, 2020
e78538b
add ajax list
tboulogne Oct 22, 2020
ec4608d
- add ajax to list
tboulogne Oct 22, 2020
6cbc853
query refactoring for get_exceptions_per_page
tboulogne Oct 23, 2020
f8da4ec
simplify query and change query to **query
tboulogne Oct 23, 2020
ea8dd3e
Move SimpleCookie into code
tboulogne Oct 23, 2020
6b946ab
fix mixin with kwarks
tboulogne Oct 23, 2020
61d28a8
filter input on keypress
tboulogne Oct 25, 2020
9ca2c49
remove 002_xx migrations
tboulogne Oct 26, 2020
ebe836e
restore migration file
tboulogne Oct 26, 2020
ad7abcf
fix test
tboulogne Oct 26, 2020
e2d04a2
ccheck
tboulogne Oct 26, 2020
0b6ae77
remove login_required
tboulogne Oct 26, 2020
04dc8fa
complete translation string
tboulogne Oct 26, 2020
209a0c1
Merge branch 'master' into master
sonus21 Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ venv.bak/
# mypy
.mypy_cache/
.idea
.vscode/settings.json
2 changes: 1 addition & 1 deletion error_tracker/django/migrations/0002_auto_20201018_1311.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class Migration(migrations.Migration):
name='ticket_raised',
field=models.BooleanField(default=False),
),
]
]
14 changes: 12 additions & 2 deletions error_tracker/django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ class AbstractErrorModel(models.Model, ModelMixin):
ticket_raised = models.BooleanField(default=False)

@classmethod
def get_exceptions_per_page(cls, page_number=1):
records = cls.objects.all().order_by('last_seen')
def get_exceptions_per_page(cls, page_number=1, **query):
if query:
if 'page' in query:
page_number = query['page']
del query['page']
query = {"{}__icontains".format(k): v for k, v in query.items()}

if not query:
records = cls.objects.all().order_by('last_seen')
else:
records = cls.objects.filter(**query).order_by('last_seen')

paginator = Paginator(records, EXCEPTION_APP_DEFAULT_LIST_SIZE)
try:
page = paginator.page(page_number)
Expand Down
21 changes: 20 additions & 1 deletion error_tracker/django/templates/error_tracker/base.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -12,14 +13,32 @@
font-size: 14px;
}
</style>

<script>
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
</script>
{% endblock %}
</head>
<title>{{ title }}</title>
<body>
<div class="container">
{% block header_block %}
<h2 class="text-center mb-5 mt-3">
<a href="{% url 'view_errors' %}" class="text-dark">Errors Seen</a>
<a href="{% url 'view_errors' %}" class="text-dark home-link">{% trans 'Errors Seen' %}</a>
</h2>
{% endblock %}
{% block content_block %}
Expand Down
16 changes: 8 additions & 8 deletions error_tracker/django/templates/error_tracker/detail.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% extends 'error_tracker/base.html' %}
{% load error_tracker %}
{% load error_tracker i18n %}

{% block content_block %}
{% if error %}
<h1 class="text-center alert alert-danger">{{ error }}</h1>
{% else %}

<div class="row mb-4">
<div class="col-md-2 bg-dark p-1 text-white text-center font-weight-bold">Method</div>
<div class="col-md-10 bg-dark p-1 text-white text-center font-weight-bold">Referrer</div>
<div class="col-md-2 bg-dark p-1 text-white text-center font-weight-bold">{%trans 'Method' %}</div>
<div class="col-md-10 bg-dark p-1 text-white text-center font-weight-bold">{%trans 'Referrer' %}</div>
<div class="col-md-2 p-1 text-center bg-light">
{{ obj.method }}
</div>
Expand All @@ -19,24 +19,24 @@ <h1 class="text-center alert alert-danger">{{ error }}</h1>

<div class="row mb-4 mt-2">
<div class="col-md-4 p-0">
<div class="col-md-12 text-center bg-dark text-white font-weight-bold p-0">First time seen</div>
<div class="col-md-12 text-center bg-dark text-white font-weight-bold p-0">{%trans 'First time seen' %}</div>
<div class="col-md-12 text-center bg-light">{{ obj.created_on }}</div>
</div>
<div class="col-md-4 p-0">
<div class="col-md-12 text-center bg-dark text-white font-weight-bold">Last seen</div>
<div class="col-md-12 text-center bg-dark text-white font-weight-bold">{%trans 'Last seen' %}</div>
<div class="col-md-12 text-center bg-light">{{ obj.last_seen }}</div>
</div>
<div class="col-md-4 p-0">
<div class="col-md-12 text-center bg-dark text-white font-weight-bold" >Occurrences</div>
<div class="col-md-12 text-center bg-dark text-white font-weight-bold" >{%trans 'Occurrences' %}</div>
<div class="col-md-12 text-center bg-light">{{ obj.count }}</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center bg-dark text-white font-weight-bold p-1">Request data</div>
<div class="col-md-12 text-center bg-dark text-white font-weight-bold p-1">{%trans 'Request data' %}</div>
<div class="col-md-12 col-lg-12 bg-light">{{obj.request_data|to_pretty}}</div>
</div>
<div class="row">
<div class="col-md-12 text-center bg-dark text-white font-weight-bold p-1">Exception detail</div>
<div class="col-md-12 text-center bg-dark text-white font-weight-bold p-1">{%trans 'Exception detail' %}</div>
<div class="col-md-12 bg-light"><pre> {{obj.traceback|escape|replace_new_line_with_br|safe}}</pre>
</div>
</div>
Expand Down
141 changes: 94 additions & 47 deletions error_tracker/django/templates/error_tracker/list.html
Original file line number Diff line number Diff line change
@@ -1,60 +1,107 @@
{% extends 'error_tracker/base.html' %}
{% load i18n %}

{% block head_script %}
{{block.super}}
<script>
$(document).ready(function(){
ajax_paginate()
filter_watch()
filter_reset()
})

function ajax_paginate(){
$('a.pagelink').click(function(e) {
e.preventDefault();
submit_data($(this).attr("href"))
});
}

function filter_watch(){
$(".filter-ajax").on('blur, keyup',function(e){
e.stopImmediatePropagation()
if(e.which == 9 || e.which == 8 || e.which == 13 || $(this).val().length>=3){
submit_data()
}
tab_stop(e)
})
}

function submit_data(url){
form = $("#my_form") //.submit()
if(url==undefined){
url = form.attr('action')
}
data = form.serializeArray().reduce(
function(a, x) { if(x.value){ a[x.name] = x.value;} return a; }, {}
);

$.get(url, data, function(response) {
$('#the_table').html(response.table)
$('#navigations').html(response.navigation)
ajax_paginate()
});
}

function filter_reset(){
$("#filter-reset").on("click", function(){

$('form[name="filter-form"] .filter-ajax').each(function(e, item){
$(item).val("")
})
submit_data()
})
}

function tab_stop(e){
var tab_stop = $(e.target).attr('tab-stop');
if(tab_stop !== undefined){
parent = $(e.target).parents("#head_filter")
parent.find('input').first().focus()
}
}
</script>
{%endblock%}

{% block content_block %}
<div class="row mb-4">
{% if error %}
<h1 class="text-center alert alert-danger">{{ error }}</h1>
{% else %}
<table class="table table-striped">
<thead>
<tr>
<th>Host</th>
<th>Method</th>
<th>Path</th>
<th>Exception</th>
<th>Last seen</th>
<th>Occurrences</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for error in errors.items %}
<tr>
<td>{{ error.host }}</td>
<td>{{ error.method }}</td>
<td>
<a class="view-link" href="{% url 'view_error' rhash=error.hash %}">
{{ error.path|truncatechars:30 }}
</a>
</td>
<td>{{ error.exception_name }}</td>
<td>{{ error.last_seen }}</td>
<td>{{ error.count }}</td>
<td>
<a href="{% url 'delete_error' rhash=error.hash %}"
class="delete btn btn-danger btn-sm">Delete</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="col-md-12">
<form method="GET" id="my_form" action="/error_tracker/" name="filter-form">
<table class="table table-striped border-1 w-100">
<thead>
<th>{% trans 'Host' %}</th>
<th width="2%">{% trans 'Method' %}</th>
<th>{% trans 'Path' %}</th>
<th>{% trans 'Exception' %}</th>
<th>{% trans 'Last seen' %}</th>
<th width="7%">#</th>
<th>{% trans 'Action' %}</th>
</thead>
<thead id="head_filter">
<td><input form='my_form' value="" type="text" name="host" id="id_host" class="form-control filter-ajax"></td>
<td><input form='my_form' value="" type="text" name="method" id="id_method" class="form-control filter-ajax"></td>
<td><input form='my_form' value="" type="text" name="path" id="id_path" class="form-control filter-ajax"></td>
<td><input form='my_form' value="" type="text" name="exception_name" id="id_exception_name" class="form-control filter-ajax"></td>
<td><input form='my_form' value="" type="text" name="last_seen" id="id_last_seen" class="form-control filter-ajax"></td>
<td><input form='my_form' value="" type="text" name="count" id="id_count" class="form-control filter-ajax" tab-stop></td>
<td><a tabindex="0" id='filter-reset' class="form-control btn btn-primary mb-2 mr-sm-2" >{% trans 'Reset' %}</a></td>
</thead>
<tbody id='the_table' class="w-100">
{% include 'error_tracker/partials/partial_table.html' %}
</tbody>

</table>
</form>

{% if prev_url or next_url %}
<hr>
<div>
<div style="margin: 0 auto;text-align: center;">
{% if prev_url %}
<a href="{{ prev_url }}" style="{% if next_url %}margin-right: 10px{% endif %}">
<i class="glyphicon glyphicon-circle-arrow-left"></i> Newer exceptions
</a>
{% endif %}
{% if next_url %}
<a href="{{ next_url }}" style="{% if prev_url %}margin-left: 10px;{% endif %}">
Older exceptions <i class="glyphicon glyphicon-circle-arrow-right"></i>
</a>
{% endif %}
</div>
<div id='navigations' class='text-center'>
{% include 'error_tracker/partials/navigation.html' %}
</div>
{% endif %}
</div>
{% endif %}
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load i18n %}

{% if prev_url %}
<a href="{{ prev_url }}" class="pagelink text-white bg-secondary p-2" style="{% if next_url %}margin-right: 10px{% endif %}">
<i class="glyphicon glyphicon-circle-arrow-left"></i> {% trans 'Newer exceptions' %} </a>
{% endif %}
{% if next_url %}
<a href="{{ next_url }}" class="pagelink text-white bg-secondary p-2" style="{% if prev_url %}margin-left: 10px;{% endif %}">
{% trans 'Older exceptions' %} <i class="glyphicon glyphicon-circle-arrow-right"></i>
</a>
{% endif %}



Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load i18n %}
{% for error in errors.items %}
<tr>
<td>{{ error.host }}</td>
<td width="2%">{{ error.method }}</td>
<td>
<a class="view-link" href="{% url 'view_error' rhash=error.hash %}">
{{ error.path|truncatechars:30 }}
</a>
</td>
<td>{{ error.exception_name }}</td>
<td>{{ error.last_seen }}</td>
<td>{{ error.count }}</td>
<td>
<a href="{% url 'delete_error' rhash=error.hash %}"
class="delete btn btn-danger btn-sm">{%trans 'Delete' %}</a>
</td>
</tr>
{% endfor %}
14 changes: 9 additions & 5 deletions error_tracker/django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
# :license: BSD-3-Clause
#

import re
import json
from django.http import RawPostDataException
import re
try:
from http.cookies import SimpleCookie
except ImportError:
pass

from error_tracker.libs.mixins import ContextBuilderMixin, NotificationMixin, ViewPermissionMixin
from error_tracker.libs.mixins import (ContextBuilderMixin, NotificationMixin,
ViewPermissionMixin)
from error_tracker.libs.utils import get_context_dict

from django.core.mail import send_mail
from django.http import RawPostDataException


class DefaultDjangoContextBuilder(ContextBuilderMixin):
Expand Down Expand Up @@ -90,7 +96,6 @@ def notify(self, request, exception,
exception.notification_sent = True
exception.save()


class DefaultDjangoViewPermission(ViewPermissionMixin):

def __call__(self, request):
Expand Down Expand Up @@ -197,7 +202,6 @@ def get_value(key, value):
except Exception as e:
if key in ["Cookie", "cookie"]:
try:
from http.cookies import SimpleCookie
try:
cookie = SimpleCookie()
cookie.load(value)
Expand Down
Loading