Skip to content

Loading…

Add support to reverse the search_terms to GetFacts #70

Merged
merged 2 commits into from

2 participants

@alexhayes

I needed a way to retrieve all tasks that did not have a particular tag - ie.. a NOT for search_terms. I imagine that it may be useful for others.

On a side note to get hamster@master installed on my Ubuntu 12.04 machine I also needed to do the following:

sudo apt-get install libglib2.0-dev gnome-doc-utils vala-dbus-binding-tool gnome-control-center-dev
sudo ln -s /usr/bin/vala-dbus-binding-tool /usr/bin/dbus-binding-tool

I'm not sure if this is something that is unique to my installation thus I haven't put it in the README - however I'm pretty much running stock Ubuntu 12.04 with Gnome 3 so I imagine it might be an issue for other users.

@tbaugis tbaugis merged commit 11ef492 into projecthamster:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 12 additions and 12 deletions.
  1. +4 −3 src/hamster-service
  2. +3 −2 src/hamster/client.py
  3. +3 −5 src/hamster/db.py
  4. +2 −2 src/hamster/storage.py
View
7 src/hamster-service
@@ -178,13 +178,14 @@ class Storage(db.Storage, dbus.service.Object):
return self.remove_fact(fact_id)
- @dbus.service.method("org.gnome.Hamster", in_signature='uus', out_signature='a(iiissisasii)')
- def GetFacts(self, start_date, end_date, search_terms):
+ @dbus.service.method("org.gnome.Hamster", in_signature='uusb', out_signature='a(iiissisasii)')
+ def GetFacts(self, start_date, end_date, search_terms, reverse_search_terms=False):
"""Gets facts between the day of start_date and the day of end_date.
Parameters:
i start_date: Seconds since epoch (timestamp). Use 0 for today
i end_date: Seconds since epoch (timestamp). Use 0 for today
s search_terms: Bleh
+ b reverse_search_terms: Reverse the behaviour of the search terms (ie.. NOT search_terms)
Returns Array of fact where fact is struct of:
i id
i start_time
@@ -206,7 +207,7 @@ class Storage(db.Storage, dbus.service.Object):
if end_date:
end = dt.datetime.utcfromtimestamp(end_date).date()
- return [to_dbus_fact(fact) for fact in self.get_facts(start, end, search_terms)]
+ return [to_dbus_fact(fact) for fact in self.get_facts(start, end, search_terms, reverse_search_terms)]
@dbus.service.method("org.gnome.Hamster", out_signature='a(iiissisasii)')
View
5 src/hamster/client.py
@@ -114,7 +114,7 @@ def get_todays_facts(self):
"""
return [from_dbus_fact(fact) for fact in self.conn.GetTodaysFacts()]
- def get_facts(self, date, end_date = None, search_terms = ""):
+ def get_facts(self, date, end_date = None, search_terms = "", reverse_search_terms=False):
"""Returns facts for the time span matching the optional filter criteria.
In search terms comma (",") translates to boolean OR and space (" ")
to boolean AND.
@@ -127,7 +127,8 @@ def get_facts(self, date, end_date = None, search_terms = ""):
return [from_dbus_fact(fact) for fact in self.conn.GetFacts(date,
end_date,
- search_terms)]
+ search_terms,
+ reverse_search_terms)]
def get_activities(self, search = ""):
"""returns list of activities name matching search criteria.
View
8 src/hamster/db.py
@@ -639,7 +639,7 @@ def __get_todays_facts(self):
return self.__get_facts(today)
- def __get_facts(self, date, end_date = None, search_terms = ""):
+ def __get_facts(self, date, end_date = None, search_terms = "", reverse_search_terms=False):
try:
from configuration import conf
day_start = conf.get("day_start_minutes")
@@ -674,11 +674,9 @@ def __get_facts(self, date, end_date = None, search_terms = ""):
self.__check_index(datetime_from, datetime_to)
search_terms = search_terms.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_').replace("'", "''")
- query += """ AND a.id in (SELECT id
+ query += """ AND a.id %sIN (SELECT id
FROM fact_index
- WHERE fact_index MATCH '%s')""" % search_terms
-
-
+ WHERE fact_index MATCH '%s')""" % (' NOT ' if reverse_search_terms else '', search_terms)
query += " ORDER BY a.start_time, e.name"
View
4 src/hamster/storage.py
@@ -82,8 +82,8 @@ def remove_fact(self, fact_id):
self.end_transaction()
- def get_facts(self, start_date, end_date, search_terms):
- return self.__get_facts(start_date, end_date, search_terms)
+ def get_facts(self, start_date, end_date, search_terms, reverse_search_terms=False):
+ return self.__get_facts(start_date, end_date, search_terms, reverse_search_terms)
def get_todays_facts(self):
Something went wrong with that request. Please try again.