Skip to content
Snippets Groups Projects
Select Git revision
  • b087a4d1424fae180b5bf78d2d250666d6fdc3f7
  • master default protected
  • MAM-110-propagate-output-sasid
  • MAM-109-specify-ingest-location
  • master-backup-september-2024
5 results

tables.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    tables.py 1.77 KiB
    # tables.py
    import django_tables2 as tables
    from .models import Task
    
    # render the StatusColumn based on the style.css
    class IDColumn(tables.Column):
        attrs = {
            "td": {
                "class": lambda record: record.status
            },
            "tr": {
                "class": lambda record: record.status
            },
            "a": {
                "href" : lambda record: record.get_absolute_url,
                "target": "_blank"
            }
        }
        def render(self, record):
            link = '<a href="{{ record.get_absolute_url }}" target="_blank">{{ record.id }} </a>'
            return "{}".format(link)
    
    # render the StatusColumn based on the style.css
    class StatusColumn(tables.Column):
        attrs = {
            "td": {
                "class": lambda record: record.status
            },
            "tr": {
                "class": lambda record: record.status
            }
        }
        def render(self, record):
            return "{}".format(record.status)
    
    
    class TaskTable(tables.Table):
    
        class Meta:
            model = Task
            template_name = "django_tables2/bootstrap4.html"
            fields = ("id", "workflow","priority", "status","project","sas_id","actions","buttons")
    
        # columns that need specific rendering
        # id = IDColumn() (too complicated, finish later.. if time
        status = StatusColumn()
    
        #creationtime = tables.Column(verbose_name='CreationTime')
    
        actions = tables.TemplateColumn(verbose_name='Details',
                                        template_name='query/action_buttons_per_row.html',
                                        orderable=False)  # orderable not sortable
    
        buttons = tables.TemplateColumn(verbose_name='Set Status',
                                        template_name='query/status_buttons_per_row.html',
                                        orderable=False)  # orderable not sortable