mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 09:26:27 +00:00
Pagination, fix intelligence dans les models plutot que views
This commit is contained in:
parent
68eb0d813d
commit
c6adb87e4b
6 changed files with 53 additions and 26 deletions
|
@ -8,7 +8,7 @@ Author : Maxime Bombar <bombar@crans.org>.
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from numpy.random import randint
|
||||
import unidecode
|
||||
import unidecode, datetime
|
||||
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
@ -16,6 +16,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||
from django.db import models
|
||||
from django.forms import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from django.template.defaultfilters import filesizeformat
|
||||
|
||||
from re2o.mixins import RevMixin, AclMixin
|
||||
|
@ -62,6 +63,10 @@ class Digicode(RevMixin, models.Model, AclMixin, FieldPermissionModelMixin):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
used_time = models.DateTimeField(null=True)
|
||||
|
||||
@classmethod
|
||||
def active_codes(cls):
|
||||
return cls.objects.filter(created__gte = timezone.now() - datetime.timedelta(days=3))
|
||||
|
||||
def _gen_code(user):
|
||||
try_again = True
|
||||
while try_again:
|
||||
|
|
|
@ -33,9 +33,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "User" %}</th>
|
||||
<th>{% trans "Code" %}</th>
|
||||
<th>{% trans "Created on" %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='code' col='user' text=tr_user %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='code' col='code' text=tr_code %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='code' col='created' text=tr_created_on %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for digicode in digicodes_list %}
|
||||
|
|
|
@ -32,10 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "File Name" %}</th>
|
||||
<th>{% trans "By user" %}</th>
|
||||
<th>{% trans "Start at" %}</th>
|
||||
<th>{% trans "Status" %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='job' col='filename' text=tr_filename %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='job' col='user' text=tr_byuser %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='job' col='starttime' text=tr_startat %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='status' col='status' text=tr_status %}</th>
|
||||
<th>{% trans "Number" %}</th>
|
||||
<th>{% trans "Price" %}</th>
|
||||
<th>{% trans "Print again" %}</th>
|
||||
|
|
|
@ -29,6 +29,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<i class="fa fa-plus"></i>
|
||||
{% trans "Print document" %}
|
||||
</a>
|
||||
{% can_create digicode %}
|
||||
<a class="list-group-item list-group-item-success" href="{% url "printer:create-digicode" %}">
|
||||
<i class="fa fa-plus"></i>
|
||||
{% trans "Create Digicode" %}
|
||||
</a>
|
||||
{% acl_end %}
|
||||
<a class="list-group-item list-group-item-info" href="{% url "printer:index-jobs" %}">
|
||||
<i class="fa fa-list-ul"></i>
|
||||
{% trans "List of jobs" %}
|
||||
|
@ -37,11 +43,4 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<i class="fa fa-list-ul"></i>
|
||||
{% trans "List of digicodes" %}
|
||||
</a>
|
||||
{% can_create digicode %}
|
||||
<a class="list-group-item list-group-item-success" href="{% url "printer:create-digicode" %}">
|
||||
<i class="fa fa-plus"></i>
|
||||
{% trans "Create Digicode" %}
|
||||
</a>
|
||||
{% acl_end %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -6,8 +6,6 @@ Author : Maxime Bombar <bombar@crans.org>.
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
from django.urls import reverse
|
||||
from django.shortcuts import render, redirect
|
||||
from django.forms import modelformset_factory, formset_factory
|
||||
|
@ -17,7 +15,10 @@ from django.utils.translation import ugettext as _
|
|||
|
||||
from re2o.views import form
|
||||
from users.models import User
|
||||
from re2o.base import re2o_paginator
|
||||
from re2o.base import (
|
||||
re2o_paginator,
|
||||
SortTable
|
||||
)
|
||||
from . import settings
|
||||
|
||||
from .utils import pdfinfo, send_mail_printer, printer_enabled
|
||||
|
@ -225,9 +226,14 @@ def index_jobs(request):
|
|||
""" Display jobs"""
|
||||
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||
jobs = JobWithOptions.objects.select_related('user')\
|
||||
.select_related('print_operation')\
|
||||
.order_by('starttime').reverse()
|
||||
jobs_list = re2o_paginator(request, jobs, pagination_number)
|
||||
.select_related('print_operation')
|
||||
jobs_list = SortTable.sort(
|
||||
jobs,
|
||||
request.GET.get('col'),
|
||||
request.GET.get('order'),
|
||||
SortTable.PRINTER_INDEX_JOB
|
||||
)
|
||||
jobs_list = re2o_paginator(request, jobs_list, pagination_number)
|
||||
return render(request, 'printer/index_jobs.html', {'jobs_list': jobs_list})
|
||||
|
||||
|
||||
|
@ -235,21 +241,25 @@ def index_jobs(request):
|
|||
def index_digicodes(request):
|
||||
"""Display available digicodes"""
|
||||
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||
digicodes = Digicode.objects.filter(created__gte=(datetime.datetime.now()
|
||||
-datetime.timedelta(3)))
|
||||
digicodes_list = re2o_paginator(request, digicodes, pagination_number)
|
||||
digicodes = Digicode.active_codes()
|
||||
digicodes_list = SortTable.sort(
|
||||
digicodes,
|
||||
request.GET.get('col'),
|
||||
request.GET.get('order'),
|
||||
SortTable.PRINTER_INDEX_CODE
|
||||
)
|
||||
digicodes_list = re2o_paginator(request, digicodes_list, pagination_number)
|
||||
return render(request,
|
||||
'printer/index_digicodes.html',
|
||||
{'digicodes_list': digicodes_list},
|
||||
)
|
||||
|
||||
@can_create(Digicode)
|
||||
@login_required
|
||||
@can_create(Digicode)
|
||||
def create_code(request):
|
||||
"""Generate a digicode"""
|
||||
code = CreateCodeForm(
|
||||
request.POST or None,
|
||||
# form_kwargs={'user': request.user},
|
||||
user = request.user,
|
||||
)
|
||||
if code.is_valid():
|
||||
|
|
13
re2o/base.py
13
re2o/base.py
|
@ -234,6 +234,19 @@ class SortTable:
|
|||
'logs_date': ['date_created'],
|
||||
'default': ['-date_created']
|
||||
}
|
||||
PRINTER_INDEX_CODE = {
|
||||
'code_code': ['code'],
|
||||
'code_user': ['user__pseudo'],
|
||||
'code_created': ['created'],
|
||||
'default': ['-created']
|
||||
}
|
||||
PRINTER_INDEX_JOB = {
|
||||
'job_filename': ['filename'],
|
||||
'job_user': ['user__pseudo'],
|
||||
'job_starttime': ['starttime'],
|
||||
'job_status': ['status'],
|
||||
'default': ['-starttime']
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def sort(request, col, order, values):
|
||||
|
|
Loading…
Reference in a new issue