def updateEditForm(request): storyId=request.session['editStoryId'] #Get story title if "storyTitle" in request.POST: storyTitle=request.POST["storyTitle"] #Get story desc if "storyDesc" in request.POST: storyDesc=request.POST["storyDesc"] if request.POST["chapterJson"]: chapterJson=request.POST["chapterJson"] objs = json.loads(chapterJson,encoding='utf-8') global counter for counter in range(0,len(objs)): record = storychapter(chapter_title = objs[counter]) data = objs[counter] #Get chapter details orderNumbder=data['order'] chapterName=data['chapterTitle'] chapterDesc= data['chapterDesc'] chapterRemove=data['isRemoved'] chapterID=data['chapterId'] if chapterRemove == 'Y': #delete chapter deletechapter=storychapter.objects.filter(chapter_id=chapterID).delete() else: #Update edited chapter details chapters=storychapter.objects.filter(chapter_id=chapterID).update (chapter_title=chapterName,chapter_desc=chapterDesc,serial_number=orderNumbder) counter += 1 #Update edited story details story=observastory.objects.filter(story_id=storyId).update(story_name=storyTitle,story_desc=storyDesc) return redirect(HTTP_HOST+'stories/')
def updateEditForm(request): storyId = request.session['editStoryId'] #Get story title if "storyTitle" in request.POST: storyTitle = request.POST["storyTitle"] #Get story desc if "storyDesc" in request.POST: storyDesc = request.POST["storyDesc"] if request.POST["chapterJson"]: chapterJson = request.POST["chapterJson"] objs = json.loads(chapterJson, encoding='utf-8') global counter for counter in range(0, len(objs)): record = storychapter(chapter_title=objs[counter]) data = objs[counter] #Get chapter details orderNumbder = data['order'] chapterName = data['chapterTitle'] chapterDesc = data['chapterDesc'] chapterRemove = data['isRemoved'] chapterID = data['chapterId'] if chapterRemove == 'Y': #delete chapter deletechapter = storychapter.objects.filter( chapter_id=chapterID).delete() else: #Update edited chapter details chapters = storychapter.objects.filter( chapter_id=chapterID).update(chapter_title=chapterName, chapter_desc=chapterDesc, serial_number=orderNumbder) counter += 1 #Update edited story details story = observastory.objects.filter(story_id=storyId).update( story_name=storyTitle, story_desc=storyDesc) return redirect(HTTP_HOST + 'stories/')
def endSaveStory(request): if request.POST["storyDetail"]: storyDetailJSON=request.POST["storyDetail"] objectJSON=json.loads(storyDetailJSON,encoding='utf-8') counter=0 for counter in range(0,len(objectJSON)): data = objectJSON[counter] #Get story_name and story_desc storyName=data['storyName'] storyDesc=data['storyDescription'] #save story_name and story_desc to observastory table saveToStoryTable=observastory(story_name=storyName,story_desc=storyDesc) saveToStoryTable.save() storyId=observastory.objects.values_list('story_id',flat=True).filter(story_name=storyName).order_by('-story_id')[0:1] for story_id in storyId: request.session['storyId']=story_id if request.POST["storyChapterJSON"]: storyChapterJSON=request.POST["storyChapterJSON"] objectJSON = json.loads(storyChapterJSON,encoding='utf-8') chapterCount=len(objectJSON) storyId=request.session['storyId'] updateChaptercount=observastory.objects.filter(story_id=storyId).update(number_of_chapters=chapterCount) counter=0 for counter in range(0,len(objectJSON)): data = objectJSON[counter] #Get chapter_details chapterUrl=data['URL'] chapterName=data['chapterName'] chapterDescription=data['chapterDescription'] chapterJs=json.dumps(data['JS']) prod_class= data['prod_class'] language=data['language'] #Get session parameters sessionParameters={} sessionParameters['product_classification']=prod_class sessionParameters['django_language']=language sessionParameters = json.dumps(sessionParameters)[1:-1] chapterSerialNo=counter+1 #save session parameter and chapter details to storychapter table saveToChapterTable=storychapter(story_id=storyId,chapter_url=chapterUrl,chapter_title=chapterName,chapter_desc=chapterDescription,chapter_js_details=chapterJs,chapter_details=sessionParameters,serial_number=chapterSerialNo) saveToChapterTable.save() #check user in session if 'userid' in request.session: storyId=request.session['storyId'] userId=request.session['userid'] updateUserId=observastory.objects.filter(story_id=storyId).update(user_id=userId) else: if request.POST["socialMediaIntegrationData"]: socialSitesDetails=request.POST["socialMediaIntegrationData"] jsonObjects=json.loads(socialSitesDetails,encoding='utf-8') index=0 for index in range(0,len(jsonObjects)): data=jsonObjects[index] #Get socialmedia details email=data['email'] name=data['name'] request.session['username']=name source=data['source'] #check user auth_type if source == 'google': #check useremail exits if observatoryuser.objects.filter(user_email=email).exists() == True: #Get userid getUserId=observatoryuser.objects.get(user_email=email) request.session['userid']=getUserId.user_id storyId=request.session['storyId'] updateUserId=observastory.objects.filter(story_id=storyId).update(user_id=getUserId.user_id) else: #Create userid and get user id observaUser=observatoryuser(user_name=name,user_email=email,user_auth_type=source) observaUser.save() getUserId=observatoryuser.objects.get(user_email=email) request.session['userid']=getUserId.user_id storyId=request.session['storyId'] updateUserId=observastory.objects.filter(story_id=storyId).update(user_id=getUserId.user_id) #check user auth_type if source == 'facebook': #check useremail exits if observatoryuser.objects.filter(user_email=email).exists() == True: #Get userid getUserId=observatoryuser.objects.get(user_email=email) request.session['userid']=getUserId.user_id storyId=request.session['storyId'] updateUserId=observastory.objects.filter(story_id=storyId).update(user_id=getUserId.user_id) else: #Create userid and get user id observaUser=observatoryuser(user_name=name,user_email=email,user_auth_type=source) observaUser.save() getUserId=observatoryuser.objects.get(user_email=email) request.session['userid']=getUserId.user_id storyId=request.session['storyId'] updateUserId=observastory.objects.filter(story_id=storyId).update(user_id=getUserId.user_id) else: storyId=request.session['storyId'] #update publish value updatePublish=observastory.objects.filter(story_id=storyId).update(published=1) iscreatemode=False request.session['create']=iscreatemode isbrowsemode=False request.session['retrieve']=isbrowsemode return redirect(HTTP_HOST+'stories/')
def endSaveStory(request): if request.POST["storyDetail"]: storyDetailJSON = request.POST["storyDetail"] objectJSON = json.loads(storyDetailJSON, encoding='utf-8') counter = 0 for counter in range(0, len(objectJSON)): data = objectJSON[counter] #Get story_name and story_desc storyName = data['storyName'] storyDesc = data['storyDescription'] #save story_name and story_desc to observastory table saveToStoryTable = observastory(story_name=storyName, story_desc=storyDesc) saveToStoryTable.save() storyId = observastory.objects.values_list( 'story_id', flat=True).filter( story_name=storyName).order_by('-story_id')[0:1] for story_id in storyId: request.session['storyId'] = story_id if request.POST["storyChapterJSON"]: storyChapterJSON = request.POST["storyChapterJSON"] objectJSON = json.loads(storyChapterJSON, encoding='utf-8') chapterCount = len(objectJSON) storyId = request.session['storyId'] updateChaptercount = observastory.objects.filter( story_id=storyId).update(number_of_chapters=chapterCount) counter = 0 for counter in range(0, len(objectJSON)): data = objectJSON[counter] #Get chapter_details chapterUrl = data['URL'] chapterName = data['chapterName'] chapterDescription = data['chapterDescription'] chapterJs = json.dumps(data['JS']) prod_class = data['prod_class'] language = data['language'] #Get session parameters sessionParameters = {} sessionParameters['product_classification'] = prod_class sessionParameters['django_language'] = language sessionParameters = json.dumps(sessionParameters)[1:-1] chapterSerialNo = counter + 1 #save session parameter and chapter details to storychapter table saveToChapterTable = storychapter( story_id=storyId, chapter_url=chapterUrl, chapter_title=chapterName, chapter_desc=chapterDescription, chapter_js_details=chapterJs, chapter_details=sessionParameters, serial_number=chapterSerialNo) saveToChapterTable.save() #check user in session if 'userid' in request.session: storyId = request.session['storyId'] userId = request.session['userid'] updateUserId = observastory.objects.filter(story_id=storyId).update( user_id=userId) else: if request.POST["socialMediaIntegrationData"]: socialSitesDetails = request.POST["socialMediaIntegrationData"] jsonObjects = json.loads(socialSitesDetails, encoding='utf-8') index = 0 for index in range(0, len(jsonObjects)): data = jsonObjects[index] #Get socialmedia details email = data['email'] name = data['name'] request.session['username'] = name source = data['source'] #check user auth_type if source == 'google': #check useremail exits if observatoryuser.objects.filter( user_email=email).exists() == True: #Get userid getUserId = observatoryuser.objects.get( user_email=email) request.session['userid'] = getUserId.user_id storyId = request.session['storyId'] updateUserId = observastory.objects.filter( story_id=storyId).update(user_id=getUserId.user_id) else: #Create userid and get user id observaUser = observatoryuser(user_name=name, user_email=email, user_auth_type=source) observaUser.save() getUserId = observatoryuser.objects.get( user_email=email) request.session['userid'] = getUserId.user_id storyId = request.session['storyId'] updateUserId = observastory.objects.filter( story_id=storyId).update(user_id=getUserId.user_id) #check user auth_type if source == 'facebook': #check useremail exits if observatoryuser.objects.filter( user_email=email).exists() == True: #Get userid getUserId = observatoryuser.objects.get( user_email=email) request.session['userid'] = getUserId.user_id storyId = request.session['storyId'] updateUserId = observastory.objects.filter( story_id=storyId).update(user_id=getUserId.user_id) else: #Create userid and get user id observaUser = observatoryuser(user_name=name, user_email=email, user_auth_type=source) observaUser.save() getUserId = observatoryuser.objects.get( user_email=email) request.session['userid'] = getUserId.user_id storyId = request.session['storyId'] updateUserId = observastory.objects.filter( story_id=storyId).update(user_id=getUserId.user_id) else: storyId = request.session['storyId'] #update publish value updatePublish = observastory.objects.filter( story_id=storyId).update(published=1) iscreatemode = False request.session['create'] = iscreatemode isbrowsemode = False request.session['retrieve'] = isbrowsemode return redirect(HTTP_HOST + 'stories/')