Compare commits

...

7 commits

14 changed files with 128 additions and 27 deletions

View file

@ -194,10 +194,10 @@
{% endif %} {% endif %}
</h1> </h1>
<form method="post" action="{% url 'dashboard:search' %}"> <form method="get" action="{% url 'dashboard:search' %}">
{% csrf_token %} {% csrf_token %}
<div class="input-group rounded"> <div class="input-group rounded">
<input type="search" name="search" class="form-control rounded" placeholder="Search your device..." aria-label="Search" aria-describedby="search-addon" /> <input type="search" name="search" class="form-control rounded" {% if search %}value="{{ search }}" {% endif %}placeholder="Search your device..." aria-label="Search" aria-describedby="search-addon" />
<span class="input-group-text border-0" id="search-addon"> <span class="input-group-text border-0" id="search-addon">
<i class="fas fa-search"></i> <i class="fas fa-search"></i>
</span> </span>

View file

@ -4,12 +4,12 @@
<ul class="pagination"> <ul class="pagination">
{% if page_number > 1 %} {% if page_number > 1 %}
<li class="previous"> <li class="previous">
<a type="button" class="btn btn-grey border border-dark" href="?page=1&limit={{ limit }}"> <a type="button" class="btn btn-grey border border-dark" href="?page=1&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
&laquo; &laquo;
</a> </a>
</li> </li>
<li class="previous"> <li class="previous">
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:-1 }}&limit={{ limit }}"> <a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:-1 }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
{% trans 'Previous' %} {% trans 'Previous' %}
</a> </a>
</li> </li>
@ -24,7 +24,7 @@
{% if p == page_number or p == "..." %} {% if p == page_number or p == "..." %}
href="#"> href="#">
{% else %} {% else %}
href="?page={{ p }}&limit={{ limit }}"> href="?page={{ p }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
{% endif %} {% endif %}
{{ p }} {{ p }}
</a> </a>
@ -34,12 +34,12 @@
{% if page_number < total_pages %} {% if page_number < total_pages %}
<li class="previous"> <li class="previous">
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:+1 }}&limit={{ limit }}"> <a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:+1 }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
{% trans 'Next' %} {% trans 'Next' %}
</a> </a>
</li> </li>
<li class="previous"> <li class="previous">
<a type="button" class="btn btn-grey border border-dark" href="?page={{ total_pages }}&limit={{ limit }}"> <a type="button" class="btn btn-grey border border-dark" href="?page={{ total_pages }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
&raquo; &raquo;
</a> </a>
</li> </li>

View file

@ -86,7 +86,7 @@
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="col"> <div class="col">
{% render_pagination page total_pages limit %} {% render_pagination page total_pages limit search %}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -3,7 +3,7 @@ from django import template
register = template.Library() register = template.Library()
@register.inclusion_tag('pagination.html') @register.inclusion_tag('pagination.html')
def render_pagination(page_number, total_pages, limit=10): def render_pagination(page_number, total_pages, limit=10, search=None):
""" """
Template tag for render pagination Template tag for render pagination
@ -16,5 +16,6 @@ def render_pagination(page_number, total_pages, limit=10):
return { return {
'page_number': page_number, 'page_number': page_number,
'total_pages': total_pages, 'total_pages': total_pages,
'limit': limit 'limit': limit,
"search": search,
} }

View file

@ -72,9 +72,20 @@ class SearchView(InventaryMixin):
title = _("Search Devices") title = _("Search Devices")
breadcrumb = "Devices / Search Devices" breadcrumb = "Devices / Search Devices"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
search_params = self.request.GET.urlencode(),
search = self.request.GET.get("search")
if search:
context.update({
'search_params': search_params,
'search': search
})
return context
def get_devices(self, user, offset, limit): def get_devices(self, user, offset, limit):
post = dict(self.request.POST) query = dict(self.request.GET).get("search")
query = post.get("search")
if not query: if not query:
return [], 0 return [], 0
@ -85,6 +96,12 @@ class SearchView(InventaryMixin):
offset, offset,
limit limit
) )
count = search(
self.request.user.institution,
query[0],
0,
9999
).size()
if not matches or not matches.size(): if not matches or not matches.size():
return self.search_hids(query, offset, limit) return self.search_hids(query, offset, limit)
@ -99,7 +116,6 @@ class SearchView(InventaryMixin):
devices.append(dev) devices.append(dev)
dev_id.append(dev.id) dev_id.append(dev.id)
count = matches.size()
# TODO fix of pagination, the count is not correct # TODO fix of pagination, the count is not correct
return devices, count return devices, count

View file

@ -336,7 +336,7 @@ class Device:
FROM FROM
RankedProperties RankedProperties
WHERE WHERE
row_num = 1; row_num = 1
ORDER BY created DESC ORDER BY created DESC
""".format( """.format(
uuid=uuid.replace("-", ""), uuid=uuid.replace("-", ""),

View file

@ -147,6 +147,7 @@ run_demo() {
'example/demo-snapshots-vc/snapshot_pre-verifiable-credential.json' \ 'example/demo-snapshots-vc/snapshot_pre-verifiable-credential.json' \
> 'example/snapshots/snapshot_workbench-script_verifiable-credential.json' > 'example/snapshots/snapshot_workbench-script_verifiable-credential.json'
fi fi
./manage.py create_default_states "${INIT_ORG}"
/usr/bin/time ./manage.py up_snapshots example/snapshots/ "${INIT_USER}" /usr/bin/time ./manage.py up_snapshots example/snapshots/ "${INIT_USER}"
} }

View file

@ -19,6 +19,11 @@ class BuildMix:
self.mac = "" self.mac = ""
self.type = "" self.type = ""
self.version = "" self.version = ""
self.default = ""
self.algorithms = {}
if not self.uuid:
logger.error("snapshot without UUID. Software {}".format(self.json.get("software")))
return
self.get_details() self.get_details()
self.generate_chids() self.generate_chids()

View file

@ -55,6 +55,9 @@ class Build:
if check: if check:
return return
if not self.build.uuid:
return
self.index() self.index()
self.create_annotations() self.create_annotations()
if settings.DPP: if settings.DPP:

View file

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2025-02-25 12:32
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('lot', '0007_lottag_inbox'),
]
operations = [
migrations.RenameField(
model_name='lot',
old_name='closed',
new_name='archived',
),
]

View file

@ -32,7 +32,7 @@ class Lot(models.Model):
name = models.CharField(max_length=STR_SIZE, blank=True, null=True) name = models.CharField(max_length=STR_SIZE, blank=True, null=True)
code = models.CharField(max_length=STR_SIZE, blank=True, null=True) code = models.CharField(max_length=STR_SIZE, blank=True, null=True)
description = models.CharField(max_length=STR_SIZE, blank=True, null=True) description = models.CharField(max_length=STR_SIZE, blank=True, null=True)
closed = models.BooleanField(default=False) archived = models.BooleanField(default=False)
owner = models.ForeignKey(Institution, on_delete=models.CASCADE) owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
type = models.ForeignKey(LotTag, on_delete=models.CASCADE) type = models.ForeignKey(LotTag, on_delete=models.CASCADE)

View file

@ -7,13 +7,13 @@
<h3>{{ subtitle }}</h3> <h3>{{ subtitle }}</h3>
</div> </div>
<div class="col text-center"> <div class="col text-center">
{% if show_closed %} {% if show_archived %}
<a href="?show_closed=false" class="btn btn-green-admin"> <a href="?show_archived=false" class="btn btn-green-admin">
{% trans 'Hide closed lots' %} {% trans 'Show active lots' %}
</a> </a>
{% else %} {% else %}
<a href="?show_closed=true" class="btn btn-green-admin"> <a href="?show_archived=true" class="btn btn-green-admin">
{% trans 'Show closed lots' %} {% trans 'Show archived lots' %}
</a> </a>
{% endif %} {% endif %}

View file

@ -25,7 +25,7 @@ class NewLotView(DashboardView, CreateView):
"name", "name",
"code", "code",
"description", "description",
"closed", "archived",
) )
def get_form(self): def get_form(self):
@ -54,7 +54,7 @@ class DeleteLotView(DashboardView, DeleteView):
"name", "name",
"code", "code",
"description", "description",
"closed", "archived",
) )
def form_valid(self, form): def form_valid(self, form):
@ -73,7 +73,7 @@ class EditLotView(DashboardView, UpdateView):
"name", "name",
"code", "code",
"description", "description",
"closed", "archived",
) )
def get_form_kwargs(self): def get_form_kwargs(self):
@ -149,15 +149,15 @@ class LotsTagsView(DashboardView, TemplateView):
tag = get_object_or_404(LotTag, owner=self.request.user.institution, id=self.pk) tag = get_object_or_404(LotTag, owner=self.request.user.institution, id=self.pk)
self.title += " {}".format(tag.name) self.title += " {}".format(tag.name)
self.breadcrumb += " {}".format(tag.name) self.breadcrumb += " {}".format(tag.name)
show_closed = self.request.GET.get('show_closed', 'false') == 'true' show_archived = self.request.GET.get('show_archived', 'false') == 'true'
lots = Lot.objects.filter(owner=self.request.user.institution).filter( lots = Lot.objects.filter(owner=self.request.user.institution).filter(
type=tag, closed=show_closed type=tag, archived=show_archived
) )
context.update({ context.update({
'lots': lots, 'lots': lots,
'title': self.title, 'title': self.title,
'breadcrumb': self.breadcrumb, 'breadcrumb': self.breadcrumb,
'show_closed': show_closed 'show_archived': show_archived
}) })
return context return context

View file

@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from user.models import Institution from user.models import Institution
from lot.models import LotTag from lot.models import LotTag, Lot
class Command(BaseCommand): class Command(BaseCommand):
@ -12,6 +12,7 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
self.institution = Institution.objects.create(name=kwargs['name']) self.institution = Institution.objects.create(name=kwargs['name'])
self.create_lot_tags() self.create_lot_tags()
self.create_lots()
def create_lot_tags(self): def create_lot_tags(self):
LotTag.objects.create( LotTag.objects.create(
@ -29,3 +30,59 @@ class Command(BaseCommand):
name=tag, name=tag,
owner=self.institution owner=self.institution
) )
def create_lots(self):
for g in LotTag.objects.all():
if g.name == "Entrada":
Lot.objects.create(
name="donante-orgA",
owner=self.institution,
archived=True,
type=g
)
Lot.objects.create(
name="donante-orgB",
owner=self.institution,
type=g
)
Lot.objects.create(
name="donante-orgC",
owner=self.institution,
type=g
)
if g.name == "Salida":
Lot.objects.create(
name="beneficiario-org1",
owner=self.institution,
type=g
)
Lot.objects.create(
name="beneficiario-org2",
owner=self.institution,
archived=True,
type=g
)
Lot.objects.create(
name="beneficiario-org3",
owner=self.institution,
type=g
)
if g.name == "Temporal":
Lot.objects.create(
name="palet1",
owner=self.institution,
type=g
)
Lot.objects.create(
name="palet2",
owner=self.institution,
type=g
)
Lot.objects.create(
name="palet3",
owner=self.institution,
archived=True,
type=g
)