Projet

Général

Profil

0001-backoffice-use-a-JOIN-clause-for-the-user-label-colu.patch

Frédéric Péters, 19 décembre 2021 16:53

Télécharger (4,34 ko)

Voir les différences:

Subject: [PATCH] backoffice: use a JOIN clause for the user label column
 (#59893)

 wcs/backoffice/management.py | 46 ++++++++++++++++++++++++++++++------
 wcs/sql.py                   |  4 +---
 2 files changed, 40 insertions(+), 10 deletions(-)
wcs/backoffice/management.py
1320 1320
                    continue
1321 1321
                classnames = ''
1322 1322
                attrs = ''
1323
                if isinstance(field, RelatedField):
1323
                if getattr(field, 'has_relations', False):
1324
                    classnames = 'has-relations-field'
1325
                    attrs = 'data-field-id="%s"' % field.id
1326
                    seen_parents.add(field.id)
1327
                elif isinstance(field, RelatedField):
1324 1328
                    classnames = 'related-field'
1325 1329
                    if field.parent_field_id in seen_parents:
1326 1330
                        classnames += ' collapsed'
1327 1331
                    attrs = 'data-relation-attr="%s"' % field.parent_field_id
1328
                elif getattr(field, 'has_relations', False):
1329
                    classnames = 'has-relations-field'
1330
                    attrs = 'data-field-id="%s"' % field.id
1331
                    seen_parents.add(field.id)
1332 1332
                r += htmltext('<li class="%s" %s><span class="handle">⣿</span>' % (classnames, attrs))
1333 1333
                r += htmltext('<label><input type="checkbox" name="%s"') % field.id
1334 1334
                if field.id in field_ids:
......
1519 1519
        yield FakeField('last_update_time', 'last_update_time', _('Last Modified'))
1520 1520

  
1521 1521
        # user fields
1522
        yield FakeField('user-label', 'user-label', _('User Label'))
1523
        if get_publisher().is_using_postgresql():
1522
        if not get_publisher().is_using_postgresql():
1523
            # full name of user, this will load individual user objects to get it
1524
            yield FakeField('user-label', 'user-label', _('User Label'))
1525
        else:
1526
            # user-label field but as a custom field, to get full name of user
1527
            # using a sql join clause.
1528
            yield UserLabelRelatedField()
1524 1529
            for field in get_publisher().user_class.get_fields():
1525 1530
                if not hasattr(field, 'get_view_value'):
1526 1531
                    continue
......
3442 3447
    def get_csv_value(self, value, **kwargs):
3443 3448
        return [self.get_view_value(value)]
3444 3449

  
3450
    def get_column_field_id(self):
3451
        from wcs.sql import get_field_id
3452

  
3453
        column_field_id = get_field_id(self.related_field)
3454
        if self.related_field.store_display_value:
3455
            column_field_id += '_display'
3456
        return column_field_id
3457

  
3445 3458

  
3446 3459
class UserRelatedField(RelatedField):
3447 3460
    # it is named 'user-label' and not 'user' for compatibility with existing
......
3456 3469
        return _('%s of User') % self.related_field.label
3457 3470

  
3458 3471

  
3472
class UserLabelRelatedField(UserRelatedField):
3473
    # custom user-label column, targetting the "name" (= full name) column
3474
    # of the users table
3475
    id = 'user-label'
3476
    type = 'user-label'
3477
    varname = 'user_label'
3478
    has_relations = True
3479

  
3480
    def __init__(self):
3481
        pass
3482

  
3483
    def get_column_field_id(self):
3484
        return 'name'
3485

  
3486
    @property
3487
    def label(self):
3488
        return _('User Label')
3489

  
3490

  
3459 3491
def do_graphs_section(period_start=None, period_end=None, criterias=None):
3460 3492
    from wcs import sql
3461 3493

  
wcs/sql.py
1589 1589
                if carddef_table_decl not in tables:
1590 1590
                    tables.append(carddef_table_decl)
1591 1591

  
1592
                column_field_id = get_field_id(field.related_field)
1593
                if field.related_field.store_display_value:
1594
                    column_field_id += '_display'
1592
                column_field_id = field.get_column_field_id()
1595 1593
                columns.append('%s.%s' % (carddef_table_alias, column_field_id))
1596 1594
                extra_fields.append(field.id)
1597 1595

  
1598
-