From c7b7b3d454906c8ee8c6d15d8549e1eb0ca721d1 Mon Sep 17 00:00:00 2001 From: Alexander Oblovatniy Date: Sat, 8 Mar 2014 19:47:37 +0200 Subject: [PATCH] Update decomposer. --- MANIFEST.in | 1 - il2ds_difficulty/__init__.py | 43 ++++++++++++++++++++---------------- il2ds_difficulty/helpers.py | 8 +++++-- setup.py | 1 + 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index ba6dc31..89446ab 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,3 @@ include README.md include LICENSE include requirements.pip -recursive-include il2ds_difficulty/locale * diff --git a/il2ds_difficulty/__init__.py b/il2ds_difficulty/__init__.py index ad2a8fe..9fda15a 100644 --- a/il2ds_difficulty/__init__.py +++ b/il2ds_difficulty/__init__.py @@ -2,11 +2,9 @@ """ Convert integer value of game difficulty into dictionary and vice versa. """ -from collections import OrderedDict - from il2ds_difficulty.constants import (DEFAULT_GAME_VERSION, SETTINGS, NUMBERS_MAPS, SETTINGS_NAMES_MAP, TABS_NAMES_MAP, ) -from il2ds_difficulty.helpers import _ +from il2ds_difficulty.helpers import _, evaluate_string from il2ds_difficulty.validators import (validate_difficulty, validate_game_version, ) @@ -38,34 +36,41 @@ def decompose_difficulty_to_tabs(difficulty, Convert an integer value into ordered difficulty settings groups. Output example: - { - 'tab1_code': { + ( + { + 'code': 'tab1_code', 'name': 'tab1_name', - 'settings': { - 'setting1_code': { + 'settings': ( + { + 'code': 'setting1_code', 'title': 'setting1_title', 'description': 'setting1_description', 'value': 'setting1_value', }, - }, + ), }, - } + ) """ validate_difficulty(difficulty) validate_game_version(game_version) settings = SETTINGS[game_version] - return OrderedDict(tuple( - (tab_code, { - 'name': TABS_NAMES_MAP[tab_code], - 'settings': OrderedDict(tuple( - (setting_code, dict( - SETTINGS_NAMES_MAP[setting_code], **{ + return tuple( + { + 'code': tab_code, + 'title': evaluate_string(TABS_NAMES_MAP[tab_code]), + 'settings': tuple( + { + 'code': setting_code, + 'title': evaluate_string( + SETTINGS_NAMES_MAP[setting_code]['title']), + 'description': evaluate_string( + SETTINGS_NAMES_MAP[setting_code]['description']), 'value': get_setting_value(difficulty, setting_number), - })) for setting_code, setting_number in tab_settings.items() - )) - }) for tab_code, tab_settings in settings.items() - )) + } for setting_code, setting_number in tab_settings.items() + ) + } for tab_code, tab_settings in settings.items() + ) def compose_difficulty(settings, game_version=DEFAULT_GAME_VERSION): diff --git a/il2ds_difficulty/helpers.py b/il2ds_difficulty/helpers.py index f731d80..69b15e7 100644 --- a/il2ds_difficulty/helpers.py +++ b/il2ds_difficulty/helpers.py @@ -6,10 +6,14 @@ try: from django.conf import settings if settings.configured: - from django.utils.translation import ugettext - _ = ugettext + from django.utils.translation import ugettext_lazy + _ = ugettext_lazy else: raise ImportError() except ImportError: def _(value): return value + + +def evaluate_string(value): + return None if value is None else unicode(value) diff --git a/setup.py b/setup.py index 5116f4f..5781e85 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ author='Alexander Oblovatniy, Alexander Kamyhin', author_email='oblovatniy@gmail.com, kamyhin@gmail.com', packages=find_packages(), + include_package_data=True, install_requires=[i.strip() for i in open("requirements.pip").readlines()], classifiers = [ 'Development Status :: 5 - Production/Stable',