Beispiel #1
0
def patch_rules():
    from services.utils import AccessibilityShortcomingCalculator
    # Verify that AccessibilityShortcomingCalculator is singleton
    assert AccessibilityShortcomingCalculator() == AccessibilityShortcomingCalculator()

    def _set_rules(rules, messages):
        AccessibilityShortcomingCalculator().rules = rules
        AccessibilityShortcomingCalculator().messages = messages

    return _set_rules
Beispiel #2
0
 def _handle_accessibility_shortcomings(self, obj):
     description, count = AccessibilityShortcomingCalculator().calculate(
         obj)
     UnitAccessibilityShortcomings.objects.update_or_create(
         unit=obj,
         defaults={
             "accessibility_shortcoming_count": count,
             "accessibility_description": description,
         },
     )
Beispiel #3
0
def _import_unit_accessibility_variables(obj, info, obj_changed,
                                         update_fields):
    if info['accessibility_properties']:
        acp = sorted(info['accessibility_properties'],
                     key=itemgetter('variable_id'))
        acp_json = json.dumps(acp, ensure_ascii=False,
                              sort_keys=True).encode('utf8')
        acp_hash = hashlib.sha1(acp_json).hexdigest()
    else:
        acp_hash = None
    if obj.accessibility_property_hash != acp_hash:
        if VERBOSITY:
            LOGGER.info("%s accessibility property set changed (%s vs. %s)" %
                        (obj, obj.accessibility_property_hash, acp_hash))
        obj.accessibility_properties.all().delete()
        for acp in info['accessibility_properties']:
            uap = UnitAccessibilityProperty(unit=obj)
            var_id = acp['variable_id']
            if var_id not in get_accessibility_variables():
                var = AccessibilityVariable(id=var_id,
                                            name=acp['variable_name'])
                var.save()
            else:
                var = get_accessibility_variables()[var_id]
            uap.variable = var
            uap.value = acp['value']
            uap.save()

        obj.accessibility_property_hash = acp_hash
        obj_changed = True
        update_fields.append('accessibility_property_hash')

        # Recalculate accessibility shortcomings
        description, shortcoming_count = AccessibilityShortcomingCalculator(
        ).calculate(obj)
        UnitAccessibilityShortcomings.objects.update_or_create(
            unit=obj,
            defaults={
                'accessibility_shortcoming_count': shortcoming_count,
                'accessibility_description': description
            })

    return obj_changed, update_fields
 def _set_rules(rules, messages):
     AccessibilityShortcomingCalculator().rules = rules
     AccessibilityShortcomingCalculator().messages = messages