From 3fe166f656ddfdc5fe57e4973ceea678f9d92a9c Mon Sep 17 00:00:00 2001 From: elbenfreund Date: Fri, 17 Nov 2017 12:33:08 +0100 Subject: [PATCH] Picking up where we left ... --- hamster_gtk/helpers.py | 18 +++++++++++++++--- hamster_gtk/overview/widgets/fact_grid.py | 14 ++++++-------- tests/preferences/conftest.py | 6 +++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/hamster_gtk/helpers.py b/hamster_gtk/helpers.py index 046a239a..85b92d5d 100644 --- a/hamster_gtk/helpers.py +++ b/hamster_gtk/helpers.py @@ -182,7 +182,7 @@ def decompose_raw_fact_string(text, raw=False): # [TODO] -# Oncec LIB-251 has been fixed this should no longer be needed. +# Once LIB-251 has been fixed this should no longer be needed. def get_recent_activities(controller, start, end): """Return a list of all activities logged in facts within the given timeframe.""" # [FIXME] @@ -196,10 +196,22 @@ def get_recent_activities(controller, start, end): return OrderedSet(recent_activities) -def serialize_activity(activity): +def serialize_activity(activity, seperator='@', none_category='not categorized'): """Provide a serialized string version of an activity.""" + + if not seperator: + raise ValueError(_("No valid separator has been provided.")) + if not none_category and none_category is not '': + raise ValueError(_("No valid text for 'none_category' has been provided.")) + if activity.category: - result = '{a.name}@{a.category.name}'.format(a=activity) + category_text = activity.category.name + else: + category_text = none_category + + if category_text: + result = '{activity_text}{seperator}{category_text}'.format(activity_text=activity.name, + category_text=category_text, seperator=seperator) else: result = activity.name return text_type(result) diff --git a/hamster_gtk/overview/widgets/fact_grid.py b/hamster_gtk/overview/widgets/fact_grid.py index 8eff81cd..c5e23f00 100644 --- a/hamster_gtk/overview/widgets/fact_grid.py +++ b/hamster_gtk/overview/widgets/fact_grid.py @@ -203,16 +203,14 @@ def _get_activity_widget(self, fact): """Return widget to render the activity, including its related category.""" # [FIXME] # Once 'preferences/config' is live, we can change this. - # Most likly we do not actually need to jump through extra hoops as + # Most likely we do not actually need to jump through extra hoops as # legacy hamster did but just use a i18n'ed string and be done. - if not fact.category: - category = 'not categorised' - else: - category = str(fact.category) activity_label = Gtk.Label() - activity_label.set_markup("{activity} - {category}".format( - activity=GObject.markup_escape_text(fact.activity.name), - category=GObject.markup_escape_text(category))) + #activity_label.set_markup("{activity} - {category}".format( + # activity=GObject.markup_escape_text(fact.activity.name), + # category=GObject.markup_escape_text(category))) + from hamster_gtk import helpers + activity_label.set_markup(GObject.markup_escape_text(helpers.serialize_activity(fact.activity))) activity_label.props.halign = Gtk.Align.START return activity_label diff --git a/tests/preferences/conftest.py b/tests/preferences/conftest.py index 94df22cc..dda65adc 100644 --- a/tests/preferences/conftest.py +++ b/tests/preferences/conftest.py @@ -87,7 +87,7 @@ def tracking_show_recent_activities_parametrized(request): @pytest.fixture(params=(0, 1, 5, 15)) -def tracking_recent_activities_items_parametrized(request): +def tracking_recent_activities_count_parametrized(request): """Return a parametrized tracking_recent_activities_items_parametrized value.""" return request.param @@ -97,7 +97,7 @@ def config_parametrized(request, store_parametrized, day_start_parametrized, fact_min_delta_parametrized, tmpfile_path_parametrized, db_engine_parametrized, db_path_parametrized, autocomplete_activities_range_parametrized, autocomplete_split_activity_parametrized, tracking_show_recent_activities_parametrized, - tracking_recent_activities_items_parametrized): + tracking_recent_activities_count_parametrized): """Return a config fixture with heavily parametrized config values.""" return { 'store': store_parametrized, @@ -109,7 +109,7 @@ def config_parametrized(request, store_parametrized, day_start_parametrized, 'autocomplete_activities_range': autocomplete_activities_range_parametrized, 'autocomplete_split_activity': autocomplete_split_activity_parametrized, 'tracking_show_recent_activities': tracking_show_recent_activities_parametrized, - 'tracking_recent_activities_items': tracking_recent_activities_items_parametrized, + 'tracking_recent_activities_count': tracking_recent_activities_count_parametrized, }