def perform_eval_type(eval_field, json_document, type_to_create, type_convert_objectid=None): """Converts eval_field's data in json-type to it's corresponding python-type, and resets eval_field with that converted data """ try: json_document[eval_field] = ast.literal_eval(json_document[eval_field]) except Exception as e: if u"\u201c" in json_document[eval_field]: json_document[eval_field] = json_document[eval_field].replace(u"\u201c", "\"") if u"\u201d" in json_document[eval_field]: json_document[eval_field] = json_document[eval_field].replace(u"\u201d", "\"") if u"\u2013" in json_document[eval_field]: json_document[eval_field] = json_document[eval_field].replace(u"\u2013", "-") try: json_document[eval_field] = ast.literal_eval(json_document[eval_field]) except Exception as e: error_message = "\n InvalidDataError: For " + type_to_create + " ("+json_document['name']+") invalid data found -- " + str(e) + "!!!\n" log_list.append(error_message) raise Exception(error_message) type_list = [] for data in json_document[eval_field]: if type_convert_objectid is None: if eval_field == "when did you attend tot?": type_list.append(datetime.datetime.strptime(data, "%d/%m/%Y")) else: type_list.append(data) else: if "(" in data or ")" in data: node = node_collection.one({'_type': type_convert_objectid, 'name': data, 'group_set': group_id }, {'_id': 1} ) else: node = node_collection.one({'_type': type_convert_objectid, '$or': [{'name': {'$regex': "^"+data+"$", '$options': 'i'}}, {'altnames': {'$regex': "^"+data+"$", '$options': 'i'}}], 'group_set': group_id }, {'_id': 1} ) if node: type_list.append(node._id) else: error_message = "\n "+type_convert_objectid+"Error ("+eval_field+"): This "+type_convert_objectid+" (" + data + ") doesn't exists for creating "+type_to_create+" (" + json_document['name'] + ") !!!\n" log_list.append(error_message) raise Exception(error_message) # Sets python-type converted list json_document[eval_field] = type_list
def partner_list(request, group_id): group_obj = get_group_name_id(group_id, get_obj=True) app_gst = node_collection.one({'_type': 'GSystemType', 'name': 'PartnerGroup'}) group_nodes = None collection_set = [] # groups_category = None if group_obj: group_id = group_obj._id group_name = group_obj.name groups_category = group_obj.agency_type # groups_category = "Partner" if groups_category == "Partner" else "Group" group_obj = node_collection.one({'_id': ObjectId(group_id)}) # if group_obj: # for each in group_obj.collection_set: # node = node_collection.one({'_id': each}) # collection_set.append(node) group_nodes = node_collection.find({'_id': {'$in':group_obj.post_node}}).sort("last_update",-1) # print GSTUDIO_NROER_MENU_MAPPINGS.get(group_name, None) # print GSTUDIO_NROER_MENU return render_to_response("ndf/partner_list.html", {'group_nodes': group_nodes, # "groups_category": groups_category, 'group_obj':group_obj, 'groupid': group_id, 'group_id': group_id, "app_gst": partner_group_gst, }, context_instance=RequestContext(request))
def link_login_ac(): """This function links Author GSystem and Respecive Person's Sub-type GSystem. """ users = User.objects.all() has_login_rt = node_collection.one({ '_type': "RelationType", 'name': "has_login" }) for each in users: person_node = node_collection.find( {'attribute_set.email_id': each.email}) auth_node = node_collection.one({ '_type': "Author", 'email': each.email }) if person_node.count() <= 0 or auth_node is None: error_message = "\n Either person_node or auth_node doesn't exists for given email (" + each.email + ") !!!" log_list.append(error_message) continue for pn in person_node: gr_node = create_grelation(pn._id, has_login_rt, auth_node._id) info_message = "\n This GRelation created for " + str( gr_node.name) + "." log_list.append(info_message)
def discussion_delete_reply(request, group_id, node_id): try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) nodes_to_delete = json.loads(request.POST.get("nodes_to_delete", "[]")) deleted_replies = [] node_obj = node_collection.one({'_id': ObjectId(node_id)}) # print "\n\nnode_obj.name", node_obj.name, node_obj.member_of_names_list,node_obj._id for each_reply in nodes_to_delete: temp_reply = node_collection.one({"_id": ObjectId(each_reply)}) if temp_reply: deleted_replies.append(temp_reply._id.__str__()) temp_reply.delete() replies_cur = node_collection.find({'origin.thread_id': ObjectId(node_id)}) # print "\n replies_cur",replies_cur.count() if (not replies_cur.count()) and (int(request.user.id) in node_obj.author_set): author_set_ids = node_obj.author_set author_set_ids.remove(int(request.user.id)) node_obj.author_set = author_set_ids node_obj.save() return HttpResponse(json.dumps(deleted_replies))
def graphs(request, group_id): # HttpResponseRedirect("ndf/visualize.html", # { # 'groupid':group_id, 'group_id':group_id, # }, # # context_instance=RequestContext(request) # ) ins_objectid = ObjectId() if ins_objectid.is_valid(group_id) is False: group_ins = node_collection.find_one({ '_type': "Group", "name": group_id }) auth = node_collection.one({ '_type': 'Author', 'name': unicode(request.user.username) }) if group_ins: group_id = str(group_ins._id) else: auth = node_collection.one({ '_type': 'Author', 'name': unicode(request.user.username) }) if auth: group_id = str(auth._id) return render_to_response("ndf/visualize.html", { 'group_id': group_id, 'groupid': group_id }, context_instance=RequestContext(request))
def detail(request, group_id, _id): student_coll = [] node = node_collection.one({'_id': ObjectId(_id)}) rt_has_batch_member = node_collection.one({ '_type': 'RelationType', 'name': 'has_batch_member' }) relation_coll = triple_collection.find({ '_type': 'GRelation', 'relation_type': rt_has_batch_member._id, 'subject': node._id, 'status': u'PUBLISHED' }) for each in relation_coll: n = node_collection.one({'_id': ObjectId(each.right_subject)}) student_coll.append(n) template = "ndf/batch_detail.html" variable = RequestContext( request, { 'node': node, 'node_name_human_readable': (node.name).replace('_', ' '), 'appId': app._id, 'groupid': group_id, 'group_id': group_id, 'title': GST_BATCH.name, 'student_coll': student_coll }) return render_to_response(template, variable)
def revert_doc(request, group_id, node_id, version_1): node = node_collection.one({'_id': ObjectId(node_id)}) group = node_collection.one({'_id': ObjectId(group_id)}) doc = history_manager.get_version_document(node, version_1) for attr in node: if attr != '_type': try: node[attr] = doc[attr] except: node[attr] = node[attr] node.modified_by = request.user.id node.save(groupid=group_id) view = 'revert' ver = history_manager.get_current_version(node) selected_versions = selected_versions = {"1": version_1, "2": ""} return render_to_response("ndf/version_page.html", { 'view': view, 'selected_versions': selected_versions, 'node': node, 'groupid': group_id, 'group_id': group_id, 'content': node, 'ver': ver }, context_instance=RequestContext(request))
def revert_doc(request,group_id,node_id,version_1): node = node_collection.one({'_id': ObjectId(node_id)}) group = node_collection.one({'_id': ObjectId(group_id)}) doc=history_manager.get_version_document(node,version_1) for attr in node: if attr != '_type': try: node[attr] = doc[attr]; except: node[attr] =node[attr] node.modified_by=request.user.id node.save(groupid=group_id) view ='revert' ver=history_manager.get_current_version(node) selected_versions=selected_versions = {"1": version_1, "2": ""} return render_to_response("ndf/version_page.html", {'view': view, 'selected_versions': selected_versions, 'node':node, 'groupid':group_id, 'group_id':group_id, 'content':node, 'ver':ver }, context_instance = RequestContext(request) )
def nroer_groups(request, group_id, groups_category): group_name, group_id = get_group_name_id(group_id) print 'groups_category: ', groups_category mapping = GSTUDIO_NROER_MENU_MAPPINGS groups_names_list = [] # loop over nroer menu except "Repository" for each_item in GSTUDIO_NROER_MENU[1:]: temp_key_name = each_item.keys()[0] if temp_key_name == groups_category: groups_names_list = each_item.get(groups_category, []) # mapping for the text names in list groups_names_list = [mapping.get(i) for i in groups_names_list] break # print "\n\ngroups_names_list",groups_names_list group_nodes = [] ''' For displaying Partners and Groups in same order as defined in settings GSTUDIO_NROER_MENU_MAPPINGS ''' for eachgroup in groups_names_list: grp_node = node_collection.one({ '_type': "Group", 'name': unicode(eachgroup) }) group_nodes.append(grp_node) # group_nodes = node_collection.find({ '_type': "Group", # '_id': {'$nin': [ObjectId(group_id)]}, # 'name': {'$nin': ["home"], '$in': groups_names_list}, # 'group_type': "PUBLIC" # }).sort('created_at', -1) if groups_category == "Partners": app_gst = node_collection.one({ '_type': 'GSystemType', 'name': 'PartnerGroup' }) elif groups_category == "Groups": app_gst = gst_group print 'group_nodes: ', groups_names_list # print "=============", app_gst # group_nodes_count = group_nodes.count() if group_nodes else 0 return render_to_response( "ndf/partner.html", { 'group_nodes': group_nodes, "groups_category": groups_category, #'group_nodes_count': group_nodes_count, 'app_gst': app_gst, 'groupid': group_id, 'group_id': group_id, 'group_name': group_name }, context_instance=RequestContext(request))
def get_profile_pic(username): auth = node_collection.one({'_type': 'Author', 'name': unicode(username)}) prof_pic = node_collection.one({ '_type': u'RelationType', 'name': u'has_profile_pic' }) # dbref_profile_pic = prof_pic.get_dbref() collection_tr = db[Triple.collection_name] prof_pic_rel = collection_tr.Triple.find({ '_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type': prof_pic._id }) # prof_pic_rel will get the cursor object of relation of user with its profile picture if prof_pic_rel.count(): index = prof_pic_rel[prof_pic_rel.count() - 1].right_subject img_obj = node_collection.one({ '_type': 'File', '_id': ObjectId(index) }) else: img_obj = "" return img_obj
def batch_detail(request, group_id): group_name, group_id = get_group_name_id(group_id) new_batch_node = None if request.is_ajax() and request.method == "GET": batch_id = request.GET.get("batch_id", '') student_coll = [] node = node_collection.one({'_id': ObjectId(batch_id)}) rt_has_batch_member = node_collection.one({ '_type': 'RelationType', 'name': 'has_batch_member' }) relation_coll = triple_collection.find({ '_type': 'GRelation', 'relation_type': rt_has_batch_member._id, 'subject': node._id, 'status': u'PUBLISHED' }) for each in relation_coll: n = node_collection.one({'_id': ObjectId(each.right_subject)}) student_coll.append(n) return HttpResponse(json.dumps(student_coll, cls=NodeJSONEncoder))
def quiz_details(request, group_id, node_id): try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) title = gst_quiz.name gst_quiz_item = node_collection.one({ '_type': 'GSystemType', 'name': u'QuizItem' }) quiz_node = node_collection.one({'_id': ObjectId(node_id)}) quiz_item_nodes = node_collection.find({ '_id': { '$in': quiz_node.collection_set }, 'member_of': gst_quiz_item._id }).sort('last_update', -1) # quiz_node.get_neighbourhood(quiz_node.member_of) context_variables = { 'groupid': group_id, 'group_id': group_id, 'title': title, 'node': quiz_node, 'quiz_item_nodes': quiz_item_nodes } return render_to_response("ndf/quiz_details.html", context_variables, context_instance=RequestContext(request))
def create_edit_quiz(request, group_id, node_id=None): """Creates/Edits quiz category. """ try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) context_variables = { 'title': gst_quiz.name, 'group_id': group_id, 'groupid': group_id } if node_id: quiz_node = node_collection.one({ '_type': u'GSystem', '_id': ObjectId(node_id) }) if request.method == "POST": if node_id: quiz_node = node_collection.one({ '_type': u'GSystem', '_id': ObjectId(node_id) }) else: quiz_node = node_collection.collection.GSystem() # get_node_common_fields(request, quiz_node, group_id, gst_quiz) quiz_node.save(is_changed=get_node_common_fields( request, quiz_node, group_id, gst_quiz), groupid=group_id) quiz_node.get_neighbourhood(quiz_node.member_of) # get_node_metadata(request, quiz_node,gst_quiz) #if teaches is required # teaches_list = request.POST.get('teaches_list','') # get the teaches list # if teaches_list !='': # teaches_list=teaches_list.split(",") # create_grelation_list(quiz_node._id,"teaches",teaches_list) # assesses_list = request.POST.get('assesses_list','') # get the assesses list # if assesses_list !='': # assesses_list=assesses_list.split(",") # create_grelation_list(quiz_node._id,"assesses",assesses_list) return HttpResponseRedirect( reverse('quiz_details', kwargs={ 'group_id': group_id, 'node_id': quiz_node._id })) else: if node_id: context_variables['node'] = quiz_node context_variables['groupid'] = group_id context_variables['group_id'] = group_id # context_variables['appId']=app._id return render_to_response("ndf/quiz_create_edit.html", context_variables, context_instance=RequestContext(request))
def create_college_group(): """ Creates private group for each college; and appends glab's (superuser) user-id as a creator for each of them. Arguments: Empty Returns: Nothing """ collegeid = node_collection.one({ '_type': "GSystemType", 'name': "College" })._id college_cur = node_collection.find({ '_type': "GSystem", 'member_of': collegeid }) groupid = node_collection.one({ '_type': "GSystemType", 'name': "Group" })._id glab_created_by = node_collection.one({ '_type': "Author", 'name': "glab" }).created_by for n in college_cur: college_exists = node_collection.one({ '_type': "Group", 'name': n.name }, { '_id': 1, 'name': 1, 'group_type': 1 }) if college_exists: # If given college is found, don't create it again and pass the iteration info_message = "\n CollegeGroupAlreadyExists: Group (" + college_exists.group_type + ") for this college (" + college_exists.name + ") already exists with this ObjectId (" + str( college_exists._id) + ") ! \n" log_list.append(info_message) continue gfc = node_collection.collection.Group() gfc._type = u"Group" gfc.name = n.name gfc.member_of = [groupid] gfc.group_type = u"PRIVATE" gfc.created_by = glab_created_by gfc.modified_by = glab_created_by gfc.contributors = [glab_created_by] gfc.status = u"PUBLISHED" gfc.save() info_message = "\n CollegeGroupCreation: Group (" + gfc.group_type + ") for this college (" + gfc.name + ") with this ObjectId (" + str( gfc._id) + ") created successfully. \n" log_list.append(info_message)
def create_task(request, task_id, group_id): if task_id: task_node = node_collection.one({ '_type': u'GSystem', '_id': ObjectId(task_id) }) edit_task_node = task_node else: task_node = node_collection.collection.GSystem() name = request.POST.get("name", "") content_org = request.POST.get("content_org", "") parent = request.POST.get("parent", "") Status = request.POST.get("Status", "") Start_date = request.POST.get("start_time", "") Priority = request.POST.get("Priority", "") Due_date = request.POST.get("end_time", "") Assignee = request.POST.get("Assignee", "") Estimated_time = request.POST.get("Estimated_time", "") watchers = request.POST.get("watchers", "") GST_TASK = node_collection.one({'_type': "GSystemType", 'name': 'Task'}) tag = "" field_value = [] file_name = (request.POST.get("files_name")) if not task_id: # create get_node_common_fields(request, task_node, group_id, GST_TASK) # Adding watchers to node's author_set if watchers: task_node.author_set = [] user_to_be_notified = [] for each_watchers in watchers.split(','): bx = User.objects.get(id=int(each_watchers)) if bx: task_node.author_set.append(bx.id) # Adding to list which holds user's to be notified about the task if bx not in user_to_be_notified: user_to_be_notified.append(bx) task_node.save(groupid=group_id) if parent: # prior node saving if not task_id: task_node.prior_node = [ObjectId(parent)] parent_object = node_collection.find_one({'_id': ObjectId(parent)}) parent_object.post_node = [task_node._id] parent_object.save(groupid=group_id) task_node.save(groupid=group_id) return task_node
def user_preferences(request, group_id, auth_id): try: grp = node_collection.one({'_id': ObjectId(auth_id)}) if request.method == "POST": lst = [] pref_to_set = request.POST['pref_to_set'] pref_list = pref_to_set.split(",") if pref_list: for each in pref_list: if each: obj = node_collection.one({'_id': ObjectId(each)}) lst.append(obj) if lst: ga_node = create_gattribute(grp._id, at_user_pref, lst) # gattribute = triple_collection.one({'$and':[{'_type':'GAttribute'},{'attribute_type.$id':at_user_pref._id},{'subject':grp._id}]}) # if gattribute: # gattribute.delete() # if lst: # create_attribute=collection.GAttribute() # create_attribute.attribute_type=at_user_pref # create_attribute.subject=grp._id # create_attribute.object_value=lst # create_attribute.save() return HttpResponse("Success") else: list_at_pref = [] user_id = request.user.id if not at_user_pref: return HttpResponse("Failure") poss_attrs = grp.get_possible_attributes(at_user_pref._id) if poss_attrs: list_at_pref = poss_attrs['user_preference_off'][ 'object_value'] all_user_groups = [] for each in get_all_user_groups(): all_user_groups.append(each.name) st = node_collection.find({ '$and': [{ '_type': 'Group' }, { 'author_set': { '$in': [user_id] } }, { 'name': { '$nin': all_user_groups } }] }) data_list = set_drawer_widget(st, list_at_pref) return HttpResponse(json.dumps(data_list)) except Exception as e: print "Exception in userpreference view " + str(e) return HttpResponse("Failure")
def display_forum(request, group_id, forum_id): hide_create_thread_btn = True other_forums_list = None other_forums = node_collection.find({ 'member_of': forum_gst._id, 'group_set': ObjectId(group_id), '_id': { '$nin': [ObjectId(forum_id)] } }) if other_forums.count(): other_forums_list = [[str(d._id), d.name] for d in other_forums] forum = node_collection.one({'_id': ObjectId(forum_id)}) usrname = User.objects.get(id=forum.created_by).username # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) forum_object = node_collection.one({'_id': ObjectId(forum_id)}) if forum_object._type == "GSystemType": return forum(request, group_id, forum_id) th_all = get_forum_twists(forum) if th_all: th_count = len(list(th_all)) else: th_count = 0 variables = RequestContext( request, { 'forum': forum, 'hide_create_thread_btn': hide_create_thread_btn, 'groupid': group_id, 'group_id': group_id, 'forum_created_by': usrname, 'other_forums': other_forums_list, 'thread_count': th_count, }) return render_to_response("ndf/forumdetails.html", variables)
def assign_groupid(system_type): """ Assigns college-group's id to group_set field of respective Student & Voluntary Teacher nodes. Arguments: system_type -- Determines type of node i.e. either Student or Voluntary Teacher Returns: Nothing """ try: system_type_id = node_collection.one({ '_type': "GSystemType", 'name': system_type })._id system_type_cur = node_collection.find({ '_type': "GSystem", 'member_of': system_type_id }) for n in system_type_cur: possible_relations = n.get_possible_relations(n.member_of) if system_type == "Student": colg_list = possible_relations["student_belongs_to_college"][ "subject_or_right_subject_list"] else: colg_list = possible_relations["trainer_of_college"][ "subject_or_right_subject_list"] group_set_updated = False for colg in colg_list: colg_group_id = node_collection.one({ '_type': "Group", 'group_type': "PRIVATE", 'name': colg.name })._id if colg_group_id not in n.group_set: n.group_set.append(colg_group_id) group_set_updated = True info_message = "\n CollegeGroupUpdation: This " + system_type + " (" + n.name + " - " + str( n._id ) + ") is added to college group (" + colg.name + " - " + str( colg_group_id) + ") successfully. \n" log_list.append(info_message) if group_set_updated: n.save() except Exception as e: error_message = " For " + n.name + " (" + str( n._id) + ") - " + str(e) + " !!!" raise Exception(error_message)
def get_id_from_hierarchy(hier_list): """ method to check hierarchy of theme-topic. returns - ObjectId or None Args: hier_list (list): # e.g: # [u'NCF', u'Biology', u'Living world', u'Biological classification'] Returns: ObjectId or None - If hierarchy found to be correct, _id/ObjectId will be returned. - else None will be returned. """ theme = hier_list[0] topic = hier_list[-1:][0] theme_items_list = hier_list[1:-1] theme_node = node_collection.one({'name': {'$regex': "^" + unicode(theme) + "$", '$options': 'i'}, 'group_set': {'$in': [home_group._id]}, 'member_of': theme_gst._id }) if not theme_node: return None node_id = theme_node._id node = theme_node for each_item in theme_items_list: node = node_collection.one({ 'name': {'$regex': "^" + unicode(each_item) + "$", '$options': 'i'}, 'prior_node': {'$in': [node_id]}, 'member_of': {'$in': [theme_item_gst._id]}, 'group_set': {'$in': [home_group._id]} }) # print each_item, "===", node.name if not node: return None node_id = node._id # print topic, "node_id : ", node_id # fetching a theme-item node topic_node = node_collection.one({ 'name': {'$regex': "^" + unicode(topic) + "$", '$options': 'i'}, 'group_set': {'$in': [home_group._id]}, 'member_of': {'$in': [topic_gst._id]}, 'prior_node': {'$in': [node_id]} }) if topic_node: return topic_node._id
def check_group_availability(*args): group_node = node_collection.one({'_id': ObjectId(CONFIG_VARIABLES.GROUP_ID)}) global log_file global DEFAULT_USER_ID print '\n\n Restoring Group' log_file.write("\n Restoring Group") if group_node: print "\n Group with restoration ID already exists." confirm_grp_data_merge = '' if args and len(args) == 4: confirm_grp_data_merge = args[2] else: confirm_grp_data_merge = raw_input("Dump Group already exists here. Would you like to merge the data ?") if confirm_grp_data_merge not in ['y', 'Y']: log_file.write("\n Group with Restore Group ID is FOUND on Target system.") call_exit() else: fp = get_file_path_with_id(CONFIG_VARIABLES.GROUP_ID) if fp: if not fp.endswith(',v'): fp = fp + ',v' log_file.write("\n Restoring Group: " + str(fp)) restore_node(fp) group_node = node_collection.one({'_id': ObjectId(CONFIG_VARIABLES.GROUP_ID)}) group_node.group_admin = [DEFAULT_USER_ID] group_node.save() log_file.write("\n Group Merge confirmed.") print " Proceeding to restore." else: print "\n Group with restoration ID DOES NOT exists." confirm_grp_data_restore = '' if args and len(args) == 4: confirm_grp_data_restore = args[2] else: confirm_grp_data_restore = raw_input("Proceed to restore ?") if confirm_grp_data_restore not in ['y', 'Y']: log_file.write("\n Group with Restore Group ID is NOT FOUND on Target system.") print " Cancelling to restore." call_exit() else: fp = get_file_path_with_id(CONFIG_VARIABLES.GROUP_ID) if fp: if not fp.endswith(',v'): fp = fp + ',v' log_file.write("\n Restoring Group: " + str(fp)) restore_node(fp) group_node = node_collection.one({'_id': ObjectId(CONFIG_VARIABLES.GROUP_ID)}) group_node.group_admin = [DEFAULT_USER_ID] group_node.save() log_file.write("\n Group Merge confirmed.") print " Proceeding to restore."
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. But to create another equivalent function and in future, replace this for write_files() ''' if not name: name = request.POST.get('name') if request else None if not created_by: created_by = request.user.id if request else None group_name, group_id = get_group_name_id(group_id) # compulsory values, if not found raise error. # if not all([name, created_by, group_id, uploaded_files]): if not all([name, created_by, group_id]): raise ValueError('"name", "created_by", "group" are mandatory args."') author_obj = node_collection.one({ '_type': u'Author', 'created_by': created_by }) author_obj_id = author_obj._id group_set = [ObjectId(group_id), ObjectId(author_obj_id)] kwargs.update({'name': unicode(name)}) kwargs.update({'created_by': created_by}) kwargs.update({'member_of': gst_asset_id}) kwargs.update({'group_set': group_set}) kwargs.update({'content': content}) if node_id: asset_gs_obj = node_collection.one({'_id': ObjectId(node_id)}) else: asset_gs_obj = node_collection.collection.GSystem() asset_gs_obj.fill_gstystem_values(request=request, **kwargs) asset_gs_obj.fill_node_values(**kwargs) asset_gs_obj.save(group_id=group_id) return asset_gs_obj
def find_file_from_media_url(source_attr): try: global log_file log_file.write("\n find_file_from_media_url invoked for: " + str(source_attr)) if "media" in source_attr: source_attr = source_attr.split("media/")[-1] file_node = node_collection.find_one({"$or": [{'if_file.original.relurl': source_attr}, {'if_file.mid.relurl': source_attr},{'if_file.thumbnail.relurl': source_attr}]}) elif "readDoc" in source_attr: split_src = source_attr.split('/') node_id = split_src[split_src.index('readDoc') + 1] file_node = node_collection.one({'_id': ObjectId(node_id)}) if file_node: log_file.write("\n media file_node gs found: " + str(file_node._id) ) get_file_node_details(file_node) except Exception as find_file_from_media_url_err: error_log = "\n !!! Error found while taking dump in find_file_from_media_url() ." error_log += "\nError: " + str(find_file_from_media_url_err) print "\n Error: ", error_log log_file.write(error_log) print error_log pass
def send_invitation(request, group_id): # Send invitation to any user to join or unsubscribe try: colg = node_collection.one({'_id': ObjectId(group_id)}) groupname = colg.name list_of_invities = request.POST.get("users", "") sender = request.user sending_user = User.objects.get(id=sender.id) list_of_users = list_of_invities.split(",") activ = "invitation to join in group" msg = "'This is to inform you that " + sending_user.username + " has subscribed you to the group " + groupname + "'" ret = "" for each in list_of_users: bx = User.objects.get(id=each) ret = set_notif_val(request, group_id, msg, activ, bx) if bx.id not in colg.author_set: colg.author_set.append(bx.id) colg.save(groupid=group_id) if ret: return HttpResponse("success") else: return HttpResponse("failure") except Exception as e: print str(e) return HttpResponse(str(e))
def getvideoThumbnail(request, group_id, _id): # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) videoobj = node_collection.one({"_id": ObjectId(_id)}) if videoobj: if hasattr(videoobj, 'if_file'): f = videoobj.get_file(videoobj.if_file.mid.relurl) return HttpResponse(f, content_type=videoobj.if_file.mime_type) else: f = videoobj.fs.files.get(ObjectId(videoobj.fs_file_ids[0])) return HttpResponse(f.read(), content_type=f.content_type)
def getFullvideo(request, group_id, _id): # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) videoobj = node_collection.one({"_id": ObjectId(_id)}) if len(videoobj.fs_file_ids) > 2: if (videoobj.fs.files.exists(videoobj.fs_file_ids[2])): f = videoobj.fs.files.get(ObjectId(videoobj.fs_file_ids[2])) return HttpResponse(f.read(), content_type=f.content_type) else : if (videoobj.fs.files.exists(videoobj.fs_file_ids[0])): f = videoobj.fs.files.get(ObjectId(videoobj.fs_file_ids[0])) return HttpResponse(f.read(), content_type=f.content_type)
def get_mid_size_img(request, group_id, _id): # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) img_obj = node_collection.one({"_id": ObjectId(_id)}) try: f = img_obj.fs.files.get(ObjectId(img_obj.fs_file_ids[2])) return HttpResponse(f.read(), content_type=f.content_type) except IndexError: f = img_obj.fs.files.get(ObjectId(img_obj.fs_file_ids[0])) return HttpResponse(f.read(), content_type=f.content_type)
def getImageThumbnail(request, group_id, _id): ''' this funciton can be called to get thumbnail of image throw url ''' # ins_objectid = ObjectId() # if ins_objectid.is_valid(group_id) is False : # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if group_ins: # group_id = str(group_ins._id) # else : # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth : # group_id = str(auth._id) # else : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) img_obj = node_collection.one({"_type": u"File", "_id": ObjectId(_id)}) if (img_obj is not None) and (len(img_obj.fs_file_ids) >= 2): # getting latest uploaded pic's _id img_fs = img_obj.fs_file_ids[1] if (img_obj.fs.files.exists(img_fs)): f = img_obj.fs.files.get(ObjectId(img_fs)) return HttpResponse(f.read(), content_type=f.content_type) else: return HttpResponse("")
def edit_comment(request, group_id, node_id=None,call_from_discussion=None): try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) if request.GET: node_id = request.GET.get('sourceObjDataId'); content_val = None if request.POST: content_val = request.POST.get("content_val", "") node_id = request.POST.get('sourceObjDataId') if node_id: node_id = node_id.strip() node_obj = node_collection.one({'_id': ObjectId(node_id)}) if content_val: node_obj.content = content_val node_obj.save() context_variables = { 'group_id': group_id, 'groupid': group_id,'node': node_obj,'node_id':node_id } template = 'ndf/html_editor.html' context_variables['var_name'] = "content_org", context_variables['var_value'] = node_obj.content context_variables['node_id'] = node_obj._id context_variables['ckeditor_toolbar'] ="BasicToolbar" return render_to_response(template, context_variables, context_instance = RequestContext(request))
def delete_multiple_resources(request, group_id): files_list = request.POST.getlist("collection[]", '') auth = node_collection.one({ '_type': 'Author', 'name': unicode(request.user.username) }) group_obj = node_collection.find_one({"_id": ObjectId(group_id)}) trash_group = node_collection.find_one({"name": "Trash"}) files_list_obj = [] for each in files_list: node_obj = node_collection.find_one({"_id": ObjectId(each)}) if ObjectId(group_id) in node_obj.group_set: node_obj.group_set.remove(ObjectId(group_id)) if ObjectId(auth._id) in node_obj.group_set: node_obj.group_set.remove(ObjectId(auth._id)) node_obj.save() if not node_obj.group_set: # Add Trash group _id to node_obj's group_set if trash_group._id not in node_obj.group_set: node_obj.group_set.append(trash_group._id) node_obj.status = u"DELETED" if node_obj.collection_set: if trash_group._id not in node_obj.group_set: node_obj.group_set.append(trash_group._id) node_obj.status = u"DELETED" node_obj.save() return HttpResponse(json.dumps(files_list))
def my_groups(request, group_id): # if request.user == 'AnonymousUser': # raise 404 try: auth_obj = get_group_name_id(group_id, get_obj=True) except: user_id = eval(group_id) auth_obj = node_collection.one({ '_type': "Author", 'created_by': user_id }) auth_id = auth_obj._id title = 'My Groups' return render_to_response('ndf/my-groups.html', { 'group_id': auth_id, 'groupid': auth_id, 'node': auth_obj, 'title': title }, context_instance=RequestContext(request))
def task_set_notify_val(request_user_id, group_id, msg, activ, to_user): ''' Attach notification mail to celery task ''' # sitename = Site.objects.all()[0] site = Site.objects.get(pk=1) site_domain = site.domain # print "=== site_domain: ", site_domain sitename = unicode(site.name.__str__()) request_user = User.objects.get(id=request_user_id) to_send_user = User.objects.get(id=to_user) try: group_obj = node_collection.one({'_id': ObjectId(group_id)}) # site = sitename.name.__str__() objurl = "http://test" render = render_to_string( "notification/label.html", { 'sender': request_user.username, 'activity': activ, 'conjunction': '-', 'object': group_obj, 'site': sitename, 'link': objurl } ) notification.create_notice_type(render, msg, "notification") notification.send([to_send_user], render, {"from_user": request_user}) return True except Exception as e: print "Error in sending notification- "+str(e) return False