def list_of_classrooms(request): root = model_reference.load('classroom-root') context = { 'classroom_list': Classroom.objects.enrolled(request.user), 'navbar': navbar_list(root, request.user), } return render(request, 'classrooms/list.jinja2', context)
def get_sys_page(name): """ Return system page by named reference. """ import model_reference return model_reference.load(name)
def make_text_questions_fuzzy(parent=None): question = TextQuestion(title='Pie', body=[ ('markdown', 'What is the value of Pi?'), ], correct_answer='ÁloMundo') parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def fill_example_questions(user): from .factories import make_example_questions if not global_data_store.get('example-questions', False): global_data_store['example-questions'] = True activities = model_reference.load('main-question-list') questions = make_example_questions(activities) for i in range(1, min(2, len(questions))): questions[i].owner = user questions[i].save()
def create_subpage(cls, parent=None, **kwargs): """ Create a new ActivitySection using the given keyword arguments under the given parent page. If no parent is chosen, uses the "main-activity-list" reference. """ parent = parent or model_reference.load('main-activity-list') new = cls(**kwargs) parent.add_child(instance=new) new.save() return new
def make_text_questions_fuzzy(parent=None): question = TextQuestion( title='Pie', body=[ ('markdown', 'What is the value of Pi?'), ], correct_answer='ÁloMundo' ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_main_activity_dashboard(): """ Creates the default site-wide activity list. Other activity lists may appear under different sections in the site. """ parent_page = model_reference.load('root-page') activity_list = ActivityList( title='Activities', slug='activities', ) return parent_page.add_child(instance=activity_list)
def create_subpage(cls, parent=None, **kwargs): """ Create a new ActivitySection using the given keyword arguments under the given parent page. If no parent is chosen, uses the "main-question-list" reference. """ parent = parent or model_reference.load('main-question-list') new = cls(**kwargs) parent.add_child(instance=new) new.save() return new
def make_regex_text_questions(parent=None): question = TextQuestion( title='The E-mail', body=[ ('markdown', 'What is your e-mail?'), ], #E-mail regex correct_answer='(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)', ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_numeric_question_fuzzy(parent=None): question = NumericQuestion( title='Pie', body=[ ('markdown', 'What is the value of Pi?'), ], correct_answer=math.pi, tolerance=0.01, ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_numeric_question(parent=None): question = NumericQuestion( title='The Answer', body=[ ('markdown', 'What is The Answer to the Ultimate Question of Life, The ' 'Universe, and Everything?'), ], correct_answer=42, ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_numeric_question_fuzzy(parent=None): question = NumericQuestion( title='Pie', body=[ ('markdown', 'What is the value of Pi?'), ], correct_answer=math.pi, tolerance=0.01, ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def navbar_view(request): from codeschool.models import User user = User.objects.last() page = model_reference.load('root-page') sections = [navsection('Foo', ['link1', 'link2', 'link3']), navsection_page_admin(page, user=user)] navbar_elem = navbar(sections) return render_tag(request, 'Navbars', div()[ div('Main content'), ], ctx={'navbar': navbar_elem})
def make_page(model, root='rogue-root', **kwargs): """ Create a new saved page under RogueRoot. """ if isinstance(model, str): model = apps.get_model(*model.split('.')) root = model_reference.load(root) page = model(**kwargs) page.full_clean(exclude=['depth', 'path']) root.add_child(instance=page) return page
def make_text_questions(parent=None): question = TextQuestion( title='The Answer', body=[ ('markdown', 'What is bigger than the answer to the Ultimate Question of Life, The ' 'Universe, and Everything?'), ], correct_answer='Quarenta e três', ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_numeric_question(parent=None): question = NumericQuestion( title='The Answer', body=[ ('markdown', 'What is The Answer to the Ultimate Question of Life, The ' 'Universe, and Everything?'), ], correct_answer=42, ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_regex_text_questions(parent=None): question = TextQuestion( title='The E-mail', body=[ ('markdown', 'What is your e-mail?'), ], #E-mail regex correct_answer='(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)', ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_text_questions(parent=None): question = TextQuestion( title='The Answer', body=[ ('markdown', 'What is bigger than the answer to the Ultimate Question of Life, The ' 'Universe, and Everything?'), ], correct_answer='Quarenta e três', ) parent = parent or model_reference.load('root-page') parent.add_child(instance=question) return question
def make_courses_list(): """ Creates the default site-wide courses list. All course pages should be children of this page. """ parent_page = model_reference.load('root-page') courses_list = CourseList( title=_('Courses'), slug='courses', ) return parent_page.add_child(instance=courses_list)
def save(self, *args, **kwargs): with transaction.atomic(): created = self.id is None if not self.path: created = False root = model_reference.load('course-list') root.add_child(instance=self) else: super().save(*args, **kwargs) if created: self.create_calendar_page() self.create_activities_page()
def navbar_view(request): from codeschool.models import User user = User.objects.last() page = model_reference.load('root-page') sections = [ navsection('Foo', ['link1', 'link2', 'link3']), navsection_page_admin(page, user=user) ] navbar_elem = navbar(sections) return render_tag(request, 'Navbars', div()[div('Main content'), ], ctx={'navbar': navbar_elem})
def make_main_activity_list(): """ Creates the default site-wide activity list. Other activity lists may appear under different sections in the site. """ parent_page = model_reference.load('root-page') try: return ActivityList.objects.get(path__startswith=parent_page.path, slug='questions') except ActivityList.DoesNotExist: activity_list = ActivityList( title=_('Questions'), slug='questions', ) return parent_page.add_child(instance=activity_list)
def make_numeric_question_42(parent=None, commit=True): question = NumericQuestion( title='The Answer', body=[ ('markdown', 'What is The Answer to the Ultimate Question of Life, The ' 'Universe, and Everything?'), ], correct_answer=42, ) if commit: parent = parent or model_reference.load('root-page') parent.add_child(instance=question) else: question.path = '0002' question.depth = 1 return question
def create_subpage(cls, parent=None, **kwargs): """ Create a new ActivityList using the given keyword arguments under the given parent page. If no parent is chosen, uses the main Wagtail root page. """ kwargs.update( title=_('Activities'), short_description=_('Activities'), slug='activities', ) parent = parent or model_reference.load('root-page') new = cls(**kwargs) parent.add_child(instance=new) new.save() return new
def create_subpage(cls, parent=None, **kwargs): """ Create a new ActivityList using the given keyword arguments under the given parent page. If no parent is chosen, uses the main Wagtail root page. """ kwargs.update( title=_('Activities'), short_description=kwargs.get('short_description', _('List of activities.')), slug='activities', ) parent = parent or model_reference.load('root-page') new = cls(**kwargs) print('parent', parent) parent.add_child(instance=new) new.save() return new
def navsection_classroom_common(page, user): """ Common sections for classroom pages. """ links = [ a(_('Enroll'), href='/classes/enroll/'), ] # Add new course for admin users if user.is_superuser: pk = model_reference.load('classroom-root').pk links.append( a(_('Add new classroom'), href='/admin/pages/%s/add_subpage/' % pk) ) # Leave course if rules.test_rule('classrooms.can_leave', user, page): links.append(a(_('Leave classroom'), srvice_bind='leave.api')) return navsection(_('Classrooms'), links, href='/classes/')
def main(self): """ Return the main ActivityList for the website. """ return model_reference.load('root-page', model=ActivityList)
def main_question_list(request): page = model_reference.load('main-question-list') return page.serve(request)
def root(db): return model_reference.load('root-page')
def main_activity_list(request): page = model_reference.load('main-activity-list') return page.serve(request)
def configure_server_view(request): """ Exhibit a form that performs basic server configuration. """ has_superuser = site_has_superuser() if not request.user.is_superuser and has_superuser: return render(request, 'core/forbidden-server-config.jinja2', {}) context = { 'config': config_options, 'user': request.user, 'disable_footer_data': True, 'disable_nav': False, 'create_superuser': not has_superuser, } if request.method == 'POST': options_form = ConfigForm(request.POST) superuser_form = NewUserForm(request.POST) sys_profile_form = SysProfileForm(request.POST) password_form = PasswordForm(request.POST) forms = [options_form, sys_profile_form] if not has_superuser: forms.extend([superuser_form, password_form]) if all(form.is_valid() for form in forms): # Create user if not has_superuser: user = create_superuser_from_forms(superuser_form, password_form) django_backend = 'django.contrib.auth.backends.ModelBackend' login(request, user, backend=django_backend) else: user = request.user global_data_store['admin-user-id'] = user.id # Populate the database data = sys_profile_form.cleaned_data if data.get('joe_user', False): fill_joe_user() if data.get('basic_activities', False): fill_basic_activities() if data.get('example_questions', False): fill_example_questions(user) if data.get('example_courses', False): fill_example_courses() if data.get('populate_courses', False): fill_courses_with_users() if data.get('exapmle_submissions', False): fill_example_submissions() # Ensure references to important pages were created model_reference.load('main-question-list') if 'codeschool.lms.courses' in settings.INSTALLED_APPS: model_reference.load('course-list') # Save global settings data = options_form.cleaned_data config_options['address'] = data['address'] config_options['initial-page'] = data['initial_page'] return index_view(request) else: options_form = ConfigForm() superuser_form = NewUserForm() sys_profile_form = SysProfileForm() password_form = PasswordForm(request.POST) context['options_form'] = options_form context['superuser_form'] = superuser_form context['sys_profile_form'] = sys_profile_form context['password_form'] = password_form return render(request, 'core/server-config.jinja2', context)
def make_basic_activities(): page = model_reference.load('main-question-list') page.update_from_template('programming-beginner') return page
def course_list(request): page = model_reference.load('course-list') return page.serve(request)
def root(db): return model_reference.load('root-page')
def configure_server_view(request): """ Exhibit a form that performs basic server configuration. """ has_superuser = site_has_superuser() if not request.user.is_superuser and has_superuser: return render(request, 'core/forbidden-server-config.jinja2', {}) context = { 'config': config_options, 'user': request.user, 'disable_footer_data': True, 'disable_nav': False, 'create_superuser': not has_superuser, } if request.method == 'POST': options_form = ConfigForm(request.POST) superuser_form = NewUserForm(request.POST) sys_profile_form = SysProfileForm(request.POST) password_form = PasswordForm(request.POST) forms = [options_form, sys_profile_form] if not has_superuser: forms.extend([superuser_form, password_form]) if all(form.is_valid() for form in forms): # Create user if not has_superuser: user = create_superuser_from_forms(superuser_form, password_form) django_backend = 'django.contrib.auth.backends.ModelBackend' login(request, user, backend=django_backend) else: user = request.user global_data_store['admin-user-id'] = user.id # Populate the database data = sys_profile_form.cleaned_data if data.get('joe_user', False): fill_joe_user() if data.get('basic_activities', False): fill_basic_activities() if data.get('example_questions', False): fill_example_questions(user) if data.get('example_courses', False): fill_example_courses() if data.get('populate_courses', False): fill_courses_with_users() if data.get('exapmle_submissions', False): fill_example_submissions() # Ensure references to important pages were created model_reference.load('main-question-list') if 'codeschool.lms.courses' in settings.INSTALLED_APPS: model_reference.load('course-list') # Save global settings data = options_form.cleaned_data config_options['address'] = data['address'] config_options['initial-page'] = data['initial_page'] return index_view(request) else: options_form = ConfigForm() superuser_form = NewUserForm() sys_profile_form = SysProfileForm() password_form = PasswordForm(request.POST) context['options_form'] = options_form context['superuser_form'] = superuser_form context['sys_profile_form'] = sys_profile_form context['password_form'] = password_form return render(request, 'core/server-config.jinja2', context)