Beispiel #1
0
def useravailsessions(form, user):
    """
    Output cells with form widget for all sessions concerning that user
    """
    if not form or not user:
        return ''
    output = ''
    for key in form.fields:
        if AVAILABILITY_FIELDKEY_HELPER_PREFIX.format(hpk=user.pk) in key:
            output += '<td>{field}</td>'.format(
                field=form.fields[key].widget.render(
                    key, form.fields[key].initial, attrs={'id': key})
                )
    return mark_safe(output)
Beispiel #2
0
def useravailsessions_readonly(struct, user, avail_content=None, sesskey=None,
                               onlyavail=False):
    """
    Output cells with the state of the availability / choice for all sessions,
    for that user
    """
    if not struct or not user:
        return ''
    output = ''
    for key in struct:
        if AVAILABILITY_FIELDKEY_HELPER_PREFIX.format(hpk=user.pk) in key:
            # If there's a sessionkey specified, skip the ones not
            # corresponding
            if sesskey:
                if key != AVAILABILITY_FIELDKEY.format(hpk=user.pk,
                                                       spk=sesskey):
                    continue
            availability = struct[key]
            avail_verb = ''  # Fulltext
            avail_label = ''  # Bootstrap glyphicon name
            avail_class = 'active'  # Bootstrap array cell class
            if availability == 'i':
                # If needed
                avail_verb = _('Si nécessaire')
                avail_label = 'ok-circle'
                avail_class = 'warning'
            elif availability == 'n':
                avail_verb = _('Non')
                avail_label = 'remove-sign'
                avail_class = 'danger'
            elif availability == 'y':
                avail_verb = _('Oui')
                avail_label = 'ok-sign'
                avail_class = 'success'

            if availability in ['y', 'i']:
                # Si le choix des moniteurs est connu, remplace le label et
                # la version verbeuse par l'état du choix
                if not sesskey:
                    thissesskey = int(search(r'-s(\d+)', key).group(1))
                    staffkey = STAFF_FIELDKEY.format(hpk=user.pk,
                                                     spk=thissesskey)
                    if staffkey in struct:
                        if struct[staffkey] == SHORTCODE_MON2:
                            avail_verb = _('Moniteur 2')
                            avail_label = 'tags'
                        elif struct[staffkey] == SHORTCODE_MON1:
                            avail_verb = _('Moniteur 1')
                            avail_label = 'tag'
                        elif struct[staffkey] == SHORTCODE_ACTOR:
                            avail_verb = _('Intervenant')
                            avail_label = 'sunglasses'
                        elif struct[staffkey] == SHORTCODE_SELECTED:
                            avail_verb = _('Choisi')
                            avail_label = 'check'
                        else:
                            avail_verb = _('Pas choisi')
                            avail_label = 'unchecked'
            elif onlyavail:
                avail_content = ' '

            output += (
                '<td style="vertical-align: middle;"'
                '    class="{avail_class}"{avail_verbose}>'
                '<!-- {key} -->{avail_label}'
                '</td>'
            ).format(
                avail_class=avail_class,
                avail_verbose=' title="%s"' % avail_verb if avail_verb else '',
                avail_label=(
                    avail_content if avail_content else
                    ('<span class="glyphicon glyphicon-%s"></span> '
                        % avail_label
                        if avail_label else '')
                    ),
                key=key,
            )
    return mark_safe(output)