def api_create_gs(request, gst_name="Page"): # curl -i -X POST -H "Content-Type: multipart/form-data" -F "[email protected]" -F "content=hey, this is sample content" -F "name=Test the FAB" -F "tags=check, 1, 2, aa" -F 'user_name=administrator' -F 'workspace=warehouse' http://172.17.0.2:8000/api/v2/create/File # print gst_name # print "===================:: ", request.POST # print "===================:: ", request.POST.dict() # print "===================:: ", request.FILES write_files(request, group_id=request.POST.get('workspace'), unique_gs_per_file=False, kwargs=request.POST.dict()) return HttpResponse(1)
def savejhapp(request,group_id): from gnowsys_ndf.ndf.views.file import save_file try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) jhapp_type = request.POST.getlist("jhapp-type", "") jhapp_type_trim = jhapp_type[0].replace(" ", "") group_obj = node_collection.one({'_id': ObjectId(group_id)}) title = request.POST.get('context_name','') usrid = request.user.id # jsmol_gst = node_collection.one({"_type":"GSystemType","name":"Jsmol" }) sel_jhapp_gst = node_collection.one({"_type":"GSystemType","name":unicode(jhapp_type_trim) }) import zipfile from gnowsys_ndf.ndf.views.filehive import write_files is_user_gstaff = check_is_gstaff(group_obj._id, request.user) fileobj_list = write_files(request, group_id) fileobj_id = fileobj_list[0]['_id'] file_node = node_collection.one({'_id': ObjectId(fileobj_id) }) if sel_jhapp_gst._id: file_node.member_of = [ObjectId(sel_jhapp_gst._id)] uploaded_files = request.FILES.getlist('filehive', []) zip_path = file_node.if_file.original['relurl'] zip_split_path = zip_path.split('.') un_zip_path = zip_path.split('/') file_name = str(uploaded_files[0]).split(".") un_zip_split_path = "/data/media/"+un_zip_path[0] + "/" + un_zip_path[1] + "/" +un_zip_path[2] + "/" with zipfile.ZipFile("/data/media/"+ file_node.if_file.original['relurl'], "r") as z: z.extractall(un_zip_split_path) relurl_path = str("/" + un_zip_path[0] + "/" + un_zip_path[1] + "/" +un_zip_path[2] + "/" + file_name[0] + "/" + "index" + ".html" ) # print "_______________________________",relurl_path discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"}) for each_gs_file in fileobj_list: #set interaction-settings each_gs_file.status = u"PUBLISHED" if usrid not in each_gs_file.contributors: each_gs_file.contributors.append(usrid) group_object = node_collection.one({'_id': ObjectId(group_id)}) if (group_object.edit_policy == "EDITABLE_MODERATED") and (group_object.moderation_level > 0): from gnowsys_ndf.ndf.views.moderation import get_moderator_group_set # print "\n\n\n\ninside editable moderated block" each_gs_file.group_set = get_moderator_group_set(each_gs_file.group_set, group_object._id) # print "\n\n\npage_node._id",page_node._id each_gs_file.status = u'MODERATION' # print "\n\n\n page_node.status",page_node.status each_gs_file.save() create_gattribute(each_gs_file._id, discussion_enable_at, True) return_status = create_thread_for_node(request,group_obj._id, each_gs_file) file_node.url = "/data/media/"+ file_node.if_file.original['relurl'] file_node.if_file.original.relurl = relurl_path file_node.if_file.mime_type = u"text/html" file_node.save() return HttpResponseRedirect( reverse('file_detail', kwargs={"group_id": group_id,'_id':fileobj_id}))
def upload_prof_pic(request, group_id): if request.method == "POST" : user = request.POST.get('user','') if_module = request.POST.get('if_module','') if if_module == "True": group_id_for_module = request.POST.get('group_id_for_module','') url_name = request.POST.get('url_name','') # used for reverse # print "\n\n url_name", url_name group_obj = node_collection.one({'_id': ObjectId(group_id)}) file_uploaded = request.FILES.get("filehive", "") pic_rt = request.POST.get("pic_rt", "") node_id = request.POST.get("node_id", "") # print "\n\n pic_rt === ", pic_rt has_profile_or_banner_rt = None if pic_rt == "is_banner": has_profile_or_banner_rt = node_collection.one({'_type': 'RelationType', 'name': unicode('has_banner_pic') }) elif pic_rt == "is_profile": has_profile_or_banner_rt = node_collection.one({'_type': 'RelationType', 'name': unicode('has_profile_pic') }) if pic_rt == "is_thumbnail": # print "================================" has_profile_or_banner_rt = node_collection.one({'_type': 'RelationType', 'name': unicode('has_thumbnail') }) choose_from_existing_pic = request.POST.get("old_pic_ele","") warehouse_grp_obj = node_collection.one({'_type': "Group", 'name': "warehouse"}) if file_uploaded: fileobj = write_files(request,group_id) gs_obj_id = fileobj[0]['_id'] # print "\n\n\nfileobj",gs_obj_id if fileobj: profile_pic_image = node_collection.one({'_id': ObjectId(gs_obj_id)}) # The 'if' below is required in case file node is deleted but exists in grid_fs if profile_pic_image and not node_id: gr_node = create_grelation(group_obj._id, has_profile_or_banner_rt, profile_pic_image._id) # Move fileobj to "Warehouse" group node_collection.collection.update({'_id': profile_pic_image._id}, {'$set': {'group_set': [warehouse_grp_obj._id] }}, upsert=False, multi=False) elif node_id: # print "-----------------------------------------------------------------",node_id gr_node = create_grelation(ObjectId(node_id), has_profile_or_banner_rt, profile_pic_image._id) # Move fileobj to "Warehouse" group node_collection.collection.update({'_id': profile_pic_image._id}, {'$set': {'group_set': [warehouse_grp_obj._id] }}, upsert=False, multi=False) else: success_state = False elif choose_from_existing_pic: # update status of old GRelation profile_pic_image = node_collection.one({'_id': ObjectId(choose_from_existing_pic)}) gr_node = create_grelation(group_obj._id,has_profile_or_banner_rt,profile_pic_image._id) # Move fileobj to "Warehouse" group if warehouse_grp_obj._id not in profile_pic_image.group_set: node_collection.collection.update({'_id': profile_pic_image._id}, {'$set': {'group_set': [warehouse_grp_obj._id] }}, upsert=False, multi=False) group_obj.reload() if user: group_id = user if if_module == "True": return HttpResponseRedirect(reverse(str(url_name), kwargs={'group_id': ObjectId(group_id_for_module),'node_id':group_obj._id })) else: return HttpResponseRedirect(reverse(str(url_name), kwargs={'group_id': group_id}))
def savejhapp(request, group_id): from gnowsys_ndf.ndf.views.file import save_file try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) jhapp_type = request.POST.getlist("jhapp-type", "") jhapp_type_trim = jhapp_type[0].replace(" ", "") group_obj = node_collection.one({'_id': ObjectId(group_id)}) title = request.POST.get('context_name', '') usrid = request.user.id # jsmol_gst = node_collection.one({"_type":"GSystemType","name":"Jsmol" }) sel_jhapp_gst = node_collection.one({ "_type": "GSystemType", "name": unicode(jhapp_type_trim) }) import zipfile from gnowsys_ndf.ndf.views.filehive import write_files is_user_gstaff = check_is_gstaff(group_obj._id, request.user) fileobj_list = write_files(request, group_id) fileobj_id = fileobj_list[0]['_id'] file_node = node_collection.one({'_id': ObjectId(fileobj_id)}) if sel_jhapp_gst._id: file_node.member_of = [ObjectId(sel_jhapp_gst._id)] uploaded_files = request.FILES.getlist('filehive', []) zip_path = file_node.if_file.original['relurl'] zip_split_path = zip_path.split('.') un_zip_path = zip_path.split('/') file_name = str(uploaded_files[0]).split(".") un_zip_split_path = "/data/media/" + un_zip_path[0] + "/" + un_zip_path[ 1] + "/" + un_zip_path[2] + "/" with zipfile.ZipFile("/data/media/" + file_node.if_file.original['relurl'], "r") as z: z.extractall(un_zip_split_path) relurl_path = str("/" + un_zip_path[0] + "/" + un_zip_path[1] + "/" + un_zip_path[2] + "/" + file_name[0] + "/" + "index" + ".html") # print "_______________________________",relurl_path discussion_enable_at = node_collection.one({ "_type": "AttributeType", "name": "discussion_enable" }) for each_gs_file in fileobj_list: #set interaction-settings each_gs_file.status = u"PUBLISHED" if usrid not in each_gs_file.contributors: each_gs_file.contributors.append(usrid) group_object = node_collection.one({'_id': ObjectId(group_id)}) if (group_object.edit_policy == "EDITABLE_MODERATED") and ( group_object.moderation_level > 0): from gnowsys_ndf.ndf.views.moderation import get_moderator_group_set # print "\n\n\n\ninside editable moderated block" each_gs_file.group_set = get_moderator_group_set( each_gs_file.group_set, group_object._id) # print "\n\n\npage_node._id",page_node._id each_gs_file.status = u'MODERATION' # print "\n\n\n page_node.status",page_node.status each_gs_file.save() create_gattribute(each_gs_file._id, discussion_enable_at, True) return_status = create_thread_for_node(request, group_obj._id, each_gs_file) file_node.url = "/data/media/" + file_node.if_file.original['relurl'] file_node.if_file.original.relurl = relurl_path file_node.if_file.mime_type = u"text/html" file_node.save() return HttpResponseRedirect( reverse('file_detail', kwargs={ "group_id": group_id, '_id': fileobj_id }))