Example #1
0
def submit_question(request):
	title = request.POST.get("title", "")
	title = title.strip()
	question_text = request.POST.get("question", "")
	question_text = question_text.strip()
	questionURL = ''.join(e for e in title if e.isalnum())
	tags = request.POST.get("tags", "")
	tags = [x.strip() for x in tags.split(',')]
	#Associate user and set the ranking
	#Check if title already exists, if so, let the user know they need a unique title
	
	if request.user.is_authenticated():
		if questionURL != "" and TextContent.objects.filter(isQuestion = True, questionURL=questionURL).count() == 0:
			question = TextContent(title=title, body=question_text, isQuestion=True, user=request.user, rank=0, questionURL=questionURL)
			question.save()
			for tag in tags:
				tag_db, tag_created = Tag.objects.get_or_create(tag=tag)
				textContentTag, textContentTag_created = TextContentTag.objects.get_or_create(tag=tag_db, textContent=question)

			return HttpResponseRedirect('/question/' + questionURL)
				
		else:
			#Update page to notify the user the title must be unique
			return render(request,'website_qanswr/question/' + questionURL, {"titleNotUnique":True})
	else:
		#User is not authenticated
		return render(request,'website_qanswr/question/' + questionURL, {"notLoggedIn":True})
Example #2
0
def submit_discussion(request):
	discussion_text = request.POST.get("discussion", "")
	discussion_text = discussion_text.strip()
	if discussion_text != "" and TextContent.objects.filter(isDiscussion = True, body=discussion_text).count() == 0:
		discussion = TextContent( body=discussion_text, isDiscussion = True, user=request.user, rank=0, responseTo=TextContent.objects.get( body = str( request.POST.get("responseTo","") ) ) )
		discussion.save()

	return HttpResponseRedirect('/question/' + request.session.get('questionURL')) 
Example #3
0
def submit_answer(request):
    answer_text = request.POST.get("answer", "")
    answer_text = answer_text.strip()
    citation_text = request.POST.get("citation", "")
    citation_text = citation_text.strip()

    if request.user.is_authenticated():
        if answer_text != "" and TextContent.objects.filter(
                isAnswer=True, body=answer_text).count() == 0:
            answer = TextContent(body=answer_text,
                                 isAnswer=True,
                                 user=request.user,
                                 rank=0,
                                 responseTo=request.session.get('question'))
            answer.save()
            if citation_text != "" and TextContent.objects.filter(
                    isCitation=True, body=citation_text).count() == 0:
                citation = TextContent(body=citation_text,
                                       isCitation=True,
                                       user=request.user,
                                       rank=0,
                                       responseTo=answer)
                citation.save()

    return HttpResponseRedirect('/question/' +
                                request.session.get('questionURL'))
Example #4
0
def submit_discussion(request):
    discussion_text = request.POST.get("discussion", "")
    discussion_text = discussion_text.strip()
    if discussion_text != "" and TextContent.objects.filter(
            isDiscussion=True, body=discussion_text).count() == 0:
        discussion = TextContent(
            body=discussion_text,
            isDiscussion=True,
            user=request.user,
            rank=0,
            responseTo=TextContent.objects.get(
                body=str(request.POST.get("responseTo", ""))))
        discussion.save()

    return HttpResponseRedirect('/question/' +
                                request.session.get('questionURL'))
Example #5
0
def submit_question(request):
    title = request.POST.get("title", "")
    title = title.strip()
    question_text = request.POST.get("question", "")
    question_text = question_text.strip()
    questionURL = ''.join(e for e in title if e.isalnum())
    tags = request.POST.get("tags", "")
    tags = [x.strip() for x in tags.split(',')]
    #Associate user and set the ranking
    #Check if title already exists, if so, let the user know they need a unique title

    if request.user.is_authenticated():
        if questionURL != "" and TextContent.objects.filter(
                isQuestion=True, questionURL=questionURL).count() == 0:
            question = TextContent(title=title,
                                   body=question_text,
                                   isQuestion=True,
                                   user=request.user,
                                   rank=0,
                                   questionURL=questionURL)
            question.save()
            for tag in tags:
                tag_db, tag_created = Tag.objects.get_or_create(tag=tag)
                textContentTag, textContentTag_created = TextContentTag.objects.get_or_create(
                    tag=tag_db, textContent=question)

            return HttpResponseRedirect('/question/' + questionURL)

        else:
            #Update page to notify the user the title must be unique
            return render(request, 'website_qanswr/question/' + questionURL,
                          {"titleNotUnique": True})
    else:
        #User is not authenticated
        return render(request, 'website_qanswr/question/' + questionURL,
                      {"notLoggedIn": True})
Example #6
0
def submit_answer(request):
	answer_text = request.POST.get("answer", "")
	answer_text = answer_text.strip()
	citation_text = request.POST.get("citation", "")
	citation_text = citation_text.strip()

	if request.user.is_authenticated():
		if answer_text != "" and TextContent.objects.filter(isAnswer = True, body=answer_text).count() == 0:
			answer = TextContent(body=answer_text, isAnswer=True, user=request.user, rank=0, responseTo=request.session.get('question'))
			answer.save()
			if citation_text != "" and TextContent.objects.filter(isCitation = True, body=citation_text).count() == 0:
				citation = TextContent(body=citation_text, isCitation=True, user=request.user, rank=0, responseTo=answer)
				citation.save()


	return HttpResponseRedirect('/question/' + request.session.get('questionURL'))