def delete_thread(request,group_id,forum_id,node_id): """ Changing status of thread to HIDDEN """ ins_objectid = ObjectId() if ins_objectid.is_valid(node_id) : thread=node_collection.one({'_id':ObjectId(node_id)}) else: return forum = node_collection.one({'_id': ObjectId(forum_id)}) 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 op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': {'status': u"HIDDEN"}}) node=node_collection.one({'_id':ObjectId(node_id)}) forum_threads = [] exstng_reply = node_collection.find({'$and':[{'_type':'GSystem'},{'prior_node':ObjectId(forum._id)}],'status':{'$nin':['HIDDEN']}}) exstng_reply.sort('created_at') forum_node=node_collection.one({'_id':ObjectId(forum_id)}) for each in exstng_reply: forum_threads.append(each.name) #send notifications to all group members colg=node_collection.one({'_id':ObjectId(group_id)}) for each in colg.author_set: if each != colg.created_by: bx=get_userobject(each) if bx: activity=request.user.username+" -deleted thread " prefix=" in the forum "+forum_node.name link="http://"+sitename+"/"+str(colg._id)+"/forum/"+str(forum_node._id) msg=activity+"-"+node.name+prefix+"- in the group '"+colg.name+"' created by you."+"'\n"+"Please visit "+link+" to see the forum." # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) activity=request.user.username+" -deleted thread " prefix=" in the forum "+forum_node.name bx=get_userobject(colg.created_by) if bx: link="http://"+sitename+"/"+str(colg._id)+"/forum/"+str(forum_node._id) msg=activity+"-"+node.name+prefix+"- in the group '"+colg.name+"' created by you."+"'\n"+"Please visit "+link+" to see the forum." # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) #send notification code ends here variables = RequestContext(request,{ 'forum':forum, 'groupid':group_id,'group_id':group_id, 'forum_created_by':User.objects.get(id=forum.created_by).username }) return render_to_response("ndf/forumdetails.html",variables)
def delete_reply(request,group_id,forum_id,thread_id,node_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 #group_name, group_id = get_group_name_id(group_id) try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) activity = "" op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': {'status': u"HIDDEN"}}) # ??? CHECK replyobj=node_collection.one({'_id':ObjectId(node_id)}) forumobj=node_collection.one({"_id": ObjectId(forum_id)}) threadobj=node_collection.one({"_id": ObjectId(thread_id)}) # notifications to all group members colg=node_collection.one({'_id':ObjectId(group_id)}) link="http://"+sitename+"/"+str(colg._id)+"/forum/thread/"+str(threadobj._id) for each in colg.author_set: if each != colg.created_by: bx=get_userobject(each) if bx: msg=request.user.username+" has deleted reply- "+replyobj.content_org+"- in the thread " + threadobj.name + " in the group -'" + colg.name+"'\n"+"Please visit "+link+" to see the thread." activity="Deleted reply" #auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) }) #if colg._id and auth: #no_check=forum_notification_status(colg._id,auth._id) # else: # no_check=True # if no_check: ret = set_notif_val(request,colg._id,msg,activity,bx) prefix="-in the forum -"+forumobj.name msg=request.user.username+" has deleted reply- "+replyobj.content_org+"- in the thread " + threadobj.name +prefix+ " in the group -'" + colg.name+"' created by you"+"\n Please visit "+link+" to see the thread." bx=get_userobject(colg.created_by) if bx: # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) variables=RequestContext(request,{'thread':threadobj,'user':request.user,'forum':forumobj,'groupid':group_id,'group_id':group_id}) return HttpResponseRedirect(reverse('thread', kwargs={'group_id':group_id,'thread_id': threadobj._id }))
def invite_meeting(request, group_id, meetingid): #ramkarnani try: # print "here in view" colg = node_collection.one({'_id': ObjectId(group_id)}) groupname=colg.name # print "\n\nPOST : ", request recipient = request.GET.get("usr","") recipient = unicodedata.normalize('NFKD', recipient).encode('ascii','ignore') #print type(recipient), recipient sender=request.user sending_user=User.objects.get(username=sender).id #print type (sitename), sitename activ="invitation to join in meeting" url_of_meeting = "http://" + str(sitename) + "/" + group_id + "/meeting/" + meetingid msg="'This is to inform you that " + str(sender) + " has invited you to the meeting of " +str(groupname)+" . Please click here " + url_of_meeting +"'" #print "\n\nmsg : ", msg ret="" bx=User.objects.get(username=recipient) 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") # msg_list=msg.split() # newmeetingid=msg[16] else: return HttpResponse("failure") except Exception as e: print str(e) return HttpResponse(str(e))
def delete_forum(request, group_id, node_id, relns=None): """ Changing status of forum to HIDDEN """ # 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) op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': { 'status': u"HIDDEN" }}) node = node_collection.one({'_id': ObjectId(node_id)}) #send notifications to all group members colg = node_collection.one({'_id': ObjectId(group_id)}) for each in colg.author_set: if each != colg.created_by: bx = get_userobject(each) if bx: activity = request.user.username + " -deleted forum " msg = activity + "-" + node.name + "- in the group '" + colg.name # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) activity = request.user.username + " -deleted forum " bx = get_userobject(colg.created_by) if bx: msg = activity + "-" + node.name + "- in the group '" + colg.name + "' created by you" # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) return HttpResponseRedirect(reverse('forum', kwargs={'group_id': group_id}))
def delete_forum(request,group_id,node_id,relns=None): """ Changing status of forum to HIDDEN """ # 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) op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': {'status': u"HIDDEN"}}) node=node_collection.one({'_id':ObjectId(node_id)}) #send notifications to all group members colg=node_collection.one({'_id':ObjectId(group_id)}) for each in colg.author_set: if each != colg.created_by: bx=get_userobject(each) if bx: activity=request.user.username+" -deleted forum " msg=activity+"-"+node.name+"- in the group '"+ colg.name # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) activity=request.user.username+" -deleted forum " bx=get_userobject(colg.created_by) if bx: msg=activity+"-"+node.name+"- in the group '"+colg.name+"' created by you" # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) return HttpResponseRedirect(reverse('forum', kwargs={'group_id': group_id}))
def invite_meeting(request, group_id, meetingid): #ramkarnani try: # print "here in view" colg = node_collection.one({'_id': ObjectId(group_id)}) groupname = colg.name # print "\n\nPOST : ", request recipient = request.GET.get("usr", "") recipient = unicodedata.normalize('NFKD', recipient).encode('ascii', 'ignore') #print type(recipient), recipient sender = request.user sending_user = User.objects.get(username=sender).id #print type (sitename), sitename activ = "invitation to join in meeting" url_of_meeting = "http://" + str( sitename) + "/" + group_id + "/meeting/" + meetingid msg = "'This is to inform you that " + str( sender) + " has invited you to the meeting of " + str( groupname) + " . Please click here " + url_of_meeting + "'" #print "\n\nmsg : ", msg ret = "" bx = User.objects.get(username=recipient) 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") # msg_list=msg.split() # newmeetingid=msg[16] else: return HttpResponse("failure") except Exception as e: print str(e) return HttpResponse(str(e))
def create_thread(request, group_id, forum_id): ''' Method to create thread ''' forum = node_collection.one({'_id': ObjectId(forum_id)}) # forum_data = { # 'name':forum.name, # 'content':forum.content, # 'created_by':User.objects.get(id=forum.created_by).username # } # print forum_data forum_threads = [] exstng_reply = node_collection.find({'$and':[{'_type':'GSystem'},{'prior_node':ObjectId(forum._id)}],'status':{'$nin':['HIDDEN']}}) exstng_reply.sort('created_at') for each in exstng_reply: forum_threads.append((each.name).strip().lower()) if request.method == "POST": colg = node_collection.one({'_id':ObjectId(group_id)}) name = unicode(request.POST.get('thread_name',"")) content_org = request.POST.get('content_org',"") # ------------------- colrep = node_collection.collection.GSystem() colrep.member_of.append(twist_gst._id) # ADDED ON 14th July colrep.access_policy = u"PUBLIC" colrep.url = set_all_urls(colrep.member_of) colrep.prior_node.append(forum._id) colrep.name = name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = content_org usrid = int(request.user.id) colrep.created_by = usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.group_set.append(colg._id) colrep.save(groupid=group_id) has_thread_rt = node_collection.one({"_type": "RelationType", "name": u"has_thread"}) gr = create_grelation(forum._id, has_thread_rt, colrep._id) '''Code to send notification to all members of the group except those whose notification preference is turned OFF''' link="http://"+sitename+"/"+str(colg._id)+"/forum/thread/"+str(colrep._id) for each in colg.author_set: bx=User.objects.filter(id=each) if bx: bx=User.objects.get(id=each) else: continue activity="Added thread" msg=request.user.username+" has added a thread in the forum " + forum.name + " in the group -'" + colg.name+"'\n"+"Please visit "+link+" to see the thread." if bx: auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) }) if colg._id and auth: no_check=forum_notification_status(colg._id,auth._id) else: no_check=True if no_check: ret = set_notif_val(request,colg._id,msg,activity,bx) url_name = "/" + group_id + "/forum/thread/" + str(colrep._id) return HttpResponseRedirect(url_name) # variables = RequestContext(request, # { 'forum':forum, # 'thread':colrep, # 'eachrep':colrep, # 'groupid':group_id, # 'group_id':group_id, # 'user': request.user, # 'reply_count':0, # 'forum_threads': json.dumps(forum_threads), # 'forum_created_by':User.objects.get(id=forum.created_by).username # }) # print "\n\n renedering to thread_details" # return render_to_response("ndf/thread_details.html",variables) else: return render_to_response("ndf/create_thread.html", { 'group_id':group_id, 'groupid':group_id, 'forum': forum, 'forum_threads': json.dumps(forum_threads), 'forum_created_by':User.objects.get(id=forum.created_by).username }, RequestContext(request))
def add_node(request, group_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 group_name, group_id = get_group_name_id(group_id) try: auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) content_org = request.POST.get("reply","") node = request.POST.get("node","") thread = request.POST.get("thread","") # getting thread _id forumid = request.POST.get("forumid","") # getting forum _id sup_id = request.POST.get("supnode","") #getting _id of it's parent node tw_name = request.POST.get("twistname","") upload_files_count=int(request.POST.get("upload_cnt",0)) #print "upfiles=",upload_files_count lst=[] lstobj_collection=[] usrid = int(request.user.id) if upload_files_count > 0: #print "uploaded items",request.FILES.items() try: thread_obj = node_collection.one({'_id': ObjectId(thread)}) access_policy = thread_obj.access_policy except: access_policy = u'PUBLIC' for key,value in request.FILES.items(): fname=unicode(value.__dict__['_name']) #print "key=",key,"value=",value,"fname=",fname fileobj,fs=save_file(value,fname,usrid,group_id, "", "", username=unicode(request.user.username), access_policy=access_policy, count=0, first_object="") if type(fileobj) == list: obid = str(list(fileobj)[1]) else: obid=str(fileobj) file_obj=node_collection.find_one({'_id': ObjectId(obid)}) lstobj_collection.append(file_obj._id) forumobj = "" groupobj = "" colg = node_collection.one({'_id':ObjectId(group_id)}) if forumid: forumobj = node_collection.one({"_id": ObjectId(forumid)}) sup = node_collection.one({"_id": ObjectId(sup_id)}) if not sup : return HttpResponse("failure") colrep = node_collection.collection.GSystem() if node == "Twist": name = tw_name colrep.member_of.append(twist_gst._id) elif node == "Reply": name = unicode("Reply of:"+str(sup._id)) colrep.member_of.append(reply_gst._id) #Adding uploaded files id's in collection set of reply if upload_files_count > 0: colrep.collection_set = lstobj_collection colrep.prior_node.append(sup._id) colrep.name = name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = content_org colrep.created_by = usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.prior_node.append(sup._id) colrep.name = name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = content_org usrid=int(request.user.id) colrep.created_by=usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.group_set.append(colg._id) colrep.save(groupid=group_id) # print "----------", colrep._id groupname = colg.name if node == "Twist" : url="http://"+sitename+"/"+str(group_id)+"/forum/thread/"+str(colrep._id) activity=request.user.username+" -added a thread '" prefix="' on the forum '"+forumobj.name+"'" nodename=name if node == "Reply": threadobj=node_collection.one({"_id": ObjectId(thread)}) url="http://"+sitename+"/"+str(group_id)+"/forum/thread/"+str(threadobj._id) activity=request.user.username+" -added a reply " prefix=" on the thread '"+threadobj.name+"' on the forum '"+forumobj.name+"'" nodename="" link = url for each in colg.author_set: if each != colg.created_by: bx=User.objects.get(id=each) msg=activity+"-"+nodename+prefix+" in the group '"+ groupname +"'\n"+"Please visit "+link+" to see the updated page" if bx: no_check=forum_notification_status(group_id,auth._id) if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) bx=User.objects.get(id=colg.created_by) msg=activity+"-"+nodename+prefix+" in the group '"+groupname+"' created by you"+"\n"+"Please visit "+link+" to see the updated page" if bx: no_check=forum_notification_status(group_id,auth._id) if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) if node == "Reply": # if exstng_reply: # exstng_reply.prior_node =[] # exstng_reply.prior_node.append(colrep._id) # exstng_reply.save() threadobj=node_collection.one({"_id": ObjectId(thread)}) variables=RequestContext(request,{'thread':threadobj,'user':request.user,'forum':forumobj,'groupid':group_id,'group_id':group_id}) return render_to_response("ndf/refreshtwist.html",variables) else: templ=get_template('ndf/refreshthread.html') html = templ.render(Context({'forum':forumobj,'user':request.user,'groupid':group_id,'group_id':group_id})) return HttpResponse(html) except Exception as e: return HttpResponse(""+str(e)) return HttpResponse("success")
def approve_resource(request, group_id): ''' Method to approve resorce. Means resource will get published by moderator to next moderated or parent group. ''' group_obj = get_group_name_id(group_id, get_obj=True) node_id = request.POST.get('node_oid', '') node_obj = node_collection.one({'_id': ObjectId(node_id)}) approve_or_reject = request.POST.get('app_rej_state', '') flag = 0 # good to check at JS/front-end level if approve_or_reject == "Approve": if node_obj: node_group_set = node_obj.group_set # task_id = get_relation_value(node_obj._id,"has_current_approval_task") # make deep copy of object and not to copy it's reference with [:]. group_set_details_dict = get_moderator_group_set(node_group_set[:], group_id, get_details=True) updated_group_set = group_set_details_dict['updated_group_set'] # print "==== updated_group_set : ", updated_group_set # print "==== node_group_set : ", node_group_set # print "==== group_set_details_dict : ", group_set_details_dict # if set(node_group_set) != set(updated_group_set): if group_set_details_dict['is_group_set_updated']: node_obj.group_set = updated_group_set # ---| checking for top group. \ # If not top group and it's fond to be sub group create task |--- # one way: # group_obj = get_group_name_id(updated_group_set[len(updated_group_set) - 1], get_obj=True) # print "===== group_obj.member_of_names_list : ", group_obj.member_of_names_list # if group_obj.member_of_names_list[0] in ['ProgramEventGroup', 'CourseEventGroup', 'PartnerGroup', 'ModeratingGroup']: # second way: if group_set_details_dict['is_new_group_top_group']: # means, resource is passed through curation flow and \ # therefore change the status from 'MODERATION' to 'PUBLISHED' node_obj.status = u'PUBLISHED' # intimate creator of object/resource and creator of parent group node_creator_username = User.objects.get(id=node_obj.created_by).username task_content_org = u"Congratulations " + unicode(node_creator_username) + \ u",\n\n Your contribution is moderated and it's published to " + \ group_set_details_dict['newly_appended_group_name'] + \ u". \n\nWe appreciate your efforts and thank you for your contribution!" create_moderator_task(request, \ group_set_details_dict['newly_appended_group_id'],\ node_obj._id, task_type_creation='multiple', \ task_type='Other', task_content_org=task_content_org,\ created_by_name=node_creator_username) else: # resource is in curation flow hence, create a task create_moderator_task(request, \ group_set_details_dict['newly_appended_group_id'],\ node_obj._id) # node_obj.modified_by = int(request.user.id) node_obj.save(groupid=group_id) flag = 1 else: flag = 0 elif approve_or_reject == "Reject": reject_reason_msg = request.POST.get('reject_reason', '') # print "reject_reason_msg----", reject_reason_msg # raise Exception("bb") # task_node,task_rt = get_relation_value(node_obj._id,"has_current_approval_task") grel_dict = get_relation_value(node_obj._id,"has_current_approval_task") is_cursor = grel_dict.get("cursor",False) if not is_cursor: task_node = grel_dict.get("grel_node") task_rt = grel_dict.get("grel_id") auth_grp = node_collection.one({'_type': "Author", 'created_by': int(node_obj.created_by)}) node_obj.group_set = [auth_grp._id] node_obj.status = u"DRAFT" node_obj.save() # is_top_group, top_group_obj = get_top_group_of_hierarchy(group_obj._id) mod_group_instance = CreateModeratedGroup(request) # is_top_group, top_group_obj = mod_group_instance.get_top_group_of_hierarchy(curr_group_id) is_top_group, top_group_obj = mod_group_instance.get_top_group_of_hierarchy(group_obj._id) list_of_recipients_ids = [] list_of_recipients_ids.extend(group_obj.group_admin) list_of_recipients_ids.extend(top_group_obj.group_admin) list_of_recipients_ids.append(node_obj.created_by) # print list_of_recipients_ids if task_node: task_content_org = u"\n\nThis task is CLOSED.\n " \ "The resource associated with Moderation Task has been REJECTED. \n" task_dict = { "name": task_node.name, "_id" : ObjectId(task_node._id), "created_by": node_obj.created_by, "modified_by": request.user.id, "contributors": [request.user.id], "content_org": unicode(task_content_org), "created_by_name": unicode(request.user.username), "Status": u"CLOSED", "Priority": u"Normal", "Assignee": list(group_obj.group_admin[:]), # "has_type": task_type_list } task_obj = create_task(task_dict, 'group') # Sending notification to all watchers about the updates of the task try: for each_user_id in list_of_recipients_ids: activ = "Contribution to " + group_obj.name +"." mail_content = u"\n The resource "+ node_obj.name +" is REJECTED by " \ + request.user.username + ". \n" \ + "Reason specified: "+ unicode(reject_reason_msg) user_obj = User.objects.get(id=int(each_user_id)) set_notif_val(request, group_obj._id, mail_content, activ, user_obj) except Exception as e: print "\n Unable to send notifications ",e flag = 1 return HttpResponse(flag)
def edit_forum(request,group_id,forum_id): ''' Method to create forum and Retrieve all the forums ''' forum = node_collection.one({ '_id': ObjectId(forum_id) }) # # method to convert group_id to ObjectId if it is groupname # 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 group_name, group_id = get_group_name_id(group_id) # getting all the values from submitted form if request.method == "POST": colg = node_collection.one({'_id':ObjectId(group_id)}) # getting group ObjectId colf = node_collection.one({'_id':ObjectId(forum_id)}) # creating new/empty GSystem object name = unicode(request.POST.get('forum_name',"")).strip() # forum name colf.name = name content_org = request.POST.get('content_org',"") # forum content if content_org: colf.content_org = unicode(content_org) usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colf.content = content_org usrid = int(request.user.id) usrname = unicode(request.user.username) colf.modified_by = usrid if usrid not in colf.contributors: colf.contributors.append(usrid) ################# ADDED 14th July.Its done! colf.access_policy = u"PUBLIC" colf.url = set_all_urls(colf.member_of) ### currently timed forum feature is not in use ### # sdate=request.POST.get('sdate',"") # shrs= request.POST.get('shrs',"") # smts= request.POST.get('smts',"") # edate= request.POST.get('edate',"") # ehrs= request.POST.get('ehrs',"") # emts=request.POST.get('emts',"") # start_dt={} # end_dt={} # if not shrs: # shrs=0 # if not smts: # smts=0 # if sdate: # sdate1=sdate.split("/") # st_date = datetime.datetime(int(sdate1[2]),int(sdate1[0]),int(sdate1[1]),int(shrs),int(smts)) # start_dt[start_time.name]=st_date # if not ehrs: # ehrs=0 # if not emts: # emts=0 # if edate: # edate1=edate.split("/") # en_date= datetime.datetime(int(edate1[2]),int(edate1[0]),int(edate1[1]),int(ehrs),int(emts)) # end_dt[end_time.name]=en_date # colf.attribute_set.append(start_dt) # colf.attribute_set.append(end_dt) colf.save(groupid=group_id) '''Code to send notification to all members of the group except those whose notification preference is turned OFF''' link="http://"+sitename+"/"+str(colg._id)+"/forum/"+str(colf._id) for each in colg.author_set: bx=User.objects.get(id=each) activity="Edited forum" msg=usrname+" has edited forum -" +colf.name+" in the group -'"+colg.name+"'\n"+"Please visit "+link+" to see the forum." if bx: auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) }) if colg._id and auth: no_check=forum_notification_status(colg._id,auth._id) else: no_check=True if no_check: ret = set_notif_val(request,colg._id,msg,activity,bx) # returning response to ndf/forumdetails.html return HttpResponseRedirect(reverse('show', kwargs={'group_id':group_id,'forum_id': colf._id })) # variables=RequestContext(request,{'forum':colf}) # return render_to_response("ndf/forumdetails.html",variables) # getting all the GSystem of forum to provide autocomplete/intellisence of forum names available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(forum_gst._id),'group_set': ObjectId(group_id) }) nodes_list = [] for each in available_nodes: nodes_list.append(str((each.name).strip().lower())) return render_to_response("ndf/edit_forum.html",{'group_id':group_id,'groupid':group_id, 'nodes_list': nodes_list,'forum':forum},RequestContext(request))
def create_partner(request, group_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 group_obj = get_group_name_id(group_id, get_obj=True) pg_gst = node_collection.one({ '_type': "GSystemType", 'name': "PartnerGroup" }) try: if request.method == "POST": colg = node_collection.collection.Group() street = request.POST.get('street', "") cname = request.POST.get('groupname', "").strip() colg.altnames = cname colg.name = unicode(cname) colg.member_of.append(gst_group._id) usrid = int(request.user.id) colg.created_by = usrid colg.author_set.append(usrid) colg.modified_by = usrid colg.contributors.append(usrid) #colg.group_type = request.POST.get('group_type', "") #colg.edit_policy = request.POST.get('edit_policy', "") #colg.subscription_policy = request.POST.get('subscription', "") colg.visibility_policy = request.POST.get('existance', 'ANNOUNCED') colg.disclosure_policy = request.POST.get('member', 'DISCLOSED_TO_MEM') colg.encryption_policy = request.POST.get('encryption', 'NOT_ENCRYPTED') colg.agency_type = "Partner" colg.save(groupid=group_id) # get alll attribute associated with partner attribute_set = colg.get_possible_attributes(colg.member_of).keys() activ = "Request to become a partner" msg = colg.name + " is interested to became a partner on the platform " set_notif_val(request, colg._id, msg, activ, request.user) for each in attribute_set: if each != "apps_list": obj_val = request.POST.get(each, "").strip() att_type = node_collection.one({ '_type': "AttributeType", "name": each }) # set Attribute type values for partner create_gattribute(colg._id, att_type, object_value=obj_val) auth = node_collection.one({ '_type': 'Author', 'name': unicode(request.user.username) }) # has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) # shelves = [] # shelf_list = {} # if auth: # shelf = triple_collection.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type': has_shelf_RT._id }) # 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 = [] return render_to_response( "ndf/groupdashboard.html", { 'groupobj': colg, 'appId': app._id, 'node': colg, 'user': request.user, 'groupid': colg._id, 'group_id': colg._id, # 'shelf_list': shelf_list,'shelves': shelves }, context_instance=RequestContext(request)) except Exception as e: print "\n\n e", e available_nodes = node_collection.find({ '_type': u'Group', 'member_of': ObjectId(gst_group._id) }) nodes_list = [] for each in available_nodes: nodes_list.append(str((each.name).strip().lower())) return render_to_response( "ndf/create_partner.html", { 'groupid': group_id, 'group_obj': group_obj, 'appId': app._id, 'group_id': group_id, 'nodes_list': nodes_list }, RequestContext(request))
def add_node(request,group_id): ins_objectid = ObjectId() if ins_objectid.is_valid(group_id) is False : group_ins = collection.Node.find_one({'_type': "Group","name": group_id}) auth = collection.Node.one({'_type': 'Author', 'name': unicode(request.user.username) }) if group_ins: group_id = str(group_ins._id) else : auth = collection.Node.one({'_type': 'Author', 'name': unicode(request.user.username) }) if auth : group_id = str(auth._id) else : pass try: sitename=Site.objects.all()[0].name.__str__() content_org=request.POST.get("reply","") node=request.POST.get("node","") thread=request.POST.get("thread","") forumid=request.POST.get("forumid","") sup_id=request.POST.get("supnode","") tw_name=request.POST.get("twistname","") forumobj="" groupobj="" colg = collection.Group.one({'_id':ObjectId(group_id)}) if forumid: forumobj=collection.GSystem.one({"_id": ObjectId(forumid)}) sup=collection.GSystem.one({"_id": ObjectId(sup_id)}) if not sup : return HttpResponse("failure") colrep=collection.GSystem() if node == "Twist": name=tw_name colrep.member_of.append(twist_st._id) elif node == "Reply": name=unicode("Reply of:"+str(sup._id)) colrep.member_of.append(reply_st._id) colrep.prior_node.append(sup._id) colrep.name=name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = org2html(content_org, file_prefix=filename) usrid=int(request.user.id) colrep.created_by=usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.group_set.append(colg._id) colrep.save() groupname=colg.name if node == "Twist" : url="http://"+sitename+"/"+str(group_id)+"/forum/thread/"+str(colrep._id) activity=str(request.user.username)+" -added a thread '" prefix="' on the forum '"+forumobj.name+"'" nodename=name if node == "Reply": threadobj=collection.GSystem.one({"_id": ObjectId(thread)}) url="http://"+sitename+"/"+str(group_id)+"/forum/thread/"+str(threadobj._id) activity=str(request.user.username)+" -added a reply " prefix=" on the thread '"+threadobj.name+"' on the forum '"+forumobj.name+"'" nodename="" link=url for each in colg.author_set: bx=User.objects.get(id=each) msg=activity+"-"+nodename+prefix+" in the group '"+str(groupname)+"'\n"+"Please visit "+link+" to see the updated page" if bx: ret = set_notif_val(request,group_id,msg,activity,bx) bx=User.objects.get(id=colg.created_by) msg=activity+"-"+nodename+prefix+" in the group '"+str(groupname)+"' created by you"+"\n"+"Please visit "+link+" to see the updated page" if bx: ret = set_notif_val(request,group_id,msg,activity,bx) if node == "Reply": # if exstng_reply: # exstng_reply.prior_node =[] # exstng_reply.prior_node.append(colrep._id) # exstng_reply.save() threadobj=collection.GSystem.one({"_id": ObjectId(thread)}) variables=RequestContext(request,{'thread':threadobj,'user':request.user,'forum':forumobj,'groupid':group_id,'group_id':group_id}) return render_to_response("ndf/refreshtwist.html",variables) else: templ=get_template('ndf/refreshthread.html') html = templ.render(Context({'forum':forumobj,'user':request.user,'groupid':group_id,'group_id':group_id})) return HttpResponse(html) except Exception as e: return HttpResponse(""+str(e)) return HttpResponse("success")
def create_moderator_task(request, group_id, node_id, \ task_type_creation='group', task_type='Moderation', task_content_org="", \ created_by_name="",on_upload=False): ''' Method to create task to group admins or moderators of the moderated groups. ''' from gnowsys_ndf.ndf.templatetags.ndf_tags import get_relation_value # def create_task(task_dict, task_type_creation="single"): # task_dict # - Required keys: _id[optional], name, group_set, created_by, modified_by, contributors, content_org, # created_by_name, Status, Priority, start_time, end_time, Assignee, has_type try: task_dict = {} node_obj = node_collection.one({'_id': ObjectId(node_id)}) # task_id_val = get_relation_value(node_obj._id,"has_current_approval_task") grel_dict = get_relation_value(node_obj._id,"has_current_approval_task") is_cursor = grel_dict.get("cursor",False) if not is_cursor: task_node = grel_dict.get("grel_node",None) if task_node: task_dict['_id'] = task_node._id # grel_id = grel_dict.get("grel_id") # if task_id_val != None: # task_dict['_id'] = get_relation_value(node_obj._id,"has_current_approval_task") # if node_obj.relation_set: # for rel in node_obj.relation_set: # if rel and 'has_current_approval_task' in rel: # task_id = rel['has_current_approval_task'][0] # task_dict["_id"] = ObjectId(task_id) # last group is next appended group group_obj = get_group_name_id(group_id, get_obj=True) at_curr_app_task = node_collection.one({'_type': "RelationType", 'name': "has_current_approval_task"}) glist_gst = node_collection.one({'_type': "GSystemType", 'name': "GList"}) task_type_list = [] task_type_list.append(node_collection.one({'member_of': glist_gst._id, 'name':unicode(task_type)})._id) site = Site.objects.get(pk=1) site_domain = site.domain # print "=== site_domain: ", site_domain site = unicode(site.name.__str__()) auth_grp = node_collection.one({'_type': "Author", 'created_by': int(node_obj.created_by)}) if task_type == "Moderation": task_title = u"Resource under moderation: " + node_obj.name if task_content_org: pass else: url = u"http://" + site_domain + "/"+ unicode(group_obj._id) \ + u"/moderation#" + unicode(node_obj._id.__str__()) task_content_org = u'\n\nResource under moderation: "' + unicode(node_obj.name) \ + u'" having id: "' + unicode(node_obj._id.__str__()) + '"' \ task_dict = { "name": task_title, "group_set": [group_obj._id], "created_by": node_obj.created_by, "modified_by": request.user.id, "contributors": [request.user.id], "content_org": unicode(task_content_org), "created_by_name": unicode(request.user.username), # "Status": u"New", "Priority": u"Normal", # "start_time": "", # "end_time": "", "Assignee": list(group_obj.group_admin[:]), "has_type": task_type_list } if on_upload: task_dict['Status'] = u"New" else: task_dict['Status'] = u"In Progress" task_obj = create_task(task_dict, task_type_creation) if task_obj: create_grelation(node_obj._id, at_curr_app_task, task_obj._id) try: url = u"http://" + site_domain + "/" + unicode(auth_grp._id) \ + u"/moderation/status/" + unicode(node_obj._id.__str__()) activ = "Contribution to " + group_obj.name + "." if not on_upload: mail_content = "Moderation status of your contributed file has been updated.\n" \ + "You may visit this link to check the status of Moderation :\t" \ + url elif on_upload: mail_content = "Your contributed file has been sent for Moderation.\n" \ + "You may visit this link to check the status of Moderation :\t" \ + url user_obj = User.objects.get(id=node_obj.created_by) set_notif_val(request, auth_grp._id, mail_content, activ, user_obj) except Exception as notif_err: # print notif_err msg = "Unable to send Notification" else: # on final publish to top group # task_title = u"\n\nResource " + node_obj.name + \ # u" in " + group_obj.name + u" is Approved. " # task_dict = { # "name": task_title, # "modified_by": request.user.id, # "created_by_name": unicode(request.user.username), # "Status": u"Feedback", # "group_set": [group_obj._id], # "created_by": node_obj.created_by, # "content_org": unicode(task_content_org), # "modified_by": request.user.id, # "contributors": [request.user.id], # "Priority": u"Normal", # "Assignee": list(group_obj.group_admin[:] + [node_obj.created_by]), # "has_type": task_type_list # } try: # delete the task associated with the resource list_of_recipients_ids = [] list_of_recipients_ids.extend(group_obj.group_admin) list_of_recipients_ids.append(node_obj.created_by) # Sending notification to all watchers about the updates of the task for each_user_id in list_of_recipients_ids: url = u"http://" + site_domain + "/"+ unicode(group_obj._id) \ + u"/file/" + unicode(node_obj._id.__str__()) activ = "Contribution to " + group_obj.name +"." mail_content = u"\n\n Contribution file "+ node_obj.name +" is moderated " \ + "and successfully published to " + \ group_obj.name + \ u". \n\nVisit this link to view the resource : " \ + url user_obj = User.objects.get(id=int(each_user_id)) set_notif_val(request, auth_grp._id, mail_content, activ, user_obj) if task_id: task_node = node_collection.one({'_id': ObjectId(task_id)}) # del_status, del_status_msg = delete_node( # node_id=task_node._id, deletion_type=0) url = u"http://" + site_domain + "/"+ unicode(group_obj._id) \ + u"/file/" + unicode(node_obj._id.__str__()) task_content_org = u"\n\nThis task is CLOSED.\n " \ "However, you may find the moderated resource at following link: \n" \ + unicode(url) task_dict = { "name": task_node.name, "group_set": [group_obj._id], "created_by": node_obj.created_by, "modified_by": request.user.id, "contributors": [request.user.id], "content_org": unicode(task_content_org), "created_by_name": unicode(request.user.username), "Status": u"CLOSED", "Priority": u"Normal", "Assignee": list(group_obj.group_admin[:]), "has_type": task_type_list } task_obj = create_task(task_dict, task_type_creation) except Exception as e: msg = "Unable to send Notification", str(e) except Exception as e: print "Error in task create moderation --- " + str(e)
def update(request, rt_list, at_list, task_node, group_id, group_name): file_id = (request.POST.get("files")) file_name = (request.POST.get("files_name")) user_to_be_notified = [] assignee_list = [] change_list = [] for each in rt_list: rel_type_node = node_collection.one({ '_type': "RelationType", 'name': each }) field_value_list = None if rel_type_node["object_cardinality"] > 1: field_value_list = request.POST.get(rel_type_node["name"], "") if "[" in field_value_list and "]" in field_value_list: field_value_list = json.loads(field_value_list) else: field_value_list = request.POST.getlist(rel_type_node["name"]) else: field_value_list = request.POST.getlist(rel_type_node["name"]) for i, field_value in enumerate(field_value_list): field_value = parse_template_data(rel_type_node.object_type, field_value, field_instance=rel_type_node) field_value_list[i] = field_value old_value = [] for rel in task_node.relation_set: for k in rel: if rel_type_node.name == k: vals_cur = node_collection.find({'_id': { '$in': rel[k] }}, {'name': 1}) for v_node in vals_cur: old_value.append(v_node.name) break new_value = [] vals_cur = node_collection.find({'_id': { '$in': field_value_list }}, {'name': 1}) for v_node in vals_cur: new_value.append(v_node.name) break if old_value != new_value: change_list.append( each.encode('utf8') + ' changed from ' + ", ".join(old_value) + ' to ' + ", ".join(new_value)) # updated details task_gs_triple_instance = create_grelation( task_node._id, node_collection.collection.RelationType(rel_type_node), field_value_list) task_node.reload() for each in at_list: if request.POST.get(each, ""): attributetype_key = node_collection.find_one({ "_type": 'AttributeType', 'name': each }) attr = triple_collection.find_one({ "_type": "GAttribute", "subject": task_node._id, "attribute_type": attributetype_key._id }) if each == "Assignee": field_value = request.POST.getlist(each, "") for i, val in enumerate(field_value): field_value[i] = int(val) assignee_list_id = field_value for eachuser in assignee_list_id: bx = User.objects.get(id=int(eachuser)) if bx: if bx.username not in assignee_list: assignee_list.append(bx.username) # 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) else: field_value = request.POST.get(each, "") date_format_string = "" if each in ["start_time", "end_time"]: date_format_string = "%d/%m/%Y" field_value = parse_template_data( eval(attributetype_key["data_type"]), field_value, date_format_string=date_format_string) if attr: # already attribute exist if not attr.object_value == field_value: # change_list.append(each.encode('utf8')+' changed from '+attr.object_value.encode('utf8')+' to '+request.POST.get(each,"").encode('utf8')) # updated details if attributetype_key["data_type"] == "datetime.datetime": change_list.append( each.encode('utf8') + ' changed from ' + attr.object_value.strftime("%d/%m/%Y") + ' to ' + field_value.strftime("%d/%m/%Y") ) # updated details else: change_list.append( each.encode('utf8') + ' changed from ' + str(attr.object_value) + ' to ' + str(field_value)) # updated details attr.object_value = field_value attr.save(groupid=group_id) else: # attributetype_key = node_collection.find_one({"_type":'AttributeType', 'name':each}) # newattribute = triple_collection.collection.GAttribute() # newattribute.subject = task_node._id # newattribute.attribute_type = attributetype_key # newattribute.object_value = request.POST.get(each,"") # newattribute.object_value = field_value # newattribute.save() ga_node = create_gattribute(task_node._id, attributetype_key, field_value) # change_list.append(each.encode('utf8')+' set to '+request.POST.get(each,"").encode('utf8')) # updated details change_list.append( each.encode('utf8') + ' set to ' + str(field_value)) # updated details elif each == 'Upload_Task': attributetype_key = node_collection.find_one({ "_type": 'AttributeType', 'name': 'Upload_Task' }) attr = triple_collection.find_one({ "_type": "GAttribute", "subject": task_node._id, "attribute_type": attributetype_key._id }) if attr: value = get_file_node(attr.object_value) change_list.append( each.encode('utf8') + ' changed from ' + str(value).strip('[]') + ' to ' + str(file_name)) # attr.object_value=file_id # attr.save() ga_node = create_gattribute(attr.subject, attributetype_key, file_id) else: # newattribute = node_collection.collection.GAttribute() # newattribute.subject = task_node._id # newattribute.attribute_type = attributetype_key # newattribute.object_value = file_id # newattribute.save() ga_node = create_gattribute(task_node._id, attributetype_key, file_id) change_list.append( each.encode('utf8') + ' set to ' + file_name.encode('utf8')) # updated details # userobj = User.objects.get(id=task_node.created_by) # if userobj and userobj not in user_to_be_notified: # user_to_be_notified.append(userobj) for each_author in task_node.author_set: each_author = User.objects.get(id=each_author) if each_author and each_author not in user_to_be_notified: user_to_be_notified.append(each_author) # Sending notification to all watchers about the updates of the task for eachuser in user_to_be_notified: activ = "task updated" msg = "Task '" + task_node.name + \ "' has been updated by " + request.user.username + \ "\n - Changes: " + str(change_list).strip('[]') + \ "\n - Status: " + request.POST.get('Status','') + \ "\n - Assignee: " + ", ".join(assignee_list) + \ "\n - Url: http://" + site_domain + "/" + group_name.replace(" ","%20").encode('utf8') + "/task/" + str(task_node._id) bx = User.objects.get(username=eachuser) set_notif_val(request, group_id, msg, activ, bx) if change_list or content_org: GST_task_update_history = node_collection.one({ '_type': "GSystemType", 'name': 'task_update_history' }) update_node = node_collection.collection.GSystem() get_node_common_fields(request, update_node, group_id, GST_task_update_history) if change_list: update_node.altnames = unicode(str(change_list)) else: update_node.altnames = unicode('[]') update_node.prior_node = [task_node._id] update_node.name = unicode(task_node.name + "-update_history") update_node.save(groupid=group_id) update_node.name = unicode(task_node.name + "-update_history-" + str(update_node._id)) update_node.save(groupid=group_id) task_node.post_node.append(update_node._id) task_node.save(groupid=group_id) # patch GST_TASK = node_collection.one({ '_type': "GSystemType", 'name': 'Task' }) get_node_common_fields(request, task_node, group_id, GST_TASK) task_node.save(groupid=group_id)
def edit_thread(request, group_id, forum_id, thread_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) forum = node_collection.one({'_id': ObjectId(forum_id)}) thread = node_collection.one({'_id': ObjectId(thread_id)}) exstng_reply = node_collection.find( {'$and': [{ '_type': 'GSystem' }, { 'prior_node': ObjectId(forum._id) }]}) nodes = [] exstng_reply.sort('created_at') for each in exstng_reply: nodes.append(each.name) request.session['nodes'] = json.dumps(nodes) colg = node_collection.one({'_id': ObjectId(group_id)}) if request.method == 'POST': name = unicode(request.POST.get('thread_name', "")) # thread name thread.name = name content_org = request.POST.get('content_org', "") # thread content # print "content=",content_org if content_org: thread.content_org = unicode(content_org) usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" thread.content = content_org thread.save(groupid=group_id) link = "http://" + sitename + "/" + str( colg._id) + "/forum/thread/" + str(thread._id) for each in colg.author_set: if each != colg.created_by: bx = get_userobject(each) if bx: msg = request.user.username + " has edited thread- " + thread.name + "- in the forum " + forum.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the thread." activity = "Edited thread" #auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) }) #if colg._id and auth: #no_check=forum_notification_status(colg._id,auth._id) # else: # no_check=True # if no_check: ret = set_notif_val(request, colg._id, msg, activity, bx) activity = request.user.username + " edited thread -" bx = get_userobject(colg.created_by) prefix = "-in the forum -" + forum.name if bx: msg = activity + "-" + thread.name + prefix + " in the group '" + colg.name + "' created by you" + "\n" + "Please visit " + link + " to see the thread" # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) variables = RequestContext( request, { 'group_id': group_id, 'thread_id': thread._id, 'nodes': json.dumps(nodes) }) return HttpResponseRedirect( reverse('thread', kwargs={ 'group_id': group_id, 'thread_id': thread._id })) else: return render_to_response( "ndf/edit_thread.html", { 'group_id': group_id, 'groupid': group_id, 'forum': forum, 'thread': thread, 'forum_created_by': User.objects.get(id=forum.created_by).username }, RequestContext(request))
def add_node(request, group_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 group_name, group_id = get_group_name_id(group_id) try: auth = node_collection.one({ '_type': 'Author', 'name': unicode(request.user.username) }) content_org = request.POST.get("reply", "") node = request.POST.get("node", "") thread = request.POST.get("thread", "") # getting thread _id forumid = request.POST.get("forumid", "") # getting forum _id sup_id = request.POST.get("supnode", "") #getting _id of it's parent node tw_name = request.POST.get("twistname", "") upload_files_count = int(request.POST.get("upload_cnt", 0)) #print "upfiles=",upload_files_count lst = [] lstobj_collection = [] usrid = int(request.user.id) if upload_files_count > 0: #print "uploaded items",request.FILES.items() try: thread_obj = node_collection.one({'_id': ObjectId(thread)}) access_policy = thread_obj.access_policy except: access_policy = u'PUBLIC' for key, value in request.FILES.items(): fname = unicode(value.__dict__['_name']) #print "key=",key,"value=",value,"fname=",fname fileobj, fs = save_file(value, fname, usrid, group_id, "", "", username=unicode( request.user.username), access_policy=access_policy, count=0, first_object="") if type(fileobj) == list: obid = str(list(fileobj)[1]) else: obid = str(fileobj) file_obj = node_collection.find_one({'_id': ObjectId(obid)}) lstobj_collection.append(file_obj._id) forumobj = "" groupobj = "" colg = node_collection.one({'_id': ObjectId(group_id)}) if forumid: forumobj = node_collection.one({"_id": ObjectId(forumid)}) sup = node_collection.one({"_id": ObjectId(sup_id)}) if not sup: return HttpResponse("failure") colrep = node_collection.collection.GSystem() if node == "Twist": name = tw_name colrep.member_of.append(twist_gst._id) elif node == "Reply": name = unicode("Reply of:" + str(sup._id)) colrep.member_of.append(reply_gst._id) #Adding uploaded files id's in collection set of reply if upload_files_count > 0: colrep.collection_set = lstobj_collection colrep.prior_node.append(sup._id) colrep.name = name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = content_org colrep.created_by = usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.prior_node.append(sup._id) colrep.name = name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = content_org usrid = int(request.user.id) colrep.created_by = usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.group_set.append(colg._id) colrep.save(groupid=group_id) # print "----------", colrep._id groupname = colg.name if node == "Twist": url = "http://" + sitename + "/" + str( group_id) + "/forum/thread/" + str(colrep._id) activity = request.user.username + " -added a thread '" prefix = "' on the forum '" + forumobj.name + "'" nodename = name if node == "Reply": threadobj = node_collection.one({"_id": ObjectId(thread)}) url = "http://" + sitename + "/" + str( group_id) + "/forum/thread/" + str(threadobj._id) activity = request.user.username + " -added a reply " prefix = " on the thread '" + threadobj.name + "' on the forum '" + forumobj.name + "'" nodename = "" link = url for each in colg.author_set: if each != colg.created_by: bx = User.objects.get(id=each) msg = activity + "-" + nodename + prefix + " in the group '" + groupname + "'\n" + "Please visit " + link + " to see the updated page" if bx: no_check = forum_notification_status(group_id, auth._id) if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) bx = User.objects.get(id=colg.created_by) msg = activity + "-" + nodename + prefix + " in the group '" + groupname + "' created by you" + "\n" + "Please visit " + link + " to see the updated page" if bx: no_check = forum_notification_status(group_id, auth._id) if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) if node == "Reply": # if exstng_reply: # exstng_reply.prior_node =[] # exstng_reply.prior_node.append(colrep._id) # exstng_reply.save() threadobj = node_collection.one({"_id": ObjectId(thread)}) variables = RequestContext( request, { 'thread': threadobj, 'user': request.user, 'forum': forumobj, 'groupid': group_id, 'group_id': group_id }) return render_to_response("ndf/refreshtwist.html", variables) else: templ = get_template('ndf/refreshthread.html') html = templ.render( Context({ 'forum': forumobj, 'user': request.user, 'groupid': group_id, 'group_id': group_id })) return HttpResponse(html) except Exception as e: return HttpResponse("" + str(e)) return HttpResponse("success")
def create_thread(request, group_id, forum_id): ''' Method to create thread ''' forum = node_collection.one({'_id': ObjectId(forum_id)}) # forum_data = { # 'name':forum.name, # 'content':forum.content, # 'created_by':User.objects.get(id=forum.created_by).username # } # print forum_data forum_threads = [] exstng_reply = node_collection.find({ '$and': [{ '_type': 'GSystem' }, { 'prior_node': ObjectId(forum._id) }], 'status': { '$nin': ['HIDDEN'] } }) exstng_reply.sort('created_at') for each in exstng_reply: forum_threads.append((each.name).strip().lower()) if request.method == "POST": colg = node_collection.one({'_id': ObjectId(group_id)}) name = unicode(request.POST.get('thread_name', "")) content_org = request.POST.get('content_org', "") # ------------------- colrep = node_collection.collection.GSystem() colrep.member_of.append(twist_gst._id) # ADDED ON 14th July colrep.access_policy = u"PUBLIC" colrep.url = set_all_urls(colrep.member_of) colrep.prior_node.append(forum._id) colrep.name = name if content_org: colrep.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colrep.content = content_org usrid = int(request.user.id) colrep.created_by = usrid colrep.modified_by = usrid if usrid not in colrep.contributors: colrep.contributors.append(usrid) colrep.group_set.append(colg._id) colrep.save(groupid=group_id) has_thread_rt = node_collection.one({ "_type": "RelationType", "name": u"has_thread" }) gr = create_grelation(forum._id, has_thread_rt, [colrep._id]) try: '''Code to send notification to all members of the group except those whose notification preference is turned OFF''' link = "http://" + sitename + "/" + str( colg._id) + "/forum/thread/" + str(colrep._id) for each in colg.author_set: bx = User.objects.filter(id=each) if bx: bx = User.objects.get(id=each) else: continue activity = "Added thread" msg = request.user.username + " has added a thread in the forum " + forum.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the thread." if bx: auth = node_collection.one({ '_type': 'Author', 'name': unicode(bx.username) }) if colg._id and auth: no_check = forum_notification_status( colg._id, auth._id) else: no_check = True if no_check: ret = set_notif_val(request, colg._id, msg, activity, bx) except Exception, e: print e url_name = "/" + group_id + "/forum/thread/" + str(colrep._id) return HttpResponseRedirect(url_name)
def edit_forum(request, group_id, forum_id): ''' Method to create forum and Retrieve all the forums ''' forum = node_collection.one({'_id': ObjectId(forum_id)}) # # method to convert group_id to ObjectId if it is groupname # 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 group_name, group_id = get_group_name_id(group_id) # getting all the values from submitted form if request.method == "POST": colg = node_collection.one({'_id': ObjectId(group_id) }) # getting group ObjectId colf = node_collection.one({'_id': ObjectId(forum_id) }) # creating new/empty GSystem object name = unicode(request.POST.get('forum_name', "")).strip() # forum name colf.name = name content_org = request.POST.get('content_org', "") # forum content if content_org: colf.content_org = unicode(content_org) usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" colf.content = content_org usrid = int(request.user.id) usrname = unicode(request.user.username) colf.modified_by = usrid if usrid not in colf.contributors: colf.contributors.append(usrid) ################# ADDED 14th July.Its done! colf.access_policy = u"PUBLIC" colf.url = set_all_urls(colf.member_of) ### currently timed forum feature is not in use ### # sdate=request.POST.get('sdate',"") # shrs= request.POST.get('shrs',"") # smts= request.POST.get('smts',"") # edate= request.POST.get('edate',"") # ehrs= request.POST.get('ehrs',"") # emts=request.POST.get('emts',"") # start_dt={} # end_dt={} # if not shrs: # shrs=0 # if not smts: # smts=0 # if sdate: # sdate1=sdate.split("/") # st_date = datetime.datetime(int(sdate1[2]),int(sdate1[0]),int(sdate1[1]),int(shrs),int(smts)) # start_dt[start_time.name]=st_date # if not ehrs: # ehrs=0 # if not emts: # emts=0 # if edate: # edate1=edate.split("/") # en_date= datetime.datetime(int(edate1[2]),int(edate1[0]),int(edate1[1]),int(ehrs),int(emts)) # end_dt[end_time.name]=en_date # colf.attribute_set.append(start_dt) # colf.attribute_set.append(end_dt) colf.save(groupid=group_id) '''Code to send notification to all members of the group except those whose notification preference is turned OFF''' try: link = "http://" + sitename + "/" + str( colg._id) + "/forum/" + str(colf._id) for each in colg.author_set: bx = User.objects.get(id=each) activity = "Edited forum" msg = usrname + " has edited forum -" + colf.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the forum." if bx: auth = node_collection.one({ '_type': 'Author', 'name': unicode(bx.username) }) if colg._id and auth: no_check = forum_notification_status( colg._id, auth._id) else: no_check = True if no_check: ret = set_notif_val(request, colg._id, msg, activity, bx) except Exception as e: print e # returning response to ndf/forumdetails.html return HttpResponseRedirect( reverse('show', kwargs={ 'group_id': group_id, 'forum_id': colf._id })) # variables=RequestContext(request,{'forum':colf}) # return render_to_response("ndf/forumdetails.html",variables) # getting all the GSystem of forum to provide autocomplete/intellisence of forum names available_nodes = node_collection.find({ '_type': u'GSystem', 'member_of': ObjectId(forum_gst._id), 'group_set': ObjectId(group_id) }) nodes_list = [] for each in available_nodes: nodes_list.append(str((each.name).strip().lower())) return render_to_response( "ndf/edit_forum.html", { 'group_id': group_id, 'groupid': group_id, 'nodes_list': nodes_list, 'forum': forum }, RequestContext(request))
def delete_reply(request, group_id, forum_id, thread_id, node_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 #group_name, group_id = get_group_name_id(group_id) try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) activity = "" op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': { 'status': u"HIDDEN" }}) # ??? CHECK replyobj = node_collection.one({'_id': ObjectId(node_id)}) forumobj = node_collection.one({"_id": ObjectId(forum_id)}) threadobj = node_collection.one({"_id": ObjectId(thread_id)}) # notifications to all group members colg = node_collection.one({'_id': ObjectId(group_id)}) link = "http://" + sitename + "/" + str(colg._id) + "/forum/thread/" + str( threadobj._id) for each in colg.author_set: if each != colg.created_by: bx = get_userobject(each) if bx: msg = request.user.username + " has deleted reply- " + replyobj.content_org + "- in the thread " + threadobj.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the thread." activity = "Deleted reply" #auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) }) #if colg._id and auth: #no_check=forum_notification_status(colg._id,auth._id) # else: # no_check=True # if no_check: ret = set_notif_val(request, colg._id, msg, activity, bx) prefix = "-in the forum -" + forumobj.name msg = request.user.username + " has deleted reply- " + replyobj.content_org + "- in the thread " + threadobj.name + prefix + " in the group -'" + colg.name + "' created by you" + "\n Please visit " + link + " to see the thread." bx = get_userobject(colg.created_by) if bx: # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) variables = RequestContext( request, { 'thread': threadobj, 'user': request.user, 'forum': forumobj, 'groupid': group_id, 'group_id': group_id }) return HttpResponseRedirect( reverse('thread', kwargs={ 'group_id': group_id, 'thread_id': threadobj._id }))
def edit_thread(request,group_id,forum_id,thread_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) forum=node_collection.one({'_id':ObjectId(forum_id)}) thread=node_collection.one({'_id':ObjectId(thread_id)}) exstng_reply = node_collection.find({'$and':[{'_type':'GSystem'},{'prior_node':ObjectId(forum._id)}]}) nodes=[] exstng_reply.sort('created_at') for each in exstng_reply: nodes.append(each.name) request.session['nodes']=json.dumps(nodes) colg=node_collection.one({'_id':ObjectId(group_id)}) if request.method == 'POST': name = unicode(request.POST.get('thread_name',"")) # thread name thread.name = name content_org = request.POST.get('content_org',"") # thread content # print "content=",content_org if content_org: thread.content_org = unicode(content_org) usrname = request.user.username filename = slugify(name) + "-" + usrname + "-" thread.content = content_org thread.save(groupid=group_id) link="http://"+sitename+"/"+str(colg._id)+"/forum/thread/"+str(thread._id) for each in colg.author_set: if each != colg.created_by: bx=get_userobject(each) if bx: msg=request.user.username+" has edited thread- "+thread.name+"- in the forum " + forum.name + " in the group -'" + colg.name+"'\n"+"Please visit "+link+" to see the thread." activity="Edited thread" #auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) }) #if colg._id and auth: #no_check=forum_notification_status(colg._id,auth._id) # else: # no_check=True # if no_check: ret = set_notif_val(request,colg._id,msg,activity,bx) activity=request.user.username+" edited thread -" bx=get_userobject(colg.created_by) prefix="-in the forum -"+forum.name if bx: msg=activity+"-"+thread.name+prefix+" in the group '"+colg.name+"' created by you"+"\n"+"Please visit "+link+" to see the thread" # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request,group_id,msg,activity,bx) variables = RequestContext(request,{'group_id':group_id,'thread_id': thread._id,'nodes':json.dumps(nodes)}) return HttpResponseRedirect(reverse('thread', kwargs={'group_id':group_id,'thread_id': thread._id })) else: return render_to_response("ndf/edit_thread.html", { 'group_id':group_id, 'groupid':group_id, 'forum': forum, 'thread':thread, 'forum_created_by':User.objects.get(id=forum.created_by).username }, RequestContext(request))
def delete_thread(request, group_id, forum_id, node_id): """ Changing status of thread to HIDDEN """ ins_objectid = ObjectId() if ins_objectid.is_valid(node_id): thread = node_collection.one({'_id': ObjectId(node_id)}) else: return forum = node_collection.one({'_id': ObjectId(forum_id)}) 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 op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': { 'status': u"HIDDEN" }}) node = node_collection.one({'_id': ObjectId(node_id)}) forum_threads = [] exstng_reply = node_collection.find({ '$and': [{ '_type': 'GSystem' }, { 'prior_node': ObjectId(forum._id) }], 'status': { '$nin': ['HIDDEN'] } }) exstng_reply.sort('created_at') forum_node = node_collection.one({'_id': ObjectId(forum_id)}) for each in exstng_reply: forum_threads.append(each.name) #send notifications to all group members colg = node_collection.one({'_id': ObjectId(group_id)}) for each in colg.author_set: if each != colg.created_by: bx = get_userobject(each) if bx: activity = request.user.username + " -deleted thread " prefix = " in the forum " + forum_node.name link = "http://" + sitename + "/" + str( colg._id) + "/forum/" + str(forum_node._id) msg = activity + "-" + node.name + prefix + "- in the group '" + colg.name + "' created by you." + "'\n" + "Please visit " + link + " to see the forum." # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) activity = request.user.username + " -deleted thread " prefix = " in the forum " + forum_node.name bx = get_userobject(colg.created_by) if bx: link = "http://" + sitename + "/" + str(colg._id) + "/forum/" + str( forum_node._id) msg = activity + "-" + node.name + prefix + "- in the group '" + colg.name + "' created by you." + "'\n" + "Please visit " + link + " to see the forum." # no_check=forum_notification_status(group_id,auth._id) # if no_check: ret = set_notif_val(request, group_id, msg, activity, bx) #send notification code ends here variables = RequestContext( request, { 'forum': forum, 'groupid': group_id, 'group_id': group_id, 'forum_created_by': User.objects.get(id=forum.created_by).username }) return render_to_response("ndf/forumdetails.html", variables)
def update(request,rt_list,at_list,task_node,group_id,group_name): file_id=(request.POST.get("files")) file_name=(request.POST.get("files_name")) user_to_be_notified = [] assignee_list = [] change_list = [] for each in rt_list: rel_type_node = node_collection.one({'_type': "RelationType", 'name': each}) field_value_list = None if rel_type_node["object_cardinality"] > 1: field_value_list = request.POST.get(rel_type_node["name"], "") if "[" in field_value_list and "]" in field_value_list: field_value_list = json.loads(field_value_list) else: field_value_list = request.POST.getlist(rel_type_node["name"]) else: field_value_list = request.POST.getlist(rel_type_node["name"]) for i, field_value in enumerate(field_value_list): field_value = parse_template_data(rel_type_node.object_type, field_value, field_instance=rel_type_node) field_value_list[i] = field_value old_value = [] for rel in task_node.relation_set: for k in rel: if rel_type_node.name == k: vals_cur = node_collection.find({'_id': {'$in': rel[k]}}, {'name': 1}) for v_node in vals_cur: old_value.append(v_node.name) break new_value = [] vals_cur = node_collection.find({'_id': {'$in': field_value_list}}, {'name': 1}) for v_node in vals_cur: new_value.append(v_node.name) break if old_value != new_value: change_list.append(each.encode('utf8') + ' changed from ' + ", ".join(old_value) + ' to ' + ", ".join(new_value)) # updated details task_gs_triple_instance = create_grelation(task_node._id, node_collection.collection.RelationType(rel_type_node), field_value_list) task_node.reload() for each in at_list: if request.POST.get(each, ""): attributetype_key = node_collection.find_one({"_type": 'AttributeType', 'name': each}) attr = triple_collection.find_one({"_type": "GAttribute", "subject": task_node._id, "attribute_type": attributetype_key._id}) if each == "Assignee": field_value = request.POST.getlist(each, "") for i, val in enumerate(field_value): field_value[i] = int(val) assignee_list_id = field_value for eachuser in assignee_list_id: bx = User.objects.get(id=int(eachuser)) if bx: if bx.username not in assignee_list: assignee_list.append(bx.username) # 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) else: field_value = request.POST.get(each, "") date_format_string = "" if each in ["start_time", "end_time"]: date_format_string = "%d/%m/%Y" field_value = parse_template_data(eval(attributetype_key["data_type"]), field_value, date_format_string=date_format_string) if attr: # already attribute exist if not attr.object_value == field_value: # change_list.append(each.encode('utf8')+' changed from '+attr.object_value.encode('utf8')+' to '+request.POST.get(each,"").encode('utf8')) # updated details if attributetype_key["data_type"] == "datetime.datetime": change_list.append(each.encode('utf8')+' changed from ' + attr.object_value.strftime("%d/%m/%Y") + ' to ' + field_value.strftime("%d/%m/%Y")) # updated details else: change_list.append(each.encode('utf8')+' changed from ' + str(attr.object_value) + ' to ' + str(field_value)) # updated details attr.object_value = field_value attr.save(groupid=group_id) else: # attributetype_key = node_collection.find_one({"_type":'AttributeType', 'name':each}) # newattribute = triple_collection.collection.GAttribute() # newattribute.subject = task_node._id # newattribute.attribute_type = attributetype_key # newattribute.object_value = request.POST.get(each,"") # newattribute.object_value = field_value # newattribute.save() ga_node = create_gattribute(task_node._id, attributetype_key, field_value) # change_list.append(each.encode('utf8')+' set to '+request.POST.get(each,"").encode('utf8')) # updated details change_list.append(each.encode('utf8')+' set to '+str(field_value)) # updated details elif each == 'Upload_Task': attributetype_key = node_collection.find_one({"_type": 'AttributeType', 'name': 'Upload_Task'}) attr = triple_collection.find_one({"_type": "GAttribute", "subject": task_node._id, "attribute_type": attributetype_key._id}) if attr: value=get_file_node(attr.object_value) change_list.append(each.encode('utf8')+' changed from '+str(value).strip('[]')+' to '+str(file_name)) # attr.object_value=file_id # attr.save() ga_node = create_gattribute(attr.subject, attributetype_key, file_id) else: # newattribute = node_collection.collection.GAttribute() # newattribute.subject = task_node._id # newattribute.attribute_type = attributetype_key # newattribute.object_value = file_id # newattribute.save() ga_node = create_gattribute(task_node._id, attributetype_key, file_id) change_list.append(each.encode('utf8')+' set to '+file_name.encode('utf8')) # updated details # userobj = User.objects.get(id=task_node.created_by) # if userobj and userobj not in user_to_be_notified: # user_to_be_notified.append(userobj) for each_author in task_node.author_set: each_author = User.objects.get(id=each_author) if each_author and each_author not in user_to_be_notified: user_to_be_notified.append(each_author) # Sending notification to all watchers about the updates of the task for eachuser in user_to_be_notified: activ="task updated" msg = "Task '" + task_node.name + \ "' has been updated by " + request.user.username + \ "\n - Changes: " + str(change_list).strip('[]') + \ "\n - Status: " + request.POST.get('Status','') + \ "\n - Assignee: " + ", ".join(assignee_list) + \ "\n - Url: http://" + site_domain + "/" + group_name.replace(" ","%20").encode('utf8') + "/task/" + str(task_node._id) bx=User.objects.get(username=eachuser) set_notif_val(request,group_id,msg,activ,bx) if change_list or content_org: GST_task_update_history = node_collection.one({'_type': "GSystemType", 'name': 'task_update_history'}) update_node = node_collection.collection.GSystem() get_node_common_fields(request, update_node, group_id, GST_task_update_history) if change_list: update_node.altnames = unicode(str(change_list)) else: update_node.altnames = unicode('[]') update_node.prior_node = [task_node._id] update_node.name = unicode(task_node.name+"-update_history") update_node.save(groupid=group_id) update_node.name = unicode(task_node.name+"-update_history-"+str(update_node._id)) update_node.save(groupid=group_id) task_node.post_node.append(update_node._id) task_node.save(groupid=group_id) # patch GST_TASK = node_collection.one({'_type': "GSystemType", 'name': 'Task'}) get_node_common_fields(request, task_node, group_id, GST_TASK) task_node.save(groupid=group_id)
def create_task_at_rt(request,rt_list,at_list,task_node,assign,group_name,group_id): file_id=(request.POST.get("files")) file_name=(request.POST.get("files_name")) for each in rt_list: rel_type_node = node_collection.one({'_type': "RelationType", 'name': each}) field_value_list = None if rel_type_node["object_cardinality"] > 1: field_value_list = request.POST.get(rel_type_node["name"], "") if "[" in field_value_list and "]" in field_value_list: field_value_list = json.loads(field_value_list) else: field_value_list = request.POST.getlist(rel_type_node["name"]) else: field_value_list = request.POST.getlist(rel_type_node["name"]) # rel_type_node_type = "GRelation" for i, field_value in enumerate(field_value_list): field_value = parse_template_data(rel_type_node.object_type, field_value, field_instance=rel_type_node) field_value_list[i] = field_value task_gs_triple_instance = create_grelation(task_node._id, node_collection.collection.RelationType(rel_type_node), field_value_list) for each in at_list: field_value = [] if request.POST.get(each,""): attributetype_key = node_collection.find_one({"_type": 'AttributeType', 'name': each}) subject = task_node._id object_value = "" if each == 'Assignee': if type(assign) == list: object_value = assign else: field_value.append(assign) object_value = field_value else: field_value = request.POST.get(each, "") date_format_string = "" if each in ["start_time", "end_time"]: date_format_string = "%d/%m/%Y" field_value = parse_template_data(eval(attributetype_key["data_type"]), field_value, date_format_string=date_format_string) # newattribute.object_value = field_value object_value = field_value # newattribute.save() ga_node = create_gattribute(subject, attributetype_key, object_value) if request.FILES.getlist('UploadTask'): attributetype_key = node_collection.find_one({"_type":'AttributeType', 'name':'Upload_Task'}) ga_node = create_gattribute(task_node._id, attributetype_key, file_id) assignee_list = [] assignee_list_id = [] if type(assign) == list: assignee_list_id = assign else: assignee_list_id.append(assign) user_to_be_notified = [] if assignee_list_id: for eachuser in assignee_list_id: if eachuser: bx = User.objects.get(id=int(eachuser)) assignee_list.append(bx.username) user_to_be_notified.append(bx) for eachuser in user_to_be_notified: activ = "Task reported" msg = "Task '" + task_node.name + \ "' has been reported by " + request.user.username + \ "\n - Status: " + request.POST.get('Status', '') + \ "\n - Assignee: " + ", ".join(assignee_list) + \ "\n - Url: http://" + site_domain + "/" + group_name.replace(" ","%20").encode('utf8') + "/task/" + str(task_node._id) set_notif_val(request, group_id, msg, activ, eachuser)
def create_task_at_rt(request, rt_list, at_list, task_node, assign, group_name, group_id): file_id = (request.POST.get("files")) file_name = (request.POST.get("files_name")) for each in rt_list: rel_type_node = node_collection.one({ '_type': "RelationType", 'name': each }) field_value_list = None if rel_type_node["object_cardinality"] > 1: field_value_list = request.POST.get(rel_type_node["name"], "") if "[" in field_value_list and "]" in field_value_list: field_value_list = json.loads(field_value_list) else: field_value_list = request.POST.getlist(rel_type_node["name"]) else: field_value_list = request.POST.getlist(rel_type_node["name"]) # rel_type_node_type = "GRelation" for i, field_value in enumerate(field_value_list): field_value = parse_template_data(rel_type_node.object_type, field_value, field_instance=rel_type_node) field_value_list[i] = field_value task_gs_triple_instance = create_grelation( task_node._id, node_collection.collection.RelationType(rel_type_node), field_value_list) for each in at_list: field_value = [] if request.POST.get(each, ""): attributetype_key = node_collection.find_one({ "_type": 'AttributeType', 'name': each }) subject = task_node._id object_value = "" if each == 'Assignee': if type(assign) == list: object_value = assign else: field_value.append(assign) object_value = field_value else: field_value = request.POST.get(each, "") date_format_string = "" if each in ["start_time", "end_time"]: date_format_string = "%d/%m/%Y" field_value = parse_template_data( eval(attributetype_key["data_type"]), field_value, date_format_string=date_format_string) # newattribute.object_value = field_value object_value = field_value # newattribute.save() ga_node = create_gattribute(subject, attributetype_key, object_value) if request.FILES.getlist('UploadTask'): attributetype_key = node_collection.find_one({ "_type": 'AttributeType', 'name': 'Upload_Task' }) ga_node = create_gattribute(task_node._id, attributetype_key, file_id) assignee_list = [] assignee_list_id = [] if type(assign) == list: assignee_list_id = assign else: assignee_list_id.append(assign) user_to_be_notified = [] if assignee_list_id: for eachuser in assignee_list_id: if eachuser: bx = User.objects.get(id=int(eachuser)) assignee_list.append(bx.username) user_to_be_notified.append(bx) for eachuser in user_to_be_notified: activ = "Task reported" msg = "Task '" + task_node.name + \ "' has been reported by " + request.user.username + \ "\n - Status: " + request.POST.get('Status', '') + \ "\n - Assignee: " + ", ".join(assignee_list) + \ "\n - Url: http://" + site_domain + "/" + group_name.replace(" ","%20").encode('utf8') + "/task/" + str(task_node._id) set_notif_val(request, group_id, msg, activ, eachuser)
def create_partner(request,group_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 group_obj = get_group_name_id(group_id, get_obj=True) pg_gst = node_collection.one({'_type': "GSystemType", 'name': "PartnerGroup"}) try: if request.method == "POST": colg = node_collection.collection.Group() street = request.POST.get('street', "") cname = request.POST.get('groupname', "").strip() colg.altnames = cname colg.name = unicode(cname) colg.member_of.append(gst_group._id) usrid = int(request.user.id) colg.created_by = usrid colg.author_set.append(usrid) colg.modified_by = usrid colg.contributors.append(usrid) #colg.group_type = request.POST.get('group_type', "") #colg.edit_policy = request.POST.get('edit_policy', "") #colg.subscription_policy = request.POST.get('subscription', "") colg.visibility_policy = request.POST.get('existance', 'ANNOUNCED') colg.disclosure_policy = request.POST.get('member', 'DISCLOSED_TO_MEM') colg.encryption_policy = request.POST.get('encryption', 'NOT_ENCRYPTED') colg.agency_type = "Partner" colg.save(groupid=group_id) # get alll attribute associated with partner attribute_set=colg.get_possible_attributes(colg.member_of).keys() activ="Request to become a partner" msg = colg.name+" is interested to became a partner on the platform " set_notif_val(request, colg._id, msg, activ, request.user) for each in attribute_set: if each !="apps_list": obj_val = request.POST.get(each, "").strip() att_type=node_collection.one({'_type':"AttributeType","name":each}) # set Attribute type values for partner create_gattribute(colg._id, att_type , object_value = obj_val) auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) # shelves = [] # shelf_list = {} # if auth: # shelf = triple_collection.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type.$id': has_shelf_RT._id }) # 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 = [] return render_to_response("ndf/groupdashboard.html", {'groupobj': colg, 'appId': app._id, 'node': colg, 'user': request.user, 'groupid': colg._id, 'group_id': colg._id, # 'shelf_list': shelf_list,'shelves': shelves },context_instance=RequestContext(request)) except Exception as e: print "\n\n e",e available_nodes = node_collection.find({'_type': u'Group', 'member_of': ObjectId(gst_group._id) }) nodes_list = [] for each in available_nodes: nodes_list.append(str((each.name).strip().lower())) return render_to_response("ndf/create_partner.html", {'groupid': group_id, 'group_obj':group_obj,'appId': app._id, 'group_id': group_id, 'nodes_list': nodes_list},RequestContext(request))