-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for local / personnal aliases #29
Changes from 3 commits
d4595e4
27d5a7b
ca5633c
decfd91
e0a676c
032ea86
13f13f4
6184494
85eb0ba
c3e3ac3
ae744fd
7352851
f192336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from taxi.parser import DateLine, EntryLine, TextLine, ParseError | ||
from taxi.utils import date as date_utils | ||
|
||
|
||
class Entry: | ||
def __init__(self, date, project_name, hours, description, id=None): | ||
self.project_name = project_name | ||
|
@@ -18,13 +19,16 @@ def __init__(self, date, project_name, hours, description, id=None): | |
self.date = date | ||
self.pushed = False | ||
self.ignored = False | ||
self.local = False | ||
self.project_id = None | ||
self.activity_id = None | ||
self.id = id | ||
|
||
def __unicode__(self): | ||
if self.is_ignored(): | ||
project_name = u'%s (ignored)' % (self.project_name) | ||
elif self.is_local(): | ||
project_name = u'%s (local)' % (self.project_name) | ||
else: | ||
project_name = u'%s (%s/%s)' % (self.project_name, self.project_id, self.activity_id) | ||
|
||
|
@@ -33,6 +37,12 @@ def __unicode__(self): | |
def is_ignored(self): | ||
return self.ignored or self.get_duration() == 0 | ||
|
||
def is_local(self): | ||
return self.local | ||
|
||
def is_selected(self, exclude_ignored, exclude_local): | ||
return not (exclude_ignored and self.is_ignored()) and not (exclude_local and self.is_local()) | ||
|
||
def get_duration(self): | ||
if isinstance(self.duration, tuple): | ||
if None in self.duration: | ||
|
@@ -50,6 +60,7 @@ def get_duration(self): | |
|
||
return self.duration | ||
|
||
|
||
class Project: | ||
STATUS_NOT_STARTED = 0 | ||
STATUS_ACTIVE = 1 | ||
|
@@ -221,13 +232,15 @@ def _update_entries(self): | |
if entry.project_name in self.mappings: | ||
entry.project_id = self.mappings[entry.project_name][0] | ||
entry.activity_id = self.mappings[entry.project_name][1] | ||
if(entry.project_id < 0 or entry.activity_id < 0): | ||
entry.local = True | ||
else: | ||
if not entry.is_ignored(): | ||
raise UndefinedAliasError(line.get_alias()) | ||
|
||
self.entries[current_date].append(entry) | ||
|
||
def get_entries(self, date=None, exclude_ignored=False): | ||
def get_entries(self, date=None, exclude_ignored=False, exclude_local=False): | ||
entries_dict = {} | ||
|
||
# Date can either be a single date (only 1 day) or a tuple for a | ||
|
@@ -240,14 +253,26 @@ def get_entries(self, date=None, exclude_ignored=False): | |
if entrydate not in entries_dict: | ||
entries_dict[entrydate] = [] | ||
|
||
if not exclude_ignored: | ||
entries_dict[entrydate].extend(entries) | ||
else: | ||
d_list = [entry for entry in entries if not entry.is_ignored()] | ||
entries_dict[entrydate].extend(d_list) | ||
d_list = [entry for entry in entries if entry.is_selected(exclude_ignored, exclude_local)] | ||
entries_dict[entrydate].extend(d_list) | ||
|
||
return entries_dict | ||
|
||
def get_local_entries(self, date=None): | ||
entries_dict = self.get_entries(date, False) | ||
local_entries = {} | ||
|
||
for (date, entries) in entries_dict.iteritems(): | ||
local_entries_list = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this? local_entries_list = [entry for entry in entries if entry.is_local()] |
||
for entry in entries: | ||
if entry.is_local(): | ||
local_entries_list.append(entry) | ||
|
||
if local_entries_list: | ||
local_entries[date] = local_entries_list | ||
|
||
return local_entries | ||
|
||
def get_ignored_entries(self, date=None): | ||
entries_dict = self.get_entries(date, False) | ||
ignored_entries = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ def get_auto_fill_days(self): | |
|
||
return [int(e.strip()) for e in auto_fill_days.split(',')] | ||
|
||
def get_aliases(self, include_shared=True): | ||
def get_aliases(self, include_shared=True, include_local=True): | ||
aliases = {} | ||
config_aliases = self.config.items('wrmap') | ||
shared_config_aliases = (self.config.items('shared_wrmap') | ||
|
@@ -68,6 +68,10 @@ def get_aliases(self, include_shared=True): | |
(alias, mapping) | ||
) | ||
|
||
if include_local: | ||
for(alias) in self.config.get('default', 'local_aliases').split(','): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the parentheses around (alias) |
||
aliases[alias.strip()] = (-1, -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we use None instead of -1? |
||
|
||
return aliases | ||
|
||
def get_reversed_aliases(self, include_shared=True): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment that explains what this method is doing would be great