def browse(request, microsite=None): general_subjects_facets = dict(get_facets_for_field("general_subjects")) general_subjects = list(GeneralSubject.objects.values("id", "slug", "name")) for o in general_subjects: o["count"] = general_subjects_facets.get(unicode(o["id"]), 0) grade_levels_facets = dict(get_facets_for_field("grade_levels")) grade_levels = list(GradeLevel.objects.values("id", "slug", "name")) for o in grade_levels: o["count"] = grade_levels_facets.get(unicode(o["id"]), 0) course_material_types_facets = dict(get_facets_for_field("course_material_types")) course_material_types = list(CourseMaterialType.objects.values("id", "slug", "name")) course_material_types_col1 = [] course_material_types_col2 = [] for i, o in enumerate(course_material_types): o["count"] = course_material_types_facets.get(unicode(o["id"]), 0) if i < (len(course_material_types) / 2 + len(course_material_types) % 2): course_material_types_col1.append(o) else: course_material_types_col2.append(o) page_title = u"Browse OER Materials" breadcrumbs = [{"url": reverse("materials:browse"), "title": u"OER Materials"}] return direct_to_template(request, "materials/browse.html", locals())
def frontpage(request): keywords = get_facets_for_field("keywords") if len(keywords) > MAX_TAGS: keywords = keywords[:MAX_TAGS] tagcloud = get_tag_cloud(dict(keywords), max_font=4, min_font=0, average_font=1) for keyword in tagcloud: name = get_name_from_slug(Keyword, keyword["slug"]) or \ get_name_from_slug(Tag, keyword["slug"]) or \ keyword["slug"] keyword["name"] = name general_subjects_facets = dict(get_facets_for_field("general_subjects")) general_subjects = list(GeneralSubject.objects.values("id", "slug", "name")) for s in general_subjects: s["count"] = general_subjects_facets.get(unicode(s["id"]), 0) grade_levels_facets = dict(get_facets_for_field("grade_levels")) grade_levels = list(GradeLevel.objects.values("id", "slug", "name")) for s in grade_levels: s["count"] = grade_levels_facets.get(unicode(s["id"]), 0) slides = Slide.objects.filter(microsite=None) microsites = Microsite.objects.all() microsites_ids = tuple(microsites.values_list("id", flat=True)) featured_k12 = SearchQuerySet().filter(featured=True, grade_levels__in=(1, 2)).exclude(microsites__in=microsites_ids).order_by("-featured_on").load_all()[:3] featured_k12 = [r.object for r in featured_k12 if r] featured_highered = SearchQuerySet().filter(featured=True, grade_levels=3).exclude(microsites__in=microsites_ids).order_by("-featured_on").load_all()[:3] featured_highered = [r.object for r in featured_highered if r] resource_number = SearchQuerySet().filter(workflow_state=PUBLISHED_STATE).count() return direct_to_template(request, "frontpage.html", dict(tagcloud=tagcloud, general_subjects=general_subjects, grade_levels=grade_levels, microsites=microsites, tweets=get_tweets(), slides=slides, featured_k12=featured_k12, featured_highered=featured_highered, resource_number=resource_number, ))
def community(request): community_topics_facets = dict(get_facets_for_field("community_topics")) community_topics = list(CommunityTopic.objects.values("id", "slug", "name")) for o in community_topics: o["count"] = community_topics_facets.get(unicode(o["id"]), 0) community_types_facets = dict(get_facets_for_field("community_types")) community_types = list(CommunityType.objects.values("id", "slug", "name")) for o in community_types: o["count"] = community_types_facets.get(unicode(o["id"]), 0) community_types = [o for o in community_types if o["count"]] page_title = u"OER Community" breadcrumbs = [{"url": reverse("materials:community"), "title": u"OER Community"}] return direct_to_template(request, "materials/community.html", locals())
def providers(request, microsite=None): course_collections_facets = dict(get_facets_for_field("collection", Course)) course_collections = list(Collection.objects.order_by("slug").values("id", "slug", "name")) for o in course_collections: o["count"] = course_collections_facets.get(unicode(o["id"]), 0) course_collections = [o for o in course_collections if o["count"]] library_collections_facets = dict(get_facets_for_field("collection", Library)) library_collections = list(Collection.objects.order_by("slug").values("id", "slug", "name")) for o in library_collections: o["count"] = library_collections_facets.get(unicode(o["id"]), 0) library_collections = [o for o in library_collections if o["count"]] page_title = u"Browse Collection Providers" breadcrumbs = [{"url": reverse("materials:browse"), "title": u"OER Materials"}] return direct_to_template(request, "materials/browse-providers.html", locals())