Skip to content

Commit

Permalink
Picking up where we left ...
Browse files Browse the repository at this point in the history
  • Loading branch information
elbenfreund committed Nov 17, 2017
1 parent 82fad51 commit edbf341
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
33 changes: 29 additions & 4 deletions hamster_gtk/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from __future__ import absolute_import, unicode_literals

import datetime
from gettext import gettext as _
import operator
import re

Expand Down Expand Up @@ -182,7 +183,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]
Expand All @@ -196,10 +197,34 @@ def get_recent_activities(controller, start, end):
return OrderedSet(recent_activities)


def serialize_activity(activity):
"""Provide a serialized string version of an activity."""
def serialize_activity(activity, separator='@', none_category='not categorized'):
"""
Provide a serialized string version of an activity.
Args:
activity (Activity): ``Activity`` instance to serialize.
separator (str, optional): ``string`` used to separate ``activity.name`` and
``category.name``. The separator will be omitted if ``none_categoty=''`` and
``activity.category=None``. Defaults to ``@``.
none_category (str, optional): ``string`` to represent the 'lack of a cactegory' for an
activity instance. Defaults to ``not categorized``.
Returns:
str: A string representation of the passed activity.
"""
if not separator:
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}{separator}{category_text}'.format(activity_text=activity.name,
category_text=category_text, separator=separator)
else:
result = activity.name
return text_type(result)
Expand Down
13 changes: 2 additions & 11 deletions hamster_gtk/overview/widgets/fact_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,9 @@ def __init__(self, fact):

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
# 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)))
label_text = helpers.serialize_activity(fact.activity)
activity_label.set_markup(GObject.markup_escape_text(label_text))
activity_label.props.halign = Gtk.Align.START
return activity_label

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def app(request, config):
"""
def monkeypatched_reload_config(self):
return config
HamsterGTK = hamster_gtk.HamsterGTK
HamsterGTK = hamster_gtk.HamsterGTK # NOQA
HamsterGTK._reload_config = monkeypatched_reload_config
app = HamsterGTK()
app._startup(app)
Expand Down
6 changes: 3 additions & 3 deletions tests/preferences/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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,
}


Expand Down
2 changes: 1 addition & 1 deletion tests/test_hamster-gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_instantiation(self, config):
"""
def monkeypatched_reload_config(self):
return config
HamsterGTK = hamster_gtk.HamsterGTK
HamsterGTK = hamster_gtk.HamsterGTK # NOQA
HamsterGTK._reload_config = monkeypatched_reload_config
app = HamsterGTK()
assert app
Expand Down

0 comments on commit edbf341

Please sign in to comment.