Projet

Général

Profil

0001-backoffice-use-status-colour-in-status-select-box-45.patch

Frédéric Péters, 06 avril 2014 14:51

Télécharger (4,17 ko)

Voir les différences:

Subject: [PATCH] backoffice: use status colour in status <select> box (#4533)

 wcs/backoffice/root.py  | 16 ++++++++++++----
 wcs/forms/backoffice.py | 10 +---------
 wcs/qommon/misc.py      | 14 ++++++++++++++
 3 files changed, 27 insertions(+), 13 deletions(-)
wcs/backoffice/root.py
381 381
        if waitpoint_status:
382 382
            r += htmltext('<h3>%s</h3>') % _('Status to display')
383 383
            r += htmltext('<select name="filter" onchange="this.form.submit()">')
384
            filters = [('all', _('All')), ('pending', _('Pending')), ('done', _('Done'))]
384
            filters = [('all', _('All'), None),
385
                    ('pending', _('Pending'), None),
386
                    ('done', _('Done'), None)]
385 387
            for status in waitpoint_status:
386
                filters.append((status.id, status.name))
387
            for filter_id, filter_label in filters:
388
                filters.append((status.id, status.name, status.colour))
389
            for filter_id, filter_label, filter_colour in filters:
388 390
                if filter_id == selected_filter:
389 391
                    selected = ' selected="selected"'
390 392
                else:
391 393
                    selected = ''
392
                r += htmltext('<option value="%s"%s/>%s</option>') % (filter_id, selected, filter_label)
394
                style = ''
395
                if filter_colour and filter_colour != 'FFFFFF':
396
                    fg_colour = misc.get_foreground_colour(filter_colour)
397
                    style = 'style="background: #%s; color: %s;"' % (
398
                            filter_colour, fg_colour)
399
                r += htmltext('<option value="%s"%s %s>' % (filter_id, selected, style))
400
                r += htmltext('%s</option>') % filter_label
393 401
            r += htmltext('</select>')
394 402
            r += htmltext('<noscript><input type="submit" value="%s"/></noscript>') % _('Refresh')
395 403

  
wcs/forms/backoffice.py
55 55
            colours = []
56 56
            for status in self.formdef.workflow.possible_status:
57 57
                if status.colour and status.colour != 'FFFFFF':
58
                    # luminance coefficients taken from section C-9 fro
59
                    # http://www.faqs.org/faqs/graphics/colorspace-faq/
60
                    brightess = int(status.colour[0:2], 16) * 0.212671 + \
61
                            int(status.colour[2:4], 16) * 0.715160 + \
62
                            int(status.colour[4:6], 16) * 0.072169
63
                    if brightess > 128:
64
                        fg_colour = 'black'
65
                    else:
66
                        fg_colour = 'white'
58
                    fg_colour = misc.get_foreground_colour(status.colour)
67 59
                    colours.append((status.id, status.colour, fg_colour))
68 60
            if colours:
69 61
                r += htmltext('<style>')
wcs/qommon/misc.py
494 494
                query = '&'.join('%s=%s' % (k,v) for (k,v) in query)
495 495
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
496 496

  
497

  
498
def get_foreground_colour(background_colour):
499
    """Calculates the luminance of the given colour (six hexadecimal digits)
500
       and returns an appropriate foreground colour."""
501
    # luminance coefficients taken from section C-9 from
502
    # http://www.faqs.org/faqs/graphics/colorspace-faq/
503
    brightess = int(background_colour[0:2], 16) * 0.212671 + \
504
            int(background_colour[2:4], 16) * 0.715160 + \
505
            int(background_colour[4:6], 16) * 0.072169
506
    if brightess > 128:
507
        fg_colour = 'black'
508
    else:
509
        fg_colour = 'white'
510
    return fg_colour
497
-