def index(request): if request.method=='POST': userObject=User.objects.get(username=request.user.username) categoriesDict={} categoriesDict['allCategories']=Category.objects.filter(userName=userObject).order_by('name') # get the attributes of the result we want to save title=request.POST.get('title','') url=request.POST.get('url','') readingRating=request.POST.get('readingRating','') sentimentRating=request.POST.get('sentimentRating','') # the category we want to put our result into categoryName=request.POST.get('category','') # if we have all of the attributes of the result and a category name, then proceed if title!='' and url!='' and readingRating!='' and sentimentRating!='' and categoryName!='': # if the category does not exist, create it, otherwise extract it from the db if not Category.objects.filter(userName=userObject, name=categoryName).exists(): c = Category(userName=userObject, name=categoryName) c.save() else: c = Category.objects.get(userName=userObject, name=categoryName) # if the page has not been saved before, save it if not Page.objects.filter(uName=request.user.username, url=url).exists(): p = Page(uName=request.user.username, category=c, title=title, url=url, readingRating=readingRating, sentimentRating=sentimentRating) p.save() # from string to list of words searched searchstr=request.POST.get('search','') search=searchstr.split(" ") # fill in the dictionaries for each api healthDict=healthapif(search) medlineDict=medlineapif(search) bingDict=bingapif(searchstr) # a dictionary, containing all of the results allapisDict=healthDict.copy() allapisDict.update(medlineDict) allapisDict.update(bingDict) return render(request,'health_search_application/index.html',{'allapis': allapisDict.iteritems(), 'healthapi': healthDict.iteritems(), 'medlineapi': medlineDict.iteritems(), 'bingapi': bingDict.iteritems(), 'search': searchstr, 'alllength': len(allapisDict), 'allCategories': categoriesDict.iteritems()}) if request.user.username and request.user.profile.is_app_user: return render(request, 'health_search_application/index.html') else: return HttpResponseRedirect(reverse('login'))
def profile(request): if request.user.username and request.user.profile.is_app_user: userObj=User.objects.get(username=request.user.username) # All of the user's data userAvatar=request.user.profile.gravatar_url userData=[] userData.append(['Username: '******'First name: ', userObj.first_name]) userData.append(['Last name: ', userObj.last_name]) userData.append(['Email: ', userObj.email]) # create/delete a category, delete a page if request.method == 'POST': nameCategory=request.POST.get('nameCategory','') urlPage=request.POST.get('urlPage','') newCategory=request.POST.get('newCategory','') newPassword=request.POST.get('newPassword','') if nameCategory!='': c=Category.objects.get(userName=userObj, name=nameCategory) c.delete() if urlPage!='': p=Page.objects.get(uName=request.user.username, url=urlPage) p.delete() if newCategory!='': if not Category.objects.filter(userName=userObj, name=newCategory).exists(): c = Category(userName=userObj, name=newCategory) c.save() if newPassword!='': u = userObj u.set_password(newPassword) u.save() cu = request.user.profile cu.is_app_user = False cu.save() return render(request,'health_search_application/login.html') catPageDict={} # dictionary with keys: the categories and values: the pages for c in Category.objects.filter(userName=User.objects.get(username=request.user.username)): catPageDict[str(c.name)]=[] pages = Page.objects.filter(uName=request.user.username, category=c).order_by('title') for p in pages: pageData=[] pageData.append(str(p.title)) pageData.append(str(p.url)) pageData.append(str(p.readingRating)) pageData.append(str(p.sentimentRating)) catPageDict[str(c.name)].append(pageData) return render(request, 'health_search_application/profile.html', {'user_categories': sorted(catPageDict.iteritems()), 'keys': catPageDict.keys(), 'userData': userData, 'avatar': userAvatar, 'email': userData[3][1]}) else: return HttpResponseRedirect(reverse('login'))
def profile(request): if request.user.username and request.user.profile.is_app_user: userObj = User.objects.get(username=request.user.username) # All of the user's data userAvatar = request.user.profile.gravatar_url userData = [] userData.append(['Username: '******'First name: ', userObj.first_name]) userData.append(['Last name: ', userObj.last_name]) userData.append(['Email: ', userObj.email]) # create/delete a category, delete a page if request.method == 'POST': nameCategory = request.POST.get('nameCategory', '') urlPage = request.POST.get('urlPage', '') newCategory = request.POST.get('newCategory', '') newPassword = request.POST.get('newPassword', '') if nameCategory != '': c = Category.objects.get(userName=userObj, name=nameCategory) c.delete() if urlPage != '': p = Page.objects.get(uName=request.user.username, url=urlPage) p.delete() if newCategory != '': if not Category.objects.filter(userName=userObj, name=newCategory).exists(): c = Category(userName=userObj, name=newCategory) c.save() if newPassword != '': u = userObj u.set_password(newPassword) u.save() cu = request.user.profile cu.is_app_user = False cu.save() return render(request, 'health_search_application/login.html') catPageDict = {} # dictionary with keys: the categories and values: the pages for c in Category.objects.filter(userName=User.objects.get( username=request.user.username)): catPageDict[str(c.name)] = [] pages = Page.objects.filter(uName=request.user.username, category=c).order_by('title') for p in pages: pageData = [] pageData.append(str(p.title)) pageData.append(str(p.url)) pageData.append(str(p.readingRating)) pageData.append(str(p.sentimentRating)) catPageDict[str(c.name)].append(pageData) return render( request, 'health_search_application/profile.html', { 'user_categories': sorted(catPageDict.iteritems()), 'keys': catPageDict.keys(), 'userData': userData, 'avatar': userAvatar, 'email': userData[3][1] }) else: return HttpResponseRedirect(reverse('login'))
def index(request): if request.method == 'POST': userObject = User.objects.get(username=request.user.username) categoriesDict = {} categoriesDict['allCategories'] = Category.objects.filter( userName=userObject).order_by('name') # get the attributes of the result we want to save title = request.POST.get('title', '') url = request.POST.get('url', '') readingRating = request.POST.get('readingRating', '') sentimentRating = request.POST.get('sentimentRating', '') # the category we want to put our result into categoryName = request.POST.get('category', '') # if we have all of the attributes of the result and a category name, then proceed if title != '' and url != '' and readingRating != '' and sentimentRating != '' and categoryName != '': # if the category does not exist, create it, otherwise extract it from the db if not Category.objects.filter(userName=userObject, name=categoryName).exists(): c = Category(userName=userObject, name=categoryName) c.save() else: c = Category.objects.get(userName=userObject, name=categoryName) # if the page has not been saved before, save it if not Page.objects.filter(uName=request.user.username, url=url).exists(): p = Page(uName=request.user.username, category=c, title=title, url=url, readingRating=readingRating, sentimentRating=sentimentRating) p.save() # from string to list of words searched searchstr = request.POST.get('search', '') search = searchstr.split(" ") # fill in the dictionaries for each api healthDict = healthapif(search) medlineDict = medlineapif(search) bingDict = bingapif(searchstr) # a dictionary, containing all of the results allapisDict = healthDict.copy() allapisDict.update(medlineDict) allapisDict.update(bingDict) return render( request, 'health_search_application/index.html', { 'allapis': allapisDict.iteritems(), 'healthapi': healthDict.iteritems(), 'medlineapi': medlineDict.iteritems(), 'bingapi': bingDict.iteritems(), 'search': searchstr, 'alllength': len(allapisDict), 'allCategories': categoriesDict.iteritems() }) if request.user.username and request.user.profile.is_app_user: return render(request, 'health_search_application/index.html') else: return HttpResponseRedirect(reverse('login'))