diff options
author | Jayaram Pai | 2013-12-08 20:43:40 +0530 |
---|---|---|
committer | Jayaram Pai | 2013-12-08 20:43:40 +0530 |
commit | b596364cf3f871887cce519291b684341cc5c014 (patch) | |
tree | 48dcb9366be1f1110f2fda27afa6485b6c3bdb64 /website | |
parent | 41e5496301cd02bff34dad877d20b2dd30349866 (diff) | |
download | FOSSEE-Forum-b596364cf3f871887cce519291b684341cc5c014.tar.gz FOSSEE-Forum-b596364cf3f871887cce519291b684341cc5c014.tar.bz2 FOSSEE-Forum-b596364cf3f871887cce519291b684341cc5c014.zip |
added nicEdit / on-the-fly question edit
Diffstat (limited to 'website')
-rw-r--r-- | website/models.py | 18 | ||||
-rw-r--r-- | website/urls.py | 1 | ||||
-rw-r--r-- | website/views.py | 36 |
3 files changed, 43 insertions, 12 deletions
diff --git a/website/models.py b/website/models.py index b38c118..22a1fe8 100644 --- a/website/models.py +++ b/website/models.py @@ -2,8 +2,11 @@ from django.conf import settings from django.db import models from django.contrib.auth.models import User +from django.contrib.auth import get_user_model +User = get_user_model() + class Question(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL) + uid = models.IntegerField() category = models.CharField(max_length=200) tutorial = models.CharField(max_length=200) minute_range = models.CharField(max_length=10) @@ -12,16 +15,25 @@ class Question(models.Model): body = models.TextField() date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) + views = models.IntegerField() + + def user(self): + user = User.objects.get(id=self.uid) + return user.username + class Reply(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL) + uid = models.IntegerField() question = models.ForeignKey(Question) body = models.TextField() date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) -# CDEEP database created using inspectdb arg of manage.py + def user(self): + user = User.objects.get(id=self.uid) + return user.username +# CDEEP database created using inspectdb arg of manage.py class TutorialDetails(models.Model): id = models.IntegerField(primary_key=True) foss_category = models.CharField(max_length=255L) diff --git a/website/urls.py b/website/urls.py index 81d61d5..774acb9 100644 --- a/website/urls.py +++ b/website/urls.py @@ -13,4 +13,5 @@ urlpatterns = patterns('', # Ajax helpers url(r'^ajax-tutorials/$', 'website.views.ajax_tutorials', name='ajax_tutorials'), url(r'^ajax-duration/$', 'website.views.ajax_duration', name='ajax_duration'), + url(r'^ajax-question-update/$', 'website.views.ajax_question_update', name='ajax_question_update'), ) diff --git a/website/views.py b/website/views.py index 29c6a76..e18a000 100644 --- a/website/views.py +++ b/website/views.py @@ -1,5 +1,5 @@ from django.http import HttpResponse, HttpResponseRedirect -from django.shortcuts import render_to_response, get_object_or_404 +from django.shortcuts import render, get_object_or_404 from django.core.context_processors import csrf from django.views.decorators.csrf import csrf_exempt from django.contrib.auth.decorators import login_required @@ -9,6 +9,7 @@ from website.models import Question, Reply, TutorialDetails, TutorialResources from website.forms import NewQuestionForm, ReplyQuesitionForm from website.helpers import get_video_info + categories = [ 'Advanced-C++', 'BASH', 'Blender', 'C-and-C++', 'CellDesigner', 'Digital-Divide', @@ -32,7 +33,7 @@ def home(request): 'questions': questions, 'user': request.user } - return render_to_response('website/templates/index.html', context) + return render(request, 'website/templates/index.html', context) def get_question(request, question_id=None): question = get_object_or_404(Question, id=question_id) @@ -44,8 +45,12 @@ def get_question(request, question_id=None): 'form': form } context.update(csrf(request)) - return render_to_response('website/templates/get-question.html', context) + # updating views count + question.views += 1 + question.save() + return render(request, 'website/templates/get-question.html', context) +@login_required def question_reply(request): if request.method == 'POST': form = ReplyQuesitionForm(request.POST) @@ -55,7 +60,7 @@ def question_reply(request): body = cleaned_data['body'] question = get_object_or_404(Question, id=qid) reply = Reply() - reply.user = request.user + reply.uid = request.user.id reply.question = question reply.body = body reply.save() @@ -79,7 +84,7 @@ def filter(request, category=None, tutorial=None, minute_range=None, second_ran questions = questions.filter(~Q(id=qid)) context['questions'] = questions - return render_to_response('website/templates/filter.html', context) + return render(request, 'website/templates/filter.html', context) @login_required def new_question(request): @@ -88,13 +93,14 @@ def new_question(request): if form.is_valid(): cleaned_data = form.cleaned_data question = Question() - question.user = request.user + question.uid = request.user.id question.category = cleaned_data['category'] question.tutorial = cleaned_data['tutorial'] question.minute_range = cleaned_data['minute_range'] question.second_range = cleaned_data['second_range'] question.title = cleaned_data['title'] question.body = cleaned_data['body'] + question.views= 1 question.save() return HttpResponseRedirect('/') else: @@ -104,7 +110,7 @@ def new_question(request): 'form': form } context.update(csrf(request)) - return render_to_response('website/templates/new-question.html', context) + return render(request, 'website/templates/new-question.html', context) @csrf_exempt def ajax_tutorials(request): @@ -114,7 +120,7 @@ def ajax_tutorials(request): context = { 'tutorials': tutorials } - return render_to_response('website/templates/ajax-tutorials.html', context) + return render(request, 'website/templates/ajax-tutorials.html', context) @csrf_exempt def ajax_duration(request): @@ -136,4 +142,16 @@ def ajax_duration(request): 'minutes': minutes, 'seconds':seconds, } - return render_to_response('website/templates/ajax-duration.html', context) + return render(request, 'website/templates/ajax-duration.html', context) + +@csrf_exempt +def ajax_question_update(request): + if request.method == 'POST': + qid = request.POST['question_id'] + body = request.POST['question_body'] + question = get_object_or_404(Question, pk=qid) + if question: + if question.uid == request.user.id: + question.body = body + question.save() + return HttpResponse("saved") |