Ejemplo n.º 1
0
class TimeEntryTable(Table):
    task = Column(order_by=(
        'task__project__client__name',
        'task__project__name',
        'task__external_reference',
    ))
    start_date = DateTimeColumn(format='Y-m-d (l)', accessor='start')
    start_time = DateTimeColumn(format='H:i', accessor='start')
    end_time = DateTimeColumn(format='H:i', accessor='end')
    duration = DurationColumn()

    class Meta:
        # TODO: May be better to have this in settings?
        template_name = 'django_tables2/bootstrap4.html'
        model = TimeEntry
        fields = (
            'start_date',
            'start_time',
            'end_time',
            'duration',
            'task',
        )

    def _order_by_date(self, qs, is_descending):
        return (qs.order_by(f'{"-" if is_descending else ""}start'), True)

    def order_start_date(self, qs, is_descending):
        return self._order_by_date(qs, is_descending)

    def order_start_time(self, qs, is_descending):
        return self._order_by_date(qs, is_descending)

    def order_end_time(self, qs, is_descending):
        return self._order_by_date(qs, is_descending)
Ejemplo n.º 2
0
class BlockTable(tables.Table):

    height = LinkColumn(verbose_name="Height", orderable=True)
    time = DateTimeColumn(verbose_name="Time (UTC)",
                          format="Y-m-d H:i:s",
                          orderable=True)
    miner = LinkColumn(verbose_name=settings.MEX_MINER)
    txcount = Column(verbose_name="TXs", orderable=True)
    size = Column(orderable=True)

    class Meta:
        model = Block
        fields = ("height", "time", "miner", "txcount", "size")
        order_by = ("-height", )
        attrs = {"class": "table table-sm table-striped table-hover"}
        orderable = False

    def render_height(self, record=None):
        link = reverse("block-detail", args=[str(record.hash)])
        return mark_safe(
            '<a href="{}" class="badge badge-info"><i class="fas fa-cube"></i>  {}</a>'
            .format(link, record.height))

    def render_miner(self, record=None):
        link = reverse("address-detail", args=[str(record.miner)])
        return mark_safe('<a href="{}">{}</a>'.format(link, record.miner))
Ejemplo n.º 3
0
class campaigns(Table):
    links = TemplateColumn(
        '<a href="/campaign/{{ record.id }}/info">'
        '<i class="fa fa-info"></i></a> &nbsp;'
        '<a href="/campaign/{{ record.id }}/results">'
        '<i class="fa fa-list"></i></a> &nbsp;'
        '<a href="/campaign/{{ record.id }}/events">'
        '<i class="fa fa-flag"></i></a> &nbsp;'
        '<a href="/campaign/{{ record.id }}/injections">'
        '<i class="fa fa-crosshairs"></i></a> &nbsp;'
        '<a href="/campaign/{{ record.id }}/category_charts">'
        '<i class="fa fa-bar-chart"></i></a>', orderable=False)
    results = Column(empty_values=(), orderable=False)
    timestamp = DateTimeColumn(format=datetime_format)

    def render_cycles(self, record):
        return '{:,}'.format(record.cycles)

    def render_execution_time(self, record):
        return '{0:.4f}'.format(record.execution_time)

    def render_results(self, record):
        return '{:,}'.format(
            record.result_set.count())

    class Meta:
        fields = ('links', 'id', 'results', 'command', 'architecture', 'simics',
                  'execution_time', 'cycles', 'timestamp')
        model = models.campaign
        order_by = 'id'
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 4
0
class BlockTable(tables.Table):

    height = LinkColumn(verbose_name='Height', orderable=True)
    time = DateTimeColumn(verbose_name='Time (UTC)',
                          format="Y-m-d H:i:s",
                          orderable=True)
    miner = LinkColumn(verbose_name=settings.MEX_MINER)
    txcount = Column(verbose_name='TXs', orderable=True)
    size = Column(orderable=True)

    class Meta:
        model = Block
        fields = (
            'height',
            'time',
            'miner',
            'txcount',
            'size',
        )
        order_by = '-height',
        attrs = {'class': 'table table-sm table-striped table-hover'}
        orderable = False

    def render_height(self, record=None):
        link = reverse('block-detail', args=[str(record.hash)])
        return mark_safe(
            '<a href="{}" class="badge badge-info"><i class="fas fa-cube"></i>  {}</a>'
            .format(link, record.height))

    def render_miner(self, record=None):
        link = reverse('address-detail', args=[str(record.miner)])
        return mark_safe('<a href="{}">{}</a>'.format(link, record.miner))
Ejemplo n.º 5
0
class campaign(Table):
    results = Column(empty_values=(), orderable=False)
    timestamp = DateTimeColumn(format=datetime_format)

    def render_checkpoints(self, record):
        return '{:,}'.format(record.checkpoints)

    def render_cycles(self, record):
        return '{:,}'.format(record.cycles)

    def render_cycles_between(self, record):
        return '{:,}'.format(record.cycles_between)

    def render_execution_time(self, record):
        return '{0:.4f}'.format(record.execution_time)

    def render_results(self, record):
        return '{:,}'.format(
            record.result_set.count())

    class Meta:
        fields = ('id', 'timestamp', 'results', 'command', 'aux_command',
                  'description', 'architecture', 'simics', 'aux',
                  'execution_time', 'cycles', 'output_file', 'checkpoints',
                  'cycles_between')
        model = models.campaign
        orderable = False
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 6
0
class result(Table):
    outcome = TemplateColumn(
        '<input id="edit_outcome" type="text" value="{{ value }}" />')
    outcome_category = TemplateColumn(
        '<input id="edit_outcome_category" type="text" value="{{ value }}" />')
    timestamp = DateTimeColumn(format=datetime_format)

    def render_cycles(self, record):
        return '{:,}'.format(record.cycles)

    def render_data_diff(self, record):
        return '{0:.2f}%'.format(
            min(record.data_diff*100, 99.99) if record.data_diff < 1
            else record.data_diff*100)

    def render_execution_time(self, record):
        return '{0:.4f}'.format(record.execution_time)

    class Meta:
        fields = ('dut_serial_port', 'timestamp', 'outcome_category', 'outcome',
                  'execution_time', 'cycles', 'num_injections', 'data_diff',
                  'detected_errors')
        model = models.result
        orderable = False
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 7
0
class events(Table):
    description = TemplateColumn(
        '{% if value %}<code class="console">{{ value }}</code>{% endif %}')
    result_id = TemplateColumn(
        '{% if value %}<a href="/result/{{ value }}">{{ value }}</a>'
        '{% else %}<a href="/campaign/{{ record.campaign_id }}/info">'
        'Campaign {{ record.campaign_id }}</a>{% endif %}',
        accessor='result_id')
    select_box = CheckBoxColumn(
        accessor='result_id',
        attrs={'th__input': {
            'onclick': 'update_selection(this)'
        }})
    success_ = TemplateColumn(
        '{% if value == None %}-'
        '{% elif value %}<span class="true">\u2714</span>'
        '{% else %}<span class="false">\u2718</span>{% endif %}',
        accessor='success')
    timestamp = DateTimeColumn(format=datetime_format)

    class Meta:
        fields = ('select_box', 'result_id', 'timestamp', 'level', 'source',
                  'type', 'success_', 'description')
        model = models.event
        order_by = '-timestamp'
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 8
0
class results(Table):
    id_ = TemplateColumn(  # LinkColumn()
        '<a href="/result/{{ value }}">{{ value }}</a>', accessor='id')
    registers = Column(empty_values=(), orderable=False)
    select_box = CheckBoxColumn(
        accessor='id',
        attrs={'th__input': {'onclick': 'update_selection(this)'}})
    timestamp = DateTimeColumn(format=datetime_format)
    targets = Column(empty_values=(), orderable=False)

    def render_cycles(self, record):
        return '{:,}'.format(record.cycles)

    def render_data_diff(self, record):
        return '{0:.2f}%'.format(
            min(record.data_diff*100, 99.99) if record.data_diff < 1
            else record.data_diff*100)

    def render_execution_time(self, record):
        return '{0:.4f}'.format(record.execution_time)

    def render_registers(self, record):
        if record is not None:
            registers = [injection.register for injection
                         in record.injection_set.all()]
        else:
            return '-'
        for index in range(len(registers)):
            if registers[index] is None:
                registers[index] = '-'
        if len(registers) > 0:
            return ', '.join(registers)
        else:
            return '-'

    def render_targets(self, record):
        if record is not None:
            targets = list(record.injection_set.values_list('target_name',
                                                            flat=True))
        else:
            return '-'
        for index in range(len(targets)):
            if targets[index] is None:
                targets[index] = '-'
        if len(targets) > 0:
            return ', '.join(targets)
        else:
            return '-'

    class Meta:
        fields = ('select_box', 'id_', 'dut_serial_port', 'timestamp',
                  'outcome_category', 'outcome', 'execution_time', 'cycles',
                  'data_diff', 'targets', 'registers')
        model = models.result
        order_by = '-id_'
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 9
0
class event(Table):
    description = TemplateColumn(
        '{% if value %}<code class="console">{{ value }}</code>{% endif %}')
    success_ = TemplateColumn(
        '{% if value == None %}-'
        '{% elif value %}<span class="true">\u2714</span>'
        '{% else %}<span class="false">\u2718</span>{% endif %}',
        accessor='success')
    timestamp = DateTimeColumn(format=datetime_format)

    class Meta:
        fields = ('timestamp', 'level', 'source', 'type', 'success_',
                  'description')
        model = models.event
        order_by = 'timestamp'
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 10
0
class injection(Table):
    success_ = TemplateColumn(
        '{% if value == None %}-'
        '{% elif value %}<span class="true">\u2714</span>'
        '{% else %}<span class="false">\u2718</span>{% endif %}',
        accessor='success')
    timestamp = DateTimeColumn(format=datetime_format)

    def render_time(self, record):
        return '{0:.6f}'.format(record.time)

    class Meta:
        fields = ('timestamp', 'time', 'checkpoint', 'target_name', 'register',
                  'register_index', 'bit', 'field', 'register_access',
                  'gold_value', 'injected_value', 'success_')
        model = models.injection
        order_by = 'id'
        template = 'django_tables2/bootstrap.html'
Ejemplo n.º 11
0
class JobTable(BaseTable):
    job_id = LinkColumn('job-detail', args=[A("cluster.slug"), A("job_id")])
    cluster = LinkColumn("cluster-detail",
                         args=[A("cluster.slug")],
                         accessor="cluster.slug",
                         verbose_name='cluster')
    object = TemplateColumn(
        template_name="ganeti/overview/object_link.html",
        accessor="obj",
        orderable=False  # Cannot access generic fk to get obj name for sort
    )
    operation = Column(accessor="op", verbose_name="operation")
    # Extra space is because it doesn't like the word status for some reason.
    status = Column(verbose_name="status ")
    finished = DateTimeColumn()

    class Meta:
        empty_text = "No jobs"
        order_by = ("job_id")

    def render_operation(self, value):
        return format_job_op(value)
Ejemplo n.º 12
0
class StreamItemTable(tables.Table):

    time = DateTimeColumn(
        verbose_name="Time (UTC)",
        format="Y-m-d H:i:s",
        orderable=True,
        linkify=True,
    )
    keys = Column(verbose_name="Keys", orderable=False)
    data = Column(verbose_name="Data", orderable=False)

    class Meta:
        model = StreamItem
        fields = ("txid", "time", "keys", "data")
        attrs = {"class": "table table-sm table-striped table-hover"}
        order_by = "-time"

    def render_txid(self, value):
        lnk = '<a href="/tx/{}">{}</a>'.format(value, value[:7])
        return mark_safe(lnk)

    def render_keys(self, value):
        if isinstance(value, list):
            value = "-".join(value)
        return value[:55]

    def render_data(self, value):
        if isinstance(value, str):
            return value[:64]
        data = value.get("json")
        if data:
            title = (data.get("title") or data.get("ISCC") or data.get("ISBN")
                     or data.get("comment"))
        else:
            title = value.get("text")
        if not title:
            title = str(value)
        return title[:64] if title else ""
Ejemplo n.º 13
0
class result(Table):
    outcome = TemplateColumn(
        '<input id="edit_outcome" type="text" value="{{ value }}" />')
    outcome_category = TemplateColumn(
        '<input id="edit_outcome_category" type="text" value="{{ value }}" />')
    timestamp = DateTimeColumn(format=datetime_format)
    next_result = TemplateColumn(
        '{% if value %}<a href="/result/{{ value.id }}">{{ value.id }}</a>'
        '{% else %}None{% endif %}',
        accessor='next_result',
        verbose_name='Next Result')
    previous_result = TemplateColumn(
        '{% if value %}<a href="/result/{{ value }}">{{ value }}</a>'
        '{% else %}None{% endif %}',
        accessor='previous_result_id')

    def render_cycles(self, record):
        return '{:,}'.format(record.cycles)

    def render_data_diff(self, record):
        return '{0:.2f}%'.format(
            min(record.data_diff *
                100, 99.99) if record.data_diff < 1 else record.data_diff *
            100)

    def render_execution_time(self, record):
        return '{0:.4f}'.format(record.execution_time)

    class Meta:
        fields = ('dut_dev_serial', 'dut_serial_port', 'timestamp',
                  'outcome_category', 'outcome', 'execution_time', 'cycles',
                  'num_injections', 'data_diff', 'data_hash',
                  'detected_errors', 'previous_result', 'next_result')
        model = models.result
        orderable = False
        template = 'django_tables2/bootstrap.html'