Add: collecor templatetags and filters

This commit is contained in:
Stepan Zhukovsky 2023-08-05 14:41:29 +09:00
parent 9478843c0f
commit 06648a237a
7 changed files with 62 additions and 12 deletions

View File

@ -1,3 +1,5 @@
{% load collector_extras %}
{% get_platforms as platforms %}
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
<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"/>
@ -43,11 +45,10 @@
{% for platform in platforms %}
<li>
<a
class="dropdown-item"
class="dropdown-item {% if request.resolver_match.kwargs.platform == platform.name %}active{% endif %}"
href="{{ platform.get_absolute_url }}"
>{{ platform.pretty_name}}
</a
>
</a>
</li>
{% endfor %}
<li><hr class="dropdown-divider" /></li>

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -1,9 +1,10 @@
{% load collector_extras %}
<li
id="li-archive-{{ archive.id }}"
class="list-group-item list-group-item-action">
<smal>
<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>
<br>
@ -13,12 +14,12 @@
<small>
<br>
<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>
<br>
<small>
<b>Size:</b>
<span style="word-wrap: break-word">{{ archive.size }}</span>
<span style="word-wrap: break-word">{{ archive.file.size|sizify }}</span>
</small>
<div class="row">
<div class="d-flex justify-content-sm-start justify-content-between" >

View File

@ -1,6 +1,6 @@
<div class="d-sm-flex w-100 justify-content-between mb-2">
<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 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>

View File

@ -7,7 +7,7 @@
<!-- Ticket -->
{% for ticket in tickets %}
<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">
{% include 'collector/includes/ticket_info.html' %}
<div class="col-xl-6 mt-1 mb-2">

View 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]

View File

@ -34,10 +34,10 @@ class ListAllTickets(generic.ListView):
context_object_name = 'tickets'
paginate_by = 5
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['platforms'] = Platform.objects.all()
return context
# def get_context_data(self, **kwargs):
# context = super().get_context_data(**kwargs)
# context['platforms'] = Platform.objects.all()
# return context
class ListPlatformTickets(generic.ListView):