lingo: reduce queryset number (#38115)
This commit is contained in:
parent
93f8357f4f
commit
9c076eceaf
|
@ -20,7 +20,7 @@ from dateutil import parser as date_parser
|
|||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Prefetch
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.utils import six
|
||||
from django.utils.timezone import make_aware, now
|
||||
|
@ -89,8 +89,12 @@ class TransactionListView(ListView):
|
|||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
qs = Transaction.objects.filter(
|
||||
status__in=(eopayment.PAID, eopayment.ACCEPTED)).order_by('-start_date')
|
||||
qs = (
|
||||
Transaction.objects
|
||||
.select_related('user')
|
||||
.prefetch_related(Prefetch('items', to_attr='prefetched_items'))
|
||||
.filter(status__in=(eopayment.PAID, eopayment.ACCEPTED))
|
||||
.order_by('-start_date'))
|
||||
query = self.request.GET.get('q')
|
||||
if query:
|
||||
try:
|
||||
|
|
|
@ -33,18 +33,21 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for object in object_list %}
|
||||
{% with object.prefetched_items|length|default:1 as nb_items %}
|
||||
<tr>
|
||||
<td rowspan="{{object.items.all.count|default:1}}">{{object.order_id}}</td>
|
||||
<td rowspan="{{object.items.all.count|default:1}}">{{object.bank_transaction_id}}</td>
|
||||
<td rowspan="{{object.items.all.count|default:1}}">{{object.start_date}}</td>
|
||||
<td rowspan="{{object.items.all.count|default:1}}">{{object.get_user_name}}</td>
|
||||
<td rowspan="{{object.items.all.count|default:1}}">{{object.amount}} €</td>
|
||||
{% for item in object.items.all %}
|
||||
<td rowspan="{{ nb_items }}">{{object.order_id}}</td>
|
||||
<td rowspan="{{ nb_items }}">{{object.bank_transaction_id}}</td>
|
||||
<td rowspan="{{ nb_items }}">{{object.start_date}}</td>
|
||||
<td rowspan="{{ nb_items }}">{{object.get_user_name}}</td>
|
||||
<td rowspan="{{ nb_items }}">{{object.amount}} €</td>
|
||||
{% for item in object.prefetched_items %}
|
||||
{% if not forloop.first %}<tr>{% endif %}
|
||||
<td style="font-size: smaller">{{item.subject}}</td> <td style="font-size: smaller" class="price">{{item.amount}} €</td></tr>
|
||||
{% endfor %}
|
||||
{% if not object.items.all %}</tr>{% endif %}
|
||||
{% empty %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
.manager-mobile-home-layout {
|
||||
display: flex; }
|
||||
.manager-mobile-home-layout div.sections {
|
||||
flex: 1; }
|
||||
|
||||
div#mobile-case {
|
||||
background: url(../img/mobile-case.svg) top left no-repeat;
|
||||
width: 400px;
|
||||
height: 720px;
|
||||
position: relative;
|
||||
overflow: hidden; }
|
||||
div#mobile-case div.screen {
|
||||
position: absolute;
|
||||
overflow: hidden;
|
||||
left: 12px;
|
||||
top: 52px;
|
||||
bottom: 67px;
|
||||
right: 28px; }
|
||||
div#mobile-case div.screen div.mobile-top-bar {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
color: white;
|
||||
box-sizing: border-box;
|
||||
padding-right: 5px;
|
||||
height: 20px; }
|
||||
div#mobile-case div.screen div.mobile-app-content {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
bottom: 0; }
|
||||
div#mobile-case div.screen div.mobile-app-content div.splash,
|
||||
div#mobile-case div.screen div.mobile-app-content iframe {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 0;
|
||||
opacity: 0;
|
||||
transition: all ease-out 0.4s; }
|
||||
div#mobile-case div.screen div.mobile-app-content div.splash {
|
||||
z-index: 100;
|
||||
opacity: 1;
|
||||
transform: scale(1); }
|
||||
div#mobile-case div.screen div.mobile-app-content.splash-off div.splash {
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transform: scale(10); }
|
||||
div#mobile-case div.screen div.mobile-app-content.splash-off iframe {
|
||||
opacity: 1; }
|
||||
div#mobile-case div.screen div.appicon {
|
||||
position: absolute;
|
||||
top: 40%;
|
||||
text-align: center; }
|
||||
div#mobile-case div.screen div.appicon img {
|
||||
width: 50%; }
|
||||
div#mobile-case div.screen div.applabel {
|
||||
position: absolute;
|
||||
bottom: 50px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 30px;
|
||||
color: white; }
|
||||
|
||||
div.section.navigation ul.navigation-entries {
|
||||
margin-bottom: 0; }
|
||||
div.section.navigation ul.navigation-entries + ul {
|
||||
margin-top: 0; }
|
||||
div.section.navigation ul.navigation-entries span.handle {
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
width: 2em; }
|
||||
div.section.navigation ul.navigation-entries span.handle + a {
|
||||
padding-left: 4ex; }
|
||||
|
||||
div.section.navigation li a.add {
|
||||
padding-left: 0; }
|
||||
div.section.navigation li a.add::before {
|
||||
content: "\f055";
|
||||
font-family: FontAwesome;
|
||||
width: 2.2em;
|
||||
display: inline-block;
|
||||
text-align: center; }
|
|
@ -216,7 +216,7 @@ def test_transactions_search(app, admin_user):
|
|||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = app.get('/manage/lingo/', status=200)
|
||||
assert resp.text.count('<tr') == 11
|
||||
assert len(ctx.captured_queries) == 74
|
||||
assert len(ctx.captured_queries) == 5
|
||||
|
||||
resp.form['q'] = 'order id 16'
|
||||
resp = resp.form.submit()
|
||||
|
|
Loading…
Reference in New Issue