Commit 168cb306 by Don Mitchell

Move tz_aware into connection config rather than settings.

Make django use_tz
parent 909fe134
...@@ -23,8 +23,7 @@ MODULESTORE_OPTIONS = { ...@@ -23,8 +23,7 @@ MODULESTORE_OPTIONS = {
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'acceptance_modulestore', 'collection': 'acceptance_modulestore',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
MODULESTORE = { MODULESTORE = {
......
...@@ -22,8 +22,7 @@ modulestore_options = { ...@@ -22,8 +22,7 @@ modulestore_options = {
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
'fs_root': GITHUB_REPO_ROOT, 'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
MODULESTORE = { MODULESTORE = {
......
...@@ -48,8 +48,7 @@ MODULESTORE_OPTIONS = { ...@@ -48,8 +48,7 @@ MODULESTORE_OPTIONS = {
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'test_modulestore', 'collection': 'test_modulestore',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
MODULESTORE = { MODULESTORE = {
......
...@@ -14,6 +14,7 @@ import sys ...@@ -14,6 +14,7 @@ import sys
import datetime import datetime
import json import json
from pytz import UTC
middleware.MakoMiddleware() middleware.MakoMiddleware()
...@@ -32,7 +33,7 @@ def group_from_value(groups, v): ...@@ -32,7 +33,7 @@ def group_from_value(groups, v):
class Command(BaseCommand): class Command(BaseCommand):
help = \ help = \
''' Assign users to test groups. Takes a list ''' Assign users to test groups. Takes a list
of groups: of groups:
a:0.3,b:0.4,c:0.3 file.txt "Testing something" a:0.3,b:0.4,c:0.3 file.txt "Testing something"
...@@ -75,7 +76,7 @@ Will log what happened to file.txt. ...@@ -75,7 +76,7 @@ Will log what happened to file.txt.
utg = UserTestGroup() utg = UserTestGroup()
utg.name = group utg.name = group
utg.description = json.dumps({"description": args[2]}, utg.description = json.dumps({"description": args[2]},
{"time": datetime.datetime.utcnow().isoformat()}) {"time": datetime.datetime.now(UTC).isoformat()})
group_objects[group] = utg group_objects[group] = utg
group_objects[group].save() group_objects[group].save()
......
...@@ -8,6 +8,7 @@ from django.conf import settings ...@@ -8,6 +8,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from student.models import TestCenterUser from student.models import TestCenterUser
from pytz import UTC
class Command(BaseCommand): class Command(BaseCommand):
...@@ -58,7 +59,7 @@ class Command(BaseCommand): ...@@ -58,7 +59,7 @@ class Command(BaseCommand):
def handle(self, **options): def handle(self, **options):
# update time should use UTC in order to be comparable to the user_updated_at # update time should use UTC in order to be comparable to the user_updated_at
# field # field
uploaded_at = datetime.utcnow() uploaded_at = datetime.now(UTC)
# if specified destination is an existing directory, then # if specified destination is an existing directory, then
# create a filename for it automatically. If it doesn't exist, # create a filename for it automatically. If it doesn't exist,
...@@ -100,7 +101,7 @@ class Command(BaseCommand): ...@@ -100,7 +101,7 @@ class Command(BaseCommand):
extrasaction='ignore') extrasaction='ignore')
writer.writeheader() writer.writeheader()
for tcu in TestCenterUser.objects.order_by('id'): for tcu in TestCenterUser.objects.order_by('id'):
if tcu.needs_uploading: # or dump_all if tcu.needs_uploading: # or dump_all
record = dict((csv_field, ensure_encoding(getattr(tcu, model_field))) record = dict((csv_field, ensure_encoding(getattr(tcu, model_field)))
for csv_field, model_field for csv_field, model_field
in Command.CSV_TO_MODEL_FIELDS.items()) in Command.CSV_TO_MODEL_FIELDS.items())
......
...@@ -8,6 +8,7 @@ from django.conf import settings ...@@ -8,6 +8,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from student.models import TestCenterRegistration, ACCOMMODATION_REJECTED_CODE from student.models import TestCenterRegistration, ACCOMMODATION_REJECTED_CODE
from pytz import UTC
class Command(BaseCommand): class Command(BaseCommand):
...@@ -51,7 +52,7 @@ class Command(BaseCommand): ...@@ -51,7 +52,7 @@ class Command(BaseCommand):
def handle(self, **options): def handle(self, **options):
# update time should use UTC in order to be comparable to the user_updated_at # update time should use UTC in order to be comparable to the user_updated_at
# field # field
uploaded_at = datetime.utcnow() uploaded_at = datetime.now(UTC)
# if specified destination is an existing directory, then # if specified destination is an existing directory, then
# create a filename for it automatically. If it doesn't exist, # create a filename for it automatically. If it doesn't exist,
......
...@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.conf import settings from django.conf import settings
from student.models import TestCenterUser, TestCenterRegistration from student.models import TestCenterUser, TestCenterRegistration
from pytz import UTC
class Command(BaseCommand): class Command(BaseCommand):
...@@ -68,7 +69,7 @@ class Command(BaseCommand): ...@@ -68,7 +69,7 @@ class Command(BaseCommand):
Command.datadog_error("Found authorization record for user {}".format(registration.testcenter_user.user.username), eacfile.name) Command.datadog_error("Found authorization record for user {}".format(registration.testcenter_user.user.username), eacfile.name)
# now update the record: # now update the record:
registration.upload_status = row['Status'] registration.upload_status = row['Status']
registration.upload_error_message = row['Message'] registration.upload_error_message = row['Message']
try: try:
registration.processed_at = strftime('%Y-%m-%d %H:%M:%S', strptime(row['Date'], '%Y/%m/%d %H:%M:%S')) registration.processed_at = strftime('%Y-%m-%d %H:%M:%S', strptime(row['Date'], '%Y/%m/%d %H:%M:%S'))
except ValueError as ve: except ValueError as ve:
...@@ -80,7 +81,7 @@ class Command(BaseCommand): ...@@ -80,7 +81,7 @@ class Command(BaseCommand):
except ValueError as ve: except ValueError as ve:
Command.datadog_error("Bad AuthorizationID value found for {}: message {}".format(client_authorization_id, ve), eacfile.name) Command.datadog_error("Bad AuthorizationID value found for {}: message {}".format(client_authorization_id, ve), eacfile.name)
registration.confirmed_at = datetime.utcnow() registration.confirmed_at = datetime.now(UTC)
registration.save() registration.save()
except TestCenterRegistration.DoesNotExist: except TestCenterRegistration.DoesNotExist:
Command.datadog_error("Failed to find record for client_auth_id {}".format(client_authorization_id), eacfile.name) Command.datadog_error("Failed to find record for client_auth_id {}".format(client_authorization_id), eacfile.name)
......
...@@ -26,6 +26,7 @@ from django.dispatch import receiver ...@@ -26,6 +26,7 @@ from django.dispatch import receiver
from django.forms import ModelForm, forms from django.forms import ModelForm, forms
import comment_client as cc import comment_client as cc
from pytz import UTC
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -53,7 +54,7 @@ class UserProfile(models.Model): ...@@ -53,7 +54,7 @@ class UserProfile(models.Model):
class Meta: class Meta:
db_table = "auth_userprofile" db_table = "auth_userprofile"
# # CRITICAL TODO/SECURITY # CRITICAL TODO/SECURITY
# Sanitize all fields. # Sanitize all fields.
# This is not visible to other users, but could introduce holes later # This is not visible to other users, but could introduce holes later
user = models.OneToOneField(User, unique=True, db_index=True, related_name='profile') user = models.OneToOneField(User, unique=True, db_index=True, related_name='profile')
...@@ -253,7 +254,7 @@ class TestCenterUserForm(ModelForm): ...@@ -253,7 +254,7 @@ class TestCenterUserForm(ModelForm):
def update_and_save(self): def update_and_save(self):
new_user = self.save(commit=False) new_user = self.save(commit=False)
# create additional values here: # create additional values here:
new_user.user_updated_at = datetime.utcnow() new_user.user_updated_at = datetime.now(UTC)
new_user.upload_status = '' new_user.upload_status = ''
new_user.save() new_user.save()
log.info("Updated demographic information for user's test center exam registration: username \"{}\" ".format(new_user.user.username)) log.info("Updated demographic information for user's test center exam registration: username \"{}\" ".format(new_user.user.username))
...@@ -555,7 +556,7 @@ class TestCenterRegistrationForm(ModelForm): ...@@ -555,7 +556,7 @@ class TestCenterRegistrationForm(ModelForm):
def update_and_save(self): def update_and_save(self):
registration = self.save(commit=False) registration = self.save(commit=False)
# create additional values here: # create additional values here:
registration.user_updated_at = datetime.utcnow() registration.user_updated_at = datetime.now(UTC)
registration.upload_status = '' registration.upload_status = ''
registration.save() registration.save()
log.info("Updated registration information for user's test center exam registration: username \"{}\" course \"{}\", examcode \"{}\"".format(registration.testcenter_user.user.username, registration.course_id, registration.exam_series_code)) log.info("Updated registration information for user's test center exam registration: username \"{}\" course \"{}\", examcode \"{}\"".format(registration.testcenter_user.user.username, registration.course_id, registration.exam_series_code))
...@@ -597,7 +598,7 @@ def unique_id_for_user(user): ...@@ -597,7 +598,7 @@ def unique_id_for_user(user):
return h.hexdigest() return h.hexdigest()
# # TODO: Should be renamed to generic UserGroup, and possibly # TODO: Should be renamed to generic UserGroup, and possibly
# Given an optional field for type of group # Given an optional field for type of group
class UserTestGroup(models.Model): class UserTestGroup(models.Model):
users = models.ManyToManyField(User, db_index=True) users = models.ManyToManyField(User, db_index=True)
......
...@@ -49,6 +49,7 @@ from courseware.views import get_module_for_descriptor, jump_to ...@@ -49,6 +49,7 @@ from courseware.views import get_module_for_descriptor, jump_to
from courseware.model_data import ModelDataCache from courseware.model_data import ModelDataCache
from statsd import statsd from statsd import statsd
from pytz import UTC
log = logging.getLogger("mitx.student") log = logging.getLogger("mitx.student")
Article = namedtuple('Article', 'title url author image deck publication publish_date') Article = namedtuple('Article', 'title url author image deck publication publish_date')
...@@ -77,7 +78,7 @@ def index(request, extra_context={}, user=None): ...@@ -77,7 +78,7 @@ def index(request, extra_context={}, user=None):
''' '''
# The course selection work is done in courseware.courses. # The course selection work is done in courseware.courses.
domain = settings.MITX_FEATURES.get('FORCE_UNIVERSITY_DOMAIN') # normally False domain = settings.MITX_FEATURES.get('FORCE_UNIVERSITY_DOMAIN') # normally False
# do explicit check, because domain=None is valid # do explicit check, because domain=None is valid
if domain == False: if domain == False:
domain = request.META.get('HTTP_HOST') domain = request.META.get('HTTP_HOST')
...@@ -630,7 +631,7 @@ def create_account(request, post_override=None): ...@@ -630,7 +631,7 @@ def create_account(request, post_override=None):
# Ok, looks like everything is legit. Create the account. # Ok, looks like everything is legit. Create the account.
ret = _do_create_account(post_vars) ret = _do_create_account(post_vars)
if isinstance(ret, HttpResponse): # if there was an error then return that if isinstance(ret, HttpResponse): # if there was an error then return that
return ret return ret
(user, profile, registration) = ret (user, profile, registration) = ret
...@@ -668,7 +669,7 @@ def create_account(request, post_override=None): ...@@ -668,7 +669,7 @@ def create_account(request, post_override=None):
if DoExternalAuth: if DoExternalAuth:
eamap.user = login_user eamap.user = login_user
eamap.dtsignup = datetime.datetime.now() eamap.dtsignup = datetime.datetime.now(UTC)
eamap.save() eamap.save()
log.debug('Updated ExternalAuthMap for %s to be %s' % (post_vars['username'], eamap)) log.debug('Updated ExternalAuthMap for %s to be %s' % (post_vars['username'], eamap))
......
...@@ -14,6 +14,7 @@ from mitxmako.shortcuts import render_to_response ...@@ -14,6 +14,7 @@ from mitxmako.shortcuts import render_to_response
from django_future.csrf import ensure_csrf_cookie from django_future.csrf import ensure_csrf_cookie
from track.models import TrackingLog from track.models import TrackingLog
from pytz import UTC
log = logging.getLogger("tracking") log = logging.getLogger("tracking")
...@@ -59,7 +60,7 @@ def user_track(request): ...@@ -59,7 +60,7 @@ def user_track(request):
"event": request.GET['event'], "event": request.GET['event'],
"agent": agent, "agent": agent,
"page": request.GET['page'], "page": request.GET['page'],
"time": datetime.datetime.utcnow().isoformat(), "time": datetime.datetime.now(UTC).isoformat(),
"host": request.META['SERVER_NAME'], "host": request.META['SERVER_NAME'],
} }
log_event(event) log_event(event)
...@@ -85,11 +86,11 @@ def server_track(request, event_type, event, page=None): ...@@ -85,11 +86,11 @@ def server_track(request, event_type, event, page=None):
"event": event, "event": event,
"agent": agent, "agent": agent,
"page": page, "page": page,
"time": datetime.datetime.utcnow().isoformat(), "time": datetime.datetime.now(UTC).isoformat(),
"host": request.META['SERVER_NAME'], "host": request.META['SERVER_NAME'],
} }
if event_type.startswith("/event_logs") and request.user.is_staff: # don't log if event_type.startswith("/event_logs") and request.user.is_staff: # don't log
return return
log_event(event) log_event(event)
......
...@@ -144,11 +144,11 @@ class InputTypeBase(object): ...@@ -144,11 +144,11 @@ class InputTypeBase(object):
self.tag = xml.tag self.tag = xml.tag
self.system = system self.system = system
# # NOTE: ID should only come from one place. If it comes from multiple, # NOTE: ID should only come from one place. If it comes from multiple,
# # we use state first, XML second (in case the xml changed, but we have # we use state first, XML second (in case the xml changed, but we have
# # existing state with an old id). Since we don't make this guarantee, # existing state with an old id). Since we don't make this guarantee,
# # we can swap this around in the future if there's a more logical # we can swap this around in the future if there's a more logical
# # order. # order.
self.input_id = state.get('id', xml.get('id')) self.input_id = state.get('id', xml.get('id'))
if self.input_id is None: if self.input_id is None:
......
...@@ -747,7 +747,7 @@ class CapaModule(CapaFields, XModule): ...@@ -747,7 +747,7 @@ class CapaModule(CapaFields, XModule):
# Problem queued. Students must wait a specified waittime before they are allowed to submit # Problem queued. Students must wait a specified waittime before they are allowed to submit
if self.lcp.is_queued(): if self.lcp.is_queued():
current_time = datetime.datetime.now() current_time = datetime.datetime.now(UTC)
prev_submit_time = self.lcp.get_recentmost_queuetime() prev_submit_time = self.lcp.get_recentmost_queuetime()
waittime_between_requests = self.system.xqueue['waittime'] waittime_between_requests = self.system.xqueue['waittime']
if (current_time - prev_submit_time).total_seconds() < waittime_between_requests: if (current_time - prev_submit_time).total_seconds() < waittime_between_requests:
......
...@@ -93,7 +93,7 @@ class Textbook(object): ...@@ -93,7 +93,7 @@ class Textbook(object):
# see if we already fetched this # see if we already fetched this
if toc_url in _cached_toc: if toc_url in _cached_toc:
(table_of_contents, timestamp) = _cached_toc[toc_url] (table_of_contents, timestamp) = _cached_toc[toc_url]
age = datetime.now() - timestamp age = datetime.now(UTC) - timestamp
# expire every 10 minutes # expire every 10 minutes
if age.seconds < 600: if age.seconds < 600:
return table_of_contents return table_of_contents
......
...@@ -231,6 +231,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -231,6 +231,7 @@ class MongoModuleStore(ModuleStoreBase):
self.collection = pymongo.connection.Connection( self.collection = pymongo.connection.Connection(
host=host, host=host,
port=port, port=port,
tz_aware=True,
**kwargs **kwargs
)[db][collection] )[db][collection]
......
...@@ -43,7 +43,7 @@ class TestMongoModuleStore(object): ...@@ -43,7 +43,7 @@ class TestMongoModuleStore(object):
def initdb(): def initdb():
# connect to the db # connect to the db
store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE,
default_class=DEFAULT_CLASS, tz_aware=True) default_class=DEFAULT_CLASS)
# Explicitly list the courses to load (don't want the big one) # Explicitly list the courses to load (don't want the big one)
courses = ['toy', 'simple'] courses = ['toy', 'simple']
import_from_xml(store, DATA_DIR, courses) import_from_xml(store, DATA_DIR, courses)
......
...@@ -18,6 +18,7 @@ from xmodule.modulestore import Location ...@@ -18,6 +18,7 @@ from xmodule.modulestore import Location
from django.http import QueryDict from django.http import QueryDict
from . import test_system from . import test_system
from pytz import UTC
class CapaFactory(object): class CapaFactory(object):
...@@ -126,7 +127,7 @@ class CapaFactory(object): ...@@ -126,7 +127,7 @@ class CapaFactory(object):
class CapaModuleTest(unittest.TestCase): class CapaModuleTest(unittest.TestCase):
def setUp(self): def setUp(self):
now = datetime.datetime.now() now = datetime.datetime.now(UTC)
day_delta = datetime.timedelta(days=1) day_delta = datetime.timedelta(days=1)
self.yesterday_str = str(now - day_delta) self.yesterday_str = str(now - day_delta)
self.today_str = str(now) self.today_str = str(now)
...@@ -475,12 +476,12 @@ class CapaModuleTest(unittest.TestCase): ...@@ -475,12 +476,12 @@ class CapaModuleTest(unittest.TestCase):
# Simulate that the problem is queued # Simulate that the problem is queued
with patch('capa.capa_problem.LoncapaProblem.is_queued') \ with patch('capa.capa_problem.LoncapaProblem.is_queued') \
as mock_is_queued,\ as mock_is_queued, \
patch('capa.capa_problem.LoncapaProblem.get_recentmost_queuetime') \ patch('capa.capa_problem.LoncapaProblem.get_recentmost_queuetime') \
as mock_get_queuetime: as mock_get_queuetime:
mock_is_queued.return_value = True mock_is_queued.return_value = True
mock_get_queuetime.return_value = datetime.datetime.now() mock_get_queuetime.return_value = datetime.datetime.now(UTC)
get_request_dict = {CapaFactory.input_key(): '3.14'} get_request_dict = {CapaFactory.input_key(): '3.14'}
result = module.check_problem(get_request_dict) result = module.check_problem(get_request_dict)
......
...@@ -12,6 +12,7 @@ from courseware.models import StudentModule, XModuleContentField, XModuleSetting ...@@ -12,6 +12,7 @@ from courseware.models import StudentModule, XModuleContentField, XModuleSetting
from courseware.models import XModuleStudentInfoField, XModuleStudentPrefsField from courseware.models import XModuleStudentInfoField, XModuleStudentPrefsField
from xmodule.modulestore import Location from xmodule.modulestore import Location
from pytz import UTC
location = partial(Location, 'i4x', 'edX', 'test_course', 'problem') location = partial(Location, 'i4x', 'edX', 'test_course', 'problem')
...@@ -28,8 +29,8 @@ class RegistrationFactory(StudentRegistrationFactory): ...@@ -28,8 +29,8 @@ class RegistrationFactory(StudentRegistrationFactory):
class UserFactory(StudentUserFactory): class UserFactory(StudentUserFactory):
email = 'robot@edx.org' email = 'robot@edx.org'
last_name = 'Tester' last_name = 'Tester'
last_login = datetime.now() last_login = datetime.now(UTC)
date_joined = datetime.now() date_joined = datetime.now(UTC)
class GroupFactory(StudentGroupFactory): class GroupFactory(StudentGroupFactory):
......
...@@ -65,8 +65,7 @@ def mongo_store_config(data_dir): ...@@ -65,8 +65,7 @@ def mongo_store_config(data_dir):
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex, 'collection': 'modulestore_%s' % uuid4().hex,
'fs_root': data_dir, 'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
} }
} }
......
...@@ -219,7 +219,7 @@ def initialize_discussion_info(course): ...@@ -219,7 +219,7 @@ def initialize_discussion_info(course):
_DISCUSSIONINFO[course.id]['id_map'] = discussion_id_map _DISCUSSIONINFO[course.id]['id_map'] = discussion_id_map
_DISCUSSIONINFO[course.id]['category_map'] = category_map _DISCUSSIONINFO[course.id]['category_map'] = category_map
_DISCUSSIONINFO[course.id]['timestamp'] = datetime.now() _DISCUSSIONINFO[course.id]['timestamp'] = datetime.now(UTC())
class JsonResponse(HttpResponse): class JsonResponse(HttpResponse):
......
...@@ -13,6 +13,7 @@ from foldit.models import PuzzleComplete, Score ...@@ -13,6 +13,7 @@ from foldit.models import PuzzleComplete, Score
from student.models import UserProfile, unique_id_for_user from student.models import UserProfile, unique_id_for_user
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pytz import UTC
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -28,7 +29,7 @@ class FolditTestCase(TestCase): ...@@ -28,7 +29,7 @@ class FolditTestCase(TestCase):
self.user2 = User.objects.create_user('testuser2', 'test2@test.com', pwd) self.user2 = User.objects.create_user('testuser2', 'test2@test.com', pwd)
self.unique_user_id = unique_id_for_user(self.user) self.unique_user_id = unique_id_for_user(self.user)
self.unique_user_id2 = unique_id_for_user(self.user2) self.unique_user_id2 = unique_id_for_user(self.user2)
now = datetime.now() now = datetime.now(UTC)
self.tomorrow = now + timedelta(days=1) self.tomorrow = now + timedelta(days=1)
self.yesterday = now - timedelta(days=1) self.yesterday = now - timedelta(days=1)
...@@ -222,7 +223,7 @@ class FolditTestCase(TestCase): ...@@ -222,7 +223,7 @@ class FolditTestCase(TestCase):
verify = {"Verify": verify_code(self.user.email, puzzles_str), verify = {"Verify": verify_code(self.user.email, puzzles_str),
"VerifyMethod":"FoldItVerify"} "VerifyMethod":"FoldItVerify"}
data = {'SetPuzzlesCompleteVerify': json.dumps(verify), data = {'SetPuzzlesCompleteVerify': json.dumps(verify),
'SetPuzzlesComplete': puzzles_str} 'SetPuzzlesComplete': puzzles_str}
request = self.make_request(data) request = self.make_request(data)
......
...@@ -18,6 +18,7 @@ from django.core.management.base import BaseCommand ...@@ -18,6 +18,7 @@ from django.core.management.base import BaseCommand
from student.models import UserProfile, Registration from student.models import UserProfile, Registration
from external_auth.models import ExternalAuthMap from external_auth.models import ExternalAuthMap
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from pytz import UTC
class MyCompleter(object): # Custom completer class MyCompleter(object): # Custom completer
...@@ -124,7 +125,7 @@ class Command(BaseCommand): ...@@ -124,7 +125,7 @@ class Command(BaseCommand):
external_credentials=json.dumps(credentials), external_credentials=json.dumps(credentials),
) )
eamap.user = user eamap.user = user
eamap.dtsignup = datetime.datetime.now() eamap.dtsignup = datetime.datetime.now(UTC)
eamap.save() eamap.save()
print "User %s created successfully!" % user print "User %s created successfully!" % user
......
...@@ -15,6 +15,7 @@ from scipy.optimize import curve_fit ...@@ -15,6 +15,7 @@ from scipy.optimize import curve_fit
from django.conf import settings from django.conf import settings
from django.db.models import Sum, Max from django.db.models import Sum, Max
from psychometrics.models import * from psychometrics.models import *
from pytz import UTC
log = logging.getLogger("mitx.psychometrics") log = logging.getLogger("mitx.psychometrics")
...@@ -110,7 +111,7 @@ def make_histogram(ydata, bins=None): ...@@ -110,7 +111,7 @@ def make_histogram(ydata, bins=None):
nbins = len(bins) nbins = len(bins)
hist = dict(zip(bins, [0] * nbins)) hist = dict(zip(bins, [0] * nbins))
for y in ydata: for y in ydata:
for b in bins[::-1]: # in reverse order for b in bins[::-1]: # in reverse order
if y > b: if y > b:
hist[b] += 1 hist[b] += 1
break break
...@@ -149,7 +150,7 @@ def generate_plots_for_problem(problem): ...@@ -149,7 +150,7 @@ def generate_plots_for_problem(problem):
agdat = pmdset.aggregate(Sum('attempts'), Max('attempts')) agdat = pmdset.aggregate(Sum('attempts'), Max('attempts'))
max_attempts = agdat['attempts__max'] max_attempts = agdat['attempts__max']
total_attempts = agdat['attempts__sum'] # not used yet total_attempts = agdat['attempts__sum'] # not used yet
msg += "max attempts = %d" % max_attempts msg += "max attempts = %d" % max_attempts
...@@ -200,7 +201,7 @@ def generate_plots_for_problem(problem): ...@@ -200,7 +201,7 @@ def generate_plots_for_problem(problem):
dtsv = StatVar() dtsv = StatVar()
for pmd in pmdset: for pmd in pmdset:
try: try:
checktimes = eval(pmd.checktimes) # update log of attempt timestamps checktimes = eval(pmd.checktimes) # update log of attempt timestamps
except: except:
continue continue
if len(checktimes) < 2: if len(checktimes) < 2:
...@@ -208,7 +209,7 @@ def generate_plots_for_problem(problem): ...@@ -208,7 +209,7 @@ def generate_plots_for_problem(problem):
ct0 = checktimes[0] ct0 = checktimes[0]
for ct in checktimes[1:]: for ct in checktimes[1:]:
dt = (ct - ct0).total_seconds() / 60.0 dt = (ct - ct0).total_seconds() / 60.0
if dt < 20: # ignore if dt too long if dt < 20: # ignore if dt too long
dtset.append(dt) dtset.append(dt)
dtsv += dt dtsv += dt
ct0 = ct ct0 = ct
...@@ -244,7 +245,7 @@ def generate_plots_for_problem(problem): ...@@ -244,7 +245,7 @@ def generate_plots_for_problem(problem):
ylast = y + ylast ylast = y + ylast
yset['ydat'] = ydat yset['ydat'] = ydat
if len(ydat) > 3: # try to fit to logistic function if enough data points if len(ydat) > 3: # try to fit to logistic function if enough data points
try: try:
cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0]) cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0])
yset['fitparam'] = cfp yset['fitparam'] = cfp
...@@ -337,10 +338,10 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key): ...@@ -337,10 +338,10 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key):
log.exception("no attempts for %s (state=%s)" % (sm, sm.state)) log.exception("no attempts for %s (state=%s)" % (sm, sm.state))
try: try:
checktimes = eval(pmd.checktimes) # update log of attempt timestamps checktimes = eval(pmd.checktimes) # update log of attempt timestamps
except: except:
checktimes = [] checktimes = []
checktimes.append(datetime.datetime.now()) checktimes.append(datetime.datetime.now(UTC))
pmd.checktimes = checktimes pmd.checktimes = checktimes
try: try:
pmd.save() pmd.save()
......
...@@ -11,6 +11,7 @@ from markdown import markdown ...@@ -11,6 +11,7 @@ from markdown import markdown
from .wiki_settings import * from .wiki_settings import *
from util.cache import cache from util.cache import cache
from pytz import UTC
class ShouldHaveExactlyOneRootSlug(Exception): class ShouldHaveExactlyOneRootSlug(Exception):
...@@ -265,7 +266,7 @@ class Revision(models.Model): ...@@ -265,7 +266,7 @@ class Revision(models.Model):
return return
else: else:
import datetime import datetime
self.article.modified_on = datetime.datetime.now() self.article.modified_on = datetime.datetime.now(UTC)
self.article.save() self.article.save()
# Increment counter according to previous revision # Increment counter according to previous revision
......
...@@ -24,8 +24,7 @@ modulestore_options = { ...@@ -24,8 +24,7 @@ modulestore_options = {
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'acceptance_modulestore', 'collection': 'acceptance_modulestore',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
MODULESTORE = { MODULESTORE = {
......
...@@ -21,8 +21,7 @@ modulestore_options = { ...@@ -21,8 +21,7 @@ modulestore_options = {
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
'fs_root': DATA_DIR, 'fs_root': DATA_DIR,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
MODULESTORE = { MODULESTORE = {
......
...@@ -50,8 +50,8 @@ MITX_FEATURES = { ...@@ -50,8 +50,8 @@ MITX_FEATURES = {
'SAMPLE': False, 'SAMPLE': False,
'USE_DJANGO_PIPELINE': True, 'USE_DJANGO_PIPELINE': True,
'DISPLAY_HISTOGRAMS_TO_STAFF': True, 'DISPLAY_HISTOGRAMS_TO_STAFF': True,
'REROUTE_ACTIVATION_EMAIL': False, # nonempty string = address for all activation emails 'REROUTE_ACTIVATION_EMAIL': False, # nonempty string = address for all activation emails
'DEBUG_LEVEL': 0, # 0 = lowest level, least verbose, 255 = max level, most verbose 'DEBUG_LEVEL': 0, # 0 = lowest level, least verbose, 255 = max level, most verbose
## DO NOT SET TO True IN THIS FILE ## DO NOT SET TO True IN THIS FILE
## Doing so will cause all courses to be released on production ## Doing so will cause all courses to be released on production
...@@ -67,13 +67,13 @@ MITX_FEATURES = { ...@@ -67,13 +67,13 @@ MITX_FEATURES = {
# university to use for branding purposes # university to use for branding purposes
'SUBDOMAIN_BRANDING': False, 'SUBDOMAIN_BRANDING': False,
'FORCE_UNIVERSITY_DOMAIN': False, # set this to the university domain to use, as an override to HTTP_HOST 'FORCE_UNIVERSITY_DOMAIN': False, # set this to the university domain to use, as an override to HTTP_HOST
# set to None to do no university selection # set to None to do no university selection
'ENABLE_TEXTBOOK': True, 'ENABLE_TEXTBOOK': True,
'ENABLE_DISCUSSION_SERVICE': True, 'ENABLE_DISCUSSION_SERVICE': True,
'ENABLE_PSYCHOMETRICS': False, # real-time psychometrics (eg item response theory analysis in instructor dashboard) 'ENABLE_PSYCHOMETRICS': False, # real-time psychometrics (eg item response theory analysis in instructor dashboard)
'ENABLE_DJANGO_ADMIN_SITE': False, # set true to enable django's admin site, even on prod (e.g. for course ops) 'ENABLE_DJANGO_ADMIN_SITE': False, # set true to enable django's admin site, even on prod (e.g. for course ops)
'ENABLE_SQL_TRACKING_LOGS': False, 'ENABLE_SQL_TRACKING_LOGS': False,
...@@ -84,7 +84,7 @@ MITX_FEATURES = { ...@@ -84,7 +84,7 @@ MITX_FEATURES = {
'DISABLE_LOGIN_BUTTON': False, # used in systems where login is automatic, eg MIT SSL 'DISABLE_LOGIN_BUTTON': False, # used in systems where login is automatic, eg MIT SSL
'STUB_VIDEO_FOR_TESTING': False, # do not display video when running automated acceptance tests 'STUB_VIDEO_FOR_TESTING': False, # do not display video when running automated acceptance tests
# extrernal access methods # extrernal access methods
'ACCESS_REQUIRE_STAFF_FOR_COURSE': False, 'ACCESS_REQUIRE_STAFF_FOR_COURSE': False,
...@@ -132,7 +132,7 @@ DEFAULT_GROUPS = [] ...@@ -132,7 +132,7 @@ DEFAULT_GROUPS = []
GENERATE_PROFILE_SCORES = False GENERATE_PROFILE_SCORES = False
# Used with XQueue # Used with XQueue
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
############################# SET PATH INFORMATION ############################# ############################# SET PATH INFORMATION #############################
...@@ -192,8 +192,8 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ...@@ -192,8 +192,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static', 'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
#'django.core.context_processors.i18n', #'django.core.context_processors.i18n',
'django.contrib.auth.context_processors.auth', # this is required for admin 'django.contrib.auth.context_processors.auth', # this is required for admin
'django.core.context_processors.csrf', # necessary for csrf protection 'django.core.context_processors.csrf', # necessary for csrf protection
# Added for django-wiki # Added for django-wiki
'django.core.context_processors.media', 'django.core.context_processors.media',
...@@ -206,7 +206,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ...@@ -206,7 +206,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'mitxmako.shortcuts.marketing_link_context_processor', 'mitxmako.shortcuts.marketing_link_context_processor',
) )
STUDENT_FILEUPLOAD_MAX_SIZE = 4 * 1000 * 1000 # 4 MB STUDENT_FILEUPLOAD_MAX_SIZE = 4 * 1000 * 1000 # 4 MB
MAX_FILEUPLOADS_PER_INPUT = 20 MAX_FILEUPLOADS_PER_INPUT = 20
# FIXME: # FIXME:
...@@ -216,7 +216,7 @@ LIB_URL = '/static/js/' ...@@ -216,7 +216,7 @@ LIB_URL = '/static/js/'
# Dev machines shouldn't need the book # Dev machines shouldn't need the book
# BOOK_URL = '/static/book/' # BOOK_URL = '/static/book/'
BOOK_URL = 'https://mitxstatic.s3.amazonaws.com/book_images/' # For AWS deploys BOOK_URL = 'https://mitxstatic.s3.amazonaws.com/book_images/' # For AWS deploys
# RSS_URL = r'lms/templates/feed.rss' # RSS_URL = r'lms/templates/feed.rss'
# PRESS_URL = r'' # PRESS_URL = r''
RSS_TIMEOUT = 600 RSS_TIMEOUT = 600
...@@ -240,14 +240,14 @@ COURSE_TITLE = "Circuits and Electronics" ...@@ -240,14 +240,14 @@ COURSE_TITLE = "Circuits and Electronics"
### Dark code. Should be enabled in local settings for devel. ### Dark code. Should be enabled in local settings for devel.
ENABLE_MULTICOURSE = False # set to False to disable multicourse display (see lib.util.views.mitxhome) ENABLE_MULTICOURSE = False # set to False to disable multicourse display (see lib.util.views.mitxhome)
WIKI_ENABLED = False WIKI_ENABLED = False
### ###
COURSE_DEFAULT = '6.002x_Fall_2012' COURSE_DEFAULT = '6.002x_Fall_2012'
COURSE_SETTINGS = {'6.002x_Fall_2012': {'number': '6.002x', COURSE_SETTINGS = {'6.002x_Fall_2012': {'number': '6.002x',
'title': 'Circuits and Electronics', 'title': 'Circuits and Electronics',
'xmlpath': '6002x/', 'xmlpath': '6002x/',
'location': 'i4x://edx/6002xs12/course/6.002x_Fall_2012', 'location': 'i4x://edx/6002xs12/course/6.002x_Fall_2012',
...@@ -308,6 +308,7 @@ import monitoring.exceptions # noqa ...@@ -308,6 +308,7 @@ import monitoring.exceptions # noqa
# Change DEBUG/TEMPLATE_DEBUG in your environment settings files, not here # Change DEBUG/TEMPLATE_DEBUG in your environment settings files, not here
DEBUG = False DEBUG = False
TEMPLATE_DEBUG = False TEMPLATE_DEBUG = False
USE_TZ = True
# Site info # Site info
SITE_ID = 1 SITE_ID = 1
...@@ -342,8 +343,8 @@ STATICFILES_DIRS = [ ...@@ -342,8 +343,8 @@ STATICFILES_DIRS = [
FAVICON_PATH = 'images/favicon.ico' FAVICON_PATH = 'images/favicon.ico'
# Locale/Internationalization # Locale/Internationalization
TIME_ZONE = 'America/New_York' # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name TIME_ZONE = 'America/New_York' # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
LANGUAGE_CODE = 'en' # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en' # http://www.i18nguy.com/unicode/language-identifiers.html
USE_I18N = True USE_I18N = True
USE_L10N = True USE_L10N = True
...@@ -364,7 +365,7 @@ ALLOWED_GITRELOAD_IPS = ['207.97.227.253', '50.57.128.197', '108.171.174.178'] ...@@ -364,7 +365,7 @@ ALLOWED_GITRELOAD_IPS = ['207.97.227.253', '50.57.128.197', '108.171.174.178']
# setting is, I'm just bumping the expiration time to something absurd (100 # setting is, I'm just bumping the expiration time to something absurd (100
# years). This is only used if DEFAULT_FILE_STORAGE is overriden to use S3 # years). This is only used if DEFAULT_FILE_STORAGE is overriden to use S3
# in the global settings.py # in the global settings.py
AWS_QUERYSTRING_EXPIRE = 10 * 365 * 24 * 60 * 60 # 10 years AWS_QUERYSTRING_EXPIRE = 10 * 365 * 24 * 60 * 60 # 10 years
################################# SIMPLEWIKI ################################### ################################# SIMPLEWIKI ###################################
SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
...@@ -373,8 +374,8 @@ SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False ...@@ -373,8 +374,8 @@ SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
################################# WIKI ################################### ################################# WIKI ###################################
WIKI_ACCOUNT_HANDLING = False WIKI_ACCOUNT_HANDLING = False
WIKI_EDITOR = 'course_wiki.editors.CodeMirror' WIKI_EDITOR = 'course_wiki.editors.CodeMirror'
WIKI_SHOW_MAX_CHILDREN = 0 # We don't use the little menu that shows children of an article in the breadcrumb WIKI_SHOW_MAX_CHILDREN = 0 # We don't use the little menu that shows children of an article in the breadcrumb
WIKI_ANONYMOUS = False # Don't allow anonymous access until the styling is figured out WIKI_ANONYMOUS = False # Don't allow anonymous access until the styling is figured out
WIKI_CAN_CHANGE_PERMISSIONS = lambda article, user: user.is_staff or user.is_superuser WIKI_CAN_CHANGE_PERMISSIONS = lambda article, user: user.is_staff or user.is_superuser
WIKI_CAN_ASSIGN = lambda article, user: user.is_staff or user.is_superuser WIKI_CAN_ASSIGN = lambda article, user: user.is_staff or user.is_superuser
...@@ -592,7 +593,7 @@ if os.path.isdir(DATA_DIR): ...@@ -592,7 +593,7 @@ if os.path.isdir(DATA_DIR):
new_filename = os.path.splitext(filename)[0] + ".js" new_filename = os.path.splitext(filename)[0] + ".js"
if os.path.exists(js_dir / new_filename): if os.path.exists(js_dir / new_filename):
coffee_timestamp = os.stat(js_dir / filename).st_mtime coffee_timestamp = os.stat(js_dir / filename).st_mtime
js_timestamp = os.stat(js_dir / new_filename).st_mtime js_timestamp = os.stat(js_dir / new_filename).st_mtime
if coffee_timestamp <= js_timestamp: if coffee_timestamp <= js_timestamp:
continue continue
os.system("rm %s" % (js_dir / new_filename)) os.system("rm %s" % (js_dir / new_filename))
...@@ -696,9 +697,9 @@ INSTALLED_APPS = ( ...@@ -696,9 +697,9 @@ INSTALLED_APPS = (
'course_groups', 'course_groups',
#For the wiki #For the wiki
'wiki', # The new django-wiki from benjaoming 'wiki', # The new django-wiki from benjaoming
'django_notify', 'django_notify',
'course_wiki', # Our customizations 'course_wiki', # Our customizations
'mptt', 'mptt',
'sekizai', 'sekizai',
#'wiki.plugins.attachments', #'wiki.plugins.attachments',
...@@ -710,7 +711,7 @@ INSTALLED_APPS = ( ...@@ -710,7 +711,7 @@ INSTALLED_APPS = (
'foldit', 'foldit',
# For testing # For testing
'django.contrib.admin', # only used in DEBUG mode 'django.contrib.admin', # only used in DEBUG mode
'debug', 'debug',
# Discussion forums # Discussion forums
......
...@@ -19,8 +19,7 @@ MODULESTORE = { ...@@ -19,8 +19,7 @@ MODULESTORE = {
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
'fs_root': GITHUB_REPO_ROOT, 'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string'
'tz_aware': True
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment