Пример #1
0
    def test_update__enable_labels(self):
        self.jar.add('Bug', 'red', False)
        self.jar.add('Question', 'green', True)
        self.jar.add('Feature', 'purple', True)

        labeling = ILabeling(self.document)
        self.assertEqual([], labeling.active_labels())

        labeling.update(['bug'])
        labeling.pers_update('feature', True)
        self.assertItemsEqual(['Bug', 'Feature'],
                              label_titles(labeling.active_labels()))
Пример #2
0
    def test_active_labels(self):
        self.jar.add('Question', '', False)
        self.jar.add('Bug', '', False)
        self.jar.add('Duplicate', '', True)

        labeling = ILabeling(self.document)
        labeling.update(['bug'])
        labeling.pers_update('duplicate', True)
        self.assertListEqual([{
            'label_id': 'bug',
            'title': 'Bug',
            'color': '',
            'by_user': False
        }, {
            'label_id': 'duplicate',
            'title': 'Duplicate',
            'color': '',
            'by_user': True
        }], labeling.active_labels())
Пример #3
0
    def test_available_label(self):
        self.jar.add('Question', '#00FF00', False)
        self.jar.add('Read', 'red', True)
        labeling = ILabeling(self.document)

        labeling.update(['question'])
        labeling.pers_update('read', True)
        self.assertEqual([[{
            'label_id': 'read',
            'title': 'Read',
            'color': 'red',
            'active': True,
            'by_user': True
        }],
                          [{
                              'label_id': 'question',
                              'title': 'Question',
                              'color': '#00FF00',
                              'active': True,
                              'by_user': False
                          }]], list(labeling.available_labels()))
Пример #4
0
 def pers_update(self):
     """Update personal labels.
     """
     labeling = ILabeling(self.context)
     label_id = self.request.form.get('label_id')
     activate = self.request.form.get('active')
     if not label_id or activate not in ['True', 'False']:
         return self._redirect()
     activate = not eval(activate)
     ret = labeling.pers_update(label_id, activate)
     self.context.reindexObject(idxs=['labels'])
     writer = getUtility(IJSONWriter)
     self.request.response.setHeader('content-type', 'application/json')
     return writer.write({'ret': (ret and 'ok' or 'nok'), 'new_status': str(activate)})
Пример #5
0
 def pers_update(self):
     """Update personal labels.
     """
     labeling = ILabeling(self.context)
     label_id = self.request.form.get('label_id')
     activate = self.request.form.get('active')
     if not label_id or activate not in ['True', 'False']:
         return self._redirect()
     activate = not eval(activate)
     ret = labeling.pers_update([label_id], activate)
     self.context.reindexObject(idxs=['labels'])
     writer = getUtility(IJSONWriter)
     self.request.response.setHeader('content-type', 'application/json')
     return writer.write({
         'ret': (ret and 'ok' or 'nok'),
         'new_status': str(activate)
     })
Пример #6
0
 def _apply(self, **data):
     if ((data.get('removed_values', None)
          and data['action_choice'] in ('remove', 'replace'))
             or (data.get('added_values', None))
             and data['action_choice'] in ('add', 'replace', 'overwrite')):
         values = {'p_a': [], 'p_r': [], 'g_a': [], 'g_r': []}
         for act, lst in (('a', data.get('added_values', [])),
                          ('r', data.get('removed_values', []))):
             for val in lst:
                 typ = (':' in val) and 'p' or 'g'
                 values['{}_{}'.format(typ, act)].append(val.split(':')[0])
         for brain in self.brains:
             obj = brain.getObject()
             labeling = ILabeling(obj)
             p_act, g_act = active_labels(labeling)
             # manage global labels
             if self.can_change_labels and (values['g_a'] or values['g_r']):
                 if data['action_choice'] in ('overwrite'):
                     items = set(values['g_a'])
                 else:
                     items = set(g_act)  # currently active labels
                     if data['action_choice'] in ('remove', 'replace'):
                         items = items.difference(values['g_r'])
                     if data['action_choice'] in ('add', 'replace'):
                         items = items.union(values['g_a'])
                 labeling.update(items)
             # manage personal labels
             if values['p_a'] or values['p_r']:
                 if data['action_choice'] in ('overwrite'):
                     items = set(values['p_a'])
                     labeling.pers_update(self.p_labels.difference(items),
                                          False)
                     labeling.pers_update(items, True)
                 else:
                     if data['action_choice'] in ('remove', 'replace'):
                         labeling.pers_update(
                             set(p_act).intersection(values['p_r']), False)
                     if data['action_choice'] in ('add', 'replace'):
                         labeling.pers_update(values['p_a'], True)
             obj.reindexObject(['labels'])