Modify

Opened 13 years ago

Closed 11 years ago

Last modified 11 years ago

#9839 closed defect (wontfix)

Pipe is not appended to single option

Reported by: Jan Beilicke Owned by: CM Lubinski
Priority: normal Component: MultiSelectCustomFieldsPatch
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

I just noticed that some queries didn't return all matching tickets. At first I thought it might be caused by old data, that was not updated (see also #9731). It turned out, that every update to a ticket (ticket properties or comments) removes the pipe of single options again.

When the multi had more than one selected options (which worked fine) and all but one options are removed, the remaining option is stored without a pipe.

I assume that the pipe is simply not set in the model.py __setitem__() where isinstance(value, list) is processed - maybe the value isn't a list anymore?

Feedback is highly appreciated. :)

Attachments (0)

Change History (2)

comment:1 Changed 13 years ago by Jan Beilicke

Summary: Pipe is not appended for single optionsPipe is not appended to single option

After some investigation I came up with the following patch. It contains the original MultiSelectPatch (only model.py) plus a quick fix for my issue, applied in populate():

  • ticket/model.py

    old new  
    132132    def __setitem__(self, name, value):
    133133        """Log ticket modifications so the table ticket_change can be updated
    134134        """
     135        if isinstance(value, list): #   account for multi-selects
     136            value = '|'.join(value) + '|'
    135137        if name in self.values and self.values[name] == value:
    136138            return
    137139        if name not in self._old: # Changed field
     
    140142            del self._old[name]
    141143        if value:
    142144            if isinstance(value, list):
    143                 raise TracError(_("Multi-values fields not supported yet")) 
     145                value = '|'.join(value) + '|'
    144146            field = [field for field in self.fields if field['name'] == name]
    145147            if field and field[0].get('type') != 'textarea':
    146148                value = value.strip()
     
    164166        field_names = [f['name'] for f in self.fields]
    165167        for name in [name for name in values.keys() if name in field_names]:
    166168            self[name] = values.get(name, '')
    167 
     169
    168170        # We have to do an extra trick to catch unchecked checkboxes
    169171        for name in [name for name in values.keys() if name[9:] in field_names
    170172                     and name.startswith('checkbox_')]:
    171173            if name[9:] not in values:
    172174                self[name[9:]] = '0'
     175
     176        for f in self.fields:
     177            # We do something similar for empty multi-selects
     178            if f['type'] == 'multi' and not f['name'] in values:
     179                self[f['name']] = ''
     180            # Single multi values should be lists, too.
     181            elif f['type'] == 'multi' and f['name'] in values:
     182                if not isinstance(values[f['name']], list):
     183                    self[f['name']] = [values[f['name']]]
     184
    173185
    174186    def insert(self, when=None, db=None):
    175187        """Add ticket to database.

So far it seems to work, the pipe gets (and stays) appended to single values.

comment:2 Changed 11 years ago by Ryan J Ollos

Resolution: wontfix
Status: newclosed

TracMultiSelectBoxPlugin is pretty good. I'm going to mark this plugin as deprecated in favor of that one, or MultiSelectFieldPlugin, which I haven't looked at.

Last edited 11 years ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain CM Lubinski.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.