def setUp(self): self.c = Client() self.user = User.objects.create_user('test_student', '*****@*****.**', 'testpassword') UserProfile.objects.get_or_create(user=self.user, gender='M', is_faculty='ST', institute='I1', specialty='S1', consent_participant=True, consent_not_participant=False, hispanic_latino='Y', year_of_graduation=2015) self.patient1 = Patient.objects.get(display_order=1) self.patient4 = Patient.objects.get(display_order=4) get_section_from_path("") # creates a root if one doesn't exist self.hierarchy = Hierarchy.objects.get(name='main') self.hierarchy.id = 3 self.hierarchy.save() self.section = self.hierarchy.get_root().append_child('Bar Baz', 'bar-baz') get_section_from_path("", "alt") # creates a root if one doesn't exist alt_hierarchy = Hierarchy.objects.get(name='alt') self.alt_section = alt_hierarchy.get_root().append_child( 'Sam I Am', 'sam-i-am')
def setUp(self): self.c = Client() self.user = User.objects.create_user('test_student', '*****@*****.**', 'testpassword') UserProfile.objects.get_or_create(user=self.user, gender='M', is_faculty='ST', institute='I1', specialty='S1', consent_participant=True, consent_not_participant=False, hispanic_latino='Y', year_of_graduation=2015) self.patient1 = Patient.objects.get(display_order=1) self.patient4 = Patient.objects.get(display_order=4) get_section_from_path("") # creates a root if one doesn't exist self.hierarchy = Hierarchy.objects.get(name='main') self.hierarchy.id = 3 self.hierarchy.save() self.section = self.hierarchy.get_root().append_child( 'Bar Baz', 'bar-baz') get_section_from_path("", "alt") # creates a root if one doesn't exist alt_hierarchy = Hierarchy.objects.get(name='alt') self.alt_section = alt_hierarchy.get_root().append_child( 'Sam I Am', 'sam-i-am')
def setUp(self): self.c = Client() self.user = User.objects.create_user("test_student", "*****@*****.**", "testpassword") get_section_from_path("") # creates a root if one doesn't exist self.hierarchy = Hierarchy.objects.get(name="main") self.section = self.hierarchy.get_root().append_child("Foo", "foo")
def setUp(self): self.c = Client() self.user = User.objects.create_user('test_student', '*****@*****.**', 'testpassword') get_section_from_path("") # creates a root if one doesn't exist self.hierarchy = Hierarchy.objects.get(name='main') self.section = self.hierarchy.get_root().append_child('Foo', 'foo')
def edit_page(request, hierarchy, path): section = get_section_from_path(path, hierarchy) ctx = dict(section=section, hierarchy=section.hierarchy, module=get_module(section), root=section.hierarchy.get_root()) return render(request, 'main/edit_page.html', ctx)
def edit_page(request, path): section = get_section_from_path(path) h = get_hierarchy() return render(request, 'carr_main/edit_page.html', dict(section=section, module=get_module(section), root=h.get_root()))
def instructor_page(request, path): if not request.user.is_superuser: return HttpResponseForbidden() # TD has only 'main' hierarchy section = get_section_from_path(path, hierarchy='main') root = section.hierarchy.get_root() if request.method == "POST": if 'clear' in request.POST.keys(): submission = get_object_or_404( Submission, id=request.POST['clear']) submission.delete() return HttpResponseRedirect( "/instructor" + section.get_absolute_url()) quizzes = [p.block() for p in section.pageblock_set.all( ) if hasattr(p.block(), 'needs_submit') and p.block().needs_submit()] return render(request, "main/instructor_page.html", dict(section=section, quizzes=quizzes, module=get_module(section), modules=root.get_children(), root=root))
def generic_instructor_page(request, path, hierarchy="main", template="pagetree/instructor_page.html", extra_context=None, ): """ generic pagetree instructor view needs the request and path hierarchy -> defaults to "main" template -> defaults to "pagetree/instructor_page.html" so you can either override that, or pass in a different one here (or just use the basic one that pagetree includes) extra_context -> dict of additional variables to pass along to the template """ section = get_section_from_path(path, hierarchy=hierarchy) root = section.hierarchy.get_root() quizzes = [p.block() for p in section.pageblock_set.all() if hasattr(p.block(), 'needs_submit') and p.block().needs_submit()] context = dict(section=section, quizzes=quizzes, module=section.get_module(), modules=root.get_children(), root=section.hierarchy.get_root()) if extra_context: context.update(extra_context) return render(request, template, context)
def generic_edit_page(request, path, hierarchy="main", template="pagetree/edit_page.html", extra_context=None, ): """ generic pagetree edit page view needs the request and path hierarchy -> defaults to "main" template -> defaults to "pagetree/edit_page.html" so you can either override that, or pass in a different one here (or just use the basic one that pagetree includes) extra_context -> dict of additional variables to pass along to the template """ section = get_section_from_path(path, hierarchy=hierarchy) root = section.hierarchy.get_root() context = dict( section=section, module=section.get_module(), modules=root.get_children(), available_pageblocks=section.available_pageblocks(), root=section.hierarchy.get_root()) if extra_context: context.update(extra_context) return render(request, template, context)
def edit_page(request, path): section = get_section_from_path(path) root = section.hierarchy.get_root() return dict(section=section, module=get_module(section), modules=root.get_children(), root=section.hierarchy.get_root())
def instructor_page(request,path): section = get_section_from_path(path) h = get_hierarchy() quizzes = [p.block() for p in section.pageblock_set.all() if hasattr(p.block(),'needs_submit') and p.block().needs_submit()] return dict(section=section, quizzes=quizzes, module=get_module(section), root=h.get_root())
def edit_page(request, path): section = get_section_from_path(path) user_profile = get_or_create_profile(user=request.user, section=section) return dict(section=section, module=get_module(section), modules=primary_nav_sections(user_profile), root=section.hierarchy.get_root(), can_edit=True)
def get_redirect_url(self, *args, **kwargs): path = kwargs.get('path') hierarchy = Hierarchy.objects.get(name='optionb-en') section = get_section_from_path( path, hierarchy_name=hierarchy.name, hierarchy_base=hierarchy.base_url) return section.get_absolute_url()
def export(request): section = get_section_from_path('/') zip_filename = export_zip(section.hierarchy) with open(zip_filename) as zipfile: resp = HttpResponse(zipfile.read()) resp['Content-Disposition'] = "attachment; filename=%s.zip" % section.hierarchy.name os.unlink(zip_filename) return resp
def export(request): section = get_section_from_path('/') zip_filename = export_zip(section.hierarchy) with open(zip_filename) as zipfile: resp = HttpResponse(zipfile.read()) resp['Content-Disposition'] = ("attachment; filename=%s.zip" % section.hierarchy.name) os.unlink(zip_filename) return resp
def edit_page(request, hierarchy, path): if not request.user.is_superuser: return HttpResponseForbidden() section = get_section_from_path(path, hierarchy) root = section.hierarchy.get_root() return dict(section=section, can_edit=True, module=get_module(section), modules=root.get_children(), root=section.hierarchy.get_root())
def profile(request, educator_id): section = get_section_from_path("map/") user_profile = get_or_create_profile(user=request.user, section=section) if not is_section_unlocked(user_profile, section): return HttpResponseRedirect("/") educator = get_object_or_404(DentalEducator, id=educator_id) return dict(educator=educator, module=get_module(section), modules=primary_nav_sections(user_profile), root=section.hierarchy.get_root())
def instructor_page(request,path): h = get_hierarchy(request.get_host()) section = get_section_from_path(path,hierarchy=h) root = section.hierarchy.get_root() module = get_module(section) quizzes = [p.block() for p in section.pageblock_set.all() if hasattr(p.block(),'needs_submit') and p.block().needs_submit()] return dict(section=section, quizzes=quizzes, module=get_module(section), modules=root.get_children(), root=h.get_root())
def page(request, hierarchy, path): profile = UserProfile.objects.filter(user=request.user).first() if profile is None: return HttpResponseRedirect(reverse('create_profile')) section = get_section_from_path(path, hierarchy) h = section.hierarchy if request.method == "POST": # user has submitted a form. deal with it return page_post(request, section) first_leaf = h.get_first_leaf(section) ancestors = first_leaf.get_ancestors() if len(ancestors) < 1: raise Http404('Page does not exist') # Skip to the first leaf, make sure to mark these sections as visited if (section != first_leaf): profile.set_has_visited(ancestors) return HttpResponseRedirect(first_leaf.get_absolute_url()) # the previous node is the last leaf, if one exists. prev_page = _get_previous_leaf(first_leaf) next_page = _get_next(first_leaf) # Is this section unlocked now? can_access = _unlocked(first_leaf, request.user, prev_page, profile) if can_access: profile.set_has_visited([section]) module = None if not first_leaf.is_root() and len(ancestors) > 1: module = ancestors[1] allow_redo = False needs_submit = first_leaf.needs_submit() if needs_submit: allow_redo = first_leaf.allow_redo() ctx = dict(request=request, ancestors=ancestors, profile=profile, hierarchy=h, section=first_leaf, can_access=can_access, module=module, root=ancestors[0], previous=prev_page, next=next_page, needs_submit=needs_submit, allow_redo=allow_redo, is_submitted=first_leaf.submitted(request.user)) return render(request, 'main/page.html', ctx)
def instructor_page(request, path): section = get_section_from_path(path) h = get_hierarchy() quizzes = [ p.block() for p in section.pageblock_set.all() if hasattr(p.block(), 'needs_submit') and p.block().needs_submit() ] return render( request, 'main/instructor_page.html', dict(section=section, quizzes=quizzes, module=get_module(section), root=h.get_root()))
def process_page(request, path, hierarchy): section = get_section_from_path(path, hierarchy=hierarchy) root = hierarchy.get_root() module = get_module(section) user_profile = get_or_create_profile(user=request.user, section=section) can_access = _unlocked(user_profile, section) if can_access: user_profile.save_visit(section) else: if request.user.is_anonymous(): return HttpResponseRedirect("/") else: return HttpResponseRedirect(user_profile.last_location) can_edit = False if not request.user.is_anonymous(): can_edit = request.user.is_staff if section.id == root.id: # trying to visit the root page if section.get_first_leaf(): # just send them to the first child, but save # the ancestors first first_leaf = section.get_first_leaf() ancestors = first_leaf.get_ancestors() user_profile.save_visits(ancestors) return HttpResponseRedirect(first_leaf.get_absolute_url()) if request.method == "POST": return handle_page_post(request, section, hierarchy, path) else: instructor_link = has_responses(section) allow_next_link = not needs_submit( section) or submitted(section, request.user) return dict(section=section, module=module, allow_next_link=allow_next_link, needs_submit=needs_submit(section), is_submitted=submitted(section, request.user), modules=root.get_children(), root=section.hierarchy.get_root(), instructor_link=instructor_link, can_edit=can_edit, allow_redo=allow_redo(section), next_unlocked=_unlocked( user_profile, section.get_next()) )
def page(request, hierarchy, path): profile = UserProfile.objects.filter(user=request.user).first() if profile is None: return HttpResponseRedirect(reverse('create_profile')) section = get_section_from_path(path, hierarchy) h = section.hierarchy if request.method == "POST": # user has submitted a form. deal with it return page_post(request, section) first_leaf = h.get_first_leaf(section) ancestors = first_leaf.get_ancestors() # Skip to the first leaf, make sure to mark these sections as visited if (section != first_leaf): profile.set_has_visited(ancestors) return HttpResponseRedirect(first_leaf.get_absolute_url()) # the previous node is the last leaf, if one exists. prev_page = _get_previous_leaf(first_leaf) next_page = _get_next(first_leaf) # Is this section unlocked now? can_access = _unlocked(first_leaf, request.user, prev_page, profile) if can_access: profile.set_has_visited([section]) module = None if not first_leaf.is_root() and len(ancestors) > 1: module = ancestors[1] allow_redo = False needs_submit = first_leaf.needs_submit() if needs_submit: allow_redo = first_leaf.allow_redo() ctx = dict(request=request, ancestors=ancestors, profile=profile, hierarchy=h, section=first_leaf, can_access=can_access, module=module, root=ancestors[0], previous=prev_page, next=next_page, needs_submit=needs_submit, allow_redo=allow_redo, is_submitted=first_leaf.submitted(request.user)) return render(request, 'main/page.html', ctx)
def get(self, request, path): section = get_section_from_path( path, hierarchy_name=self.hierarchy_name, hierarchy_base=self.hierarchy_base) pool = self_and_descendants(section) user_timestamps = SectionTimestamp.objects.filter(user=request.user) already_visited = [t for t in user_timestamps if t.section in pool] if len(already_visited) == 0: return HttpResponseRedirect("/" + section.get_path()) most_recently_visited = sorted( already_visited, key=lambda x: x.timestamp)[-1] latest_section_visited = most_recently_visited.section return HttpResponseRedirect("/" + latest_section_visited.get_path())
def exporter(request): if not request.user.is_superuser: return HttpResponseForbidden() hierarchy = request.get_host() section = get_section_from_path('/', hierarchy=hierarchy) zip_filename = export_zip(section.hierarchy) with open(zip_filename) as zipfile: resp = HttpResponse(zipfile.read()) resp['Content-Disposition'] = \ "attachment; filename=%s.zip" % section.hierarchy.name os.unlink(zip_filename) return resp
def page(request, hierarchy, path): section = get_section_from_path(path, hierarchy=hierarchy.name) root = section.hierarchy.get_root() module = get_module(section) user_profile = get_or_create_profile(user=request.user, section=section) can_access = _unlocked(user_profile, section) if can_access: user_profile.save_visit(section) else: # need to redirect them back return HttpResponseRedirect(user_profile.last_location) can_edit = False if not request.user.is_anonymous(): can_edit = request.user.is_staff if section.id == root.id or section.id == root.get_first_child().id: # trying to visit the root page -- send them to the first leaf first_leaf = section.hierarchy.get_first_leaf(section) ancestors = first_leaf.get_ancestors() user_profile.save_visits(ancestors) return HttpResponseRedirect(first_leaf.get_absolute_url()) if request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action', '') == 'reset': section.reset(request.user) return HttpResponseRedirect(section.get_absolute_url()) proceed = section.submit(request.POST, request.user) return proceed_redirect(section, proceed) else: instructor_link = has_responses(section) return dict(section=section, module=module, glossary=GlossaryTerm.objects.all(), needs_submit=needs_submit(section), is_submitted=submitted(section, request.user), allow_redo=allow_redo(section), modules=root.get_children(), root=section.hierarchy.get_root(), instructor_link=instructor_link, can_edit=can_edit, next_unlocked=_unlocked(user_profile, section.get_next()) )
def edit_page(request, path): hierarchy = request.get_host() section = get_section_from_path(path, hierarchy=hierarchy) if not request.stand.can_edit(request.user): return HttpResponse("you do not have admin permission") can_admin = request.stand.can_admin(request.user) root = section.hierarchy.get_root() return render( request, 'main/edit_page.html', dict(section=section, module=get_module(section), modules=root.get_children(), stand=request.stand, can_admin=can_admin, available_pageblocks=request.stand.available_pageblocks(), root=section.hierarchy.get_root()))
def precheck(self, request, path): # bypass the inital material if the user has already submitted # the pretest: pretest = get_pretest(hierarchy=self.hierarchy) if pretest.user_has_submitted(path, request.user): return HttpResponseRedirect( pretest.section.get_next().get_absolute_url()) section = get_section_from_path(path, hierarchy=self.hierarchy) set_timestamp_for_section(section, request.user) # We're leaving the top level pages as blank and navigating # around them. if send_to_first_child(section, section.hierarchy.get_root()): return HttpResponseRedirect(section.get_next().get_absolute_url()) self.section = section return None
def module_three_glossary(request): hierarchy = Hierarchy.objects.get(name="module_three") section = get_section_from_path("speechpathology/", hierarchy=hierarchy.name) root = section.hierarchy.get_root() module = get_module(section) can_edit = False if not request.user.is_anonymous(): can_edit = request.user.is_staff return dict(section=section, module=module, glossary=GlossaryTerm.objects.all().order_by("term"), modules=root.get_children(), root=section.hierarchy.get_root(), can_edit=can_edit)
def cloner(request): if request.method == "GET": return {} new_hierarchy = request.POST['new_hierarchy'] old_stand = get_stand(request.get_host()) fake_request = HttpRequest() fake_request.method = "POST" fake_request.POST['hostname'] = new_hierarchy fake_request.POST['title'] = old_stand.title fake_request.POST['css'] = old_stand.css fake_request.POST['description'] = old_stand.description fake_request.POST['access'] = old_stand.access form = StandForm(fake_request.POST) stand = form.save() su = StandUser.objects.create(stand=stand, user=request.user, access="admin") if request.POST.get('copy_userperms'): for standuser in StandUser.objects.filter(stand=old_stand).exclude(user=request.user): StandUser.objects.create(stand=stand, user=standuser.user, access=standuser.access ).save() for old_sapb in old_stand.standavailablepageblock_set.all(): StandAvailablePageBlock.objects.create( stand=stand, block=old_sapb.block).save() hierarchy = request.get_host() section = get_section_from_path('/', hierarchy=hierarchy) zip_filename = export_zip(section.hierarchy) zipfile = ZipFile(zip_filename) hierarchy_name = new_hierarchy hierarchy = import_zip(zipfile, hierarchy_name) os.unlink(zip_filename) if new_hierarchy.endswith(".forest.ccnmtl.columbia.edu"): # if it's a *.forest site, just send them on their way return HttpResponseRedirect("http://%s/_stand/" % new_hierarchy) else: return cloner_created(request, dict(created=True,stand=stand))
def page(request,path): hierarchy = request.get_host() section = get_section_from_path(path,hierarchy=hierarchy) root = section.hierarchy.get_root() module = get_module(section) if not request.stand.can_view(request.user): return HttpResponse("you do not have permission") can_edit = request.stand.can_edit(request.user) can_admin = request.stand.can_admin(request.user) if section.id == root.id: # trying to visit the root page if section.get_next(): # just send them to the first child return HttpResponseRedirect(section.get_next().get_absolute_url()) else: # send them to the stand admin interface return HttpResponseRedirect("/_stand/") if request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action','') == 'reset': section.reset(request.user) return HttpResponseRedirect(section.get_absolute_url()) proceed = section.submit(request.POST,request.user) if proceed: return HttpResponseRedirect(section.get_next().get_absolute_url()) else: # giving them feedback before they proceed return HttpResponseRedirect(section.get_absolute_url()) else: instructor_link = has_responses(section) return dict(section=section, module=module, needs_submit=needs_submit(section), is_submitted=submitted(section,request.user), stand=request.stand, modules=root.get_children(), root=section.hierarchy.get_root(), can_edit=can_edit, can_admin=can_admin, instructor_link=instructor_link, )
def pagetree_page(request, path): section = get_section_from_path(path) root = section.hierarchy.get_root() if not check_course_enrollment(request.user, section): return HttpResponseRedirect('/courses/') module = get_module(section) submodule = get_submodule(section) sub_submodule_index = get_sub_submodule_index(section) # using this number in the accordion settings # for the left nav. if section.id == root.id: # trying to visit the root page if section.get_next(): # just send them to the first child return HttpResponseRedirect(section.get_next().get_absolute_url()) if request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action', '') == 'reset': section.reset(request.user) return HttpResponseRedirect(section.get_absolute_url()) proceed = section.submit(request.POST, request.user) if proceed: return HttpResponseRedirect(section.get_next().get_absolute_url()) else: # giving them feedback before they proceed return HttpResponseRedirect(section.get_absolute_url()) else: return render( request, 'main/page.html', dict( section=section, module=module, submodule=submodule, sub_submodule_index=sub_submodule_index, needs_submit=needs_submit(section), is_submitted=submitted(section, request.user), modules=root.get_children(), root=section.hierarchy.get_root(), ))
def page(request, path): hierarchy = request.get_host() section = get_section_from_path(path, hierarchy=hierarchy) root = section.hierarchy.get_root() module = get_module(section) if not request.stand.can_view(request.user): return HttpResponse("you do not have permission") if section.id == root.id: return root_page(section, root) if request.method == "POST": # user has submitted a form. deal with it section.submit(request.POST, request.user) next_path = path_from_destination(request, section) if next_path is not None: return HttpResponseRedirect(next_path) # Wings-specific modifications: if not check_next_page(request, section): return ( HttpResponseRedirect( destination_on_check_next_page_fail(request)) ) show_decorations = whether_to_show_decorations(section) the_decoration_info = decoration_info(section) action_type_summary = ActionType.summary() return render( request, 'main/page.html', dict( section=section, module=module, needs_submit=needs_submit(section), is_submitted=submitted(section, request.user), stand=request.stand, modules=root.get_children(), root=section.hierarchy.get_root(), can_edit=request.stand.can_edit(request.user), can_admin=request.stand.can_admin(request.user), show_decorations=show_decorations, decoration_info=the_decoration_info, action_type_summary=action_type_summary ))
def page(request, path): section = get_section_from_path(path) hierarchy = section.hierarchy module = get_module(section) user_profile = get_or_create_profile(user=request.user, section=section) accessible = is_section_unlocked(user_profile, section) if accessible: user_profile.save_visit(section) can_edit = can_user_edit(request) first_leaf = hierarchy.get_first_leaf(section) ancestors = first_leaf.get_ancestors() # Skip to the first leaf, make sure to mark these sections as visited if (section != first_leaf): user_profile.save_visits(ancestors) return HttpResponseRedirect(first_leaf.get_absolute_url()) if accessible and request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action', '') == 'reset': section.reset(request.user) return HttpResponseRedirect(section.get_absolute_url()) section.submit(request.POST, request.user) if section.slug == "ce-credit": next_section = section.get_next() if next_section: return HttpResponseRedirect(next_section.get_absolute_url()) else: return HttpResponseRedirect(section.get_absolute_url()) else: instructor_link = has_responses(section) items = get_items(request, section, module, accessible, path, can_edit, instructor_link, user_profile) template_name = template_from_path(accessible, path) return render_to_response(template_name, items, context_instance=RequestContext(request))
def page(request, path): template_name = 'main/page.html' section = get_section_from_path(path) # redirects to first (welcome) page for parent nodes section = section.get_first_leaf() h = get_hierarchy() profile = get_profile(request, path) if request.method == "POST": return page_post(request, section) else: return render( request, template_name, dict(section=section, needs_submit=needs_submit(section), module=get_module(section), profile=profile, is_submitted=submitted(section, request.user), root=h.get_root()))
def page(request, path): section = get_section_from_path(path) root = section.hierarchy.get_root() module = section.get_module() page_dict = dict( section=section, module=module, modules=root.get_children(), root=section.hierarchy.get_root(), is_mod_one=is_mod_one(module), ) rv = redirect_to_first_section_if_root(section, root) if rv: return rv if request.method == "POST": # giving them feedback before they proceed return HttpResponseRedirect(section.get_absolute_url()) return page_dict
def instructor_page(request, path): hierarchy_name, slash, section_path = path.partition('/') section = get_section_from_path(section_path, hierarchy=hierarchy_name) root = section.hierarchy.get_root() if request.method == "POST": if 'clear' in request.POST.keys(): submission = get_object_or_404( Submission, id=request.POST['clear']) submission.delete() path = "/instructor" + section.get_absolute_url() return HttpResponseRedirect(path) quizzes = [p.block() for p in section.pageblock_set.all( ) if hasattr(p.block(), 'needs_submit') and p.block().needs_submit()] return dict(section=section, quizzes=quizzes, module=get_module(section), modules=root.get_children(), root=root)
def edit_page(request, path): if not request.user.is_staff: return HttpResponseRedirect(reverse("dashboard")) section = get_section_from_path(path) root = section.hierarchy.get_root() edit_page = True dashboard, created = DashboardInfo.objects.get_or_create( dashboard=section) module_type, created = ModuleType.objects.get_or_create( module_type=section) update_module_type_info(module_type, request) section_css, created = SectionCss.objects.get_or_create( section_css=section) if request.method == "POST": try: dashboard.info = request.POST['dashboard_info'] except MultiValueDictKeyError: pass try: section_css.css_field = request.POST['section_css_field'] except MultiValueDictKeyError: pass dashboard.save() section_css.save() module_type.save() return dict(section=section, section_css=section_css, dashboard=dashboard, module_type=module_type, module=section.get_module(), modules=root.get_children(), root=section.hierarchy.get_root(), edit_page=edit_page)
def page(request, path): template_name = "main/page.html" section = get_section_from_path(path) # redirects to first (welcome) page for parent nodes section = section.get_first_leaf() h = get_hierarchy() profile = get_profile(request, path) if request.method == "POST": return page_post(request, section) else: return render( request, template_name, dict( section=section, needs_submit=needs_submit(section), module=get_module(section), profile=profile, is_submitted=submitted(section, request.user), root=h.get_root(), ), )
def page(request,path): section = get_section_from_path(path) section = section.get_first_leaf() # redirects to first (welcome) page for parent nodes h = get_hierarchy() if not request.user.is_anonymous(): try: profile = request.user.get_profile() profile.current_location = path profile.save() except UserProfile.DoesNotExist: pass profile = None if not request.user.is_anonymous(): try: profile = request.user.get_profile() except UserProfile.DoesNotExist: pass if request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action','') == 'reset': # it's a reset request for p in section.pageblock_set.all(): if hasattr(p.block(),'needs_submit'): if p.block().needs_submit(): p.block().clear_user_submissions(request.user) return HttpResponseRedirect(section.get_absolute_url()) proceed = True for p in section.pageblock_set.all(): if hasattr(p.block(),'needs_submit'): if p.block().needs_submit(): prefix = "pageblock-%d-" % p.id data = dict() for k in request.POST.keys(): if k.startswith(prefix): # handle lists for multi-selects v = request.POST.getlist(k) if len(v) == 1: data[k[len(prefix):]] = request.POST[k] else: data[k[len(prefix):]] = v p.block().submit(request.user,data) if hasattr(p.block(),'redirect_to_self_on_submit'): # semi bug here? # proceed will only be set by the last submittable # block on the page. previous ones get ignored. proceed = not p.block().redirect_to_self_on_submit() if proceed: return HttpResponseRedirect(section.get_next().get_absolute_url()) else: # giving them feedback before they proceed return HttpResponseRedirect(section.get_absolute_url()) else: return dict(section=section, needs_submit=needs_submit(section), module=get_module(section), profile=profile, is_submitted=submitted(section,request.user), root=h.get_root())
def test_empty(self): s = get_section_from_path("/") self.assertEqual(s.hierarchy.name, "main")
def edit_page(request, path): section = get_section_from_path(path) h = get_hierarchy() return render( request, 'main/edit_page.html', dict(section=section, module=get_module(section), root=h.get_root()))
def get_section(self, path): return get_section_from_path(path, hierarchy_name=self.hierarchy_name, hierarchy_base=self.hierarchy_base)
def page(request, path): section = get_section_from_path(path) hierarchy = section.hierarchy module = get_module(section) user_profile = get_or_create_profile(user=request.user, section=section) accessible = is_section_unlocked(user_profile, section) if accessible: user_profile.save_visit(section) can_edit = can_user_edit(request) first_leaf = hierarchy.get_first_leaf(section) ancestors = first_leaf.get_ancestors() # Skip to the first leaf, make sure to mark these sections as visited if (section != first_leaf): user_profile.save_visits(ancestors) return HttpResponseRedirect(first_leaf.get_absolute_url()) if accessible and request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action', '') == 'reset': section.reset(request.user) return HttpResponseRedirect(section.get_absolute_url()) section.submit(request.POST, request.user) if section.slug == "ce-credit": next_section = section.get_next() if next_section: return HttpResponseRedirect(next_section.get_absolute_url()) else: return HttpResponseRedirect(section.get_absolute_url()) else: instructor_link = has_responses(section) items = dict(section=section, module=module, accessible=accessible, needs_submit=needs_submit(section), is_submitted=submitted(section, request.user), modules=primary_nav_sections(user_profile), root=section.hierarchy.get_root(), instructor_link=instructor_link, can_edit=can_edit, allow_redo=allow_redo(section), next_unlocked=is_section_unlocked(user_profile, section.get_next())) template_name = template_from_path(accessible, path) if accessible and path.startswith('map'): items['career_stages'] = CAREER_STAGE_CHOICES items['clinical_fields'] = \ ClinicalField.objects.all().distinct().order_by('name') items['teaching_responsibilities'] = \ TeachingResponsibility.objects.all().order_by('name') items['paid_time_commitments'] = TimeCommitment.objects.all() items['volunteer_time_commitments'] = TimeCommitment.objects.all() items['trainee_types'] = PrimaryTraineesType.objects.all() return render_to_response(template_name, items, context_instance=RequestContext(request))
def generic_view_page(request, path, hierarchy="main", gated=False, template="pagetree/page.html", extra_context=None, no_root_fallback_url="/admin/" ): """ generic pagetree page view needs the request and path hierarchy -> defaults to "main" gated -> whether to block users from skipping ahead (ie, force sequential access) template -> defaults to "pagetree/page.html" so you can either override that, or pass in a different one here (or just use the basic one that pagetree includes) extra_context -> dict of additional variables to pass along to the template no_root_fallback -> where to send the user if there are no sections at all in the tree (not even a root). defaults to "/admin/" """ section = get_section_from_path(path, hierarchy=hierarchy) root = section.hierarchy.get_root() module = section.get_module() if section.is_root(): return visit_root(section, no_root_fallback_url) if gated: # we need to check that they have visited all previous pages # first allow, first = section.gate_check(request.user) if not allow: # redirect to the first one that they need to visit return HttpResponseRedirect(first.get_absolute_url()) upv = UserPageVisitor(section, request.user) if request.method == "POST": # user has submitted a form. deal with it if request.POST.get('action', '') == 'reset': upv.visit(status="incomplete") return reset_page(section, request) upv.visit(status="complete") return page_submit(section, request) else: allow_redo = False needs_submit = section.needs_submit() if needs_submit: allow_redo = section.allow_redo() upv.visit() instructor_link = has_responses(section) context = dict( section=section, module=module, needs_submit=needs_submit, allow_redo=allow_redo, is_submitted=section.submitted(request.user), modules=root.get_children(), root=section.hierarchy.get_root(), instructor_link=instructor_link, ) if extra_context: context.update(extra_context) return render(request, template, context)
def create_tree_root(request): get_section_from_path("") # creates a root if one doesn't exist return HttpResponseRedirect(request.META['HTTP_REFERER'])
def edit_page(request, hierarchy, path): section = get_section_from_path(path, hierarchy) return dict(section=section, hierarchy=section.hierarchy, module=get_module(section), root=section.hierarchy.get_root())
def current_module(self): if self.current_location == "": return None return get_module(get_section_from_path(self.current_location))