Skip to content

Commit

Permalink
Improve projects management
Browse files Browse the repository at this point in the history
Add project status in "search" command, don't show inactive projects when using
"add", add start and end dates as well as project status in project detail.
  • Loading branch information
sephii committed Oct 8, 2012
1 parent 521e117 commit fd2122e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 15 deletions.
2 changes: 1 addition & 1 deletion taxi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.3'
__version__ = '2.4-dev'
14 changes: 6 additions & 8 deletions taxi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def add(options, args):
raise Exception(add.__doc__)

search = args[1:]
projects = db.search(search)
projects = db.search(search, active_only=True)

if len(projects) == 0:
print 'No project matches your search string \'%s\'' % ' '.join(search)
Expand All @@ -131,10 +131,7 @@ def add(options, args):

project = projects[number]

print project

if project.status == 0:
print 'Warning: this project is not active'
print(project)

print "\nActivities:"
for (key, activity) in enumerate(project.activities):
Expand Down Expand Up @@ -171,7 +168,8 @@ def add(options, args):
def search(options, args):
"""Usage: search search_string
Searches for a project by its name.
Searches for a project by its name. The letter in the first column indicates
the status of the project: [N]ot started, [A]ctive, [F]inished, [C]ancelled.
"""

db = ProjectsDb()
Expand Down Expand Up @@ -221,8 +219,8 @@ def show(options, args):
else:
print project

if project.status == 1:
print "\nActivities:"
if project.is_active():
print(u"\nActivities:")
for activity in project.activities:
print '%-4s %s' % (activity.id, activity.name)

Expand Down
50 changes: 47 additions & 3 deletions taxi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ def get_duration(self):
return self.duration

class Project:
STATUS_NOT_STARTED = 0;
STATUS_ACTIVE = 1;
STATUS_FINISHED = 2;
STATUS_CANCELLED = 3;

STATUSES = {
STATUS_NOT_STARTED: 'Not started',
STATUS_ACTIVE: 'Active',
STATUS_FINISHED: 'Finished',
STATUS_CANCELLED: 'Cancelled',
}

SHORT_STATUSES = {
STATUS_NOT_STARTED: 'N',
STATUS_ACTIVE: 'A',
STATUS_FINISHED: 'F',
STATUS_CANCELLED: 'C',
}

def __init__(self, id, name, status = None, description = None, budget = None):
self.id = int(id)
self.name = name
Expand All @@ -54,18 +73,43 @@ def __init__(self, id, name, status = None, description = None, budget = None):
self.budget = budget

def __unicode__(self):
return """\nId: %s
if self.status in self.STATUSES:
status = self.STATUSES[self.status]
else:
status = 'Unknown'

return """Id: %s
Name: %s
Active: %s
Status: %s
Start date: %s
End date: %s
Budget: %s
Description: %s""" % (self.id, self.name, 'yes' if self.status else 'no', self.budget, self.description)
Description: %s""" % (
self.id, self.name,
status,
self.start_date.strftime('%d.%m.%Y'),
self.end_date.strftime('%d.%m.%Y'),
self.budget,
self.description
)

def __str__(self):
return unicode(self).encode('utf-8')

def add_activity(self, activity):
self.activities.append(activity)

def is_active(self):
return (self.status == self.STATUS_ACTIVE and
self.start_date <= datetime.datetime.now() and
self.end_date > datetime.datetime.now())

def get_short_status(self):
if self.status not in self.SHORT_STATUSES:
return '?'

return self.SHORT_STATUSES[self.status]

class Activity:
def __init__(self, id, name, price):
self.id = int(id)
Expand Down
7 changes: 4 additions & 3 deletions taxi/projectsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def update(self, base_url, username, password):

print 'Projects database updated successfully'

def search(self, search):
def search(self, search, active_only=False):
projects = self._get_projects()
found_list = []

Expand All @@ -47,7 +47,8 @@ def search(self, search):
break

if found:
found_list.append(project)
if not active_only or project.is_active():
found_list.append(project)

return found_list

Expand All @@ -64,7 +65,7 @@ def get(self, id):

class LocalProjectsDb:
projects = []
VERSION = 1
VERSION = 2

def __init__(self, projects):
self.projects = projects
12 changes: 12 additions & 0 deletions taxi/remote.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import urllib, urllib2, urlparse, cookielib
import json
from datetime import datetime

from models import Project, Activity

Expand Down Expand Up @@ -159,6 +160,17 @@ def get_projects(self):
p = Project(int(project['id']), project['name'],\
project['status'], project['description'],\
project['budget'])

try:
p.start_date = datetime.strptime(project['startdate'], '%Y-%m-%d')
except ValueError:
p.start_date = None

try:
p.end_date = datetime.strptime(project['enddate'], '%Y-%m-%d')
except ValueError:
p.end_date = None

i += 1

if p.status == 1:
Expand Down

0 comments on commit fd2122e

Please sign in to comment.