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':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 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':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 switch_group(request,group_id,node_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: node=collection.Node.one({"_id":ObjectId(node_id)}) exstng_grps=node.group_set if request.method == "POST": node.group_set=[] new_grps = request.POST['new_grps'] new_grps_list=new_grps.split(",") if new_grps_list: for each in new_grps_list: if each: node.group_set.append(ObjectId(each)); node.save() return HttpResponse("Success") else: coll_obj_list = [] data_list=[] user_id=request.user.id all_user_groups=[] for each in get_all_user_groups(): all_user_groups.append(each.name) st = collection.Node.find({'$and':[{'_type':'Group'},{'author_set':{'$in':[user_id]}},{'name':{'$nin':all_user_groups}}]}) for each in node.group_set: coll_obj_list.append(collection.Node.one({'_id':each})) data_list=set_drawer_widget(st,coll_obj_list) return HttpResponse(json.dumps(data_list)) except Exception as e: print "Exception in switch_group"+str(e) return HttpResponse("Failure")
def invite_admins(request, group_id): #inorder to be a group admin, the user must be member of that group try: sending_user = request.user node = node_collection.one({'_id': ObjectId(group_id)}) if request.method == "POST": exst_users = [] new_users = [] users = [] deleted_users = node.group_admin groupname = node.name users_to_invite = request.POST['users'] not_status = request.POST['notif_status'] new_users_list = users_to_invite.split(",") for each in new_users_list: if each: users.append(int(each)) if users: for each in users: if each in node.group_admin: exst_users.append(each) else: if each not in node.group_admin: new_users.append(each) node.group_admin.append(each) node.save(groupid=group_id) # Send invitations according to not_status variable activ = "invitation to join in group" if not_status == "ON": for each in exst_users: bx = User.objects.get(id=each) msg = "'This is to inform you that " + sending_user.username + " has subscribed you to the group " + groupname + " as admin'" set_notif_val(request, group_id, msg, activ, bx) for each in new_users: bx = User.objects.get(id=each) msg = "'This is to inform you that " + sending_user.username + " has subscribed you to the group " + groupname + " as admin'" set_notif_val(request, group_id, msg, activ, bx) deleted_users = set(deleted_users) - set(users) activ = "Unsubscribed from group" if deleted_users: for each in deleted_users: bx = User.objects.get(id=each) node.group_admin.remove(each) msg = "'This is to inform you that " + sending_user.username + " has unsubscribed you from the group " + groupname + " as admin'" set_notif_val(request, group_id, msg, activ, bx) node.save(groupid=group_id) return HttpResponse("Success") else: coll_obj_list = [] lstusers = [] owner = node.created_by users = User.objects.all().order_by("email") user_names = [] st = [] user_grps = get_all_user_groups() usergrps = [] subscribed = get_all_subscribed_users(group_id) for each in user_grps: usergrps.append(each.created_by) for each in users: if each.id != owner and each.id not in node.group_admin and each.id in usergrps: if each.id in subscribed: st.append(each) else: if each.id != owner and each.id in usergrps: coll_obj_list.append(each) data_list = set_drawer_widget_for_users(st, coll_obj_list) return HttpResponse(json.dumps(data_list)) except Exception as e: print "Exception in invite_admins in notify view " + str(e) return HttpResponse("Failure")
''' -- imports from application folders/files -- ''' from gnowsys_ndf.settings import GAPPS, GSTUDIO_GROUP_AGENCY_TYPES, GSTUDIO_NROER_MENU, GSTUDIO_NROER_MENU_MAPPINGS # from gnowsys_ndf.ndf.models import GSystemType, GSystem, Group, Triple from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.ajax_views import set_drawer_widget from gnowsys_ndf.ndf.templatetags.ndf_tags import get_existing_groups, get_all_user_groups from gnowsys_ndf.ndf.views.methods import * from gnowsys_ndf.ndf.views.notify import set_notif_val # ###################################################################################################################################### gst_group = node_collection.one({"_type": "GSystemType", 'name': GAPPS[2]}) partner_group_gst = node_collection.one({"_type": "GSystemType", 'name': u'PartnerGroup'}) get_all_usergroups=get_all_user_groups() at_apps_list=node_collection.one({'$and':[{'_type':'AttributeType'},{'name':'apps_list'}]}) ins_objectid = ObjectId() app=gst_group # ###################################################################################################################################### # V I E W S D E F I N E D F O R P A R T N E R ' # ###################################################################################################################################### @login_required @get_execution_time 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) })
def invite_admins(request,group_id): #inorder to be a group admin, the user must be member of that group try: sending_user=request.user node = node_collection.one({'_id': ObjectId(group_id)}) if request.method == "POST": exst_users=[] new_users=[] users=[] deleted_users=node.group_admin groupname=node.name users_to_invite = request.POST['users'] not_status=request.POST['notif_status'] new_users_list=users_to_invite.split(",") for each in new_users_list: if each : users.append(int(each)) if users: for each in users: if each in node.group_admin: exst_users.append(each) else: if each not in node.group_admin: new_users.append(each) node.group_admin.append(each); node.save(groupid=group_id) try: # Send invitations according to not_status variable activ="invitation to join in group" if not_status == "ON": for each in exst_users: bx=User.objects.get(id=each) msg="'This is to inform you that " +sending_user.username+ " has subscribed you to the group " +groupname+" as admin'" set_notif_val(request,group_id,msg,activ,bx) for each in new_users: bx=User.objects.get(id=each) msg="'This is to inform you that " +sending_user.username+ " has subscribed you to the group " +groupname+" as admin'" set_notif_val(request,group_id,msg,activ,bx) except Exception as mailerr: pass deleted_users=set(deleted_users)-set(users) activ="Unsubscribed from group" if deleted_users: for each in deleted_users: bx=User.objects.get(id=each) node.group_admin.remove(each) try: msg="'This is to inform you that " +sending_user.username+ " has unsubscribed you from the group " +groupname+" as admin'" set_notif_val(request,group_id,msg,activ,bx) except Exception as mailerror: pass node.save(groupid=group_id) return HttpResponse("Success") else: coll_obj_list = [] lstusers=[] owner=node.created_by users=User.objects.all().order_by("email") user_names=[] st=[] user_grps=get_all_user_groups() usergrps=[] subscribed=get_all_subscribed_users(group_id) for each in user_grps: usergrps.append(each.created_by) for each in users: if each.id != owner and each.id not in node.group_admin and each.id in usergrps: if each.id in subscribed: st.append(each) else: if each.id !=owner and each.id in usergrps: coll_obj_list.append(each) from gnowsys_ndf.ndf.views.ajax_views import set_drawer_widget_for_users data_list=set_drawer_widget_for_users(st,coll_obj_list) return HttpResponse(json.dumps(data_list)) except Exception as e: print "Exception in invite_admins in notify view "+str(e) return HttpResponse("Failure")