Fix saving datagrid columns.

Review Request #13611 — Created March 4, 2024 and discarded — Latest diff uploaded

Information

Djblets
release-5.x

Reviewers

When we first implemented the datagrids, it was the case that assigning
a list value into a TextField would serialize it as a comma-separated
list of the values in the list. This is no longer the case, and setting
the datagrid columns would end up saving as a list repr, which wasn't
parsable when loading the value back out.

This change fixes it so we explicitly join the datagrid columns when
saving them back to the profile, and adds some unit tests to make sure
that saving the columns and sort order work correctly.

  • Ran unit tests.
  • Enabled, disabled, and moved some columns around and saw that it got
    properly saved to the profile.

Diff Revision 2 (Latest)

orig
1
2

Commits

First Last Summary ID Author
Fix saving datagrid columns.
When we first implemented the datagrids, it was the case that assigning a list value into a TextField would serialize it as a comma-separated list of the values in the list. This is no longer the case, and setting the datagrid columns would end up saving as a list repr, which wasn't parsable when loading the value back out. This change fixes it so we explicitly join the datagrid columns when saving them back to the profile, and adds some unit tests to make sure that saving the columns and sort order work correctly. Testing Done: - Ran unit tests. - Enabled, disabled, and moved some columns around and saw that it got properly saved to the profile.
4752b2b98f43f7faecb9c79678aff2ec900b9c79 David Trowbridge

Files

djblets/datagrid/grids.py
djblets/datagrid/tests.py
djblets/datagrid/grids.py
Revision 5977ffe9f505f52874825383f3b2589324adb960 New Change
1497 lines
class DataGrid:
1498

    
   
1498

   
1499
    #: The profile field storing the column list for the datagrid.
1499
    #: The profile field storing the column list for the datagrid.
1500
    #:
1500
    #:
1501
    #: Type:
1501
    #: Type:
1502
    #:     str
1502
    #:     str
1503
    profile_column_field: Optional[str]
1503
    profile_columns_field: Optional[str]
1504

    
   
1504

   
1505
    #: The profile field storing the sort order for the datagrid.
1505
    #: The profile field storing the sort order for the datagrid.
1506
    #:
1506
    #:
1507
    #: Type:
1507
    #: Type:
1508
    #:     str
1508
    #:     str
473 lines
def load_state(
1982
        # Now that we have all that, figure out if we need to save new
1982
        # Now that we have all that, figure out if we need to save new
1983
        # settings back to the profile.
1983
        # settings back to the profile.
1984
        if profile:
1984
        if profile:
1985
            if (self.profile_columns_field and
1985
            if (self.profile_columns_field and
1986
                colnames != profile_columns_list):
1986
                colnames != profile_columns_list):
1987
                setattr(profile, self.profile_columns_field, colnames)
1987
                setattr(profile, self.profile_columns_field,

    
   
1988
                        ','.join(colnames))
1988
                profile_dirty_fields.append(self.profile_columns_field)
1989
                profile_dirty_fields.append(self.profile_columns_field)
1989

    
   
1990

   
1990
            if self.profile_sort_field and sort_str != profile_sort_list:
1991
            if self.profile_sort_field and sort_str != profile_sort_list:
1991
                setattr(profile, self.profile_sort_field, sort_str)
1992
                setattr(profile, self.profile_sort_field, sort_str)
1992
                profile_dirty_fields.append(self.profile_sort_field)
1993
                profile_dirty_fields.append(self.profile_sort_field)
763 lines
djblets/datagrid/tests.py
Loading...