def new_question(request): context = {} if request.method == 'POST': form = NewQuestionForm(request.POST) if form.is_valid(): cleaned_data = form.cleaned_data question = Question() question.uid = request.user.id question.category = cleaned_data['category'].replace(' ', '-') question.tutorial = cleaned_data['tutorial'].replace(' ', '-') question.minute_range = cleaned_data['minute_range'] question.second_range = cleaned_data['second_range'] question.title = cleaned_data['title'] question.body = cleaned_data['body'].encode('unicode_escape') question.views = 1 question.save() # Sending email when a new question is asked subject = 'New Forum Question' message = """ The following new question has been posted in the Spoken Tutorial Forum: <br> Title: <b>{0}</b><br> Category: <b>{1}</b><br> Tutorial: <b>{2}</b><br> Link: <a href="{3}">{3}</a><br> Question: <b>{4}</b><br> """.format( question.title, question.category, question.tutorial, 'http://forums.spoken-tutorial.org/question/' + str(question.id), question.body ) email = EmailMultiAlternatives( subject, '', 'forums', ['*****@*****.**', '*****@*****.**'], headers={"Content-type": "text/html;charset=iso-8859-1"} ) email.attach_alternative(message, "text/html") email.send(fail_silently=True) # End of email send return HttpResponseRedirect('/') else: # get values from URL. category = request.GET.get('category', None) tutorial = request.GET.get('tutorial', None) minute_range = request.GET.get('minute_range', None) second_range = request.GET.get('second_range', None) # pass minute_range and second_range value to NewQuestionForm to populate on select form = NewQuestionForm(category=category, tutorial=tutorial, minute_range=minute_range, second_range=second_range) context['category'] = category context['form'] = form context.update(csrf(request)) return render(request, 'website/templates/new-question.html', context)
def new_question(request): context = {} if request.method == 'POST': form = NewQuestionForm(request.POST) if form.is_valid(): cleaned_data = form.cleaned_data question = Question() question.uid = request.user.id question.category = cleaned_data['category'].replace(' ', '-') question.tutorial = cleaned_data['tutorial'].replace(' ', '-') question.minute_range = cleaned_data['minute_range'] question.second_range = cleaned_data['second_range'] question.title = cleaned_data['title'] question.body = cleaned_data['body'].encode('unicode_escape') question.views= 1 question.save() # Sending email when a new question is asked subject = 'New Forum Question' message = """ The following new question has been posted in the Spoken Tutorial Forum: <br> Title: <b>{0}</b><br> Category: <b>{1}</b><br> Tutorial: <b>{2}</b><br> Link: <a href="{3}">{3}</a><br> Question: <b>{4}</b><br> """.format( question.title, question.category, question.tutorial, 'http://forums.spoken-tutorial.org/question/'+str(question.id), question.body ) email = EmailMultiAlternatives( subject,'', 'forums', ['*****@*****.**', '*****@*****.**'], headers={"Content-type":"text/html;charset=iso-8859-1"} ) email.attach_alternative(message, "text/html") email.send(fail_silently=True) # End of email send return HttpResponseRedirect('/') else: # get values from URL. category = request.GET.get('category', None) tutorial = request.GET.get('tutorial', None) minute_range = request.GET.get('minute_range', None) second_range = request.GET.get('second_range', None) # pass minute_range and second_range value to NewQuestionForm to populate on select form = NewQuestionForm(category=category, tutorial=tutorial, minute_range=minute_range,second_range=second_range) context['category'] = category context['form'] = form context.update(csrf(request)) return render(request, 'website/templates/new-question.html', context)
def new_question(request): context = {} if request.method == 'POST': form = NewQuestionForm(request.POST) if form.is_valid(): cleaned_data = form.cleaned_data question = Question() question.user = request.user question.category = cleaned_data['category'] question.title = cleaned_data['title'] question.body = cleaned_data['body'].encode('unicode_escape') question.views= 1 question.save() #Sending email when a new question is asked subject = 'New Forum Question' message = """ The following new question has been posted in the FOSSEE Forum: <br> Title: <b>{0}</b><br> Category: <b>{1}</b><br> Link: <a href="{2}">{2}</a><br> """.format( question.title, question.category, #question.tutorial, 'http://forums.fossee.in/question/'+str(question.id) ) email = EmailMultiAlternatives( subject,'', 'forums', ['*****@*****.**'], headers={"Content-type":"text/html;charset=iso-8859-1"} ) email.attach_alternative(message, "text/html") email.send(fail_silently=True) return HttpResponseRedirect('/') else: category = request.GET.get('category') form = NewQuestionForm(category=category) context['category'] = category context['form'] = form context.update(csrf(request)) return render(request, 'website/templates/new-question.html', context)