diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-09-04 19:27:54 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-09-04 19:27:54 (GMT) |
commit | 6b98488a23caa7b4ca9d7484dedf0f2b6673292a (patch) | |
tree | ad7227e6d67a3ea14fb99ac1d5b7926e98411c5f | |
parent | c6f62a5a3987b6e5f466f0603afdefa11a7e6a7f (diff) |
Refactor: Timestamp for upload view
-rw-r--r-- | webapp/polls/views.py | 11 | ||||
-rw-r--r-- | webapp/webapp/features/upload_poll_result.py | 1 | ||||
-rw-r--r-- | webapp/webapp/settings.py | 2 | ||||
-rw-r--r-- | webapp/webapp/test_settings.py | 9 |
4 files changed, 22 insertions, 1 deletions
diff --git a/webapp/polls/views.py b/webapp/polls/views.py index b8efe96..d3b0fb4 100644 --- a/webapp/polls/views.py +++ b/webapp/polls/views.py @@ -3,6 +3,7 @@ import os import json import StringIO import warnings +from importlib import import_module from datetime import datetime @@ -29,6 +30,13 @@ from polls.forms import PollForm from pollster.models import Pollster +module_path = settings.CLOCK_CLASS.split('.')[:-1] +module_path = ".".join(module_path) +module = import_module(module_path) +class_name = settings.CLOCK_CLASS.split('.')[-1:][0] +Clock = getattr(module, class_name) + + __all__ = [ 'StructureFormView', 'PollFormView', @@ -412,13 +420,14 @@ class UnploadPollResultFormView(TemplateView): else: # End validations + date_time_string = Clock().get_time_string() uploaded_files = [ (f.name, f.temporary_file_path()) for f in files ] for name, path in uploaded_files: result_file = PollResultFile(path) result_file.name = name - result_file.set_upload_timestamp("31/12/1999 23:59hs") + result_file.set_upload_timestamp(date_time_string) result_file.save() processed_files = [file.name for file in files] diff --git a/webapp/webapp/features/upload_poll_result.py b/webapp/webapp/features/upload_poll_result.py index 51177ff..b4a6283 100644 --- a/webapp/webapp/features/upload_poll_result.py +++ b/webapp/webapp/features/upload_poll_result.py @@ -48,4 +48,5 @@ def file_name_has_the_time_string_time_string(step, file_name, time_string): result_files = poll.get_result_files() result_file = filter( lambda f: file_name == f.get_file_name(), result_files)[0] + # Using (mock) Clock class from django settings assert_equals(time_string, result_file.get_upload_timestamp()) diff --git a/webapp/webapp/settings.py b/webapp/webapp/settings.py index 2df2228..e1fd37b 100644 --- a/webapp/webapp/settings.py +++ b/webapp/webapp/settings.py @@ -225,6 +225,8 @@ IMAGES_MEDIA_URL = MEDIA_URL + 'images' THUMBNAIL_DEBUG = True +CLOCK_CLASS = None + try: from env_settings import * except ImportError: diff --git a/webapp/webapp/test_settings.py b/webapp/webapp/test_settings.py index 2f02cf5..f4aa21f 100644 --- a/webapp/webapp/test_settings.py +++ b/webapp/webapp/test_settings.py @@ -29,3 +29,12 @@ DATABASES['default']['TEST_NAME'] = '/tmp/testserver.db' RESULT_BCK_ROOT = '/tmp' + + +class MockClock(object): + + def get_time_string(self): + return "31/12/1999 23:59hs" + + +CLOCK_CLASS = "webapp.test_settings.MockClock" |