mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	(Un)validate transactions
This commit is contained in:
		
				
					committed by
					
						
						Bombar Maxime
					
				
			
			
				
	
			
			
			
						parent
						
							c43e8c2dc2
						
					
				
				
					commit
					cc5185b3ed
				
			@@ -1,6 +1,8 @@
 | 
			
		||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
 | 
			
		||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
import html
 | 
			
		||||
 | 
			
		||||
import django_tables2 as tables
 | 
			
		||||
from django.db.models import F
 | 
			
		||||
from django_tables2.utils import A
 | 
			
		||||
@@ -19,23 +21,38 @@ class HistoryTable(tables.Table):
 | 
			
		||||
        model = Transaction
 | 
			
		||||
        exclude = ("id", "polymorphic_ctype", )
 | 
			
		||||
        template_name = 'django_tables2/bootstrap4.html'
 | 
			
		||||
        sequence = ('...', 'total', 'valid')
 | 
			
		||||
        sequence = ('...', 'total', 'valid', )
 | 
			
		||||
        orderable = False
 | 
			
		||||
 | 
			
		||||
    total = tables.Column()  # will use Transaction.total() !!
 | 
			
		||||
 | 
			
		||||
    valid = tables.Column(attrs={"td": {"id": lambda record: "validate_" + str(record.id),
 | 
			
		||||
                                        "class": lambda record: str(record.valid).lower() + ' validate'}})
 | 
			
		||||
 | 
			
		||||
    def order_total(self, queryset, is_descending):
 | 
			
		||||
        # needed for rendering
 | 
			
		||||
        queryset = queryset.annotate(total=F('amount') * F('quantity')) \
 | 
			
		||||
            .order_by(('-' if is_descending else '') + 'total')
 | 
			
		||||
        return (queryset, True)
 | 
			
		||||
        return queryset, True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def render_amount(self, value):
 | 
			
		||||
        return pretty_money(value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def render_total(self, value):
 | 
			
		||||
        return pretty_money(value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Django-tables escape strings. That's a wrong thing.
 | 
			
		||||
    def render_reason(self, value):
 | 
			
		||||
        return html.unescape(value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def render_valid(self, value):
 | 
			
		||||
        return "✔" if value else "✖"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AliasTable(tables.Table):
 | 
			
		||||
    class Meta:
 | 
			
		||||
        attrs = {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user