def test_utcnow(): """ tznow should return a datetime object in UTC """ now = utcnow() assert is_near_now(now) assert now.tzinfo.zone == pytz.utc.zone
def staff_upload_annotated(self, request, suffix=''): # pylint: disable=unused-argument """ Save annotated assignment from staff. """ require(self.is_course_staff()) upload = request.params['annotated'] sha1 = get_sha1(upload.file) if self.file_size_over_limit(upload.file): raise JsonHandlerError( 413, 'Unable to upload file. Max size limit is {size}'.format( size=self.student_upload_max_size())) module = self.get_student_module(request.params['module_id']) state = json.loads(module.state) state['annotated_sha1'] = sha1 state['annotated_filename'] = filename = upload.file.name state['annotated_mimetype'] = mimetypes.guess_type(upload.file.name)[0] state['annotated_timestamp'] = utcnow().strftime( DateTime.DATETIME_FORMAT) path = self.file_storage_path(sha1, filename) if not default_storage.exists(path): default_storage.save(path, File(upload.file)) module.state = json.dumps(state) module.save() log.info("staff_upload_annotated for course:%s module:%s student:%s ", module.course_id, module.module_state_key, module.student.username) return Response(json_body=self.staff_grading_data())
def staff_upload_annotated(self, request, suffix=''): # pylint: disable=unused-argument """ Save annotated assignment from staff. """ require(self.is_course_staff()) upload = request.params['annotated'] sha1 = get_sha1(upload.file) if self.file_size_over_limit(upload.file): raise JsonHandlerError( 413, 'Unable to upload file. Max size limit is {size}'.format( size=self.student_upload_max_size() ) ) module = self.get_student_module(request.params['module_id']) state = json.loads(module.state) state['annotated_sha1'] = sha1 state['annotated_filename'] = filename = upload.file.name state['annotated_mimetype'] = mimetypes.guess_type(upload.file.name)[0] state['annotated_timestamp'] = utcnow().strftime( DateTime.DATETIME_FORMAT ) path = self.file_storage_path(sha1, filename) if not default_storage.exists(path): default_storage.save(path, File(upload.file)) module.state = json.dumps(state) module.save() log.info( "staff_upload_annotated for course:%s module:%s student:%s ", module.course_id, module.module_state_key, module.student.username ) return Response(json_body=self.staff_grading_data())
def update_staff_debug_context(self, context): # pylint: disable=no-member """ Add context info for the Staff Debug interface. """ published = self.start context['is_released'] = published and published < utcnow() context['location'] = self.location context['category'] = type(self).__name__ context['fields'] = [(name, field.read_from(self)) for name, field in self.fields.items()]
def update_staff_debug_context(self, context): # pylint: disable=no-member """ Add context info for the Staff Debug interface. """ published = self.start context['is_released'] = published and published < utcnow() context['location'] = self.location context['category'] = type(self).__name__ context['fields'] = [ (name, field.read_from(self)) for name, field in self.fields.items()]
def past_due(self): """ Return whether due date has passed. """ due = get_extended_due_date(self) try: graceperiod = self.graceperiod except AttributeError: # graceperiod and due are defined in InheritanceMixin # It's used automatically in edX but the unit tests will need to mock it out graceperiod = None if graceperiod is not None and due: close_date = due + graceperiod else: close_date = due if close_date is not None: return utcnow() > close_date return False