mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 09:12:11 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
 | 
						|
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
						|
 | 
						|
import django_tables2 as tables
 | 
						|
from django.utils.translation import gettext_lazy as _
 | 
						|
 | 
						|
from .models import Food
 | 
						|
 | 
						|
 | 
						|
class FoodTable(tables.Table):
 | 
						|
    """
 | 
						|
    List all foods.
 | 
						|
    """
 | 
						|
    qr_code_numbers = tables.Column(empty_values=(), verbose_name=_("QR Codes"), orderable=False)
 | 
						|
 | 
						|
    date = tables.Column(empty_values=(), verbose_name=_("Arrival/creation date"), orderable=False)
 | 
						|
 | 
						|
    def render_date(self, record):
 | 
						|
        if record.__class__.__name__ == "BasicFood":
 | 
						|
            return record.arrival_date.strftime("%d/%m/%Y %H:%M")
 | 
						|
        elif record.__class__.__name__ == "TransformedFood":
 | 
						|
            return record.creation_date.strftime("%d/%m/%Y %H:%M")
 | 
						|
        else:
 | 
						|
            return "--"
 | 
						|
 | 
						|
    def render_qr_code_numbers(self, record):
 | 
						|
        return ", ".join(str(q.qr_code_number) for q in record.QR_code.all())
 | 
						|
 | 
						|
    class Meta:
 | 
						|
        model = Food
 | 
						|
        template_name = 'django_tables2/bootstrap4.html'
 | 
						|
        fields = ('name', 'owner', 'qr_code_numbers', 'allergens', 'date', 'expiry_date')
 | 
						|
        row_attrs = {
 | 
						|
            'class': 'table-row',
 | 
						|
            'data-href': lambda record: 'detail/' + str(record.pk),
 | 
						|
            'style': 'cursor:pointer',
 | 
						|
        }
 |