Add: collecor templatetags and filters
This commit is contained in:
parent
9478843c0f
commit
06648a237a
@ -1,3 +1,5 @@
|
|||||||
|
{% load collector_extras %}
|
||||||
|
{% get_platforms as platforms %}
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
|
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
|
||||||
<symbol id="check2" viewBox="0 0 16 16">
|
<symbol id="check2" viewBox="0 0 16 16">
|
||||||
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
|
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
|
||||||
@ -43,11 +45,10 @@
|
|||||||
{% for platform in platforms %}
|
{% for platform in platforms %}
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
class="dropdown-item"
|
class="dropdown-item {% if request.resolver_match.kwargs.platform == platform.name %}active{% endif %}"
|
||||||
href="{{ platform.get_absolute_url }}"
|
href="{{ platform.get_absolute_url }}"
|
||||||
>{{ platform.pretty_name}}
|
>{{ platform.pretty_name}}
|
||||||
</a
|
</a>
|
||||||
>
|
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li><hr class="dropdown-divider" /></li>
|
<li><hr class="dropdown-divider" /></li>
|
||||||
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.5 KiB |
@ -1,9 +1,10 @@
|
|||||||
|
{% load collector_extras %}
|
||||||
<li
|
<li
|
||||||
id="li-archive-{{ archive.id }}"
|
id="li-archive-{{ archive.id }}"
|
||||||
class="list-group-item list-group-item-action">
|
class="list-group-item list-group-item-action">
|
||||||
<smal>
|
<smal>
|
||||||
<b>File:</b>
|
<b>File:</b>
|
||||||
<span style="word-wrap: break-word">{{ archive.file }}</span>
|
<span style="word-wrap: break-word">{{ archive.file.name|clean_filename }}</span>
|
||||||
</small>
|
</small>
|
||||||
<small>
|
<small>
|
||||||
<br>
|
<br>
|
||||||
@ -13,12 +14,12 @@
|
|||||||
<small>
|
<small>
|
||||||
<br>
|
<br>
|
||||||
<b>Uploaded:</b>
|
<b>Uploaded:</b>
|
||||||
<span style="word-wrap: break-word">{{ archive.time_update }}</span>
|
<span style="word-wrap: break-word">{{ archive.time_update|date:"D d.m.y H:i" }}</span>
|
||||||
</small>
|
</small>
|
||||||
<br>
|
<br>
|
||||||
<small>
|
<small>
|
||||||
<b>Size:</b>
|
<b>Size:</b>
|
||||||
<span style="word-wrap: break-word">{{ archive.size }}</span>
|
<span style="word-wrap: break-word">{{ archive.file.size|sizify }}</span>
|
||||||
</small>
|
</small>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="d-flex justify-content-sm-start justify-content-between" >
|
<div class="d-flex justify-content-sm-start justify-content-between" >
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div class="d-sm-flex w-100 justify-content-between mb-2">
|
<div class="d-sm-flex w-100 justify-content-between mb-2">
|
||||||
<h4 class="card-title mb-1">Ticket: {{ ticket.number }}</h4>
|
<h4 class="card-title mb-1">Ticket: {{ ticket.number }}</h4>
|
||||||
<small><i class="bi bi-clock-history"></i> {{ ticket.time_create }}</small>
|
<small><i class="bi bi-clock-history"></i> {{ ticket.time_create|date:"D d.m.y H:i" }}</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-switch form-check-reverse d-flex w-100 justify-content-left">
|
<div class="form-check form-switch form-check-reverse d-flex w-100 justify-content-left">
|
||||||
<label class="form-check-label" for="ticket-state">Resolved:</label>
|
<label class="form-check-label" for="ticket-state">Resolved:</label>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<!-- Ticket -->
|
<!-- Ticket -->
|
||||||
{% for ticket in tickets %}
|
{% for ticket in tickets %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="div-ticket-{{ ticket.number }}" class="list-group mb-2">
|
<div id="div-ticket-{{ ticket.number }}" class="list-group mb-2 ms-1">
|
||||||
<div class="list-group-item list-group-item-action disable" aria-current="true">
|
<div class="list-group-item list-group-item-action disable" aria-current="true">
|
||||||
{% include 'collector/includes/ticket_info.html' %}
|
{% include 'collector/includes/ticket_info.html' %}
|
||||||
<div class="col-xl-6 mt-1 mb-2">
|
<div class="col-xl-6 mt-1 mb-2">
|
||||||
|
0
logs_collector/collector/templatetags/__init__.py
Normal file
0
logs_collector/collector/templatetags/__init__.py
Normal file
48
logs_collector/collector/templatetags/collector_extras.py
Normal file
48
logs_collector/collector/templatetags/collector_extras.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from django import template
|
||||||
|
from collector.models import Platform
|
||||||
|
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag()
|
||||||
|
def get_platforms():
|
||||||
|
return Platform.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter(name='sizify')
|
||||||
|
def sizify(value: int) -> str:
|
||||||
|
"""Simple kb/mb/gb size snippet for templates:
|
||||||
|
|
||||||
|
{{ Archive.file.size|sizify }}
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (int): size of file from Filefield
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: format human readable size like 4.2 Gb
|
||||||
|
"""
|
||||||
|
|
||||||
|
if value < 512000:
|
||||||
|
value = value / 1024.0
|
||||||
|
ext = 'Kb'
|
||||||
|
elif value < 4194304000:
|
||||||
|
value = value / 1048576.0
|
||||||
|
ext = 'Mb'
|
||||||
|
else:
|
||||||
|
value = value / 1073741824.0
|
||||||
|
ext = 'Gb'
|
||||||
|
return f'{round(value, 2)} {ext}'
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter(name='clean_filename')
|
||||||
|
def clean_filename(filename: str) -> str:
|
||||||
|
"""delete prefix ticket number folder for template
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filename (str): filename from Filefield
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: only filename
|
||||||
|
"""
|
||||||
|
return filename.rpartition('/')[-1]
|
@ -34,10 +34,10 @@ class ListAllTickets(generic.ListView):
|
|||||||
context_object_name = 'tickets'
|
context_object_name = 'tickets'
|
||||||
paginate_by = 5
|
paginate_by = 5
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
# def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
# context = super().get_context_data(**kwargs)
|
||||||
context['platforms'] = Platform.objects.all()
|
# context['platforms'] = Platform.objects.all()
|
||||||
return context
|
# return context
|
||||||
|
|
||||||
|
|
||||||
class ListPlatformTickets(generic.ListView):
|
class ListPlatformTickets(generic.ListView):
|
||||||
|
Loading…
Reference in New Issue
Block a user