Exemple #1
0
def module_five(request, path):
    if not demographic_survey_complete(request):
        hierarchy = get_hierarchy('demographic')
        return HttpResponseRedirect(hierarchy.get_root().get_absolute_url())

    hierarchy = get_hierarchy('module-five')
    return process_page(request, path, hierarchy)
    def setUp(self):
        self.client = Client()

        self.hierarchy = get_hierarchy("a", "/pages/a/")
        self.root = self.hierarchy.get_root()
        self.root.add_child_section_from_dict({
            'label': 'Section 1',
            'slug': 'section-1',
            'pageblocks': [],
            'children': [],
        })

        self.hierarchy_b = get_hierarchy("b", "/pages/b/")
        root = self.hierarchy_b.get_root()
        root.add_child_section_from_dict({
            'label': 'Section 1',
            'slug': 'section-1',
            'pageblocks': [],
            'children': [],
        })

        self.user = UserFactory()
        self.client.login(username=self.user.username, password="******")

        self.superuser = UserFactory(is_superuser=True)
Exemple #3
0
def dashboard(request):
    # full module listing available for logged in users
    return dict(
        root=get_hierarchy("main").get_root(),
        dashboard_info=DashboardInfo.objects.all(),
        module_type=ModuleType.objects.all(),
        section_css=SectionCss.objects.all())
Exemple #4
0
def edit_lab(request, id):
    lab = get_object_or_404(Lab, id=id)
    section = lab.pageblock().section
    h = get_hierarchy()
    return render(request, 'exercises/edit_lab.html',
                  dict(lab=lab, section=section,
                       root=h.get_root()))
Exemple #5
0
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()))
Exemple #6
0
def edit_quiz(request, id):
    quiz = get_object_or_404(Quiz, id=id)
    section = quiz.pageblock().section
    h = get_hierarchy()
    return render(request, 'quiz/edit_quiz.html',
                  dict(quiz=quiz, section=section,
                       root=h.get_root()))
Exemple #7
0
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())
Exemple #8
0
def session(request,id):
    s = get_object_or_404(Session,id=id)
    h = get_hierarchy()
    return dict(session=s,
                sessions=Session.objects.filter(user=request.user),
                categories=Category.objects.all(),
                root = h.get_root()
                )
Exemple #9
0
def session(request, id):
    s = get_object_or_404(Session, id=id)
    h = get_hierarchy()
    return render(request, 'healthhabitplan/session.html',
                  dict(session=s,
                       sessions=Session.objects.filter(user=request.user),
                       categories=Category.objects.all(),
                       root=h.get_root()))
Exemple #10
0
def has_submitted_pretest(the_user, hierarchy="main"):
    h = get_hierarchy(hierarchy)
    the_pretest_section = Section.objects.get(
        sectionpreference__preference__slug=settings.PRETEST_PREF_SLUG,
        hierarchy=h)
    for s in Submission.objects.filter(user=the_user):
        if s.quiz.pageblock().section == the_pretest_section:
            return True
    return False
Exemple #11
0
def get_pretest(hierarchy="main"):
    h = get_hierarchy(hierarchy)
    try:
        return Pretest(
            Section.objects.get(
                hierarchy=h,
                sectionpreference__preference__slug='pre-test'))
    except Section.DoesNotExist:
        return NullPretest()
Exemple #12
0
    def get_context_data(self, **kwargs):
        context = super(InstructorPage, self).get_context_data(**kwargs)
        h = get_hierarchy('labs')
        root = h.get_root()
        all_modules = root.get_children()
        context['students'] = User.objects.all().order_by('last_name')
        context['all_modules'] = all_modules

        return context
Exemple #13
0
 def setUp(self):
     self.h = get_hierarchy("main", "/pages/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict({
         'label': 'Section 1',
         'slug': 'section-1',
         'pageblocks': [],
         'children': [],
     })
Exemple #14
0
    def get_context_data(self, **kwargs):
        context = super(InstructorPage, self).get_context_data(**kwargs)
        h = get_hierarchy("labs")
        root = h.get_root()
        all_modules = root.get_children()
        context["students"] = User.objects.all().order_by("last_name")
        context["all_modules"] = all_modules

        return context
Exemple #15
0
 def setUp(self):
     self.h = get_hierarchy("main", "/pages/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict(
         {
             'label': 'Section 1',
             'slug': 'section-1',
             'pageblocks': [],
             'children': [],
         })
Exemple #16
0
 def setUp(self):
     ModuleFactory("main", "/pages/main/")
     self.hierarchy = get_hierarchy(name='main')
     self.section = self.hierarchy.get_root().get_first_leaf()
     self.grp_usr_profile = GroupUpFactory()
     self.grp_usr_profile.user.set_password("test")
     self.grp_usr_profile.user.save()
     self.client = Client()
     self.client.login(
         username=self.grp_usr_profile.user.username,
         password="******")
Exemple #17
0
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())
Exemple #18
0
 def setUp(self):
     self.h = get_hierarchy("main", "/pages/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict({
         'label': 'Section 1',
         'slug': 'section-1',
         'pageblocks': [],
         'children': [],
     })
     self.u = User.objects.create(username="******")
     self.u.set_password("test")
     self.u.save()
     self.client.login(username="******", password="******")
Exemple #19
0
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()))
Exemple #20
0
 def setUp(self):
     self.h = get_hierarchy("main", "/pages/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict(
         {
             'label': 'Section 1',
             'slug': 'section-1',
             'pageblocks': [],
             'children': [],
         })
     self.u = User.objects.create(username="******")
     self.u.set_password("test")
     self.u.save()
     self.client.login(username="******", password="******")
    def test_user(self):
        hierarchy = get_hierarchy("a", "/pages/a/")
        root = hierarchy.get_root()
        root.add_child_section_from_dict({
            'label': 'Section 1',
            'slug': 'section-1',
            'pageblocks': [],
            'children': [],
        })

        user = UserFactory()
        self.assertTrue(
            self.client.login(username=user.username, password="******"))
        response = self.client.get('/')
        self.assertEquals(response.status_code, 302)
    def setUp(self):
        self.hierarchy_a = get_hierarchy("a", "/pages/a/")
        root = self.hierarchy_a.get_root()
        root.add_child_section_from_dict({
            'label': 'Section 1',
            'slug': 'section-1',
            'pageblocks': [],
            'children': [],
        })

        super(YouTubeReportColumnTest, self).setUp()

        self.column = YouTubeReportColumn(self.hierarchy_a, 'avideo', 'atitle')

        self.user = UserFactory()
Exemple #23
0
 def setUp(self):
     self.c = Client()
     self.h = get_hierarchy("labs", "/pages/labs/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict(
         {
             'label': 'Section 1',
             'slug': 'section-1',
             'pageblocks': [],
             'children': [],
         })
     self.staff = User.objects.create(username="******")
     self.staff.set_password("test")
     self.staff.is_staff = True
     self.staff.save()
     self.c.login(username="******", password="******")
Exemple #24
0
 def setUp(self):
     self.client = Client()
     self.h = get_hierarchy("main", "/pages/main/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict(
         {
             'label': 'Section 1',
             'slug': 'section-1',
             'pageblocks': [],
             'children': [],
         })
     self.case = CaseFactory()
     self.profile = AdminUpFactory()
     self.gu = GroupUpFactory()
     self.cohort = CohortFactory()
     self.client.login(username=self.profile.user.username, password='******')
Exemple #25
0
 def setUp(self):
     self.c = Client()
     self.h = get_hierarchy("main", "/pages/main/")
     self.root = self.h.get_root()
     self.root.add_child_section_from_dict(
         {
             'label': 'Section 1',
             'slug': 'section-1',
             'pageblocks': [],
             'children': [],
         })
     self.grp_usr_profile = GroupUpFactory()
     self.grp_usr_profile.user.set_password("test")
     self.grp_usr_profile.user.save()
     self.c.login(
         username=self.grp_usr_profile.user.username,
         password="******")
Exemple #26
0
def index(request):
    """Need to determine here whether to redirect
    to profile creation or registraion and profile creation"""
    try:
        profile = UserProfile.objects.get(user=request.user)
    except UserProfile.DoesNotExist:
        profile = None

    if profile is not None and profile.has_consented():
        profile = UserProfile.objects.get(user=request.user)
        hierarchy = get_hierarchy(name=profile.role())
        return {'user': request.user,
                'profile': profile,
                'hierarchy': hierarchy,
                'root': hierarchy.get_root()}
    else:
        return HttpResponseRedirect(reverse('create_profile'))
Exemple #27
0
def primary_nav_sections(profile):
    sections = []
    hierarchy = get_hierarchy()
    modules = hierarchy.get_root().get_children()
    for x in modules:
        sections.append({
            'id':
            x.id,
            'label':
            x.label,
            'url':
            x.get_absolute_url(),
            'locked':
            not is_section_unlocked(profile, x),
            'complete':
            is_section_unlocked(profile, x.get_next_sibling())
        })
    return sections
Exemple #28
0
def index(request):
    """Need to determine here whether to redirect
    to profile creation or registraion and profile creation"""
    try:
        profile = UserProfile.objects.get(user=request.user)
    except UserProfile.DoesNotExist:
        profile = None

    if profile is not None and profile.has_consented():
        profile = UserProfile.objects.get(user=request.user)
        hierarchy = get_hierarchy(name=profile.role())
        return {
            'user': request.user,
            'profile': profile,
            'hierarchy': hierarchy,
            'root': hierarchy.get_root()
        }
    else:
        return HttpResponseRedirect(reverse('create_profile'))
Exemple #29
0
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()))
Exemple #30
0
def import_zip(zipfile):
    if 'site.xml' not in zipfile.namelist():
        raise TypeError("Badly formatted import file")
    if 'version.txt' not in zipfile.namelist():
        raise TypeError("Badly formatted import file")
    if zipfile.read("version.txt") != "1":
        raise TypeError("Badly formatted import file")
    structure = zipfile.read("site.xml")
    structure = etree.fromstring(structure)

    name = structure.get("name")
    base_url = structure.get("base_url")

    hierarchy = get_hierarchy(name=name)
    hierarchy.base_url = base_url
    hierarchy.save()

    for section in structure.getchildren():
        import_node(hierarchy, section, zipfile)

    return hierarchy
Exemple #31
0
def import_zip(zipfile):
    if 'site.xml' not in zipfile.namelist():
        raise TypeError("Badly formatted import file")
    if 'version.txt' not in zipfile.namelist():
        raise TypeError("Badly formatted import file")
    if zipfile.read("version.txt") != "1":
        raise TypeError("Badly formatted import file")
    structure = zipfile.read("site.xml")
    structure = etree.fromstring(structure)

    name = structure.get("name")
    base_url = structure.get("base_url")

    hierarchy = get_hierarchy(name=name)
    hierarchy.base_url = base_url
    hierarchy.save()

    for section in structure.getchildren():
        import_node(hierarchy, section, zipfile)

    return hierarchy
Exemple #32
0
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(),
            ),
        )
Exemple #33
0
def edit_page(request,path):
    section = get_section_from_path(path)
    h = get_hierarchy()
    return dict(section=section,
                module=get_module(section),
                root=h.get_root())
Exemple #34
0
 def render(self, context):
     h = get_hierarchy(self.hierarchy)
     r = h.get_root()
     context[self.var_name] = r
     return ''
 def test_dont_care_about_type(self):
     h = get_hierarchy()
     h2 = get_hierarchy(h)
     self.assertEqual(h.id, h2.id)
Exemple #36
0
def demographic(request, path):
    hierarchy = get_hierarchy('demographic')
    return process_page(request, path, hierarchy)
Exemple #37
0
def reports(request, path):
    if not request.user.is_staff:
        return HttpResponseForbidden()

    hierarchy = get_hierarchy('reports')
    return process_page(request, path, hierarchy)
Exemple #38
0
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()))
Exemple #39
0
def all_sessions(request):
    h = get_hierarchy()
    sessions = Session.objects.filter(user=request.user)
    return render(request, 'healthhabitplan/all_sessions.html',
                  dict(sessions=sessions, categories=Category.objects.all(),
                       root=h.get_root()))
Exemple #40
0
def edit_lab(request, id):
    lab = get_object_or_404(Lab, id=id)
    section = lab.pageblock().section
    h = get_hierarchy()
    return render(request, 'exercises/edit_lab.html',
                  dict(lab=lab, section=section, root=h.get_root()))
 def test_default_args(self):
     h = get_hierarchy()
     self.assertEqual(h.name, "main")
     self.assertEqual(h.base_url, "/")
Exemple #42
0
 def render(self,context):
     h = get_hierarchy(self.hierarchy)
     r = h.get_root()
     context[self.var_name] = r
     return ''
Exemple #43
0
def all_sessions(request):
    user = request.user
    h = get_hierarchy()
    sessions = Session.objects.filter(user=request.user)
    return dict(sessions=sessions, categories=Category.objects.all(), root = h.get_root())
Exemple #44
0
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_idempotent(self):
     self.assertEqual(Hierarchy.objects.count(), 0)
     get_hierarchy()
     self.assertEqual(Hierarchy.objects.count(), 1)
     get_hierarchy()
     self.assertEqual(Hierarchy.objects.count(), 1)