def handle(self, *args, **options): gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('announced_unit') gst_course_ev_gr = node_collection.one({'_type': 'GSystemType', 'name': 'CourseEventGroup'}) all_course_groups = node_collection.find({'_type': 'Group', 'member_of': {'$in': [gst_course_ev_gr._id, gst_base_unit_id]} }) all_course_groups_count = all_course_groups.count() csv_created_count = 0 for gr_index, each_group_obj in enumerate(all_course_groups, 1): assessment_and_quiz_data = True print "\n\n[ %d / %d ]" % (gr_index, all_course_groups_count) try: print "Exporting CSV for :", each_group_obj.name, "(Altnames:", each_group_obj.altnames, ")\n" except Exception as e: print "\n!! Exception in printing name of unit: ", e print "\n\nExporting CSV for :", each_group_obj._id, "\n" pass csv_created_count += export_group_analytics(each_group_obj, assessment_and_quiz_data) # print "Enter 'group name(case sensitive)' OR 'id': " # group_name_or_id = raw_input() # group_obj = Group.get_group_name_id(group_name_or_id, get_obj=True) # if not group_obj: # raise ValueError('\nSorry. Request could not be visited. \ # \nGroup/Course, matching argument entered "' + group_name_or_id + '" does not exists!!') # export_group_analytics(group_obj,False) print "RESULT OF CSV EXPORT:\n\t- CREATED: %d\n\t- NOT CREATED: %d"%(csv_created_count, (all_course_groups_count - csv_created_count)) print "=" * 100
def created_trans_node(request, group_id, node_id, trans_node_id, language): rt_translation_of = Node.get_name_id_from_type('translation_of', 'RelationType', get_obj=True) trans_node_gst_name, trans_node_gst_id = GSystemType.get_gst_name_id("trans_node") print "trans_node_id", type(trans_node_id), " -- ", trans_node_id if trans_node_id: translated_node = Node.get_node_by_id(trans_node_id) else: translated_node = node_collection.collection.GSystem() name,content = get_quiz_item_name_content(request) translated_node.name = name translated_node.altnames = content translated_node.content = content translated_node.member_of = [trans_node_gst_id] translated_node.group_set = [group_id] translated_node.created_by = translated_node.modified_by = request.user.id translated_node.contributors = [request.user.id] translated_node.language = language translated_node.status = u"PUBLISHED" translated_node.save() if not trans_node_id: trans_grel_list = [ObjectId(translated_node._id)] trans_grels = triple_collection.find({'_type': 'GRelation', \ 'relation_type': rt_translation_of._id, \ 'subject': ObjectId(node_id)},{'_id': 0, 'right_subject': 1}) for each_rel in trans_grels: trans_grel_list.append(each_rel['right_subject']) translate_grel = create_grelation(node_id, rt_translation_of, trans_grel_list, language=language) return translated_node
def handle(self, *args, **options): gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('announced_unit') gst_course_ev_gr = node_collection.one({'_type': 'GSystemType', 'name': 'CourseEventGroup'}) all_course_groups = node_collection.find({'_type': 'Group', 'member_of': {'$in': [gst_course_ev_gr._id, gst_base_unit_id]}}) for each_group_obj in all_course_groups: print "\n\n Exporting CSV for :", each_group_obj.name, "(Altnames:", each_group_obj.altnames, ")\n" export_group_analytics(each_group_obj)
def handle(self, *args, **options): gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('announced_unit') gst_course_ev_gr = node_collection.one({'_type': 'GSystemType', 'name': 'CourseEventGroup'}) all_course_groups = node_collection.find({'_type': 'Group', 'member_of': {'$in': [gst_course_ev_gr._id, gst_base_unit_id]} }) for each_group_obj in all_course_groups: assessment_and_quiz_data = True print "\n\n Exporting CSV for :", each_group_obj.name, "(Altnames:", each_group_obj.altnames, ")\n" export_group_analytics(each_group_obj, assessment_and_quiz_data)
def gst_attributes(gst_name_or_id): if not gst_name_or_id: return node_collection.find({'_type': 'AttributeType'}).distinct('name') try: gst_id = ObjectId(gst_name_or_id) except Exception as e: gst_name, gst_id = GSystemType.get_gst_name_id(gst_name_or_id) return [at.name for at in node_collection.find({'_type': 'AttributeType', 'subject_type': gst_id})]
def handle(self, *args, **options): gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('announced_unit') gst_course_ev_gr = node_collection.one({'_type': 'GSystemType', 'name': 'CourseEventGroup'}) all_course_groups = node_collection.find({'_type': 'Group', 'member_of': {'$in': [gst_course_ev_gr._id, gst_base_unit_id]} }) all_course_groups_count = all_course_groups.count() csv_created_count = 0 for gr_index, each_group_obj in enumerate(all_course_groups, 1): assessment_and_quiz_data = True print "\n\n[ %d / %d ]" % (gr_index, all_course_groups_count) try: print "Exporting CSV for :", each_group_obj.name, "(Altnames:", each_group_obj.altnames, ")\n" except Exception as e: print "\n!! Exception in printing name of unit: ", e print "\n\nExporting CSV for :", each_group_obj._id, "\n" pass csv_created_count += export_group_analytics(each_group_obj, assessment_and_quiz_data) print "RESULT OF CSV EXPORT:\n\t- CREATED: %d\n\t- NOT CREATED: %d"%(csv_created_count, (all_course_groups_count - csv_created_count)) print "=" * 100
def handle(self, *args, **options): if args and len(args)==2 : domain_name = args[0] confirm_process = args[1] else: print "\n Example domain names: \n\t\t1. https://clixserver" + \ " \n\t\t2.https://clixplatform.tiss.edu" domain_name = raw_input("Enter domain name/IP(with 'https://'): ") confirm_process = raw_input("\nConfirm to proceed with domain-name: " + \ str(domain_name) + "\n(Enter y or Y to continue)") if (domain_name.startswith("https://")) and confirm_process in ['y', 'Y']: print "\nProceeding with Domain: ", domain_name gst_announced_unit_name, gst_announced_unit_id = GSystemType.get_gst_name_id("announced_unit") announced_unit_cur = node_collection.find({'member_of': gst_announced_unit_id}) for each_ann_unit in announced_unit_cur: get_all_iframes_of_unit(each_ann_unit, domain_name) else: print "\nPlease try again."
from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse from gnowsys_ndf.ndf.models import Node, GSystem, GSystemType, RelationType, Group from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.methods import get_group_name_id, get_language_tuple, create_grelation from gnowsys_ndf.settings import GSTUDIO_DEFAULT_LANGUAGE from gnowsys_ndf.ndf.templatetags.ndf_tags import get_relation_value # gst_page_name, gst_page_id = GSystemType.get_gst_name_id(u'Page') rt_translation_of = Node.get_name_id_from_type('translation_of', 'RelationType', get_obj=True) supported_languages = ['Hindi', 'Telugu'] trans_node_gst_name, trans_node_gst_id = GSystemType.get_gst_name_id( "trans_node") def all_translations(request, group_id, node_id): ''' returns all translated nodes of provided node. ''' node_obj = Node.get_node_by_id(node_id) # node_translation_grels = node_obj.get_relation('translation_of', status='PUBLISHED') # return node_translation_grels # node_translation_grels = node_obj.get_relation('translation_of') all_translation_nodes = node_obj.get_relation_right_subject_nodes( 'translation_of') return render_to_response("ndf/translation_list.html", {
import operator from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User from django.template.defaultfilters import slugify from gnowsys_ndf.ndf.models import node_collection, triple_collection, filehive_collection, counter_collection,benchmark_collection, GSystemType, Author, HistoryManager from gnowsys_ndf.settings import GSTUDIO_DATA_ROOT, GSTUDIO_LOGS_DIR_PATH, MEDIA_ROOT, GSTUDIO_INSTITUTE_ID, GSTUDIO_INSTITUTE_ID from export_logic import create_log_file, write_md5_of_dump, get_counter_ids, dump_node, delete_user_artifacts, get_counter_data, get_bnchmrk_data, get_nonadmin_users from gnowsys_ndf.ndf.views.methods import delete_node,get_group_name_id UNIT_IDS = [] UNIT_NAMES = [] log_file = None log_file_path = None USER_SERIES = [] ann_unit_gst_name, ann_unit_gst_id = GSystemType.get_gst_name_id(u"announced_unit") def call_exit(): print "\nExiting..." os._exit(0) class Command(BaseCommand): def handle(self, *args, **options): global UNIT_IDS global UNIT_NAMES global log_file global log_file_path global USER_SERIES USER_SERIES = ['sp','cc','mz','ct','tg','rj'] if not args[:2] in USER_SERIES:
from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse ''' -- imports from application folders/files -- ''' from gnowsys_ndf.ndf.models import GSystemType, Group, Node, GSystem #, Triple from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.group import CreateGroup from gnowsys_ndf.ndf.views.methods import get_execution_time, staff_required, create_gattribute, get_language_tuple, delete_gattribute from gnowsys_ndf.ndf.views.ajax_views import get_collection from gnowsys_ndf.settings import GSTUDIO_RESOURCES_EDUCATIONAL_LEVEL, GSTUDIO_RESOURCES_EDUCATIONAL_SUBJECT, GSTUDIO_PRIMARY_COURSE_LANGUAGE from gnowsys_ndf.ndf.templatetags.ndf_tags import check_is_gstaff, get_attribute_value gst_module_name, gst_module_id = GSystemType.get_gst_name_id('Module') gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('base_unit') gst_announced_unit_name, gst_announced_unit_id = GSystemType.get_gst_name_id( 'announced_unit') gst_ce_name, gst_ce_id = GSystemType.get_gst_name_id('CourseEventGroup') at_items_sort_list = node_collection.one({ '_type': "AttributeType", 'name': "items_sort_list" }) @get_execution_time def list_modules(request, group_id): ''' listing of modules '''
from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse ''' -- imports from application folders/files -- ''' from gnowsys_ndf.ndf.models import GSystemType, Group, Node, GSystem #, Triple from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.group import CreateGroup from gnowsys_ndf.ndf.views.methods import get_execution_time, staff_required, create_gattribute,get_language_tuple, delete_gattribute from gnowsys_ndf.ndf.views.ajax_views import get_collection from gnowsys_ndf.settings import GSTUDIO_RESOURCES_EDUCATIONAL_LEVEL, GSTUDIO_RESOURCES_EDUCATIONAL_SUBJECT, GSTUDIO_PRIMARY_COURSE_LANGUAGE from gnowsys_ndf.ndf.templatetags.ndf_tags import check_is_gstaff, get_attribute_value gst_module_name, gst_module_id = GSystemType.get_gst_name_id('Module') gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('base_unit') gst_announced_unit_name, gst_announced_unit_id = GSystemType.get_gst_name_id('announced_unit') gst_ce_name, gst_ce_id = GSystemType.get_gst_name_id('CourseEventGroup') at_items_sort_list = node_collection.one({'_type': "AttributeType", 'name': "items_sort_list"}) @get_execution_time def list_modules(request, group_id): ''' listing of modules ''' all_modules = GSystem.query_list(group_id, 'Module', request.user.id) template = "ndf/explore_2017.html" context_variable = {
from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse ''' -- imports from application folders/files -- ''' from gnowsys_ndf.ndf.models import GSystemType, Group, Node, GSystem #, Triple from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.group import CreateGroup from gnowsys_ndf.ndf.views.translation import get_lang_node, get_unit_hierarchy from gnowsys_ndf.ndf.views.methods import get_execution_time, staff_required, create_gattribute, get_language_tuple, create_grelation, update_unit_in_modules from gnowsys_ndf.ndf.views.ajax_views import get_collection gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('base_unit') gst_lesson_name, gst_lesson_id = GSystemType.get_gst_name_id('lesson') gst_activity_name, gst_activity_id = GSystemType.get_gst_name_id('activity') gst_module_name, gst_module_id = GSystemType.get_gst_name_id('Module') rt_translation_of = Node.get_name_id_from_type('translation_of', 'RelationType', get_obj=True) @login_required @get_execution_time def unit_create_edit(request, group_id, unit_group_id=None): ''' creation as well as eit of units '''
def api_get_gs_nodes(request): get_parameters_dict = request.GET.dict() if not get_parameters_dict: aggregated_dict = gst_api_fields_dict.copy() aggregated_dict.update(api_name_model_name_dict) aggregated_dict.pop('_id') query_parameters_dict = { 'Fields': aggregated_dict.keys(), 'Attributes': node_collection.find({ '_type': 'AttributeType' }).distinct('name'), 'Relations': node_collection.find({ '_type': 'RelationType' }).distinct('name') } return HttpResponse(json.dumps(query_parameters_dict, indent=4), content_type='application/json') # GET: api/v1/<group_id>/<files>/<nroer_team>/ exception_occured = '' oid_name_dict = {} gst_id = None # try: # group_id = ObjectId(group_name_or_id) # except Exception as e: # group_name, group_id = get_group_name_id(group_name_or_id) # oid_name_dict[group_id] = group_name gsystem_structure_dict = GSystem.structure gsystem_keys = gsystem_structure_dict.keys() gst_all_fields_dict = {i: 1 for i in gsystem_keys} query_dict = { '_type': 'GSystem', 'status': u'PUBLISHED', 'access_policy': 'PUBLIC', # 'group_set': ObjectId(group_id), # 'member_of': ObjectId(gst_id), # 'created_by': user_id, } sample_gs = GSystem() attributes = {} # GET parameters: get_created_by = request.GET.get('created_by', None) if get_created_by: username_or_id_int = 0 try: username_or_id_int = int(get_created_by) except Exception as e: pass auth_obj = node_collection.one({ '_type': u'Author', '$or': [{ 'name': unicode(get_created_by) }, { 'created_by': username_or_id_int }] }) if auth_obj: oid_name_dict[auth_obj._id] = auth_obj.name # user_id = auth_obj.created_by get_parameters_dict['created_by'] = auth_obj.created_by else: return HttpResponse('Requested user does not exists.', content_type='text/plain') get_resource_type = request.GET.get('resource_type', None) if get_resource_type: gst_name, gst_id = GSystemType.get_gst_name_id(get_resource_type) oid_name_dict[gst_id] = gst_name get_parameters_dict['member_of'] = [gst_id] attributes = sample_gs.get_possible_attributes([gst_id]) get_workspace = request.GET.get('workspace', None) if get_workspace: group_name, group_id = Group.get_group_name_id(get_workspace) oid_name_dict[group_id] = group_name get_parameters_dict['group_set'] = [group_id] for key, val in get_parameters_dict.iteritems(): stripped_key = key.split('.')[0] if stripped_key in gsystem_keys: query_dict.update({ key: ({ '$regex': val, '$options': 'i' } if isinstance(gsystem_structure_dict[stripped_key], basestring or unicode) else val) }) elif stripped_key in gst_attributes(gst_id): query_dict.update({ ('attribute_set.' + stripped_key): { '$regex': val, '$options': 'i' } }) # print "query_dict: ", query_dict human = eval(request.GET.get('human', '1')) gst_fields = gst_api_fields_dict if human else gst_all_fields_dict all_resources = node_collection.find(query_dict, gst_fields) if human: gst_fields = gst_api_fields_dict # converting ids to human readable names: # Django User: user_fields = ['created_by', 'modified_by', 'contributors'] all_users = [] for each_field in user_fields: all_users += all_resources.distinct(each_field) all_users = list(set(all_users)) userid_name_dict_cur = node_collection.find( { '_type': u'Author', 'created_by': { '$in': all_users } }, { 'name': 1, 'created_by': 1, '_id': 0 }) userid_name_dict = { i['created_by']: i['name'] for i in userid_name_dict_cur } # Mongo ids oid_fields = [ k for k, v in gsystem_structure_dict.iteritems() if v in [bson.objectid.ObjectId, [bson.objectid.ObjectId]] ] all_oid_list = [] for each_field in oid_fields: all_oid_list += all_resources.distinct(each_field) all_oid_list = list(set(all_oid_list)) oid_name_dict_cur = node_collection.find( {'_id': { '$in': all_oid_list }}, {'name': 1}) oid_name_dict = {i['_id']: i['name'] for i in oid_name_dict_cur} python_cur_list = [] python_cur_list_append = python_cur_list.append for each_gs in all_resources: # attaching attributes: # NEEDS to optimize. for key, value in each_gs.get_possible_attributes( each_gs.member_of).iteritems(): each_gs[key] = value['data_type'] each_gs[key] = value['object_value'] # mapping user id to username. for each_field in user_fields: each_gs[each_field] = [ userid_name_dict.get(i, i) for i in each_gs[each_field] ] if isinstance(each_gs[each_field], list) else userid_name_dict.get( each_gs[each_field], each_gs[each_field]) # mapping mongo _id to name. for each_field in oid_fields: each_gs[each_field] = [ oid_name_dict.get(i, i) for i in each_gs[each_field] ] if isinstance(each_gs[each_field], list) else oid_name_dict[each_gs[each_field]] python_cur_list_append(each_gs) json_result = json.dumps(python_cur_list, cls=NodeJSONEncoder, sort_keys=True, indent=4) else: json_result = dumps(all_resources, sort_keys=True, indent=4) return HttpResponse(json_result, content_type='application/json')
def node_create_edit(request, group_id=None, member_of=None, detail_url_name=None, node_type='GSystem', node_id=None): ''' creation as well as edit of node ''' # check for POST method to node update operation if request.method == "POST": # put validations if node_type not in node_collection.db.connection._registered_documents.keys(): raise ValueError('Improper node_type passed') kwargs={} group_name, group_id = Group.get_group_name_id(group_id) member_of_name, member_of_id = GSystemType.get_gst_name_id(member_of) if node_id: # existing node object node_obj = Node.get_node_by_id(node_id) else: # create new kwargs={ 'group_set': group_id, 'member_of': member_of_id } node_obj = node_collection.collection[node_type]() language = get_language_tuple(request.POST.get('language', None)) node_obj.fill_gstystem_values(request=request, language=language, **kwargs) node_obj.save(group_id=group_id) node_id = node_obj['_id'] # Consider for Blog page creation if member_of_name == "Page": blog_page_gst_name, blog_page_gst_id = GSystemType.get_gst_name_id("Blog page") if blog_page_gst_id in node_obj.type_of: discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"}) create_gattribute(node_obj._id, discussion_enable_at, True) return_status = create_thread_for_node(request,group_id, node_obj) active_user_ids_list = [request.user.id] if GSTUDIO_BUDDY_LOGIN: active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now()) # removing redundancy of user ids: active_user_ids_list = dict.fromkeys(active_user_ids_list).keys() counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list, group_id) for each_counter_obj in counter_objs_cur: each_counter_obj['page']['blog']['created'] += 1 each_counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS each_counter_obj.last_update = datetime.datetime.now() each_counter_obj.save() post_req = request.POST attrs_to_create_update = [f for f in post_req.keys() if ('attribute' in f)] attrs_to_create_update = [a.split('_')[1] for a in attrs_to_create_update] for each_attr_name in attrs_to_create_update: each_attr_name_obj = Node.get_name_id_from_type(each_attr_name, 'AttributeType', get_obj=True) post_req_attr_key = 'attribute_'+each_attr_name post_method = 'getlist' if (each_attr_name_obj.data_type in [list, 'list']) else 'get' create_gattribute(node_id, each_attr_name_obj, object_value=getattr(post_req, post_method)(post_req_attr_key)) return HttpResponseRedirect(reverse(detail_url_name, kwargs={'group_id': group_id, 'node_id': node_id}))
import datetime try: from bson import ObjectId except ImportError: # old pymongo from pymongo.objectid import ObjectId from django.http import HttpRequest from gnowsys_ndf.ndf.models import Node, GSystemType, Buddy, Counter from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.methods import get_group_name_id, get_language_tuple, create_grelation from gnowsys_ndf.settings import GSTUDIO_BUDDY_LOGIN, GSTUDIO_DEFAULT_LANGUAGE, GSTUDIO_FILE_UPLOAD_POINTS # gst_asset = node_collection.one({'_type': u'GSystemType', 'name': u'Asset'}) gst_asset_name, gst_asset_id = GSystemType.get_gst_name_id(u'Asset') gst_page_name, gst_page_id = GSystemType.get_gst_name_id(u'Page') gst_file_name, gst_file_id = GSystemType.get_gst_name_id(u'File') def create_asset(name, group_id, created_by, node_id=None, content=None, request=HttpRequest(), **kwargs): ''' This method is equivalent to write_files() but also (about to) incorporate page creation. So plan is to not to change write_files() which is working smoothly at various places.
def api_get_gs_nodes(request): get_parameters_dict = request.GET.dict() if not get_parameters_dict: aggregated_dict = gst_api_fields_dict.copy() aggregated_dict.update(api_name_model_name_dict) aggregated_dict.pop('_id') query_parameters_dict = { 'Fields': aggregated_dict.keys(), 'Attributes': node_collection.find({'_type': 'AttributeType'}).distinct('name'), 'Relations': node_collection.find({'_type': 'RelationType'}).distinct('name') } return HttpResponse(json.dumps(query_parameters_dict, indent=4), content_type='application/json') # GET: api/v1/<group_id>/<files>/<nroer_team>/ exception_occured = '' oid_name_dict = {} gst_id = None # try: # group_id = ObjectId(group_name_or_id) # except Exception as e: # group_name, group_id = get_group_name_id(group_name_or_id) # oid_name_dict[group_id] = group_name gsystem_structure_dict = GSystem.structure gsystem_keys = gsystem_structure_dict.keys() gst_all_fields_dict = {i: 1 for i in gsystem_keys} query_dict = { '_type': 'GSystem', 'status': u'PUBLISHED', 'access_policy': 'PUBLIC', # 'group_set': ObjectId(group_id), # 'member_of': ObjectId(gst_id), # 'created_by': user_id, } sample_gs = GSystem() attributes = {} # GET parameters: get_created_by = request.GET.get('created_by', None) if get_created_by: username_or_id_int = 0 try: username_or_id_int = int(get_created_by) except Exception as e: pass auth_obj = node_collection.one({'_type': u'Author', '$or': [{'name': unicode(get_created_by)}, {'created_by': username_or_id_int} ] }) if auth_obj: oid_name_dict[auth_obj._id] = auth_obj.name # user_id = auth_obj.created_by get_parameters_dict['created_by'] = auth_obj.created_by else: return HttpResponse('Requested user does not exists.', content_type='text/plain') get_resource_type = request.GET.get('resource_type', None) if get_resource_type: gst_name, gst_id = GSystemType.get_gst_name_id(get_resource_type) oid_name_dict[gst_id] = gst_name get_parameters_dict['member_of'] = [gst_id] attributes = sample_gs.get_possible_attributes([gst_id]) get_workspace = request.GET.get('workspace', None) if get_workspace: group_name, group_id = Group.get_group_name_id(get_workspace) oid_name_dict[group_id] = group_name get_parameters_dict['group_set'] = [group_id] for key, val in get_parameters_dict.iteritems(): stripped_key = key.split('.')[0] if stripped_key in gsystem_keys: query_dict.update({ key: ({'$regex': val, '$options': 'i'} if isinstance(gsystem_structure_dict[stripped_key], basestring or unicode) else val) }) elif stripped_key in gst_attributes(gst_id): query_dict.update({('attribute_set.' + stripped_key): {'$regex': val, '$options': 'i'}}) # print "query_dict: ", query_dict human = eval(request.GET.get('human', '1')) gst_fields = gst_api_fields_dict if human else gst_all_fields_dict all_resources = node_collection.find(query_dict, gst_fields) if human: gst_fields = gst_api_fields_dict # converting ids to human readable names: # Django User: user_fields = ['created_by', 'modified_by', 'contributors'] all_users = [] for each_field in user_fields: all_users += all_resources.distinct(each_field) all_users = list(set(all_users)) userid_name_dict_cur = node_collection.find({'_type': u'Author', 'created_by': {'$in': all_users}}, {'name': 1, 'created_by': 1, '_id': 0}) userid_name_dict = {i['created_by']: i['name'] for i in userid_name_dict_cur} # Mongo ids oid_fields = [ k for k, v in gsystem_structure_dict.iteritems() if v in [bson.objectid.ObjectId, [bson.objectid.ObjectId]] ] all_oid_list = [] for each_field in oid_fields: all_oid_list += all_resources.distinct(each_field) all_oid_list = list(set(all_oid_list)) oid_name_dict_cur = node_collection.find({'_id': {'$in': all_oid_list}}, {'name': 1}) oid_name_dict = {i['_id']: i['name'] for i in oid_name_dict_cur} python_cur_list = [] python_cur_list_append = python_cur_list.append for each_gs in all_resources: # attaching attributes: # NEEDS to optimize. for key, value in each_gs.get_possible_attributes(each_gs.member_of).iteritems(): each_gs[key] = value['data_type'] each_gs[key] = value['object_value'] # mapping user id to username. for each_field in user_fields: each_gs[each_field] = [userid_name_dict.get(i, i) for i in each_gs[each_field]] if isinstance(each_gs[each_field], list) else userid_name_dict.get(each_gs[each_field], each_gs[each_field]) # mapping mongo _id to name. for each_field in oid_fields: each_gs[each_field] = [oid_name_dict.get(i, i) for i in each_gs[each_field]] if isinstance(each_gs[each_field], list) else oid_name_dict[each_gs[each_field]] python_cur_list_append(each_gs) json_result = json.dumps(python_cur_list, cls=NodeJSONEncoder, sort_keys=True, indent=4) else: json_result = dumps(all_resources, sort_keys=True, indent=4) return HttpResponse(json_result, content_type='application/json')
from django.http import HttpRequest from django.http import HttpResponseRedirect from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse from gnowsys_ndf.ndf.models import Node, GSystem, GSystemType, RelationType, Group from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.methods import get_group_name_id, get_language_tuple, create_grelation from gnowsys_ndf.settings import GSTUDIO_DEFAULT_LANGUAGE # gst_page_name, gst_page_id = GSystemType.get_gst_name_id(u'Page') rt_translation_of = Node.get_name_id_from_type('translation_of', 'RelationType', get_obj=True) supported_languages = ['Hindi', 'Telugu'] trans_node_gst_name, trans_node_gst_id = GSystemType.get_gst_name_id("trans_node") def all_translations(request, group_id, node_id): ''' returns all translated nodes of provided node. ''' node_obj = Node.get_node_by_id(node_id) # node_translation_grels = node_obj.get_relation('translation_of', status='PUBLISHED') # return node_translation_grels # node_translation_grels = node_obj.get_relation('translation_of') all_translation_nodes = node_obj.get_relation_right_subject_nodes('translation_of') return render_to_response("ndf/translation_list.html",
import datetime try: from bson import ObjectId except ImportError: # old pymongo from pymongo.objectid import ObjectId from django.http import HttpRequest from gnowsys_ndf.ndf.models import Node, GSystemType, Buddy, Counter from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.methods import get_group_name_id, get_language_tuple, create_grelation, get_execution_time, auto_enroll from gnowsys_ndf.settings import GSTUDIO_BUDDY_LOGIN, GSTUDIO_DEFAULT_LANGUAGE, GSTUDIO_FILE_UPLOAD_POINTS # gst_asset = node_collection.one({'_type': u'GSystemType', 'name': u'Asset'}) gst_asset_name, gst_asset_id = GSystemType.get_gst_name_id(u'Asset') gst_page_name, gst_page_id = GSystemType.get_gst_name_id(u'Page') gst_file_name, gst_file_id = GSystemType.get_gst_name_id(u'File') @auto_enroll @get_execution_time def create_asset(name, group_id, created_by, node_id=None, content=None, request=HttpRequest(), **kwargs): ''' This method is equivalent to write_files() but also (about to) incorporate page creation.
from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse ''' -- imports from application folders/files -- ''' from gnowsys_ndf.ndf.models import GSystemType, Group, Node, GSystem #, Triple from gnowsys_ndf.ndf.models import node_collection,triple_collection from gnowsys_ndf.ndf.views.group import CreateGroup from gnowsys_ndf.ndf.views.translation import get_lang_node,get_unit_hierarchy from gnowsys_ndf.ndf.views.methods import get_execution_time, staff_required, create_gattribute,get_language_tuple,create_grelation, update_unit_in_modules from gnowsys_ndf.ndf.views.ajax_views import get_collection gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('base_unit') gst_lesson_name, gst_lesson_id = GSystemType.get_gst_name_id('lesson') gst_activity_name, gst_activity_id = GSystemType.get_gst_name_id('activity') gst_module_name, gst_module_id = GSystemType.get_gst_name_id('Module') rt_translation_of = Node.get_name_id_from_type('translation_of', 'RelationType', get_obj=True) @login_required @get_execution_time def unit_create_edit(request, group_id, unit_group_id=None): ''' creation as well as eit of units ''' parent_group_name, parent_group_id = Group.get_group_name_id(group_id) unit_node = None if request.method == "GET":
def handle(self, *args, **options): global UNIT_IDS global UNIT_NAMES global log_file global log_file_path global DATA_EXPORT_PATH global SCHEMA_MAP_PATH global TOP_PATH print "\nUSER DATA EXPORT FOR : ", GSTUDIO_INSTITUTE_ID ann_unit_gst_name, ann_unit_gst_id = GSystemType.get_gst_name_id( u"announced_unit") if args: try: args_ids = map(ObjectId, args) except Exception as e: print "\n\nPlease enter Valid ObjectId." call_exit() all_ann_units_cur = node_collection.find( {'_id': { '$in': args_ids }}) for each_un in all_ann_units_cur: UNIT_IDS.append(each_un._id) UNIT_NAMES.append(each_un.name) else: all_ann_units_cur = node_collection.find( {'member_of': ann_unit_gst_id}) print "\nTotal Units : ", all_ann_units_cur.count() for ind, each_ann_unit in enumerate(all_ann_units_cur, start=1): unit_selection = raw_input( "\n\t{0}. Unit: {1} \n\tEnter y/Y to select: ".format( ind, each_ann_unit.name)) if unit_selection in ['y', 'Y']: print "\t Yes" UNIT_IDS.append(each_ann_unit._id) UNIT_NAMES.append(each_ann_unit.name) else: print "\t No" print "\nUser Artifacts Data Export of following Units:" print("\n\t".join([ "{0}. {1}".format(i, unit_name) for i, unit_name in enumerate(UNIT_NAMES, 1) ])) proceed_flag = raw_input("\nEnter y/Y to Confirm: ") if proceed_flag: try: datetimestamp = datetime.datetime.now().strftime( "%Y-%m-%d_%H-%M-%S") log_file_name = 'artifacts_dump_' + str( GSTUDIO_INSTITUTE_ID) + "_" + str(datetimestamp) TOP_PATH = os.path.join(GSTUDIO_DATA_ROOT, 'data_export', log_file_name) SCHEMA_MAP_PATH = TOP_PATH log_file_path = create_log_file(log_file_name) setup_dump_path() log_file = open(log_file_path, 'w+') log_file.write("\n######### Script ran on : " + str(datetime.datetime.now()) + " #########\n\n") log_file.write("User Artifacts Data Export for Units: " + str(UNIT_IDS)) query = {'member_of': ann_unit_gst_id} rec = node_collection.collection.aggregate([{ "$match": query }, { "$group": { '_id': 0, 'count': { '$sum': 1 }, "author_set": { "$addToSet": "$author_set" }, "group_admin": { "$addToSet": "$group_admin" } }, }, { "$project": { '_id': 0, 'total': '$count', "user_ids": { "$cond": [{ "$eq": ["$author_set", []] }, [], "$author_set"] }, "admin_ids": { "$cond": [{ "$eq": ["$group_admin", []] }, [], "$group_admin"] } } }]) for e in rec['result']: print e user_ids_lists = e['user_ids'] admin_ids_lists = e['admin_ids'] user_id_list = reduce(operator.concat, user_ids_lists) admin_id_list = reduce(operator.concat, admin_ids_lists) non_admin_user_id_list = list( set(user_id_list) - set(admin_id_list)) non_admin_user_id_list = [ x for x in non_admin_user_id_list if x is not None ] print "user_ids", non_admin_user_id_list if non_admin_user_id_list: log_file.write("Users ids: " + str(non_admin_user_id_list)) pull_nodes(non_admin_user_id_list) create_users_dump(DATA_EXPORT_PATH, user_id_list) get_counter_ids(user_ids=user_id_list) create_factory_schema_mapper(SCHEMA_MAP_PATH) configs_file_path = create_configs_file() write_md5_of_dump(DATA_EXPORT_PATH, configs_file_path) else: log_file.write("No users with non-admin rights found.") except Exception as user_data_export_err: log_file.write("Error occurred: " + str(user_data_export_err)) pass finally: log_file.write( "\n*************************************************************" ) log_file.write("\n######### Script Completed at : " + str(datetime.datetime.now()) + " #########\n\n") print "\nSTART : ", str(datetimestamp) print "\nEND : ", str( datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")) print "*" * 70 print "\n Log will be found at: ", log_file_path print "*" * 70 log_file.close() call_exit() else: call_exit()
import os import json import datetime try: from bson import ObjectId except ImportError: # old pymongo from pymongo.objectid import ObjectId from django.contrib.auth.models import User from gnowsys_ndf.ndf.models import node_collection, GSystemType user_json = {"user_id": None, "user_name": None, "user_author_id": None, "user_email": None } gst_author_name, gst_author_id = GSystemType.get_gst_name_id('Author') def create_users_dump(path, user_id_list): dump_list = [user_json] schema_dump_path = os.path.join(path, 'users_dump.json') auth_cur = node_collection.find({'_type': 'Author', 'created_by': {'$in': user_id_list}}, {'name':1, 'email': 1, 'created_by': 1}) user_json_list = [] for each_auth in auth_cur: try: user_obj = User.objects.get(pk=each_auth.created_by) except Exception as no_user: pass if user_obj: each_user_json = user_json.copy() each_user_json['user_id'] = user_obj.id each_user_json['user_name'] = user_obj.username
from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse ''' -- imports from application folders/files -- ''' from gnowsys_ndf.ndf.models import GSystemType, Group, Node, GSystem #, Triple from gnowsys_ndf.ndf.models import node_collection from gnowsys_ndf.ndf.views.group import CreateGroup from gnowsys_ndf.ndf.views.methods import get_execution_time, staff_required, create_gattribute, get_language_tuple from gnowsys_ndf.ndf.views.ajax_views import get_collection from gnowsys_ndf.settings import GSTUDIO_RESOURCES_EDUCATIONAL_LEVEL, GSTUDIO_RESOURCES_EDUCATIONAL_SUBJECT from gnowsys_ndf.ndf.templatetags.ndf_tags import check_is_gstaff gst_module_name, gst_module_id = GSystemType.get_gst_name_id('Module') gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('base_unit') gst_announced_unit_name, gst_announced_unit_id = GSystemType.get_gst_name_id( 'announced_unit') @get_execution_time def list_modules(request, group_id): ''' listing of modules ''' all_modules = GSystem.query_list(group_id, 'Module', request.user.id) template = "ndf/explore_2017.html" context_variable = { 'title': 'Modules',
from gnowsys_ndf.ndf.models import Node, Group, GSystemType, AttributeType, RelationType from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.methods import get_execution_time, get_language_tuple, create_gattribute from gnowsys_ndf.ndf.templatetags.ndf_tags import check_is_gstaff, get_attribute_value # from gnowsys_ndf.ndf.views.methods import get_group_name_id # from gnowsys_ndf.ndf.views.methods import get_node_common_fields, parse_template_data, get_execution_time, delete_node, replicate_resource gst_course = node_collection.one({'_type': "GSystemType", 'name': "Course"}) gst_basecoursegroup = node_collection.one({'_type': "GSystemType", 'name': "BaseCourseGroup"}) ce_gst = node_collection.one({'_type': "GSystemType", 'name': "CourseEventGroup"}) announced_unit_gst = node_collection.one({'_type': "GSystemType", 'name': "announced_unit"}) gst_acourse = node_collection.one({'_type': "GSystemType", 'name': "Announced Course"}) gst_group = node_collection.one({'_type': "GSystemType", 'name': "Group"}) group_id = node_collection.one({'_type': "Group", 'name': "home"})._id gst_module_name, gst_module_id = GSystemType.get_gst_name_id('Module') gst_base_unit_name, gst_base_unit_id = GSystemType.get_gst_name_id('base_unit') def explore(request): return HttpResponseRedirect(reverse('explore_courses', kwargs={})) title = 'explore' context_variable = {'title': title, 'group_id': group_id, 'groupid': group_id} return render_to_response( "ndf/explore.html", context_variable, context_instance=RequestContext(request)) '''