def load_extra_data(accident, streets, roads): """ loads more data about the accident :return: a dictionary containing all the extra fields and their values :rtype: dict """ extra_fields = {} # if the accident occurred in an urban setting if bool(accident[field_names.urban_intersection]): main_street, secondary_street = get_streets(accident, streets) if main_street: extra_fields[field_names.street1] = main_street if secondary_street: extra_fields[field_names.street2] = secondary_street # if the accident occurred in a non urban setting (highway, etc') if bool(accident[field_names.non_urban_intersection]): junction = get_junction(accident, roads) if junction: extra_fields[field_names.junction_name] = junction # localize static accident values for field in localization.get_supported_tables(): if accident[field]: # if we have a localized field for that particular field, save the field value # it will be fetched we deserialized if localization.get_field(field, accident[field]): extra_fields[field] = accident[field] return extra_fields
def format_description(field, value): # if the field's value is a static localizable field, fetch it. if field in localization.get_supported_tables(): value = localization.get_field(field, value).decode(db_encoding) name = localization.get_field(field).decode(db_encoding) return u"{0}: {1}".format(name, value)