# Path: pendulum/models.py
# class Entry(models.Model):
#     """
#     This class is where all of the time logs are taken care of
#     """
# 
#     user = models.ForeignKey(User, related_name='pendulum_entries')
#     project = models.ForeignKey(Project,
#                                 limit_choices_to={'is_active': True,
#                                                   'sites': CURRENT_SITE},
#                                 related_name='entries')
#     activity = models.ForeignKey(Activity, blank=True, null=True, related_name='entries')
#     start_time = models.DateTimeField()
#     end_time = models.DateTimeField(blank=True, null=True)
#     seconds_paused = models.PositiveIntegerField(default=0)
#     pause_time = models.DateTimeField(blank=True, null=True)
#     comments = models.TextField(blank=True, null=True)
#     date_updated = models.DateTimeField(auto_now=True)
#     site = models.ForeignKey(Site, related_name='pendulum_entries')
# 
#     objects = EntryManager()
# 
#     def get_seconds(self):
#         """
#         Determines the difference between the starting and ending time.  The
#         result is returned as an integer of seconds.
#         """
#         if self.start_time and self.end_time:
#             # only calculate when the start and end are defined
#             delta = self.end_time - self.start_time
#             seconds = delta.seconds - self.seconds_paused
#         else:
#             seconds = 0
#             delta = timedelta(days=0)
# 
#         return seconds + (delta.days * 86400)
# 
#     def __total_hours(self):
#         """
#         Determined the total number of hours worked in this entry
#         """
#         return self.get_seconds() / 3600.0
#     total_hours = property(__total_hours)
# 
#     def __total_time(self):
#         """
#         Determines the amount of time spent and return it as a string formatted
#         as HH:MM:SS
#         """
#         return utils.get_total_time(self.get_seconds())
#     total_time = property(__total_time)
# 
#     def __paused_time(self):
#         """
#         Returns the total time paused for this entry in HH:MM:SS format
#         """
#         return utils.get_total_time(self.seconds_paused)
#     paused_time = property(__paused_time)
# 
#     def __hours(self):
#         """
#         Print the hours in a nice, rounded format
#         """
#         return "%.02f" % self.total_hours
#     hours = property(__hours)
# 
#     def __is_paused(self):
#         """
#         Determine whether or not this entry is paused
#         """
#         return self.pause_time != None
#     is_paused = property(__is_paused)
# 
#     def pause(self):
#         """
#         If this entry is not paused, pause it.
#         """
#         if not self.is_paused:
#             self.pause_time = datetime.now()
# 
#     def unpause(self):
#         """
#         If this entry is paused, unpause it
#         """
#         if self.is_paused:
#             delta = datetime.now() - self.pause_time
#             self.seconds_paused += delta.seconds
#             self.pause_time = None
# 
#     def toggle_paused(self):
#         """
#         Toggle the paused state of this entry.  If the entry is already paused,
#         it will be unpaused; if it is not paused, it will be paused.
#         """
#         if self.is_paused:
#             self.unpause()
#         else:
#             self.pause()
# 
#     def __is_closed(self):
#         """
#         Determine whether this entry has been closed or not
#         """
#         return self.end_time != None
#     is_closed = property(__is_closed)
# 
#     def clock_in(self, user, project):
#         """
#         Set this entry up for saving the first time, as an open entry.
#         """
#         if not self.is_closed:
#             self.user = user
#             self.project = project
#             self.site = CURRENT_SITE
#             self.start_time = datetime.now()
# 
#     def clock_out(self, activity, comments):
#         """
#         Save some vital pieces of information about this entry upon closing
#         """
#         if self.is_paused:
#             self.unpause()
# 
#         if not self.is_closed:
#             self.end_time = datetime.now()
#             self.activity = activity
#             self.comments = comments
# 
#     def __delete_key(self):
#         """
#         Make it a little more interesting for deleting logs
#         """
#         salt = '%i-%i-apple-%s-sauce' % (self.id, self.is_paused, self.is_closed)
#         try:
#             import hashlib
#         except ImportError:
#             import sha
#             key = sha.new(salt).hexdigest()
#         else:
#             key = hashlib.sha1(salt).hexdigest()
#         return key
#     delete_key = property(__delete_key)
# 
#     def __unicode__(self):
#         """
#         The string representation of an instance of this class
#         """
#         return '%s on %s' % (self.user, self.project)
# 
#     class Meta:
#         ordering = ['-start_time']
#         verbose_name_plural = 'entries'
#         permissions = (
#             ('can_clock_in', 'Can use Pendulum to clock in'),
#             ('can_pause', 'Can pause and unpause log entries'),
#             ('can_clock_out', 'Can use Pendulum to clock out'),
#         )
# 
# Path: pendulum/views.py
# def view_entries(request, delta=0):
# def clock_in(request):
# def clock_out(request, entry_id):
# def toggle_paused(request, entry_id):
# def update_entry(request, entry_id):
# def delete_entry(request, entry_id):
# def add_entry(request):


from django.conf.urls.defaults import *
from pendulum.models import Entry
from pendulum import views

urlpatterns = patterns('',
    url(r'^$', views.view_entries, name='pendulum-entries'),
    url(r'^period/(?P<delta>\d+)/$', views.view_entries, name='pendulum-previous-entries'),
    url(r'^clockin/$', views.clock_in, name='pendulum-clock-in'),
    url(r'^clockout/(?P<entry_id>\d+)/$', views.clock_out, name='pendulum-clock-out'),

# Path: pendulum/models.py
# class Entry(models.Model):
#     """
#     This class is where all of the time logs are taken care of
#     """
# 
#     user = models.ForeignKey(User, related_name='pendulum_entries')
#     project = models.ForeignKey(Project,
#                                 limit_choices_to={'is_active': True,
#                                                   'sites': CURRENT_SITE},
#                                 related_name='entries')
#     activity = models.ForeignKey(Activity, blank=True, null=True, related_name='entries')
#     start_time = models.DateTimeField()
#     end_time = models.DateTimeField(blank=True, null=True)
#     seconds_paused = models.PositiveIntegerField(default=0)
#     pause_time = models.DateTimeField(blank=True, null=True)
#     comments = models.TextField(blank=True, null=True)
#     date_updated = models.DateTimeField(auto_now=True)
#     site = models.ForeignKey(Site, related_name='pendulum_entries')
# 
#     objects = EntryManager()
# 
#     def get_seconds(self):
#         """
#         Determines the difference between the starting and ending time.  The
#         result is returned as an integer of seconds.
#         """
#         if self.start_time and self.end_time:
#             # only calculate when the start and end are defined
#             delta = self.end_time - self.start_time
#             seconds = delta.seconds - self.seconds_paused
#         else:
#             seconds = 0
#             delta = timedelta(days=0)
# 
#         return seconds + (delta.days * 86400)
# 
#     def __total_hours(self):
#         """
#         Determined the total number of hours worked in this entry
#         """
#         return self.get_seconds() / 3600.0
#     total_hours = property(__total_hours)
# 
#     def __total_time(self):
#         """
#         Determines the amount of time spent and return it as a string formatted
#         as HH:MM:SS
#         """
#         return utils.get_total_time(self.get_seconds())
#     total_time = property(__total_time)
# 
#     def __paused_time(self):
#         """
#         Returns the total time paused for this entry in HH:MM:SS format
#         """
#         return utils.get_total_time(self.seconds_paused)
#     paused_time = property(__paused_time)
# 
#     def __hours(self):
#         """
#         Print the hours in a nice, rounded format
#         """
#         return "%.02f" % self.total_hours
#     hours = property(__hours)
# 
#     def __is_paused(self):
#         """
#         Determine whether or not this entry is paused
#         """
#         return self.pause_time != None
#     is_paused = property(__is_paused)
# 
#     def pause(self):
#         """
#         If this entry is not paused, pause it.
#         """
#         if not self.is_paused:
#             self.pause_time = datetime.now()
# 
#     def unpause(self):
#         """
#         If this entry is paused, unpause it
#         """
#         if self.is_paused:
#             delta = datetime.now() - self.pause_time
#             self.seconds_paused += delta.seconds
#             self.pause_time = None
# 
#     def toggle_paused(self):
#         """
#         Toggle the paused state of this entry.  If the entry is already paused,
#         it will be unpaused; if it is not paused, it will be paused.
#         """
#         if self.is_paused:
#             self.unpause()
#         else:
#             self.pause()
# 
#     def __is_closed(self):
#         """
#         Determine whether this entry has been closed or not
#         """
#         return self.end_time != None
#     is_closed = property(__is_closed)
# 
#     def clock_in(self, user, project):
#         """
#         Set this entry up for saving the first time, as an open entry.
#         """
#         if not self.is_closed:
#             self.user = user
#             self.project = project
#             self.site = CURRENT_SITE
#             self.start_time = datetime.now()
# 
#     def clock_out(self, activity, comments):
#         """
#         Save some vital pieces of information about this entry upon closing
#         """
#         if self.is_paused:
#             self.unpause()
# 
#         if not self.is_closed:
#             self.end_time = datetime.now()
#             self.activity = activity
#             self.comments = comments
# 
#     def __delete_key(self):
#         """
#         Make it a little more interesting for deleting logs
#         """
#         salt = '%i-%i-apple-%s-sauce' % (self.id, self.is_paused, self.is_closed)
#         try:
#             import hashlib
#         except ImportError:
#             import sha
#             key = sha.new(salt).hexdigest()
#         else:
#             key = hashlib.sha1(salt).hexdigest()
#         return key
#     delete_key = property(__delete_key)
# 
#     def __unicode__(self):
#         """
#         The string representation of an instance of this class
#         """
#         return '%s on %s' % (self.user, self.project)
# 
#     class Meta:
#         ordering = ['-start_time']
#         verbose_name_plural = 'entries'
#         permissions = (
#             ('can_clock_in', 'Can use Pendulum to clock in'),
#             ('can_pause', 'Can pause and unpause log entries'),
#             ('can_clock_out', 'Can use Pendulum to clock out'),
#         )
# 
# Path: pendulum/views.py
# def view_entries(request, delta=0):
# def clock_in(request):
# def clock_out(request, entry_id):
# def toggle_paused(request, entry_id):
# def update_entry(request, entry_id):
# def delete_entry(request, entry_id):
# def add_entry(request):


# Path: pendulum/urls.py
from django.conf.urls.defaults import *
from pendulum.models import Entry
from pendulum import views


urlpatterns = patterns('',
    url(r'^$', views.view_entries, name='pendulum-entries'),
    url(r'^period/(?P<delta>\d+)/$', views.view_entries, name='pendulum-previous-entries'),
    url(r'^clockin/$', views.clock_in, name='pendulum-clock-in'),
    url(r'^clockout/(?P<entry_id>\d+)/$', views.clock_out, name='pendulum-clock-out'),

    url(r'^toggle/(?P<entry_id>\d+)/$', views.toggle_paused, name='pendulum-toggle-paused'),