Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,41 @@ def main():
current_user = api.current_user.first()
user_id = current_user.id

print "Successfully connected to TSheets. Grabbed the current user's id: {}".format(user_id)
print("Successfully connected to TSheets. Grabbed the current user's id: {}".format(user_id))

# Make sure we can pull last-modified, non-paginated
last_modified = api.last_modified_timestamps.where(endpoints='timesheets')
print "Found timestamp for timesheets: {}".format(last_modified.first().timesheets)
print("Found timestamp for timesheets: {}".format(last_modified.first().timesheets))

# get a list of job codes
my_jobcode = None
my_jobname = 'Ancient Artifacts Inc.'
jobcodes = api.jobcodes.where(type = 'regular', active = True)
for jobcode in jobcodes:
if jobcode.name == 'Ancient Artifacts Inc.':
if jobcode.name == my_jobname:
my_jobcode = jobcode

if not my_jobcode:
print "No jobcode named 'Ancient Artifacts Inc.' found. " \
"Make sure you have that created for your account for this test to continue"
print("No jobcode named {0} found. " \
"Make sure you have that created for your account " \
"for this test to continue".format(my_jobname))
return

print " - Selecting Jobcode {}".format(my_jobcode.name)
print(" - Selecting Jobcode {}".format(my_jobcode.name))

# check to see if I am already on the clock
timesheet = None
timesheets = api.timesheets.where(modified_since=datetime(2015,7,1), on_the_clock = True, user_ids=[current_user.id]).all()
if len(timesheets) > 0:
print ' - Already clocked-in'
print(' - Already clocked-in')
timesheet = timesheets[0]
print timesheet
print(timesheet)
else:
print ' - Not clocked-in'
print(' - Not clocked-in')

# Toggle clock-in or clock-out
if timesheet == None:
print ' - Clocking in'
print(' - Clocking in')

# create a new timesheet
timesheet = Timesheet()
Expand All @@ -79,14 +82,14 @@ def main():
timesheet.jobcode_id = my_jobcode.id
result = api.timesheets.insert(timesheet)
if not result.is_success():
print result.message()
print(result.message())
else:
print ' - Clocking out'
print(' - Clocking out')
# edit existing timesheet
timesheet.end = datetime.now()
result = api.timesheets.update(timesheet)
if not result.is_success():
print result.message()
print(result.message())

if __name__ == '__main__':
main()
Expand Down
4 changes: 2 additions & 2 deletions tsheets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import repos
import models
from . import repos
from . import models
10 changes: 5 additions & 5 deletions tsheets/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logger
from models import *
from config import Config
from bridge import Bridge
from helpers import class_to_endpoint
from . import logger
from .models import *
from .config import Config
from .bridge import Bridge
from .helpers import class_to_endpoint
from tsheets.repository import Repository


Expand Down
14 changes: 7 additions & 7 deletions tsheets/bridge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from result import Result
from error import TSheetsError
from .result import Result
from .error import TSheetsError


class Bridge(object):
Expand All @@ -10,13 +10,13 @@ def __init__(self, config):

def items_from_data(self, data, name, is_singleton, mode):
if mode == "report":
objects = data["results"].values()[0]
return [] if not objects else objects.values()
objects = list(data["results"].values())[0]
return [] if not objects else list(objects.values())

if is_singleton or (not isinstance(data['results'][name], dict)):
return data['results'][name]
else:
return data['results'][name].values()
return list(data['results'][name].values())

def next_batch(self, url, name, options, is_singleton = False, mode="list"):
method = "get" if mode == "list" else "post"
Expand All @@ -36,8 +36,8 @@ def next_batch(self, url, name, options, is_singleton = False, mode="list"):
else:
s_dict = {}
if 'supplemental_data' in data:
for key, value in data['supplemental_data'].iteritems():
s_dict[key] = value.values()
for key, value in data['supplemental_data'].items():
s_dict[key] = list(value.values())
has_more = data.get('more', None)
result = {"items": self.items_from_data(data, name, is_singleton, mode),
"has_more": (has_more == 'true'),
Expand Down
2 changes: 1 addition & 1 deletion tsheets/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rest_adapter import RestAdapter
from .rest_adapter import RestAdapter


class Config(object):
Expand Down
6 changes: 5 additions & 1 deletion tsheets/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import os
import tempfile


log = logging.getLogger("tsheets_logger")
Expand All @@ -8,7 +10,9 @@
"%(levelname)-6s %(message)s")

# Log to file
filehandler = logging.FileHandler("/tmp/log.txt", "w")
filehandler = logging.FileHandler(
os.path.join(tempfile.gettempdir(), "tsheets-log.txt"),
"w")
filehandler.setLevel(logging.DEBUG)
filehandler.setFormatter(formatter)
log.addHandler(filehandler)
6 changes: 3 additions & 3 deletions tsheets/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytz
import helpers
from . import helpers
import dateutil.parser
from datetime import datetime, date

Expand Down Expand Up @@ -33,7 +33,7 @@ def from_raw(cls, hash):
def mass_assign(cls, instance, hash):
dynamic = instance._dynamic_accessors

for k,v in hash.iteritems():
for k,v in hash.items():
casted = cls.cast_raw(v, k)
if hasattr(instance, k):
setattr(instance, k, casted)
Expand Down Expand Up @@ -142,7 +142,7 @@ def cast_to_raw(self, value, key, type = None):
def to_raw(self, mode=None):
attributes = self.get_attributes(mode)
obj = {}
for k, v in attributes.iteritems():
for k, v in attributes.items():
obj[k] = self.cast_to_raw(v, k)
return obj

Expand Down
32 changes: 16 additions & 16 deletions tsheets/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from notification import Notification
from reminder import Reminder
from payroll import Payroll
from project import Project
from current_totals import CurrentTotals
from effective_settings import EffectiveSettings
from last_modified_timestamps import LastModifiedTimestamps
from user_permissions_set import UserPermissionsSet
from user import User
from jobcode import Jobcode
from timesheet_deleted import TimesheetDeleted
from timesheet import Timesheet
from jobcode_assignment import JobcodeAssignment
from custom_field import CustomField
from custom_field_item import CustomFieldItem
from geolocation import Geolocation
from .notification import Notification
from .reminder import Reminder
from .payroll import Payroll
from .project import Project
from .current_totals import CurrentTotals
from .effective_settings import EffectiveSettings
from .last_modified_timestamps import LastModifiedTimestamps
from .user_permissions_set import UserPermissionsSet
from .user import User
from .jobcode import Jobcode
from .timesheet_deleted import TimesheetDeleted
from .timesheet import Timesheet
from .jobcode_assignment import JobcodeAssignment
from .custom_field import CustomField
from .custom_field_item import CustomFieldItem
from .geolocation import Geolocation
32 changes: 16 additions & 16 deletions tsheets/repos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from notifications import Notifications
from reminders import Reminders
from project import Project
from payroll import Payroll
from current_totals import CurrentTotals
from last_modified_timestamps import LastModifiedTimestamps
from effective_settings import EffectiveSettings
from geolocations import Geolocations
from custom_field_items import CustomFieldItems
from custom_fields import CustomFields
from jobcodes import Jobcodes
from jobcode_assignments import JobcodeAssignments
from timesheets_deleted import TimesheetsDeleted
from timesheets import Timesheets
from users import Users
from current_user import CurrentUser
from .notifications import Notifications
from .reminders import Reminders
from .project import Project
from .payroll import Payroll
from .current_totals import CurrentTotals
from .last_modified_timestamps import LastModifiedTimestamps
from .effective_settings import EffectiveSettings
from .geolocations import Geolocations
from .custom_field_items import CustomFieldItems
from .custom_fields import CustomFields
from .jobcodes import Jobcodes
from .jobcode_assignments import JobcodeAssignments
from .timesheets_deleted import TimesheetsDeleted
from .timesheets import Timesheets
from .users import Users
from .current_user import CurrentUser
2 changes: 1 addition & 1 deletion tsheets/repos/current_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CurrentTotals(Repository):
CurrentTotals.add_me_to_subcls()
CurrentTotals.add_url("/reports/current_totals")
CurrentTotals.add_model(models.CurrentTotals)
CurrentTotals.add_actions([u'report'])
CurrentTotals.add_actions(['report'])
CurrentTotals.filter("user_ids", [int])
CurrentTotals.filter("group_ids", [int])
CurrentTotals.filter("on_the_clock", str)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/current_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class CurrentUser(Repository):
CurrentUser.add_me_to_subcls()
CurrentUser.add_url("/current_user")
CurrentUser.add_model(models.User)
CurrentUser.add_actions([u'list'])
CurrentUser.add_actions(['list'])
2 changes: 1 addition & 1 deletion tsheets/repos/custom_field_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CustomFieldItems(Repository):
CustomFieldItems.add_me_to_subcls()
CustomFieldItems.add_url("/customfielditems")
CustomFieldItems.add_model(models.CustomFieldItem)
CustomFieldItems.add_actions([u'list', u'add', u'edit'])
CustomFieldItems.add_actions(['list', 'add', 'edit'])
CustomFieldItems.filter("customfield_id", int)
CustomFieldItems.filter("ids", [int])
CustomFieldItems.filter("active", str)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CustomFields(Repository):
CustomFields.add_me_to_subcls()
CustomFields.add_url("/customfields")
CustomFields.add_model(models.CustomField)
CustomFields.add_actions([u'list'])
CustomFields.add_actions(['list'])
CustomFields.filter("ids", [int])
CustomFields.filter("active", bool)
CustomFields.filter("applies_to", str)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/effective_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EffectiveSettings(Repository):
EffectiveSettings.add_me_to_subcls()
EffectiveSettings.add_url("/effective_settings")
EffectiveSettings.add_model(models.EffectiveSettings, singleton=True)
EffectiveSettings.add_actions([u'list'])
EffectiveSettings.add_actions(['list'])
EffectiveSettings.filter("user_id", int)
EffectiveSettings.filter("modified_before", datetime)
EffectiveSettings.filter("modified_since", datetime)
2 changes: 1 addition & 1 deletion tsheets/repos/geolocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Geolocations(Repository):
Geolocations.add_me_to_subcls()
Geolocations.add_url("/geolocations")
Geolocations.add_model(models.Geolocation)
Geolocations.add_actions([u'list', u'add'])
Geolocations.add_actions(['list', 'add'])
Geolocations.filter("ids", [int])
Geolocations.filter("modified_before", datetime)
Geolocations.filter("modified_since", datetime)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/jobcode_assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class JobcodeAssignments(Repository):
JobcodeAssignments.add_me_to_subcls()
JobcodeAssignments.add_url("/jobcode_assignments")
JobcodeAssignments.add_model(models.JobcodeAssignment)
JobcodeAssignments.add_actions([u'list', u'add', u'delete'])
JobcodeAssignments.add_actions(['list', 'add', 'delete'])
JobcodeAssignments.filter("user_ids", [int])
JobcodeAssignments.filter("type", str)
JobcodeAssignments.filter("jobcode_parent_id", int)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/jobcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Jobcodes(Repository):
Jobcodes.add_me_to_subcls()
Jobcodes.add_url("/jobcodes")
Jobcodes.add_model(models.Jobcode)
Jobcodes.add_actions([u'list', u'add', u'edit'])
Jobcodes.add_actions(['list', 'add', 'edit'])
Jobcodes.filter("ids", [int])
Jobcodes.filter("parent_ids", [int])
Jobcodes.filter("type", str)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/last_modified_timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class LastModifiedTimestamps(Repository):
LastModifiedTimestamps.add_me_to_subcls()
LastModifiedTimestamps.add_url("/last_modified_timestamps")
LastModifiedTimestamps.add_model(models.LastModifiedTimestamps, singleton=True)
LastModifiedTimestamps.add_actions([u'list'])
LastModifiedTimestamps.add_actions(['list'])
LastModifiedTimestamps.filter("endpoints", str)
2 changes: 1 addition & 1 deletion tsheets/repos/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Notifications(Repository):
Notifications.add_me_to_subcls()
Notifications.add_url("/notifications")
Notifications.add_model(models.Notification)
Notifications.add_actions([u'list', u'add', u'delete'])
Notifications.add_actions(['list', 'add', 'delete'])
Notifications.filter("ids", [int])
Notifications.filter("delivery_before", datetime)
Notifications.filter("delivery_after", datetime)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/payroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Payroll(Repository):
Payroll.add_me_to_subcls()
Payroll.add_url("/reports/payroll")
Payroll.add_model(models.Payroll)
Payroll.add_actions([u'report'])
Payroll.add_actions(['report'])
Payroll.filter("start_date", date)
Payroll.filter("end_date", date)
Payroll.filter("user_ids", int)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Project(Repository):
Project.add_me_to_subcls()
Project.add_url("/reports/project")
Project.add_model(models.Project)
Project.add_actions([u'report'])
Project.add_actions(['report'])
Project.filter("start_date", date)
Project.filter("end_date", date)
Project.filter("user_ids", [int])
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Reminders(Repository):
Reminders.add_me_to_subcls()
Reminders.add_url("/reminders")
Reminders.add_model(models.Reminder)
Reminders.add_actions([u'list', u'add', u'edit'])
Reminders.add_actions(['list', 'add', 'edit'])
Reminders.filter("user_ids", [int])
Reminders.filter("reminder_types", [str])
Reminders.filter("modified_since", datetime)
2 changes: 1 addition & 1 deletion tsheets/repos/timesheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Timesheets(Repository):
Timesheets.add_me_to_subcls()
Timesheets.add_url("/timesheets")
Timesheets.add_model(models.Timesheet)
Timesheets.add_actions([u'list', u'add', u'edit', u'delete'])
Timesheets.add_actions(['list', 'add', 'edit', 'delete'])
Timesheets.filter("ids", [int])
Timesheets.filter("start_date", date)
Timesheets.filter("end_date", date)
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/timesheets_deleted.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TimesheetsDeleted(Repository):
TimesheetsDeleted.add_me_to_subcls()
TimesheetsDeleted.add_url("/timesheets_deleted")
TimesheetsDeleted.add_model(models.TimesheetDeleted)
TimesheetsDeleted.add_actions([u'list'])
TimesheetsDeleted.add_actions(['list'])
TimesheetsDeleted.filter("start_date", date)
TimesheetsDeleted.filter("end_date", date)
TimesheetsDeleted.filter("ids", [int])
Expand Down
2 changes: 1 addition & 1 deletion tsheets/repos/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Users(Repository):
Users.add_me_to_subcls()
Users.add_url("/users")
Users.add_model(models.User)
Users.add_actions([u'list', u'add', u'edit'])
Users.add_actions(['list', 'add', 'edit'])
Users.filter("ids", [int])
Users.filter("usernames", [str])
Users.filter("active", bool)
Expand Down
Loading