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