def orderForumActivityHome(request, offset): """ @AUTHOR:Fouzia Riaz @DESCRIPTION:Function For Latest Forum Content Order BY Display on Home Page (AJAX) """ user_status = is_userLogged(request) if user_status: logged_user = request.session["User_id"] else: logged_user = "" try: order_field = str(offset) except ValueError: pass forumContent = get_latest_threads(order_field, "limit 4") user_status = is_userLogged(request) latest_forum = "" if len(forumContent) > 0: for forum_row in forumContent: thread_date = forum_row[6] thread_time = forum_row[7] if forum_row[6] is None or forum_row[6] <= 0: thread_date = "0" if forum_row[7] is None or forum_row[7] <= 0: thread_time = "0" if forum_row[5] > 0: thread_count = forum_row[5] - 1 elif forum_row[5] == 0: thread_count = forum_row[5] if logged_user == forum_row[11]: display_activity_links = "true" elif logged_user != forum_row[11]: display_activity_links = "false" if forum_row[12]: is_locked = True else: is_locked = False forum_context = { "id": forum_row[0], "thread_count": thread_count, "thread_date": thread_date, "thread_time": thread_time, "first_name": forum_row[3], "last_name": forum_row[4], "thread_topic": forum_row[1], "thread_body": mark_safe(forum_row[2]), "topic_id": forum_row[10], "most_popular": forum_row[8], "user_isLogged": user_status, "display_activity_links": display_activity_links, "is_locked": is_locked, "view_from_page": "home", } forum_template = get_template("home_forumContent.html") latest_forum += forum_template.render(Context(forum_context)) elif len(forumContent) == 0: latest_forum += "<br/><br/><center><i>No records found.</i></center></br/></br/>" return HttpResponse(latest_forum)
def display_feeds(request, news_id=None): userstatus = is_userLogged(request) reply_form = new_thread_form() if news_id: return render_to_response('news_item.html', {'user_isLogged':userstatus, 'reply_form':reply_form, 'news_id':news_id}, context_instance=RequestContext(request)) return render_to_response('horizontal_summarized_all.html', context_instance=RequestContext(request))
def homepage(request): """ # URL recieved e.g. http://healthpark.ca/99/9999 """ user_status = is_userLogged(request) if user_status: user_id = request.session['User_id'] else: user_id = '' #Remove action user_action = isUserAction(request); if user_action == True: action = request.session['Action'] try: del request.session['Action'] except: pass else: action = '' a = request.get_full_path() return render_to_response('home_content.html', {'user_isLogged':user_status, 'user_id':user_id,'path':a,'action':action}, context_instance=RequestContext(request))
def displayAllThreads(request, view_all=None): user_status = is_userLogged(request) if user_status: user_id = request.session["User_id"] else: user_id = "" # Remove action user_action = isUserAction(request) if user_action == True: action = request.session["Action"] try: del request.session["Action"] except: pass else: action = "" return render_to_response( "forum_thread_page.html", {"user_isLogged": user_status, "owner": user_id, "action": action}, context_instance=RequestContext(request), )
def threadVote(request, thread_id, topic_id, origthread_id, up=None, down=None, view_all=None): """ For the given thread_id increases or decreases the votes for that thread, depending on parameters """ if is_userLogged(request): try: # Fetch the thread from database that matches given thread id. vote_thread = Thread.objects.get(id=thread_id) except: pass if up: # If up parameter recieved, add one to popularity field vote_thread.most_popular = vote_thread.most_popular + 1 if down: # If down parameter recieved, subtract one from popularity field vote_thread.most_popular = vote_thread.most_popular - 1 try: vote_thread.save() except: pass if origthread_id: redirect_url = "/forum/?topic_id=" + topic_id + "&thread_id=" + origthread_id elif topic_id: if view_all: redirect_url = "/forum/view-all/" else: redirect_url = "/forum/?cat_id=" + topic_id else: redirect_url = "/" # redirects_url = '/refresh_page/' return HttpResponseRedirect(redirect_url) redirect_path = request.get_full_path() return HttpResponseRedirect("/login/?next=" + redirect_path)
def getArticleContentByProductIDArticleID(request, productID, articleID): """ # URL recieved e.g. http://healthpark.ca/99/9999 """ artical = customModels.MArtical() artical.video_list = [] artical.content_list = [] artical.related_list = [] artical.image_list=[] error_list=[] xmlpath = settings.XML_ROOT.replace('\\','/') mediapath = settings.MEDIA_ROOT.replace('\\','/') try: articleInfo = get_articleinfo(productID, articleID) if articleInfo: product = unicode(articleInfo[0][0]) doc = xml.dom.minidom.parse(xmlpath + "/" + product + "/" + productID + "/" + articleID+".xml") subcontent = unicode(articleInfo[0][1]) title = unicode(articleInfo[0][2]) else: raise Http404("The page You requested was not found") except IOError: raise Http404("The page You requested was not found") # if XML file found then parser # get Header for node in doc.getElementsByTagName("adamContent"): artical.headerTitle = node.getAttribute("title") artical.headerSubContent = node.getAttribute("subContent") # get Content for node in doc.getElementsByTagName("textContent"): for textNode in doc.getElementsByTagName("textLink"): if textNode: pid=textNode.getAttribute("projectTypeID") gid=textNode.getAttribute("genContentID") extlink=textNode.getAttribute("extLink") if not pid=="" and not gid=="": link = doc.createElement("a") if request.is_secure(): hrefString = "https://" + request.get_host()+'/' +'adamcontent'+'/'+pid+'/'+gid+'/' else: hrefString = "http://" + request.get_host()+'/' +'adamcontent'+'/'+pid+'/'+gid+'/' link.setAttribute("href", hrefString) for t in textNode.childNodes: if t.nodeType == t.TEXT_NODE: link.appendChild(t) #add this new anchor textNode.parentNode.replaceChild(link, textNode) """if not extlink=="": link.setAttribute("href", extlink) for t in textNode.childNodes: if t.nodeType == t.TEXT_NODE: link.appendChild(t) #add this new anchor textNode.parentNode.replaceChild(link, textNode)""" #Inline VisualContent display """for visualNode in doc.getElementsByTagName("visualContent"): if visualNode: if visualNode.getAttribute("mediaType")=="jpg" or visualNode.getAttribute("mediaType")=="gif" or visualNode.getAttribute("mediaType")=="png": images = customModels.MArtical.imageContent() images.imageID=visualNode.getAttribute("genContentID") images.imageType=visualNode.getAttribute("mediaType") artical.image_list.append(images) for node in visualNode: if visualNode.childNodes: link = doc.createElement("a") pid=visualNode.childNodes[0].getAttribute("projectTypeID") gid=visualNode.childNodes[0].getAttribute("genContentID") hrefString = "http://" + request.get_host()+'/'+'adamcontent/'+pid+'/'+gid+'/' link.setAttribute("href", hrefString) image = doc.createElement("img") imageSource='/media/graphics/images/en/'+visualNode.getAttribute("genContentID")+'.'+visualNode.getAttribute("mediaType") image.setAttribute("src", imageSource) image.setAttribute("width","100") image.setAttribute("height","100") link.appendChild(image) add this image visualNode.parentNode.replaceChild(link, visualNode) if visualNode.getAttribute("mediaType")=="swf" or visualNode.getAttribute("mediaType")=="flv" : video = customModels.MArtical.videoContent() video.videoFolder=node.getAttribute("genContentID") video.videoID=node.getAttribute("genContentID")+'.'+node.getAttribute("mediaType") artical.video_list.append(video)""" cv = customModels.MArtical.contentView() if not "*" in unicode(node.getAttribute("title")): cv.title = node.getAttribute("title") cv.content = node.toxml() artical.content_list.append(cv) # get Related Item for node in doc.getElementsByTagName("relatedItems"): if node.getAttribute('type') == 'readMore': for nodeRelated in doc.getElementsByTagName("item"): cv = customModels.MArtical.contentView() cv.projectTypeID = nodeRelated.getAttribute("projectTypeID") cv.genContentID = nodeRelated.getAttribute("genContentID") cv.title = nodeRelated.getAttribute("Title") artical.related_list.append(cv) # get footer for node in doc.getElementsByTagName("versionInfo"): artical.footerReviewDate = node.getAttribute("reviewDate") artical.footerReviewBy = node.getAttribute("reviewedBy") # get Article video for visualNode in doc.getElementsByTagName("visualContent"): if visualNode: if visualNode.getAttribute("mediaType")=="jpg" or visualNode.getAttribute("mediaType")=="png" or visualNode.getAttribute("mediaType")=="gif": images = customModels.MArtical.imageContent() images.imageID=visualNode.getAttribute("genContentID") images.imageType=visualNode.getAttribute("mediaType") artical.image_list.append(images) if visualNode.getAttribute("mediaType")=="mov" or visualNode.getAttribute("mediaType")=="flv" or visualNode.getAttribute("mediaType")=="swf" or visualNode.getAttribute("mediaType")=="dcr": video=customModels.MArtical.videoContent() video.videoFolder=visualNode.getAttribute("genContentID") if visualNode.getAttribute("mediaType")=="mov": video.videoID=visualNode.getAttribute("genContentID")+".flv" filepath=mediapath+"/graphics/multimedia/en/"+video.videoFolder+"/"+video.videoID if os.path.exists(filepath): artical.video_list.append(video) else: error_list.append("Video not found") if visualNode.getAttribute("mediaType")=="flv": video.videoID=visualNode.getAttribute("genContentID")+"."+visualNode.getAttribute("mediaType") filepath=mediapath+"/graphics/multimedia/en/"+video.videoFolder+"/"+video.videoID if os.path.exists(filepath): artical.video_list.append(video) else: error_list.append("Video not found") if visualNode.getAttribute("mediaType")=="swf": video.videoID=visualNode.getAttribute("genContentID")+"."+visualNode.getAttribute("mediaType") filepath=mediapath+"/raphics/multimedia/en/"+video.videoFolder+"/"+video.videoID if os.path.exists(filepath): artical.video_list.append(video) else: error_list.append("Video not found") if visualNode.getAttribute("mediaType")=="dcr": video.videoID=visualNode.getAttribute("genContentID")+"."+visualNode.getAttribute("mediaType") filepath=mediapath+"/graphics/multimedia/en/"+video.videoFolder+"/"+video.videoID error_list.append("Video Format not Supported") user_status = is_userLogged(request) return render_to_response('medicalcontent/inner.html', {'MArtical': artical,'productID':productID,'articleID':articleID,'product':product,'subcontent':subcontent,'title':title,'error_list':error_list,'user_isLogged':user_status},context_instance=RequestContext(request))
def displayProfiles(request): if hp_utils.is_userLogged(request): if request.method == "GET": if request.GET.get("profile"): profile = request.GET.get("profile") personalProfile = userprofile.objects.get(id = uuid.UUID(profile)) try: socialHistory = socialhistory.objects.get(userprofile = personalProfile.id) except socialhistory.DoesNotExist: socialHistory = socialhistory.objects.none() familyHistory = familyhistory.objects.filter(userprofile = personalProfile.id).values_list('id','condition','period','gender','relation','relationshiptype') try: personalProfilePhone = personalprofile_phone.objects.get(userprofile = personalProfile.id) except socialhistory.DoesNotExist: personalProfilePhone = personalprofile_phone.objects.none() try: personalProfileEmail = personalprofile_email.objects.get(userprofile = personalProfile.id) except socialhistory.DoesNotExist: personalProfileEmail = personalprofile_email.objects.none() try: personalProfileAdress = personalprofile_adress.objects.get(userprofile = personalProfile.id) except socialhistory.DoesNotExist: personalProfileAdress = personalprofile_adress.objects.none() emergencyContacts = emergencycontacts.objects.filter(userprofile = personalProfile.id) emergencyContactsPhone = [] emergencyContactsEmail = [] emergencyContactsAdress = [] for ec in emergencyContacts: try: emergencyContactsPhone.extend(emergencycontacts_phone.objects.filter(emergencycontacts = ec.id).values_list()) except emergencycontacts_phone.DoesNotExist: emergencyContactsPhone.extend(emergencycontacts_phone.objects.none().values_list()) try: emergencyContactsEmail.extend(emergencycontacts_email.objects.filter(emergencycontacts = ec.id).values_list()) except emergencycontacts_email.DoesNotExist: emergencyContactsEmail.extend(emergencycontacts_email.objects.none().values_list()) try: emergencyContactsAdress.extend(emergencycontacts_adress.objects.filter(emergencycontacts = ec.id).values_list()) except socialhistory.DoesNotExist: emergencyContactsAdress.extend(emergencycontacts_adress.objects.none().values_list()) emergencyContacts = emergencycontacts.objects.filter(userprofile = personalProfile.id).values_list() return render_to_response('phrprofile.html', {'personalProfile':personalProfile, 'socialHistory':socialHistory, 'familyHistory':familyHistory, 'personalProfilePhone':personalProfilePhone, 'personalProfileEmail':personalProfileEmail, 'personalProfileAdress':personalProfileAdress, 'emergencyContacts':emergencyContacts, 'emergencyContactsPhone':emergencyContactsPhone, 'emergencyContactsEmail':emergencyContactsEmail, 'emergencyContactsAdress':emergencyContactsAdress}, context_instance=RequestContext(request)) else: phrprofiles = userprofile.objects.filter(user = uuid.UUID(request.session["User_id"])) currentuser = User.objects.get(id = uuid.UUID(request.session["User_id"])) return render_to_response('phrprofiles.html', {'phrprofiles':phrprofiles, 'currentuser':currentuser}, context_instance=RequestContext(request)) if request.method == "POST": if 'deleteprofile' in request.POST: currentprofile = request.POST.get("currentprofile") userprofile.objects.filter(id = currentprofile, user = uuid.UUID(request.session["User_id"])).delete() return HttpResponseRedirect('/phrprofiles') else: return HttpResponseRedirect('/')
def addProfile(request): if hp_utils.is_userLogged(request): errors = [] if request.method == 'POST': form6 = CreateEmergencyContacts(request.POST, prefix = 'form6') form7 = CreateEmergencyContacts_Phone(request.POST, prefix = 'form7') form8 = CreateEmergencyContacts_Email(request.POST, prefix = 'form8') form9 = CreateEmergencyContacts_Adress(request.POST, prefix = 'form9') if 'createprofile' in request.POST: num = 0 form1 = CreatePersonalProfile(request.POST, prefix = 'form1') form2 = CreatePersonalProfile_Phone(request.POST, prefix = 'form2') form3 = CreatePersonalProfile_Email(request.POST, prefix = 'form3') form4 = CreatePersonalProfile_Adress(request.POST, prefix = 'form4') if form1.is_valid() and form2.is_valid() and form3.is_valid() and form4.is_valid(): cd1 = form1.cleaned_data cd2 = form2.cleaned_data cd3 = form3.cleaned_data cd4 = form4.cleaned_data currentuser = User.objects.get(id = uuid.UUID(request.session["User_id"])) if cd1['myHiddenField']: p = userprofile.objects.get(id = cd1['myHiddenField']) p.firstname = cd1['firstName'] p.middlename = cd1['middleName'] p.lastname = cd1['lastName'] p.dob = cd1['dob'] p.sex = cd1['sex'] p.bloodtype = cd1['bloodType'] p.ethinicity = cd1['ethinicity'] p.save() p = personalprofile_phone.objects.get(userprofile = cd1['myHiddenField']) p.phone = cd2['phone'] p.phonetype = cd2['phoneType'] p.save() p = personalprofile_email.objects.get(userprofile = cd1['myHiddenField']) p.email = cd3['email'] p.emailtype = cd3['emailType'] p.save() p = personalprofile_adress.objects.get(userprofile = cd1['myHiddenField']) p.adress = cd4['adress'] p.adresstype = cd4['adressType'] p.save() return HttpResponseRedirect('/phrprofiles?profile=' + cd1['myHiddenField']) else: try: personalprofile = userprofile.objects.get(profilename = cd1['profileName'], user = uuid.UUID(request.session["User_id"])) except userprofile.DoesNotExist: p = userprofile( profilename = cd1['profileName'], firstname = cd1['firstName'], middlename = cd1['middleName'], lastname = cd1['lastName'], dob = cd1['dob'], sex = cd1['sex'], bloodtype = cd1['bloodType'], ethinicity = cd1['ethinicity'], user = currentuser, ) p.save() x = p.id personalprofileid = userprofile.objects.get(id = uuid.UUID(x)) p = personalprofile_phone( phone = cd2['phone'], phonetype = cd2['phoneType'], userprofile = personalprofileid, ) p.save() p = personalprofile_email( email = cd3['email'], emailtype = cd3['emailType'], userprofile = personalprofileid, ) p.save() p = personalprofile_adress( adress = cd4['adress'], adresstype = cd4['adressType'], userprofile = personalprofileid, ) p.save() displaymsgt1 = [] displaymsgt1.append('Profile created successfully!') return HttpResponseRedirect('/phrprofiles?profile=' + personalprofileid.id) if personalprofile: displaymsgt1 = [] displaymsgt1.append('hideit') errors.append('Profile already exists!') return render_to_response('createphrprofile.html', {'form1': form1,'form2': form2,'form3': form3,'form4': form4, 'num':num,'displaymsgt1':displaymsgt1[0],'errors': errors[0]}, context_instance=RequestContext(request)) else: displaymsgt1 = [] displaymsgt1.append('hideit') return render_to_response('createphrprofile.html', {'form1': form1,'form2': form2,'form3': form3,'form4': form4, 'num':num,'displaymsgt1':displaymsgt1[0]}, context_instance=RequestContext(request)) if 'createemergencycontacts' in request.POST: num = 2 if form6.is_valid() and form7.is_valid() and form8.is_valid() and form9.is_valid(): cd6 = form6.cleaned_data cd7 = form7.cleaned_data cd8 = form8.cleaned_data cd9 = form9.cleaned_data try: p = emergencycontacts.objects.get(id = cd6['myHiddenField2']) p.relationship = cd6['relationship'] p.firstname = cd6['firstName'] p.middlename = cd6['middleName'] p.lastname = cd6['lastName'] p.save() p = emergencycontacts_phone.objects.get(emergencycontacts = cd6['myHiddenField2']) p.phone = cd7['phone'] p.phonetype = cd7['phoneType'] p.save() p = emergencycontacts_email.objects.get(emergencycontacts = cd6['myHiddenField2']) p.email = cd8['email'] p.emailtype = cd8['emailType'] p.save() p = emergencycontacts_adress.objects.get(emergencycontacts = cd6['myHiddenField2']) p.adress = cd9['adress'] p.adresstype = cd9['adressType'] p.save() return HttpResponseRedirect('/phrprofiles?profile=' + cd6['myHiddenField1']) except emergencycontacts.DoesNotExist: personalprofile = userprofile.objects.get(id = cd6['myHiddenField1']) p = emergencycontacts( relationship = cd6['relationship'], firstname = cd6['firstName'], middlename = cd6['middleName'], lastname = cd6['lastName'], userprofile = personalprofile, ) p.save() x = p.id emergencycontact = emergencycontacts.objects.get(id = uuid.UUID(x)) p = emergencycontacts_phone( phone = cd7['phone'], phonetype = cd7['phoneType'], emergencycontacts = emergencycontact, ) p.save() p = emergencycontacts_email( email = cd8['email'], emailtype = cd8['emailType'], emergencycontacts = emergencycontact, ) p.save() p = emergencycontacts_adress( adress = cd9['adress'], adresstype = cd9['adressType'], emergencycontacts = emergencycontact, ) p.save() displaymsgt3 = [] displaymsgt3.append('Emergency Contact created successfully!') return HttpResponseRedirect('/phrprofiles?profile=' + cd6['myHiddenField1']) else: return render_to_response('createphrprofile.html', {'form6': form6,'form7': form7,'form8': form8,'form9': form9, 'num':num}, context_instance=RequestContext(request)) if 'createfamilyhistory' in request.POST: num = 1 form5 = CreateFamilyHistory(request.POST, prefix = 'form5') if form5.is_valid(): cd5 = form5.cleaned_data try: p = familyhistory.objects.get(id = cd5['myHiddenField2']) p.condition = cd5['condition'] p.relation = cd5['relation'] p.relationshiptype = cd5['relationshipType'] p.period = cd5['period'] p.gender = cd5['gender'] p.save() return HttpResponseRedirect('/phrprofiles?profile=' + cd5['myHiddenField1']) except familyhistory.DoesNotExist: personalprofile = userprofile.objects.get(id = cd5['myHiddenField1']) p = familyhistory( condition = cd5['condition'], relation = cd5['relation'], relationshiptype = cd5['relationshipType'], period = cd5['period'], gender = cd5['gender'], userprofile = personalprofile, ) p.save() displaymsgt2 = [] displaymsgt2.append('Family history has created successfully!') return HttpResponseRedirect('/phrprofiles?profile=' + cd5['myHiddenField1']) else: return render_to_response('createphrprofile.html', {'form5': form5, 'num':num}, context_instance=RequestContext(request)) if 'createsocialhistory' in request.POST: num = 3 form10 = CreateSocialHistory(request.POST, prefix = 'form10') if form10.is_valid(): cd10 = form10.cleaned_data try: p = socialhistory.objects.get(userprofile = cd10['myHiddenField']) p.maritalstatus = cd10['maritalStatus'] p.workconditions = cd10['workConditions'] p.druguse = cd10['drugUse'] p.physicalactivity = cd10['physicalActivity'] p.save() return HttpResponseRedirect('/phrprofiles?profile=' + cd10['myHiddenField']) except socialhistory.DoesNotExist: personalprofile = userprofile.objects.get(id = cd10['myHiddenField']) p = socialhistory( maritalstatus = cd10['maritalStatus'], workconditions = cd10['workConditions'], druguse = cd10['drugUse'], physicalactivity = cd10['physicalActivity'], userprofile = personalprofile, ) p.save() displaymsgt4 = [] displaymsgt4.append('Social history has created successfully!') return HttpResponseRedirect('/phrprofiles?profile=' + cd10['myHiddenField']) else: return render_to_response('createphrprofile.html', {'form10': form10, 'num':num}, context_instance=RequestContext(request)) if request.method == 'GET': num = 0 if 'profile' in request.GET: currentprofile = request.GET.get("profile") personalProfile = userprofile.objects.get(id = currentprofile) editform1 = CreatePersonalProfile(initial={ 'myHiddenField':currentprofile, 'profileName':personalProfile.profilename, 'firstName':personalProfile.firstname, 'middleName':personalProfile.middlename, 'lastName':personalProfile.lastname, 'dob':personalProfile.dob, 'sex':personalProfile.sex, 'bloodType':personalProfile.bloodtype, 'ethinicity':personalProfile.ethinicity }, prefix = 'form1') personalProfilePhone = personalprofile_phone.objects.get(userprofile = currentprofile) editform2 = CreatePersonalProfile_Phone(initial={ 'phone':personalProfilePhone.phone, 'phoneType':personalProfilePhone.phonetype }, prefix = 'form2') personalProfileEmail = personalprofile_email.objects.get(userprofile = currentprofile) editform3 = CreatePersonalProfile_Email(initial={ 'email':personalProfileEmail.email, 'emailType':personalProfileEmail.emailtype }, prefix = 'form3') personalProfileAdress = personalprofile_adress.objects.get(userprofile = currentprofile) editform4 = CreatePersonalProfile_Adress(initial={ 'adress':personalProfileAdress.adress, 'adressType':personalProfileAdress.adresstype }, prefix = 'form4') return render_to_response('createphrprofile.html', {'form1': editform1,'form2': editform2,'form3': editform3,'form4': editform4, 'num':num}, context_instance=RequestContext(request)) if 'familyprofile' in request.GET: num = 1 currentprofile = request.GET.get("familyprofile") try: currentfamilyrecord = request.GET["familyrecord"] familyHistoryProfile = familyhistory.objects.get(id = currentfamilyrecord) editform5 = CreateFamilyHistory(initial={'myHiddenField1':currentprofile, 'myHiddenField2':currentfamilyrecord, 'condition':familyHistoryProfile.condition, 'relation':familyHistoryProfile.relation, 'relationshipType':familyHistoryProfile.relationshiptype, 'period':familyHistoryProfile.period, 'gender':familyHistoryProfile.gender }, prefix = 'form5') except KeyError: familyHistoryProfile = familyhistory.objects.none() editform5 = CreateFamilyHistory(initial={'myHiddenField1':currentprofile}, prefix = 'form5') return render_to_response('createphrprofile.html', {'form5': editform5, 'num':num}, context_instance=RequestContext(request)) if 'contactprofile' in request.GET: num = 2 currentprofile = request.GET.get("contactprofile") try: currentcontactrecord = request.GET["contactrecord"] emergencyContactsProfile = emergencycontacts.objects.get(id = currentcontactrecord) emergencyContactsPhone = emergencycontacts_phone.objects.get(emergencycontacts = currentcontactrecord) emergencyContactsEmail = emergencycontacts_email.objects.get(emergencycontacts = currentcontactrecord) emergencyContactsAdress= emergencycontacts_adress.objects.get(emergencycontacts = currentcontactrecord) editform6 = CreateEmergencyContacts(initial={'myHiddenField1':currentprofile, 'myHiddenField2':currentcontactrecord, 'firstName':emergencyContactsProfile.firstname, 'middleName':emergencyContactsProfile.middlename, 'lastName':emergencyContactsProfile.lastname, 'relationship':emergencyContactsProfile.relationship }, prefix = 'form6') editform7 = CreateEmergencyContacts_Phone(initial={ 'phone':emergencyContactsPhone.phone, 'phoneType':emergencyContactsPhone.phonetype }, prefix = 'form7') editform8 = CreateEmergencyContacts_Email(initial={ 'email':emergencyContactsEmail.email, 'emailType':emergencyContactsEmail.emailtype }, prefix = 'form8') editform9 = CreateEmergencyContacts_Adress(initial={ 'adress':emergencyContactsAdress.adress, 'adressType':emergencyContactsAdress.adresstype }, prefix = 'form9') except KeyError: editform6 = CreateEmergencyContacts(initial={'myHiddenField1':currentprofile}, prefix = 'form6') editform7 = CreateEmergencyContacts_Phone(prefix = 'form7') editform8 = CreateEmergencyContacts_Email(prefix = 'form8') editform9 = CreateEmergencyContacts_Adress(prefix = 'form9') return render_to_response('createphrprofile.html', {'form6': editform6,'form7': editform7,'form8': editform8,'form9': editform9, 'num':num}, context_instance=RequestContext(request)) if 'socialprofile' in request.GET: num = 3 currentprofile = request.GET.get("socialprofile") try: socialHistoryProfile = socialhistory.objects.get(userprofile = currentprofile) editform10 = CreateSocialHistory(initial={'myHiddenField':currentprofile, 'maritalStatus':socialHistoryProfile.maritalstatus, 'workConditions':socialHistoryProfile.workconditions, 'drugUse':socialHistoryProfile.druguse, 'physicalActivity':socialHistoryProfile.physicalactivity }, prefix = 'form10') except socialhistory.DoesNotExist: socialHistoryProfile = socialhistory.objects.none() editform10 = CreateSocialHistory(initial={'myHiddenField':currentprofile}, prefix = 'form10') return render_to_response('createphrprofile.html', {'form10': editform10, 'num':num}, context_instance=RequestContext(request)) else: form1 = CreatePersonalProfile(prefix = 'form1') form2 = CreatePersonalProfile_Phone(prefix = 'form2') form3 = CreatePersonalProfile_Email(prefix = 'form3') form4 = CreatePersonalProfile_Adress(prefix = 'form4') form5 = CreateFamilyHistory(prefix = 'form5') form6 = CreateEmergencyContacts(prefix = 'form6') form7 = CreateEmergencyContacts_Phone(prefix = 'form7') form8 = CreateEmergencyContacts_Email(prefix = 'form8') form9 = CreateEmergencyContacts_Adress(prefix = 'form9') form10 = CreateSocialHistory(prefix = 'form10') displaymsgt1 = [] displaymsgt1.append('hideit') num = 0 return render_to_response('createphrprofile.html', {'form1': form1,'form2': form2,'form3': form3,'form4': form4,'form5': form5,'form6': form6,'form7': form7,'form8': form8,'form9': form9,'form10': form10,'num':num, 'displaymsgt1':displaymsgt1[0]}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/')
def signup(request): if not is_userLogged(request): if request.method == "POST": signupform = signup_form(request.POST) if signupform.is_valid(): clean_data = signupform.cleaned_data # Check if a User already exists by the given username. try: get_user = User.objects.get(nickname = clean_data['nickname']) # If username found display error if get_user: return render_to_response('sign_up.html', {'signupform':signupform, 'userExists': True}, context_instance=RequestContext(request)) # If no user found, match passwords and create new user except User.DoesNotExist: pass try: get_email_user = User.objects.get(email = clean_data['email']) if get_email_user: return render_to_response('sign_up.html', {'signupform':signupform, 'emailExists': True}, context_instance=RequestContext(request)) except User.DoesNotExist: if clean_data['password'] != clean_data['repeat_password']: return render_to_response('sign_up.html', {'signupform':signupform, 'passwordMismatch' : True}, context_instance=RequestContext(request)) if not clean_data['terms_agree']: return render_to_response('sign_up.html', {'signupform':signupform, 'terms_error' : True}, context_instance=RequestContext(request)) # Generate a random user salt user_salt = gen_rand_str() # Generate hash for user password pw_hash = hashlib.sha256(user_salt + clean_data['password']).hexdigest() new_user = User(nickname = clean_data['nickname'], #first_name = clean_data['first_name'], #last_name = clean_data['last_name'], password = pw_hash, pw_salt = user_salt, email = clean_data['email'], join_date_time = datetime.datetime.now() #address = clean_data['address'], #phone_number = clean_data['phone_number'], #fax_number = clean_data['fax_number'], #website = clean_data['website'] ) # Try to save new user to Databse. return userCreateError if unable # to save user to databse, due to any reason. try: new_user.save() get_user = User.objects.get(nickname = clean_data['nickname']) request.session.flush() request.session['User_id'] = get_user.id settings.SESSION_EXPIRE_AT_BROWSER_CLOSE = True request.session.set_expiry((datetime.datetime.now() + datetime.timedelta(hours = 6))) return HttpResponseRedirect('/refresh_page/') except: return render_to_response('sign_up.html', {'signupform':signupform, 'userCreateError': True}, context_instance=RequestContext(request)) # If method not POST return blank signup form. else: signupform = signup_form() return render_to_response('sign_up.html', {'signupform':signupform, 'start' : True}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/refresh_page/')
def editThread(request, thread_id=None, view_page=None, topic_id=None, parent_id=None): """ @AUTHOR:Fouzia Riaz @DESCRIPTION:Edit thread to the database with given relations. """ # Check if a user is logged in. Otherwise redirect to login page. user_status = is_userLogged(request) # Remove action user_action = isUserAction(request) if user_action == True: action = request.session["Action"] try: del request.session["Action"] except: pass else: action = "" try: logged_user = request.session["User_id"] if request.method == "POST": editThreadForm = edit_thread_form(request.POST) if editThreadForm.is_valid(): clean_data = editThreadForm.cleaned_data owner_user = User.objects.get(id=uuid.UUID(logged_user)) if not clean_data["thread_name"]: return render_to_response( "new_thread.html", { "threadForm": editThreadForm, "emptyThreadName": True, "actions": "edit", "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) if not clean_data["thread_body"]: return render_to_response( "new_thread.html", { "threadForm": editThreadForm, "emptyThreadBody": True, "actions": "edit", "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) # Edit thread instance to save to the db. try: edit_thread = Thread.objects.get(id=thread_id) edit_thread.thread_name = clean_data["thread_name"] edit_thread.thread_body = clean_data["thread_body"] edit_thread.keyword_dict = clean_data["keywords"] # edit_thread.topic = clean_data['category_id'] except: return HttpResponseRedirect("/") try: if edit_thread.owner == owner_user: edit_thread.save() try: allowed_content_list = [ "application/pdf", "application/zip", "image/gif", "image/jpeg", "image/pjpeg", ] docfile1 = request.FILES["docfile"] c_type = docfile1.content_type if "docfile" in request.FILES and c_type in allowed_content_list: newdoc = hptb_attachments( hptable_ID="th", hprecord_id=thread_id, docfile=request.FILES["docfile"] ) newdoc.save() except: pass if view_page == "home": redirect_url = "/" if view_page == "forum": redirect_url = r"/forum/?cat_id=%s/" % (topic_id) if view_page == "thread": redirect_url = r"/forum/?topic_id=%s&thread_id=%s/" % (topic_id, parent_id) if view_page == "view-all": redirect_url = "/forum/view-all/" request.session["Action"] = "edit-post" return HttpResponseRedirect(redirect_url) except: return render_to_response( "new_thread.html", { "threadFrom": editThreadForm, "dberror": True, "actions": "edit", "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) except KeyError: return HttpResponseRedirect("/login/") # Select Values From Database try: thread_content = Thread.objects.get(id=thread_id) category_content = Topic.objects.get(id=topic_id) threadForm = edit_thread_form( initial={ #'category_id':category_content, "thread_name": thread_content.thread_name, "thread_body": thread_content.thread_body, "keywords": thread_content.keyword_dict, } ) return render_to_response( "new_thread.html", { "threadForm": threadForm, "actions": "edit", "user_isLogged": user_status, "category_name": category_content.topic_name, "cat_id": category_content.id, "action": action, }, context_instance=RequestContext(request), ) except: return HttpResponseRedirect("/")
def editCategory(request, category_id=None, topic_id=None, thread_id=None): """ @AUTHOR:Fouzia Riaz @DESCRIPTION:Function For Change Category """ # Remove action user_action = isUserAction(request) if user_action == True: action = request.session["Action"] try: del request.session["Action"] except: pass else: action = "" try: # Check if a user is logged in. Otherwise redirect to login page. logged_user = request.session["User_id"] user_status = is_userLogged(request) if request.method == "POST": editTopicForm = edit_category_form(request.POST) if editTopicForm.is_valid(): clean_data = editTopicForm.cleaned_data owner_user = User.objects.get(id=uuid.UUID(logged_user)) try: # owner_user = User.objects.get(id=uuid.UUID(logged_user)) if len(clean_data["category_name"]) == 0: return render_to_response( "edit_category.html", { "editTopicForm": editTopicForm, "emptyCategory": True, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) else: editCategory = Topic.objects.get(id=category_id) editCategory.topic_name = clean_data["category_name"] editCategory.topic_body = topic_body = clean_data["category_body"] editCategory.keyword_dict = keyword_dict = clean_data["category_keywords"] try: if editCategory.owner == owner_user: editCategory.save() if not topic_id is None and not thread_id is None: id_list = (topic_id, thread_id) redirect_url = r"/forum/?topic_id=%s&thread_id=%s/" % id_list elif not topic_id is None and thread_id is None: if topic_id == "community": redirect_url = r"/forum/" elif topic_id == "view-all": redirect_url = r"/forum/view-all/" else: redirect_url = r"/forum/?cat_id=%s" % (topic_id) elif topic_id is None and thread_id is None: redirect_url = r"/" request.session["Action"] = "edit-category" return HttpResponseRedirect(redirect_url) except: return render_to_response( "edit_category.html", { "editTopicForm": editTopicForm, "dberror": True, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) except: return HttpResponseRedirect("/") # except KeyError: # return HttpResponseRedirect('/login/')*/ # Select Values From Database category_content = Topic.objects.get(id=category_id) editTopicForm = edit_category_form( initial={ "category_name": category_content.topic_name, "category_body": category_content.topic_body, "category_keywords": category_content.keyword_dict, } ) return render_to_response( "edit_category.html", { "editTopicForm": editTopicForm, "user_isLogged": user_status, "category_name": category_content.topic_name, "action": action, }, context_instance=RequestContext(request), ) except: return HttpResponseRedirect("/")
def search(request, is_adv=None): # Remove action user_action = isUserAction(request) if user_action == True: action = request.session["Action"] try: del request.session["Action"] except: pass else: action = "" if is_adv: return render_to_response("advanced_search.html", context_instance=RequestContext(request)) if request.method == "POST": searchform = search_form(request.POST) if searchform.is_valid(): clean_data = searchform.cleaned_data if clean_data["category_choices"]: # Fend chosen category to template for display category_choices = "'" + str(clean_data["category_choices"]) + "'" + " category" # Retrieve records matching the search query for given category try: result_set = Thread.objects.filter( Q(topic=clean_data["category_choices"]), ( Q(thread_name__contains=clean_data["search_text"]) | Q(thread_body__contains=clean_data["search_text"]) ), Q(parent_thread=None), ) except: pass else: category_choices = "all forums" try: result_set = Thread.objects.filter( Q(thread_name__contains=clean_data["search_text"]) | Q(thread_body__contains=clean_data["search_text"]), Q(parent_thread=None), ) except: pass result_set_count = len(list(result_set)) user_status = is_userLogged(request) return render_to_response( "search.html", { "threads": result_set, "threads_count": result_set_count, "search_text": clean_data["search_text"], "category_choices": category_choices, "search_form": searchform, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) return render_to_response("search.html", {"search_form": searchform}) return HttpResponseRedirect("/forum/")
def forumContentByTopic(request, offset): """ @AUTHOR:Fouzia Riaz @DESCRIPTION:Function For Latest Forum Content Order BY Display on Forum Page """ user_status = is_userLogged(request) if user_status: logged_user = request.session["User_id"] else: logged_user = "" try: topic_id = offset except ValueError: pass try: topic_id = offset except ValueError: pass try: getCategory = Topic.objects.get(id=topic_id) if getCategory.id: forumContent = get_topic_threads(topic_id) latest_forum_by_topic = "" if len(forumContent) > 0: for forum_row in forumContent: thread_date = forum_row[7] thread_time = forum_row[8] # thread_count = forum_row[6] if forum_row[7] is None or forum_row[7] <= 0: thread_date = "0" if forum_row[8] is None or forum_row[8] <= 0: thread_time = "0" if forum_row[6] > 0: thread_count = forum_row[6] - 1 elif forum_row[6] == 0: thread_count = thread_count if logged_user == forum_row[11]: display_activity_links = "true" elif logged_user != forum_row[11]: display_activity_links = "false" forum_context = { "id": forum_row[0], "thread_count": thread_count, "thread_date": thread_date, "thread_time": thread_time, "first_name": forum_row[3], "last_name": forum_row[4], "thread_topic": forum_row[1], "thread_body": mark_safe(forum_row[2]), "is_userLogged": user_status, "display_activity_links": display_activity_links, } forum_template = get_template("home_forumContent.html") latest_forum_by_topic += forum_template.render(Context(forum_context)) elif len(forumContent) == 0: latest_forum_by_topic += "<br/><br/><center><i>No records found.</i></center></br/></br/>" return HttpResponse(latest_forum_by_topic) else: return HttpResponseRedirect("/") except: return HttpResponseRedirect("/")
def orderMoreForumActivity(request, offset): """ @AUTHOR:Fouzia Riaz @DESCRIPTION:Function For Latest Forum Content Order BY/See more on Forum Page """ user_status = is_userLogged(request) if user_status: logged_user = request.session["User_id"] else: logged_user = "" order_field = "mostpopular" try: # If parameters send in url (LIMITS, COUNTS, ORDERS, Category) (For See more, category) if ( (request.GET.get("lim") and request.GET.get("off") and request.GET.get("counts")) or request.GET.get("orders") or (request.GET.get("cat_id")) ): content_limit = str(request.GET.get("lim")).rstrip("/") content_offset = str(request.GET.get("off")).rstrip("/") content_count = str(request.GET.get("counts")).rstrip("/") order_field = str(request.GET.get("orders")).rstrip("/") catid_field = str(request.GET.get("cat_id")).rstrip("/") catid_field = catid_field.rstrip("/") order_field = order_field.rstrip("/") except ValueError: pass if order_field != "": # If no limits provided in url if content_limit == "None" or content_limit is None: if catid_field is None or catid_field == "None": catid_field = "null" forumContent = get_topic_threads(catid_field, order_field, "limit 5") # If limits provided in url else: limits = "limit " + content_limit + " offset " + content_offset forumContent = get_topic_threads(catid_field, order_field, limits) forumActivityCount = get_topic_threads(catid_field, "mostpopular", "") topic_count = len(forumActivityCount) is_topic = "true" forum_activity = "" if catid_field == "null": view_page = "view-all-forum" else: view_page = "" if len(forumContent) > 0: for forum_row in forumContent: if is_topic == "true": forum_context = getForumContext( forum_row, is_topic, topic_count, user_status, logged_user, view_page ) else: forum_context = getForumContext( forum_row, is_topic, topic_count, user_status, logged_user, view_page ) forum_template = get_template("home_forumContent.html") forum_activity += forum_template.render(Context(forum_context)) elif len(forumContent) == 0: forum_activity += "<br/><br/><center><i>No records found.</i></center></br/></br/>" if len(catid_field) != 0: forum_activity += '<input type="hidden" value="' + catid_field + '" id="cat_id"/>' forum_activity += ( '<input type="hidden" value="' + ` topic_count ` + '" id="topic_count"/><input type="hidden" value="' + order_field + '" id="order_by"/>' ) return HttpResponse(forum_activity)
def newThread(request, news_id=None, topic_id=None, parent_id=None, is_parent=None, origthread_id=None): """ Inserts a new thread to the database with given relations. """ # Remove action user_action = isUserAction(request) if user_action == True: action = request.session["Action"] try: del request.session["Action"] except: pass else: action = "" try: user_status = is_userLogged(request) if (Topic.objects.get(id=topic_id)).is_locked: redirect_url = r"/forum/?cat_id=%s/" % topic_id return HttpResponseRedirect(redirect_url) else: try: # Check if a user is logged in. Otherwise redirect to login page. logged_user = request.session["User_id"] if request.method == "POST": newThreadForm = new_thread_form(request.POST) if newThreadForm.is_valid(): clean_data = newThreadForm.cleaned_data if is_parent and not clean_data["thread_name"]: redirect_url = r"/forum/?cat_id=%s/" % topic_id return render_to_response( "new_thread.html", { "threadForm": newThreadForm, "emptyThreadName": True, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) if not clean_data["thread_body"]: return render_to_response( "new_thread.html", { "threadForm": newThreadForm, "emptyThreadBody": True, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) try: # Get the user,topic, and thread objects from the database, # for the logged user and given topic and thread ids. owner_user = User.objects.get(id=uuid.UUID(logged_user)) # Insert New Category if clean_data["new_category"]: new_topic_name = clean_data["new_category"] category = add_new_category(new_topic_name, owner_user) categ_topic = Topic.objects.get(id=str(category)) else: if clean_data["category_id"]: categ_topic = Topic.objects.get(id=topic_id) else: return render_to_response( "new_thread.html", { "threadForm": newThreadForm, "emptyCategory": True, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) parentThread = Thread.objects.get(id=parent_id) except User.DoesNotExist: pass except Topic.DoesNotExist: pass except Thread.DoesNotExist: # If no parent_id was passed to the view, # set parentThread to None. parentThread = None # Create a new uuid. new_thread_id = uuid.uuid4() # Create a new thread instance to save to the db. new_thread = Thread( id=new_thread_id, thread_name=clean_data["thread_name"], thread_body=clean_data["thread_body"], datetime_created=datetime.datetime.now(), keyword_dict=clean_data["keywords"], topic=categ_topic, owner=owner_user, parent_thread=parentThread, most_popular=0, ) try: new_thread.save() allowed_content_list = [ "application/pdf", "application/zip", "image/gif", "image/jpeg", "image/pjpeg", ] try: docfile1 = request.FILES["docfile"] c_type = docfile1.content_type if "docfile" in request.FILES and c_type in allowed_content_list: newdoc = hptb_attachments( hptable_ID="th", hprecord_id=new_thread_id, docfile=request.FILES["docfile"] ) newdoc.save() except: pass # If the thread to be saved is a top-level parent thread, # redirect to the new parent thread created. Otherwise # redirect to the same thread page where user was last. if is_parent: id_list = (topic_id, new_thread_id) else: id_list = (topic_id, origthread_id) request.session["Action"] = "add-post" redirect_url = r"/forum/?topic_id=%s&thread_id=%s/" % id_list return HttpResponseRedirect(redirect_url) except: return render_to_response( "new_thread.html", { "threadForm": newThreadForm, "dberror": True, "user_isLogged": user_status, "action": action, }, context_instance=RequestContext(request), ) except KeyError: return HttpResponseRedirect("/login/") categ_topic = Topic.objects.get(id=topic_id) threadForm = new_thread_form(initial={"category_id": categ_topic}) return render_to_response( "new_thread.html", { "threadForm": threadForm, "user_isLogged": user_status, "category_name": categ_topic.topic_name, "cat_id": topic_id, "action": action, }, context_instance=RequestContext(request), ) except: return HttpResponseRedirect("/")
def displayTopic(request, topic_id=None, parent_id=None): is_locked = "" category_name = "" thread_name = "" if request.method == "POST": reply_form = new_thread_form(request.POST) if reply_form.is_valid(): clean_data = reply_form.cleaned_data logged_user = request.session["User_id"] try: owner_user = User.objects.get(id=uuid.UUID(logged_user)) parentThread = Thread.objects.get(id=parent_id) categ_topic = Topic.objects.get(id=topic_id) except: return HttpResponseRedirect("/") new_thread = Thread( thread_name=clean_data["thread_name"], thread_body=clean_data["thread_body"], datetime_created=datetime.datetime.now(), keyword_dict=clean_data["keywords"], topic=categ_topic, owner=owner_user, parent_thread=parentThread, most_popular=0, ) try: new_thread.save() id_list = (topic_id, parent_id) redirect_url = r"/forum/?topic_id=%s&thread_id=%s/" % id_list return HttpResponseRedirect(redirect_url) except: pass try: thread_id = "" cat_id = "" display_forum = 0 display_thread = 0 threadsList = [] topic_id = "" if request.GET.get("cat_id"): cat_id = str(request.GET.get("cat_id")) cat_id = cat_id.rstrip("/") categories = "" if request.GET.get("topic_id"): topic_id = str(request.GET.get("topic_id")) topic_id = topic_id.rstrip("/") try: category_content = Topic.objects.get(id=topic_id) category_name = category_content.topic_name except: pass # return HttpResponseRedirect('/') categories = "" if request.GET.get("thread_id"): thread_id = str(request.GET.get("thread_id")) thread_id = thread_id.rstrip("/") try: parentThread = Thread.objects.get(id=thread_id) thread_name = parentThread.thread_name except: pass categories = "" except ValueError: pass # if (not thread_id or thread_id == '' or len(thread_id) == 0): # thread_id = None # threadsList = get_threads_by_id(thread_id) # else: # threadsList = get_threads_by_id(thread_id) if not thread_id and not cat_id: categories = "TRUE" is_locked = "" if request.GET.get("cat_id"): display_forum = "TRUE" try: category_content = Topic.objects.get(id=cat_id) except: return HttpResponseRedirect("/") is_locked = category_content.is_locked category_name = category_content.topic_name if request.GET.get("thread_id"): parent_id = request.GET.get("thread_id") parent_id = parent_id.rstrip("/") try: parentThread = Thread.objects.get(id=parent_id) thread_name = parentThread.thread_name except: pass # return HttpResponseRedirect('/') display_thread = "TRUE" is_locked = "" user_status = is_userLogged(request) if user_status: logged_user = request.session["User_id"] else: logged_user = "" # Remove action user_action = isUserAction(request) if user_action == True: action = request.session["Action"] try: del request.session["Action"] except: pass else: action = "" reply_form = new_thread_form() template_search_form = search_form() return render_to_response( "forum_page.html", { #'threads':threadsList, "display_forum": display_forum, "display_thread": display_thread, "category": cat_id, "thread": thread_id, "topic_id": topic_id, "display_category": categories, "path": request.get_full_path(), "user_isLogged": user_status, "reply_form": reply_form, "search_form": template_search_form, "owner": logged_user, "topic_is_locked": is_locked, "action": action, "category_name": category_name, "thread_name": thread_name, }, context_instance=RequestContext(request), )