def _make_new_course(self, uid, title): """Make a new course entry.""" errors = [] admin_email = users.get_current_user().email() entry = sites.add_new_course_entry(uid, title, admin_email, errors) if errors: raise Exception(errors) app_context = sites.get_all_courses(entry)[0] new_course = models.courses.Course(None, app_context=app_context) new_course.init_new_course_settings(title, admin_email) return app_context
def _make_new_course(self, uid, title): """Make a new course entry.""" errors = [] admin_email = users.get_current_user().email() entry = sites.add_new_course_entry( uid, title, admin_email, errors) if errors: raise Exception(errors) app_context = sites.get_all_courses(entry)[0] new_course = models.courses.Course(None, app_context=app_context) new_course.init_new_course_settings(title, admin_email) return app_context
def put(self): """Handles HTTP PUT verb.""" request = transforms.loads(self.request.get('request')) if not self.assert_xsrf_token_or_fail( request, 'add-course-put', {}): return if not ConfigPropertyRights.can_edit(): transforms.send_json_response( self, 401, 'Access denied.') return payload = request.get('payload') json_object = transforms.loads(payload) name = json_object.get('name') title = json_object.get('title') admin_email = json_object.get('admin_email') gDefier_module = json_object.get('gDefier_module') # If G-Defier module is active the name of the course will have a tag if gDefier_module: name = name + "_DFR" # Add the new course entry. errors = [] entry = sites.add_new_course_entry(name, title, admin_email, errors) if not entry: errors.append('Error adding a new course entry.') if errors: transforms.send_json_response(self, 412, '\n'.join(errors)) return # We can't expect our new configuration being immediately available due # to datastore queries consistency limitations. So we will instantiate # our new course here and not use the normal sites.get_all_courses(). app_context = sites.get_all_courses(entry)[0] # Update course with a new title and admin email. new_course = courses.Course(None, app_context=app_context) if not new_course.init_new_course_settings(title, admin_email): transforms.send_json_response( self, 412, 'Added new course entry, but failed to update title and/or ' 'admin email. The course.yaml file already exists and must be ' 'updated manually.') return transforms.send_json_response( self, 200, 'Added.', {'entry': entry})
def put(self): """Handles HTTP PUT verb.""" request = transforms.loads(self.request.get('request')) if not self.assert_xsrf_token_or_fail(request, 'add-course-put', {}): return if not CoursesPropertyRights.can_add(): transforms.send_json_response(self, 401, 'Access denied.') return payload = request.get('payload') json_object = transforms.loads(payload) name = json_object.get('name') title = json_object.get('title') admin_email = json_object.get('admin_email') # Add the new course entry. errors = [] entry = sites.add_new_course_entry(name, title, admin_email, errors) if not entry: errors.append('Error adding a new course entry.') if errors: transforms.send_json_response(self, 412, '\n'.join(errors)) return # We can't expect our new configuration being immediately available due # to datastore queries consistency limitations. So we will instantiate # our new course here and not use the normal sites.get_all_courses(). if sites.USE_COURSE_LIST: app_context = sites.get_app_context_for_namespace('ns_%s' % name) else: app_context = sites.get_all_courses(entry)[0] # Update course with a new title and admin email. new_course = courses.Course(None, app_context=app_context) if not new_course.init_new_course_settings(title, admin_email): transforms.send_json_response( self, 412, 'Added new course entry, but failed to update title and/or ' 'admin email. The course.yaml file already exists and must be ' 'updated manually.') return transforms.send_json_response(self, 200, 'Added.', {'entry': entry})
def put(self): """Handles HTTP PUT verb.""" request = transforms.loads(self.request.get("request")) if not self.assert_xsrf_token_or_fail(request, "add-course-put", {}): return if not CoursesPropertyRights.can_add(): transforms.send_json_response(self, 401, "Access denied.") return payload = request.get("payload") json_object = transforms.loads(payload) name = json_object.get("name") title = json_object.get("title") admin_email = json_object.get("admin_email") # Add the new course entry. errors = [] entry = sites.add_new_course_entry(name, title, admin_email, errors) if not entry: errors.append("Error adding a new course entry.") if errors: transforms.send_json_response(self, 412, "\n".join(errors)) return # We can't expect our new configuration being immediately available due # to datastore queries consistency limitations. So we will instantiate # our new course here and not use the normal sites.get_all_courses(). app_context = sites.get_all_courses(entry)[0] # Update course with a new title and admin email. new_course = courses.Course(None, app_context=app_context) if not new_course.init_new_course_settings(title, admin_email): transforms.send_json_response( self, 412, "Added new course entry, but failed to update title and/or " "admin email. The course.yaml file already exists and must be " "updated manually.", ) return transforms.send_json_response(self, 200, "Added.", {"entry": entry})
def put(self): """Handles HTTP PUT verb.""" request = transforms.loads(self.request.get('request')) if not self.assert_xsrf_token_or_fail( request, self.XSRF_ACTION, {}): return if not CoursesPropertyRights.can_add(): self._send_json_error_response(401, 'Access denied.') return payload = request.get('payload') json_object = transforms.loads(payload) name = json_object.get('name') namespace = 'ns_' + name title = json_object.get('title') admin_email = json_object.get('admin_email') template_course = json_object.get('template_course') errors = [] with common_utils.Namespace(namespace): if CourseDeleteHandler.get_any_undeleted_kind_name(): errors.append( 'Unable to add new entry "%s": the corresponding ' 'namespace "%s" is not empty. If you removed a ' 'course with that name in the last few minutes, the ' 'background cleanup job may still be running. ' 'You can use the App Engine Dashboard to manually ' 'remove all database entities from this namespace.' % (name, namespace)) # Add the new course entry. if not errors: entry = sites.add_new_course_entry(name, title, admin_email, errors) if not entry and not errors: errors.append('Error adding a new course entry.') if errors: self._send_json_error_response(412, errors) return # We can't expect our new configuration being immediately available due # to datastore queries consistency limitations. So we will instantiate # our new course here and not use the normal sites.get_all_courses(). app_context = sites.get_all_courses(entry)[0] # Update course with a new title and admin email. new_course = courses.Course(None, app_context=app_context) if not new_course.init_new_course_settings(title, admin_email): self._send_json_error_response(412, 'Added new course entry, but failed to update title and/or ' 'admin email. The course.yaml file already exists and must be ' 'updated manually.') return if template_course: if template_course != 'sample': self._send_json_error_response( 412, 'Unknown template course: %s' % template_course) return src_app_context = sites.get_all_courses('course:/:/:')[0] new_course.import_from(src_app_context, errors) new_course.save() if not errors: common_utils.run_hooks( self.COPY_SAMPLE_COURSE_HOOKS, app_context, errors) if not errors: common_utils.run_hooks( self.NEW_COURSE_ADDED_HOOKS.itervalues(), app_context, errors) if errors: # Any errors at this point are the result of one or more failed # _HOOKS callbacks. It is probably not possible to determine if # these are caused by bad server state or instead by bad user # input, so return a rather generic 500 HTTP status. self._send_json_error_response(500, errors) else: transforms.send_json_response( self, 200, 'Added.', {'entry': entry})
def put(self): """Handles HTTP PUT verb.""" request = transforms.loads(self.request.get('request')) if not self.assert_xsrf_token_or_fail(request, self.XSRF_ACTION, {}): return if not CoursesPropertyRights.can_add(): self._send_json_error_response(401, 'Access denied.') return payload = request.get('payload') json_object = transforms.loads(payload) name = json_object.get('name') namespace = 'ns_' + name title = json_object.get('title') admin_email = json_object.get('admin_email') template_course = json_object.get('template_course') errors = [] with common_utils.Namespace(namespace): if CourseDeleteHandler.get_any_undeleted_kind_name(): errors.append( 'Unable to add new entry "%s": the corresponding ' 'namespace "%s" is not empty. If you removed a ' 'course with that name in the last few minutes, the ' 'background cleanup job may still be running. ' 'You can use the App Engine Dashboard to manually ' 'remove all database entities from this namespace.' % (name, namespace)) # Add the new course entry. if not errors: entry = sites.add_new_course_entry(name, title, admin_email, errors) if not entry and not errors: errors.append('Error adding a new course entry.') if errors: self._send_json_error_response(412, errors) return # We can't expect our new configuration being immediately available due # to datastore queries consistency limitations. So we will instantiate # our new course here and not use the normal sites.get_all_courses(). app_context = sites.get_all_courses(entry)[0] # Update course with a new title and admin email. new_course = courses.Course(None, app_context=app_context) if not new_course.init_new_course_settings(title, admin_email): self._send_json_error_response( 412, 'Added new course entry, but failed to update title and/or ' 'admin email. The course.yaml file already exists and must be ' 'updated manually.') return if template_course: if template_course != 'sample': self._send_json_error_response( 412, 'Unknown template course: %s' % template_course) return src_app_context = sites.get_all_courses('course:/:/:')[0] new_course.import_from(src_app_context, errors) new_course.save() if not errors: common_utils.run_hooks(self.COPY_SAMPLE_COURSE_HOOKS, app_context, errors) if not errors: common_utils.run_hooks(self.NEW_COURSE_ADDED_HOOKS.itervalues(), app_context, errors) if errors: # Any errors at this point are the result of one or more failed # _HOOKS callbacks. It is probably not possible to determine if # these are caused by bad server state or instead by bad user # input, so return a rather generic 500 HTTP status. self._send_json_error_response(500, errors) else: transforms.send_json_response(self, 200, 'Added.', {'entry': entry})
def put(self): """Handles HTTP PUT verb.""" request = transforms.loads(self.request.get('request')) if not self.assert_xsrf_token_or_fail( request, self.XSRF_ACTION, {}): return if not CoursesPropertyRights.can_add(): transforms.send_json_response( self, 401, 'Access denied.') return payload = request.get('payload') json_object = transforms.loads(payload) name = json_object.get('name') title = json_object.get('title') admin_email = json_object.get('admin_email') template_course = json_object.get('template_course') # Add the new course entry. errors = [] entry = sites.add_new_course_entry(name, title, admin_email, errors) if not entry and not errors: errors.append('Error adding a new course entry.') if errors: transforms.send_json_response(self, 412, '\n'.join(errors)) return # We can't expect our new configuration being immediately available due # to datastore queries consistency limitations. So we will instantiate # our new course here and not use the normal sites.get_all_courses(). app_context = sites.get_all_courses(entry)[0] # Update course with a new title and admin email. new_course = courses.Course(None, app_context=app_context) if not new_course.init_new_course_settings(title, admin_email): transforms.send_json_response( self, 412, 'Added new course entry, but failed to update title and/or ' 'admin email. The course.yaml file already exists and must be ' 'updated manually.') return if template_course: if template_course != 'sample': transforms.send_json_response( self, 412, 'Unknown template course: %s' % template_course) return errors = [] src_app_context = sites.get_all_courses('course:/:/:')[0] new_course.import_from(src_app_context, errors) new_course.save() if not errors: common_utils.run_hooks( self.COPY_SAMPLE_COURSE_HOOKS, app_context, errors) if errors: transforms.send_json_response(self, 412, '\n'.join(errors)) return transforms.send_json_response( self, 200, 'Added.', {'entry': entry})