Skip to content

Commit

Permalink
Merge pull request #32 from ambitioninc/develop
Browse files Browse the repository at this point in the history
Added an update method to localized recurrences
  • Loading branch information
wesleykendall committed Jul 9, 2015
2 parents a4ce666 + c05ed48 commit 42a896c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions localized_recurrence/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class LocalizedRecurrenceAdmin(ModelAdmin):
'id',
'interval',
'timezone',
'offset',
'previous_scheduled',
'next_scheduled',
]
exclude = ['offset']


site.register(LocalizedRecurrence, LocalizedRecurrenceAdmin)
7 changes: 7 additions & 0 deletions localized_recurrence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ class LocalizedRecurrence(models.Model):
def __str__(self):
return 'ID: {0}, Interval: {1}, Next Scheduled: {2}'.format(self.id, self.interval, self.next_scheduled)

def update(self, **updates):
"""Updates fields in the localized recurrence."""
for update in updates:
setattr(self, update, updates[update])

return self.save()

def update_schedule(self, time=None):
"""Update the schedule for this recurrence or an object it tracks.
Expand Down
1 change: 1 addition & 0 deletions localized_recurrence/tests/admin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_model_admin_load(self):
'id',
'interval',
'timezone',
'offset',
'previous_scheduled',
'next_scheduled'
]
Expand Down
22 changes: 22 additions & 0 deletions localized_recurrence/tests/models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@
from ..models import _replace_with_offset, _update_schedule


class LocalizedRecurrenceUpdateTest(TestCase):
"""
Tests calling 'update' on a localized recurrence.
"""
def test_update_creation(self):
lr = LocalizedRecurrence()
lr.update()
self.assertIsNotNone(lr.id)

def test_update_timezone(self):
lr = G(LocalizedRecurrence)
lr.update(timezone='US/Eastern')
lr = LocalizedRecurrence.objects.get(id=lr.id)
self.assertEqual(lr.timezone, pytz.timezone('US/Eastern'))

def test_update_offset(self):
lr = G(LocalizedRecurrence)
lr.update(offset=1)
lr = LocalizedRecurrence.objects.get(id=lr.id)
self.assertEqual(lr.offset, timedelta(seconds=1))


class LocalizedRecurrenceQuerySetTest(TestCase):
"""Simple test to ensure the custom query set is being used.
"""
Expand Down
2 changes: 1 addition & 1 deletion localized_recurrence/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.1'
__version__ = '1.2.0'

0 comments on commit 42a896c

Please sign in to comment.