コード例 #1
0
ファイル: views.py プロジェクト: ccnmtl/pass
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())
                    )
コード例 #2
0
def get_items(request, section, module, accessible, path, can_edit,
              instructor_link, user_profile):
    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()))

    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 items
コード例 #3
0
ファイル: views.py プロジェクト: ccnmtl/match
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())
                    )
コード例 #4
0
ファイル: views.py プロジェクト: ccnmtl/wacep
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(),
            ))
コード例 #5
0
ファイル: views.py プロジェクト: ccnmtl/wings
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
        ))
コード例 #6
0
ファイル: views.py プロジェクト: djredhand/phtc
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,
                    )
コード例 #7
0
ファイル: views.py プロジェクト: ccnmtl/diabeaters
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()))
コード例 #8
0
 def get_context(self, request):
     path_list = list(self.section.get_ancestors())[1:]
     path_list.append(self.section)
     return dict(
         section=self.section,
         path=path_list,
         depth=len(path_list),
         can_download_stats=get_can_download_stats(request.user),
         module=get_module(self.section),
         needs_submit=needs_submit(self.section),
         is_submitted=submitted(self.section, request.user),
         modules=self.section.hierarchy.get_root().get_children(),
         root=self.section.hierarchy.get_root(),
         section_preferences=get_section_preferences(self.section),
         module_info=module_info(self.section),
         already_answered=SectionQuizAnsweredCorrectly.objects.filter(
             section=self.section, user=request.user).exists(),
         already_visited=whether_already_visited(
             self.section, request.user),
         whether_to_show_nav=whether_to_show_nav(
             self.section, request.user)
     )
コード例 #9
0
ファイル: views.py プロジェクト: ccnmtl/diabeaters
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(),
            ),
        )
コード例 #10
0
ファイル: views.py プロジェクト: mrenoch/Diabeaters
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())
コード例 #11
0
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))