Example #1
0
def resource_list(request, group_id, app_id=None, page_no=1):
    """
	* Renders a list of all 'Resources' available within the database (except eBooks).
	"""

    is_video = request.GET.get('is_video', "")

    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)

    if app_id is None:
        app_id = str(app._id)

    # # Code for displaying user shelf
    # shelves = []
    # shelf_list = {}
    # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })

    # if auth:
    #   has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' })
    #   dbref_has_shelf = has_shelf_RT.get_dbref()
    #   shelf = collection_tr.Triple.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type': dbref_has_shelf })
    #   shelf_list = {}

    #   if shelf:
    # 	for each in shelf:
    # 		shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)})
    # 		shelves.append(shelf_name)

    # 		shelf_list[shelf_name.name] = []
    # 		for ID in shelf_name.collection_set:
    # 		  shelf_item = node_collection.one({'_id': ObjectId(ID) })
    # 		  shelf_list[shelf_name.name].append(shelf_item.name)

    #   else:
    # 	shelves = []
    # # End of user shelf

    # pandoravideoCollection = node_collection.find({'member_of':pandora_video_st._id, 'group_set': ObjectId(group_id) })

    # if e_library_GST._id == ObjectId(app_id):
    title = e_library_GST.name
    file_id = GST_FILE._id
    datavisual = []
    no_of_objs_pp = 24

    # filters = request.POST.get("filters", "")
    # filters = json.loads(filters)
    # filters = get_filter_querydict(filters)

    # print "filters in E-Library : ", filters

    # declaring empty (deliberately to avoid errors), query dict to be pass-on in query
    query_dict = []
    # query_dict = filters

    selfilters = urllib.unquote(request.GET.get('selfilters', ''))
    if selfilters:
        selfilters = json.loads(selfilters)
        query_dict = get_filter_querydict(selfilters)

    query_dict.append({'attribute_set.educationaluse': {'$ne': 'eBooks'}})

    # files = node_collection.find({
    # 								'member_of': ObjectId(GST_FILE._id),
    # 								'_type': 'File',
    # 								'fs_file_ids': {'$ne': []},
    # 								'group_set': ObjectId(group_id),
    # 								'$and': query_dict,
    # 								'$or': [
    # 										{ 'access_policy': u"PUBLIC" },
    # 										{ '$and': [
    # 													{'access_policy': u"PRIVATE"},
    # 													{'created_by': request.user.id}
    # 												]
    # 										}
    # 									]

    # 								}).sort("last_update", -1)

    files = node_collection.find({
        # 'member_of': {'$in': [GST_FILE._id, GST_PAGE._id]},
        'member_of': {
            '$in': [GST_FILE._id]
        },
        # '_type': 'File',
        # 'fs_file_ids': {'$ne': []},
        'group_set': {
            '$all': [ObjectId(group_id)]
        },
        '$and':
        query_dict,
        '$or': [{
            'access_policy': u"PUBLIC"
        }, {
            '$and': [{
                'access_policy': u"PRIVATE"
            }, {
                'created_by': request.user.id
            }]
        }]
    }).sort("last_update", -1)

    # print "files.count : ", files.count()

    # pageCollection=node_collection.find({'member_of':GST_PAGE._id, 'group_set': ObjectId(group_id),
    # 									'$or': [
    # 									{ 'access_policy': u"PUBLIC" },
    # 									{ '$and': [
    # 												{'access_policy': u"PRIVATE"},
    # 												{'created_by': request.user.id}
    # 											]
    # 									}
    # 								],
    # 							'type_of': {'$in': [wiki_page._id]}
    # 							}).sort("last_update", -1)

    educationaluse_stats = {}

    if files:
        eu_list = []  # count
        for each in files:
            eu_list += [
                i.get("educationaluse") for i in each.attribute_set
                if i.has_key("educationaluse")
            ]

        files.rewind()

        if set(eu_list):
            if len(set(eu_list)) > 1:
                educationaluse_stats = dict(
                    (x, eu_list.count(x)) for x in set(eu_list))
            elif len(set(eu_list)) == 1:
                educationaluse_stats = {eu_list[0]: eu_list.count(eu_list[0])}
            educationaluse_stats["all"] = files.count()

        # print educationaluse_stats
        result_paginated_cur = files
        result_pages = paginator.Paginator(result_paginated_cur, page_no,
                                           no_of_objs_pp)

    collection_pages_cur = node_collection.find({
        'member_of': {
            '$in': [GST_FILE._id]
        },
        'group_set': {
            '$all': [ObjectId(group_id)]
        },
        '$and':
        query_dict,
        '$or': [{
            'access_policy': u"PUBLIC"
        }, {
            '$and': [{
                'access_policy': u"PRIVATE"
            }, {
                'created_by': request.user.id
            }]
        }],
        'collection_set': {
            '$exists': "true",
            '$not': {
                '$size': 0
            }
        }
    }).sort("last_update", -1)

    coll_page_count = collection_pages_cur.count(
    ) if collection_pages_cur else 0
    collection_pages = paginator.Paginator(collection_pages_cur, page_no,
                                           no_of_objs_pp)

    datavisual.append({
        "name": "Doc",
        "count": educationaluse_stats.get("Documents", 0)
    })
    datavisual.append({
        "name": "Page",
        "count": educationaluse_stats.get("Pages", 0)
    })
    datavisual.append({
        "name": "Image",
        "count": educationaluse_stats.get("Images", 0)
    })
    datavisual.append({
        "name": "Video",
        "count": educationaluse_stats.get("Videos", 0)
    })
    datavisual.append({
        "name": "Interactives",
        "count": educationaluse_stats.get("Interactives", 0)
    })
    datavisual.append({
        "name": "Audios",
        "count": educationaluse_stats.get("Audios", 0)
    })
    datavisual.append({
        "name": "eBooks",
        "count": educationaluse_stats.get("eBooks", 0)
    })
    if collection_pages_cur:
        datavisual.append({"name": "Collections", "count": coll_page_count})
    datavisual = json.dumps(datavisual)

    return render_to_response(
        "ndf/resource_list.html",
        {
            'title': title,
            'app': e_library_GST,
            'appId': app._id,
            "app_gst": app,
            # 'already_uploaded': already_uploaded,'shelf_list': shelf_list,'shelves': shelves,
            'files': files,
            "detail_urlname": "file_detail",
            'ebook_pages': educationaluse_stats.get("eBooks", 0),
            # 'page_count': pageCollection.count(),
            # 'page_nodes':pageCollection
            'file_pages': result_pages,
            'image_pages': educationaluse_stats.get("Images", 0),
            'interactive_pages': educationaluse_stats.get("Interactives", 0),
            'educationaluse_stats': json.dumps(educationaluse_stats),
            'doc_pages': educationaluse_stats.get("Documents", 0),
            'video_pages': educationaluse_stats.get("Videos", 0),
            'audio_pages': educationaluse_stats.get("Audios", 0),
            'collection_pages': collection_pages,
            'collection': collection_pages_cur,
            'groupid': group_id,
            'group_id': group_id,
            "datavisual": datavisual,
        },
        context_instance=RequestContext(request))
Example #2
0
def ebook_listing(request, group_id, page_no=1):
    from gnowsys_ndf.settings import GSTUDIO_NO_OF_OBJS_PP
    import urllib

    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)

    selfilters = urllib.unquote(request.GET.get('selfilters', ''))
    # print "===\n", selfilters, "===\n"
    query_dict = [{}]
    if selfilters:
        selfilters = json.loads(selfilters)
        query_dict = get_filter_querydict(selfilters)
    # else:
    # 	query_dict.append({'collection_set': {'$exists': "true", '$not': {'$size': 0} }})

    # print "\n----\n", query_dict
    # all_ebooks = node_collection.find({
    # 		# "_type": "File",
    # 		# "attribute_set.educationaluse": "eBooks",
    # 		'$and': query_dict,
    # 		'collection_set': {'$exists': "true", '$not': {'$size': 0} }
    # 	})

    all_ebooks = node_collection.find({
        'member_of': {
            '$in': [GST_FILE._id, GST_PAGE._id]
        },
        # '_type': 'File',
        # 'fs_file_ids': {'$ne': []},
        'group_set': {
            '$in': [ObjectId(group_id)]
        },
        'attribute_set.educationaluse':
        'eBooks',
        '$and':
        query_dict,
        '$or': [{
            'access_policy': u"PUBLIC"
        }, {
            '$and': [{
                'access_policy': u"PRIVATE"
            }, {
                'created_by': request.user.id
            }]
        }],
        'collection_set': {
            '$exists': "true",
            '$not': {
                '$size': 0
            }
        }
    }).sort("last_update", -1)

    ebooks_page_info = paginator.Paginator(all_ebooks, page_no,
                                           GSTUDIO_NO_OF_OBJS_PP)

    return render_to_response("ndf/ebook.html", {
        "all_ebooks": all_ebooks,
        "ebook_gst": ebook_gst,
        "page_info": ebooks_page_info,
        "title": "eBooks",
        "group_id": group_id,
        "groupid": group_id
    },
                              context_instance=RequestContext(request))
Example #3
0
def elib_paged_file_objs(request, group_id, filetype, page_no):
    '''
	Method to implement pagination in File and E-Library app.
	'''
    if request.is_ajax() and request.method == "POST":
        group_name, group_id = get_group_name_id(group_id)

        no_of_objs_pp = 24
        result_pages = None

        filters = request.POST.get("filters", "")
        filters = json.loads(filters)
        filters = get_filter_querydict(filters)

        # print "filters in E-Library : ", filters

        # declaring empty (deliberately to avoid errors), query dict to be pass-on in query
        # query_dict = [{}]
        query_dict = filters

        selfilters = urllib.unquote(request.GET.get('selfilters', ''))
        if selfilters:
            selfilters = json.loads(selfilters)
            query_dict = get_filter_querydict(selfilters)

        query_dict.append({'attribute_set.educationaluse': {'$ne': u'eBooks'}})

        detail_urlname = "file_detail"
        if filetype != "all":
            # if filetype == "Pages":
            # 	detail_urlname = "page_details"
            # 	result_cur = node_collection.find({'member_of': GST_PAGE._id,
            #                                  '_type': 'GSystem',
            #                                  'group_set': {'$all': [ObjectId(group_id)]},
            #                                  '$or': [
            #                                      {'access_policy': u"PUBLIC"},
            #                                      {'$and': [
            #                                          {'access_policy': u"PRIVATE"},
            #                                          {'created_by': request.user.id}
            #                                      ]
            #                                   }
            #                                  ]
            #                              }).sort("last_update", -1)

            # 	result_paginated_cur = result_cur
            # 	result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp)

            # elif filetype == "Collections":
            if filetype == "Collections":
                pass
                # detail_urlname = "page_details"
                # result_cur = node_collection.find({
                # 					'member_of': {'$in': [GST_FILE._id, GST_PAGE._id]},
                #                                 'group_set': {'$all': [ObjectId(group_id)]},
                #                                 '$or': [
                #                                     {'access_policy': u"PUBLIC"},
                #                                     {'$and': [
                #                                         {'access_policy': u"PRIVATE"},
                #                                         {'created_by': request.user.id}
                #                                     ]
                #                                  }
                #                                 ],
                #                                 'collection_set': {'$exists': "true", '$not': {'$size': 0} }
                #                             }).sort("last_update", -1)
                # # print "=====================", result_cur.count()

                # result_paginated_cur = result_cur
                # result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp)
                # # print "=====================", result_pages

                # query_dict.append({ 'collection_set': {'$exists': "true", '$not': {'$size': 0} } })
            else:
                query_dict.append({"attribute_set.educationaluse": filetype})

        # print filters
        # if filters:
        # 	temp_list = []
        # 	for each in filters:
        # 		filter_grp = each["or"]
        # 		for each_filter in filter_grp:
        # 			temp_dict = {}
        # 			each_filter["selFieldText"] = cast_to_data_type(each_filter["selFieldText"], each_filter["selFieldPrimaryType"])

        # 			if each_filter["selFieldPrimaryType"] == unicode("list"):
        # 				each_filter["selFieldText"] = {"$in": each_filter["selFieldText"]}

        # 			if each_filter["selFieldGstudioType"] == "attribute":

        # 				temp_dict["attribute_set." + each_filter["selFieldValue"]] = each_filter["selFieldText"]
        # 				temp_list.append(temp_dict)
        # 				# print "temp_list : ", temp_list
        # 			elif each_filter["selFieldGstudioType"] == "field":
        # 				temp_dict[each_filter["selFieldValue"]] = each_filter["selFieldText"]
        # 				temp_list.append(temp_dict)

        # 		if temp_list:
        # 			query_dict.append({ "$or": temp_list})

        # print "query_dict : ", query_dict

        files = node_collection.find({
            'member_of': {
                '$in': [GST_FILE._id]
            },
            # 'member_of': {'$in': [GST_FILE._id, GST_PAGE._id]},
            # '_type': 'File',
            # 'fs_file_ids': {'$ne': []},
            'group_set': {
                '$all': [ObjectId(group_id)]
            },
            '$and':
            query_dict,
            '$or': [{
                'access_policy': u"PUBLIC"
            }, {
                '$and': [{
                    'access_policy': u"PRIVATE"
                }, {
                    'created_by': request.user.id
                }]
            }]
        }).sort("last_update", -1)

        educationaluse_stats = {}
        # print "files_count: ", files.count()

        # if filetype == "Pages":
        # 	filter_result = "True" if (result_cur.count() > 0) else "False"
        # else:
        if files:  # and not result_pages:
            # print "=======", educationaluse_stats

            eu_list = []  # count
            collection_set_count = 0
            for each in files:
                eu_list += [
                    i.get("educationaluse") for i in each.attribute_set
                    if i.has_key("educationaluse")
                ]
                collection_set_count += 1 if each.collection_set else 0

            files.rewind()

            if set(eu_list):
                if len(set(eu_list)) > 1:
                    educationaluse_stats = dict(
                        (x, eu_list.count(x)) for x in set(eu_list))
                elif len(set(eu_list)) == 1:
                    educationaluse_stats = {
                        eu_list[0]: eu_list.count(eu_list[0])
                    }
                educationaluse_stats["all"] = files.count()
                educationaluse_stats["Collections"] = collection_set_count

            result_paginated_cur = files
            result_pages = paginator.Paginator(result_paginated_cur, page_no,
                                               no_of_objs_pp)

        filter_result = "True" if (files.count() > 0) else "False"

        if filetype == "Collections":
            detail_urlname = "page_details"
            result_cur = node_collection.find({
                'member_of': {
                    '$in': [GST_FILE._id, GST_PAGE._id]
                },
                'group_set': {
                    '$all': [ObjectId(group_id)]
                },
                '$and':
                query_dict,
                '$or': [{
                    'access_policy': u"PUBLIC"
                }, {
                    '$and': [{
                        'access_policy': u"PRIVATE"
                    }, {
                        'created_by': request.user.id
                    }]
                }],
                'collection_set': {
                    '$exists': "true",
                    '$not': {
                        '$size': 0
                    }
                }
            }).sort("last_update", -1)
            # print "=====================", result_cur.count()

            result_paginated_cur = result_cur
            result_pages = paginator.Paginator(result_paginated_cur, page_no,
                                               no_of_objs_pp)

        # if filetype == "all":
        #     if files:
        #         result_paginated_cur = files
        #         result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp)

        # # else:
        # elif filetype == "Documents":
        #     d_Collection = node_collection.find({'_type': "GAttribute", 'attribute_type.$id': gattr._id,"subject": {'$in': coll} ,"object_value": "Documents"}).sort("last_update", -1)

        #     doc = []
        #     for e in d_Collection:
        #         doc.append(e.subject)

        #     result_paginated_cur = node_collection.find({ '$or':[{'_id': {'$in': doc}},

        #                 {'member_of': {'$nin': [ObjectId(GST_IMAGE._id), ObjectId(GST_VIDEO._id),ObjectId(pandora_video_st._id)]},
        #                                     '_type': 'File', 'group_set': {'$all': [ObjectId(group_id)]},
        #                                     # 'mime_type': {'$not': re.compile("^audio.*")},
        #                                     '$or': [
        #                                           {'access_policy': u"PUBLIC"},
        #                                             {'$and': [{'access_policy': u"PRIVATE"}, {'created_by': request.user.id}]}
        #                                            ]
        #                                     }]

        #         }).sort("last_update", -1)

        #     result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp)

        # print "educationaluse_stats: ", educationaluse_stats

        return render_to_response(
            "ndf/file_list_tab.html", {
                "filter_result": filter_result,
                "group_id": group_id,
                "group_name_tag": group_id,
                "groupid": group_id,
                'title': "E-Library",
                "educationaluse_stats": json.dumps(educationaluse_stats),
                "resource_type": result_paginated_cur,
                "detail_urlname": detail_urlname,
                "filetype": filetype,
                "res_type_name": "",
                "page_info": result_pages
            },
            context_instance=RequestContext(request))
Example #4
0
def get_filtered_topic_resources(request, group_id, node_id):

    selfilters = request.POST.get('filters', None)
    query_dict = get_filter_querydict(
        json.loads(selfilters)) if selfilters else {}
    # print query_dict

    node_rel_cur = node_collection.one(
        {
            '_id': ObjectId(node_id),
            'relation_set.taught_by': {
                '$exists': 'true'
            }
        }, {
            'relation_set.taught_by': 1,
            '_id': 0
        })

    node_rel_list = node_rel_cur.relation_set[0].get('taught_by', [])

    filtered_taught_by_res = node_collection.find({
        '_id': {
            '$in': node_rel_list
        },
        '$and': query_dict
    })

    primary_lang_resources = {}
    other_lang_resources = {}
    all_educationaluse = []
    language_selected = list(get_language_tuple(request.LANGUAGE_CODE))
    # print language_selected,"request.LANGUAGE_CODE: ", request.LANGUAGE_CODE

    # print filtered_taught_by_res.count()
    for each_res in filtered_taught_by_res:
        # if each_res.language :
        #     pass
        att_set_dict = get_dict_from_list_of_dicts(each_res.attribute_set)
        educationaluse = att_set_dict['educationaluse']

        all_educationaluse.append(educationaluse)

        if language_selected == each_res.language:
            temp = primary_lang_resources.get(educationaluse, [])
            temp.append(each_res)
            primary_lang_resources[educationaluse] = temp
            temp = ""
        else:
            temp = other_lang_resources.get(educationaluse, [])
            temp.append(each_res)
            other_lang_resources[educationaluse] = temp
            temp = ""

    # print "primary_lang_resources : ", primary_lang_resources
    # print "other_lang_resources: ", other_lang_resources

    all_educationaluse = list(set(all_educationaluse))

    # data = json.dumps({'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse })

    # return HttpResponse(data)

    # return HttpResponse({'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse })

    return render_to_response(
        'ndf/topic_resources_listing.html',
        {
            'primary_lang_resources': primary_lang_resources,
            'other_lang_resources': other_lang_resources,
            'all_educationaluse': all_educationaluse,
            # 'node': obj,'app_id': app_id,"theme_id": theme_id, "prior_obj": prior_obj,
            'group_id': group_id,
            'groupid': group_id,
            'filtered_topics': 'filtered_topics'
            # 'shelves': shelves,'topic': topic, 'nav_list':nav_li,
            # 'shelf_list': shelf_list,'breadcrumbs_list': breadcrumbs_list
        },
        context_instance=RequestContext(request))
Example #5
0
def resource_list(request, group_id, app_id=None, page_no=1):
    """
	* Renders a list of all 'Resources' available within the database (except eBooks).
	"""
    print "inside resource_list of e-library "
    is_video = request.GET.get('is_video', "")

    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)
    print "group name and id", group_name, group_id
    if app_id is None:
        app_id = str(app[0].id)

    # # Code for displaying user shelf
    # shelves = []
    # shelf_list = {}
    # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })

    # if auth:
    #   has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' })
    #   dbref_has_shelf = has_shelf_RT.get_dbref()
    #   shelf = collection_tr.Triple.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type': dbref_has_shelf })
    #   shelf_list = {}

    #   if shelf:
    # 	for each in shelf:
    # 		shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)})
    # 		shelves.append(shelf_name)

    # 		shelf_list[shelf_name.name] = []
    # 		for ID in shelf_name.collection_set:
    # 		  shelf_item = node_collection.one({'_id': ObjectId(ID) })
    # 		  shelf_list[shelf_name.name].append(shelf_item.name)

    #   else:
    # 	shelves = []
    # # End of user shelf

    # pandoravideoCollection = node_collection.find({'member_of':pandora_video_st._id, 'group_set': ObjectId(group_id) })

    # if e_library_GST._id == ObjectId(app_id):
    title = e_library_GST[0].name
    file_id = GST_FILE[0].id
    datavisual = []
    no_of_objs_pp = 5

    # filters = request.POST.get("filters", "")
    # filters = json.loads(filters)
    # filters = get_filter_querydict(filters)

    # print "filters in E-Library : ", filters

    # declaring empty (deliberately to avoid errors), query dict to be pass-on in query
    query_dict = []
    # query_dict = filters

    selfilters = urllib.unquote(request.GET.get('selfilters', ''))
    if selfilters:
        print "post fetching filters", selfilters
        selfilters = json.loads(selfilters)
        print "post json loads :", selfilters
        query_dict = get_filter_querydict(selfilters)
    print "query dict", query_dict

    lists = esearch.es_filters(query_dict)
    print "post esearch", lists
    strconcat1 = ""
    for value in lists:
        strconcat1 = strconcat1 + 'eval(str("' + value + '")),'
    # query_dict.append({'attribute_set.educationaluse': {'$ne': 'eBooks'}})

    # files = node_collection.find({
    # 								'member_of': ObjectId(GST_FILE._id),
    # 								'_type': 'File',
    # 								'fs_file_ids': {'$ne': []},
    # 								'group_set': ObjectId(group_id),
    # 								'$and': query_dict,
    # 								'$or': [
    # 										{ 'access_policy': u"PUBLIC" },
    # 										{ '$and': [
    # 													{'access_policy': u"PRIVATE"},
    # 													{'created_by': request.user.id}
    # 												]
    # 										}
    # 									]

    # 								}).sort("last_update", -1)

    q = Q('bool',
          must=[
              Q('terms', member_of=[GST_FILE[0].id, GST_JSMOL[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC')
          ],
          must_not=[Q('match', attribute_set__educationaluse='ebooks')])

    allfiles1 = (Search(using=es, index=index,
                        doc_type=doc_type).query(q)).sort(
                            {"last_update": {
                                "order": "desc"
                            }})

    allfiles2 = allfiles1.execute()

    educationaluse_stats = {}
    print "all_files:", allfiles1

    q = Q('bool',
          must=[
              Q('terms', member_of=[GST_FILE[0].id, GST_JSMOL[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('exists', field='collection_set')
          ])
    collection_pages_cur = (Search(using=es, index=index,
                                   doc_type=doc_type).query(q)).sort(
                                       {"last_update": {
                                           "order": "desc"
                                       }})

    if int(page_no) == 1:
        collection_pages_cur = collection_pages_cur[0:5]
    else:
        temp = (int(page_no) - 1) * 5
        collection_pages_cur = collection_pages_cur[temp:temp + 5]

    paginator = Paginator(collection_pages_cur, 5)

    coll_page_count = collection_pages_cur.count(
    ) if collection_pages_cur else 0

    # collection_pages_cur = node_collection.find({
    # 								'member_of': {'$in': [GST_FILE[0].id, GST_PAGE[0].id ]},
    #                                    'group_set': {'$all': [ObjectId(group_id)]},
    #                                       # '$and': query_dict,
    #                                    # '$or': [
    #                                    'access_policy': u"PUBLIC",
    #                                    #     {'$and': [
    #                                    #     		 {'access_policy': u"PRIVATE"},
    #                                    #         # {'created_by': request.user.id}
    #                                    #     ]
    #                                    #  }
    #                                    # ],
    #                                    'collection_set': {'$exists': "true", '$not': {'$size': 0} }
    #                                }).sort("last_update", -1)

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', if_file__mime_type='image')
          ])
    allimages1 = (Search(using=es, index=index,
                         doc_type=doc_type).query(q)).sort(
                             {"last_update": {
                                 "order": "desc"
                             }})
    allimages2 = allimages1.execute()
    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', if_file__mime_type='video')
          ])

    allvideos1 = (Search(using=es, index=index,
                         doc_type=doc_type).query(q)).sort(
                             {"last_update": {
                                 "order": "desc"
                             }})

    allvideos2 = allvideos1.execute()

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', if_file__mime_type='audio')
          ])

    allaudios1 = (Search(using=es, index=index,
                         doc_type=doc_type).query(q)).sort(
                             {"last_update": {
                                 "order": "desc"
                             }})

    allaudios2 = allaudios1.execute()

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', name='Handbook'),
              Q('match_phrase', if_file__mime_type='pdf')
          ])

    alldocs1 = (Search(using=es, index=index,
                       doc_type=doc_type).query(q)).sort(
                           {"last_update": {
                               "order": "desc"
                           }})

    alldocs2 = alldocs1.execute()

    q = Q('bool',
          must=[
              Q('match', member_of=gst_module[0].id),
              Q('match', status='PUBLISHED')
          ])

    all_modules = (Search(using=es, index=index,
                          doc_type=doc_type).query(q)).sort(
                              {"last_update": {
                                  "order": "desc"
                              }})

    all_modules2 = all_modules.execute()

    files_new = allfiles1[0:24]

    if int(page_no) == 1:
        files_new = allfiles1[0:24]
    else:
        temp = (int(page_no) - 1) * 24
        files_new = allfiles1[temp:temp + 24]

    if files_new:
        eu_list = []
        if set(eu_list):
            if len(set(eu_list)) > 1:
                educationaluse_stats = dict(
                    (x, eu_list.count(x)) for x in set(eu_list))

            elif len(set(eu_list)) == 1:
                educationaluse_stats = {eu_list[0]: eu_list.count(eu_list[0])}
                educationaluse_stats["all"] = files.count()

        paginator = Paginator(files_new, 24)

        #page_no = request.GET.get('page_no')
        try:
            result_pages = paginator.page(page_no)
        except PageNotAnInteger:
            result_pages = paginator.page(1)
        except EmptyPage:
            result_pages = paginator.page(paginator.num_pages)

    try:
        results = paginator.page(page_no)
    except PageNotAnInteger:
        results = paginator.page(1)
    except EmptyPage:
        results = paginator.page(paginator.num_pages)

    coll_page_count = collection_pages_cur.count(
    ) if collection_pages_cur else 0
    print "coll_page_count", coll_page_count
    # collection_pages = paginator.Paginator(collection_pages_cur, page_no, no_of_objs_pp)

    print "result_pages:", result_pages
    datavisual.append({"name": "Doc", "count": alldocs1.count()})
    datavisual.append({
        "name": "Page",
        "count": educationaluse_stats.get("Pages", 0)
    })
    datavisual.append({"name": "Image", "count": allimages1.count()})
    datavisual.append({"name": "Video", "count": allvideos1.count()})
    datavisual.append({
        "name": "Interactives",
        "count": educationaluse_stats.get("Interactives", 0)
    })
    datavisual.append({"name": "Audios", "count": allaudios1.count()})
    datavisual.append({
        "name": "eBooks",
        "count": educationaluse_stats.get("eBooks", 0)
    })

    if collection_pages_cur:
        datavisual.append({"name": "Collections", "count": coll_page_count})
    datavisual = json.dumps(datavisual)
    print "educational stats:", educationaluse_stats
    return render_to_response(
        "ndf/resource_list.html",
        {
            'title': title,
            'app': e_library_GST[0],
            'appId': app[0].id,
            "app_gst": app[0],
            # 'already_uploaded': already_uploaded,'shelf_list': shelf_list,'shelves': shelves,
            'files': files_new,
            "detail_urlname": "file_detail",
            'ebook_pages': educationaluse_stats.get("eBooks", 0),
            # 'page_count': pageCollection.count(),
            # 'page_nodes':pageCollection
            'file_pages': result_pages,
            'image_pages': allimages1.count(),
            'interactive_pages': educationaluse_stats.get("Interactives", 0),
            'educationaluse_stats': json.dumps(educationaluse_stats),
            'doc_pages': alldocs1.count(),
            'video_pages': allvideos1.count(),
            'audio_pages': allaudios1.count(),
            'collection_pages': results,
            'collection': collection_pages_cur,
            'collection_count': coll_page_count,
            'groupid': group_id,
            'group_id': group_id,
            "datavisual": datavisual,
        },
        context_instance=RequestContext(request))
Example #6
0
def elib_paged_file_objs(request, group_id, filetype, page_no):
    '''
	Method to implement pagination in File and E-Library app.
	'''
    if request.is_ajax() and request.method == "POST":
        group_name, group_id = get_group_name_id(group_id)

        no_of_objs_pp = 5
        result_pages = None
        filetype = filetype.lower()
        filters = request.POST.get("filters", "")
        filters = json.loads(filters)
        filters = get_filter_querydict(filters)
        query_dict = filters

        selfilters = urllib.unquote(request.GET.get('selfilters', ''))
        if selfilters:
            selfilters = json.loads(selfilters)
            query_dict = get_filter_querydict(selfilters)

        # query_dict.append("Q('match',"+t+"=dict(query='"+value+"',type='phrase'))")

        detail_urlname = "file_detail"
        print "filetype:", filetype
        if filetype != 'Module':
            if filetype == 'document':
                print "in Document elif"
                q = Q('bool',
                      must=[
                          Q('terms',
                            member_of=[
                                GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id
                            ]),
                          Q('match', access_policy='PUBLIC'),
                          Q('match_phrase', if_file__mime_type='pdf'),
                          Q('match_phrase', name='Handbook')
                      ])
            else:
                q = Q('bool',
                      must=[
                          Q('terms',
                            member_of=[
                                GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id
                            ]),
                          Q('match', group_set=str(group_id)),
                          Q('match', access_policy='PUBLIC'),
                          Q('match_phrase', if_file__mime_type=filetype)
                      ])
        else:
            q = Q('bool',
                  must=[
                      Q('match', member_of=gst_module[0].id),
                      Q('match', status='PUBLISHED')
                  ])
        allfiletypes1 = (Search(using=es, index=index,
                                doc_type=doc_type).query(q)).sort(
                                    {"last_update": {
                                        "order": "desc"
                                    }})

        allfiletypes2 = allfiletypes1.execute()

        educationaluse_stats = {}

        if int(page_no) == 1:
            files_new = allfiletypes1[0:5]
        else:
            temp = (int(page_no) - 1) * 5
            files_new = allfiletypes1[temp:temp + 5]

        # print "files_count: ", files.count()

        # if filetype == "Pages":
        # 	filter_result = "True" if (result_cur.count() > 0) else "False"
        # else:
        if files_new:  # and not result_pages:
            # print "=======", educationaluse_stats

            eu_list = []  # count
            collection_set_count = 0
            # for each in files_new:
            # 	eu_list += [i.get("educationaluse") for i in each.attribute_set if i.has_key("educationaluse")]
            # 	collection_set_count += 1 if each.collection_set else 0

            # files.rewind()

            if set(eu_list):
                if len(set(eu_list)) > 1:
                    educationaluse_stats = dict(
                        (x, eu_list.count(x)) for x in set(eu_list))
                elif len(set(eu_list)) == 1:
                    educationaluse_stats = {
                        eu_list[0]: eu_list.count(eu_list[0])
                    }
                educationaluse_stats["all"] = files.count()
                educationaluse_stats["Collections"] = collection_set_count

            paginator = Paginator(files_new, 5)

            #page_no = request.GET.get('page_no')
            try:
                result_pages = paginator.page(page_no)
            except PageNotAnInteger:
                result_pages = paginator.page(1)
            except EmptyPage:
                result_pages = paginator.page(paginator.num_pages)

        filter_result = "True" if (allfiletypes1.count() > 0) else "False"

        if filetype == "Collections":
            detail_urlname = "page_details"
            q = Q('bool',
                  must=[
                      Q('terms', member_of=[GST_FILE[0].id, GST_JSMOL[0].id]),
                      Q('match', group_set=str(group_id)),
                      Q('match', access_policy='PUBLIC'),
                      Q('exists', field='collection_set')
                  ])
            collection_pages_cur = (Search(using=es,
                                           index=index,
                                           doc_type=doc_type).query(q)).sort({
                                               "last_update": {
                                                   "order": "desc"
                                               }
                                           })

            # result_cur = node_collection.find({
            # 					'member_of': {'$in': [GST_FILE._id, GST_PAGE._id]},
            #                                 'group_set': {'$all': [ObjectId(group_id)]},
            # 					'$and': query_dict,
            #                                 '$or': [
            #                                     {'access_policy': u"PUBLIC"},
            #                                     {'$and': [
            #                                         {'access_policy': u"PRIVATE"},
            #                                         {'created_by': request.user.id}
            #                                     ]
            #                                  }
            #                                 ],
            #                                 'collection_set': {'$exists': "true", '$not': {'$size': 0} }
            #                             }).sort("last_update", -1)
            # print "=====================", result_cur.count()

            # result_paginated_cur = result_cur
            result_pages = paginator.Paginator(collection_pages_cur, page_no,
                                               no_of_objs_pp)

        # if filetype == "all":
        #     if files:
        #         result_paginated_cur = files
        #         result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp)

        # # else:
        # elif filetype == "Documents":
        #     d_Collection = node_collection.find({'_type': "GAttribute", 'attribute_type': gattr._id,"subject": {'$in': coll} ,"object_value": "Documents"}).sort("last_update", -1)

        #     doc = []
        #     for e in d_Collection:
        #         doc.append(e.subject)

        #     result_paginated_cur = node_collection.find({ '$or':[{'_id': {'$in': doc}},

        #                 {'member_of': {'$nin': [ObjectId(GST_IMAGE._id), ObjectId(GST_VIDEO._id),ObjectId(pandora_video_st._id)]},
        #                                     '_type': 'File', 'group_set': {'$all': [ObjectId(group_id)]},
        #                                     # 'mime_type': {'$not': re.compile("^audio.*")},
        #                                     '$or': [
        #                                           {'access_policy': u"PUBLIC"},
        #                                             {'$and': [{'access_policy': u"PRIVATE"}, {'created_by': request.user.id}]}
        #                                            ]
        #                                     }]

        #         }).sort("last_update", -1)

        #     result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp)

        # print "educationaluse_stats: ", educationaluse_stats

        return render_to_response(
            "ndf/file_list_tab.html", {
                "filter_result": filter_result,
                "group_id": group_id,
                "group_name_tag": group_id,
                "groupid": group_id,
                'title': "E-Library",
                "educationaluse_stats": json.dumps(educationaluse_stats),
                "resource_type": allfiletypes1,
                "detail_urlname": detail_urlname,
                "filetype": filetype,
                "res_type_name": "",
                "page_info": result_pages
            },
            context_instance=RequestContext(request))
Example #7
0
def resource_list(request, group_id, app_id=None, page_no=1):
    """
	* Renders a list of all 'Resources' available within the database (except eBooks).
	"""
    print "inside resource_list of e-library ", group_id
    is_video = request.GET.get('is_video', "")
    print "request:", request.session.get_expiry_age(
    ), request.session.get_expire_at_browser_close()
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)
    print "group name and id", group_id
    if app_id is None:
        app_id = str(app[0].id)

    title = e_library_GST[0].name
    file_id = GST_FILE[0].id
    datavisual = []
    no_of_objs_pp = 5

    # filters = request.POST.get("filters", "")
    # filters = json.loads(filters)
    # filters = get_filter_querydict(filters)

    # print "filters in E-Library : ", filters

    # declaring empty (deliberately to avoid errors), query dict to be pass-on in query
    query_dict = []
    # query_dict = filters

    selfilters = urllib.unquote(request.GET.get('selfilters', ''))
    if selfilters:
        print "post fetching filters", selfilters
        selfilters = json.loads(selfilters)
        print "post json loads :", selfilters
        query_dict = get_filter_querydict(selfilters)
    print "query dict", query_dict

    lists = esearch.es_filters(query_dict)
    print "post esearch", lists
    strconcat1 = ""
    for value in lists:
        strconcat1 = strconcat1 + 'eval(str("' + value + '")),'

    q = Q('bool',
          must=[
              Q('terms', member_of=[GST_FILE[0].id, GST_JSMOL[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC')
          ],
          must_not=[Q('match', attribute_set__educationaluse='ebooks')])

    allfiles1 = (Search(using=es, index=index,
                        doc_type=doc_type).query(q)).sort(
                            {"last_update": {
                                "order": "desc"
                            }})

    allfiles2 = allfiles1.execute()

    educationaluse_stats = {}
    #print "all_files:",allfiles1

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', if_file__mime_type='image')
          ])
    allimages1 = (Search(using=es, index=index,
                         doc_type=doc_type).query(q)).sort(
                             {"last_update": {
                                 "order": "desc"
                             }})
    allimages2 = allimages1.execute()
    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', if_file__mime_type='video')
          ])

    allvideos1 = (Search(using=es, index=index,
                         doc_type=doc_type).query(q)).sort(
                             {"last_update": {
                                 "order": "desc"
                             }})

    allvideos2 = allvideos1.execute()

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', group_set=str(group_id)),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', if_file__mime_type='audio')
          ])

    allaudios1 = (Search(using=es, index=index,
                         doc_type=doc_type).query(q)).sort(
                             {"last_update": {
                                 "order": "desc"
                             }})

    allaudios2 = allaudios1.execute()

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', tags='Handbook')
          ])

    alldocs1 = (Search(using=es, index=index,
                       doc_type=doc_type).query(q)).sort(
                           {"last_update": {
                               "order": "desc"
                           }})

    alldocs2 = alldocs1.execute()

    q = Q('bool',
          must=[
              Q('terms',
                member_of=[GST_FILE[0].id, GST_JSMOL[0].id, GST_PAGE[0].id]),
              Q('match', access_policy='PUBLIC'),
              Q('match_phrase', tags='Tool')
          ])

    allinteractives1 = (Search(using=es, index=index,
                               doc_type=doc_type).query(q)).sort(
                                   {"last_update": {
                                       "order": "desc"
                                   }})

    allinteractives2 = allinteractives1.execute()
    #print "interactives count:",allinteractives1.count()

    domain_set = ['English', 'Mathematics', 'Science']
    domain_nds = [get_group_name_id(each)[1] for each in domain_set]
    domains = get_nodes_by_ids_list(domain_nds)
    moduleids = []
    for each in domains:
        moduleids.extend(each.collection_set)
    q = Q('bool',
          must=[
              Q('match', member_of=gst_module[0].id),
              Q('match', status='PUBLISHED'),
              Q('terms', id=moduleids)
          ])

    all_modules = (Search(using=es, index=index,
                          doc_type=doc_type).query(q)).sort(
                              {"last_update": {
                                  "order": "asc"
                              }})

    all_modules2 = all_modules.execute()

    files_new = all_modules[0:24]

    #for each in files_new:
    #        print each

    datavisual.append({"name": "Doc", "count": alldocs1.count()})
    datavisual.append({
        "name": "Page",
        "count": educationaluse_stats.get("Pages", 0)
    })
    datavisual.append({"name": "Image", "count": allimages1.count()})
    datavisual.append({"name": "Video", "count": allvideos1.count()})
    datavisual.append({
        "name": "Interactives",
        "count": allinteractives1.count()
    })
    datavisual.append({"name": "Audios", "count": allaudios1.count()})
    datavisual.append({
        "name": "eBooks",
        "count": educationaluse_stats.get("eBooks", 0)
    })

    with open(
            '/home/docker/code/clixoer/gnowsys-ndf/gnowsys_ndf/ndf/static/ndf/module.json',
            'r') as json_file:
        moduledata = json.load(json_file)

    return render_to_response(
        "ndf/Elibrary.html",
        {
            'title': title,
            'app': e_library_GST[0],
            'appId': app[0].id,
            "app_gst": app[0],
            # 'already_uploaded': already_uploaded,'shelf_list': shelf_list,'shelves': shelves,
            'files': files_new,
            "detail_urlname": "file_detail",
            'ebook_pages': educationaluse_stats.get("eBooks", 0),
            'file_pages': all_modules.count(),
            'interactive_pages': allinteractives1.count(),
            'image_pages': allimages1.count(),
            #'interactive_pages': educationaluse_stats.get("Interactives", 0),
            'educationaluse_stats': json.dumps(educationaluse_stats),
            'doc_pages': alldocs1.count(),
            'video_pages': allvideos1.count(),
            'audio_pages': allaudios1.count(),
            'groupid': group_id,
            'group_id': group_id,
            "datavisual": datavisual
        },
        context_instance=RequestContext(request))