示例#1
0
 def test_sluggify(self):
     inp_exps = [
         ['A B C', 'a_b_c'],
         # add examples here...
     ]
     for strs in inp_exps:
         if len(strs) > 2:
             opts = strs[3]
         else:
             opts = {}
         _converted = sluggify(strs[0], opts)
         self.assertEqual(strs[1], _converted)
示例#2
0
 def test_sluggify(self):
     inp_exps = [
         ['A B C', 'a_b_c'],
         # add examples here...
     ]
     for strs in inp_exps:
         if len(strs) > 2:
             opts = strs[3]
         else:
             opts = {}
         _converted = sluggify(strs[0], opts)
         self.assertEqual(strs[1], _converted)
示例#3
0
def autovalue_choices_in_place(surv_content, destination_key):
    """
    choice names must have spaces removed because select-multiple
    results are presented in a space-delimited string.

    we have been ensuring that choice names are unique to
    avoid errors leading to submission of ambiguous responses.
    """
    surv_choices = surv_content.get('choices', [])
    choice_value_key = 'name'
    choices = OrderedDict()
    for choice in surv_choices:
        _list_name = choice.get('list_name')
        if _list_name in ['', None]:
            continue
        if _list_name not in choices:
            choices[_list_name] = []
        choices[_list_name].append(choice)

    for list_name, choice_list in choices.items():
        previous_values = []
        for choice in choice_list:
            if choice_value_key in choice and choice[choice_value_key]:
                choice[destination_key] = choice[choice_value_key]
            else:
                if isinstance(choice['label'], list):
                    _slug = _first_non_falsey_item(choice['label'])
                else:
                    _slug = choice['label']
                choice[destination_key] = sluggify(
                    _slug, {
                        'replaceNonWordCharacters': False,
                        'underscores': True,
                        'preventDuplicateUnderscores': True,
                        'lowerCase': False,
                        'preventDuplicates': previous_values,
                    })
            previous_values.append(choice[destination_key])
示例#4
0
def autovalue_choices_in_place(surv_content, destination_key):
    '''
    choice names must have spaces removed because select-multiple
    results are presented in a space-delimited string.

    we have been ensuring that choice names are unique to
    avoid errors leading to submission of ambiguous responses.
    '''
    surv_choices = surv_content.get('choices', [])
    choice_value_key = 'name'
    choices = OrderedDict()
    for choice in surv_choices:
        _list_name = choice.get('list_name')
        if _list_name in ['', None]:
            continue
        if _list_name not in choices:
            choices[_list_name] = []
        choices[_list_name].append(choice)

    for (list_name, choice_list) in choices.iteritems():
        previous_values = []
        for choice in choice_list:
            if choice_value_key in choice and choice[choice_value_key]:
                choice[destination_key] = choice[choice_value_key]
            else:
                if isinstance(choice['label'], list):
                    _slug = _first_non_falsey_item(choice['label'])
                else:
                    _slug = choice['label']
                choice[destination_key] = sluggify(_slug, {
                    'replaceNonWordCharacters': False,
                    'underscores': True,
                    'preventDuplicateUnderscores': True,
                    'lowerCase': False,
                    'preventDuplicates': previous_values,
                })
            previous_values.append(choice[destination_key])