diff options
author | Jayaram Pai | 2014-01-23 23:03:03 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-01-23 23:03:03 +0530 |
commit | 9f7c82e28316490ff479e31eb7b50db1e6ef1cd8 (patch) | |
tree | fe31b073d1fb838f2c7737ec90ef5ced0e68c310 /website | |
parent | 1d0d09f88b76a0f6827beff3b854e8ff30757306 (diff) | |
download | FOSSEE-Forum-9f7c82e28316490ff479e31eb7b50db1e6ef1cd8.tar.gz FOSSEE-Forum-9f7c82e28316490ff479e31eb7b50db1e6ef1cd8.tar.bz2 FOSSEE-Forum-9f7c82e28316490ff479e31eb7b50db1e6ef1cd8.zip |
added question edit.
added question details change.
added admin_user feature.
Diffstat (limited to 'website')
-rw-r--r-- | website/context_processors.py | 10 | ||||
-rw-r--r-- | website/templatetags/permission_tags.py | 12 | ||||
-rw-r--r-- | website/urls.py | 1 | ||||
-rw-r--r-- | website/views.py | 45 |
4 files changed, 61 insertions, 7 deletions
diff --git a/website/context_processors.py b/website/context_processors.py new file mode 100644 index 0000000..2497e7c --- /dev/null +++ b/website/context_processors.py @@ -0,0 +1,10 @@ +from website.views import admins + +def admin_processor(request): + return {'admins': admins} + +def booleans(): + return { + 'True': True, + 'False': False, + } diff --git a/website/templatetags/permission_tags.py b/website/templatetags/permission_tags.py new file mode 100644 index 0000000..b85d747 --- /dev/null +++ b/website/templatetags/permission_tags.py @@ -0,0 +1,12 @@ +from django import template + +from website.views import admins + +register = template.Library() + +def can_edit(user, obj): + if user.id == obj.uid or user.id in admins: + return True + return False + +register.filter(can_edit) diff --git a/website/urls.py b/website/urls.py index bdad667..9288e1e 100644 --- a/website/urls.py +++ b/website/urls.py @@ -19,6 +19,7 @@ urlpatterns = patterns('', 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'), + url(r'^ajax-details-update/$', 'website.views.ajax_details_update', name='ajax_details_update'), url(r'^ajax-reply-update/$', 'website.views.ajax_reply_update', name='ajax_reply_update'), url(r'^ajax-similar-questions/$', 'website.views.ajax_similar_questions', name='ajax_similar_questions'), url(r'^ajax-notification-remove/$', 'website.views.ajax_notification_remove', name='ajax_notification_remove'), diff --git a/website/views.py b/website/views.py index e470e09..38bd973 100644 --- a/website/views.py +++ b/website/views.py @@ -12,8 +12,11 @@ from website.models import Question, Reply, Notification, TutorialDetails, Tutor from website.forms import NewQuestionForm, ReplyQuesitionForm from website.helpers import get_video_info +admins = ( + 99999, +) -categories = [ +categories = ( 'Advanced-C++', 'BASH', 'Blender', 'C-and-C++', 'CellDesigner', 'Digital-Divide', 'Drupal', 'Firefox', 'GChemPaint', 'Geogebra', @@ -28,7 +31,7 @@ categories = [ 'QCad', 'R', 'Ruby', 'Scilab', 'Selenium', 'Single-Board-Heater-System', 'Spoken-Tutorial-Technology', 'Step', 'Thunderbird', 'Tux-Typing', 'What-is-Spoken-Tutorial', 'Xfig' -] +) def home(request): marker = 0 @@ -219,6 +222,13 @@ def search(request): # Ajax Section # All the ajax views go below @csrf_exempt +def ajaX_category(request): + context = { + 'categories': categories + } + return render(request, 'website/templates/ajax_categories.html', context) + +@csrf_exempt def ajax_tutorials(request): if request.method == 'POST': category = request.POST.get('category') @@ -241,9 +251,10 @@ def ajax_duration(request): Q(tutorial_detail_id=video_detail.id), Q(language='English') ) - video_path = '/Sites/spoken_tutorial_org/sites/default/files/{0}'.format( - video_resource.tutorial_video - ) + #video_path = '/Sites/spoken_tutorial_org/sites/default/files/{0}'.format( + # video_resource.tutorial_video + #) + video_path = '/home/cheese/test-video.ogv' video_info = get_video_info(video_path) # convert minutes to 1 if less than 0 @@ -264,22 +275,42 @@ def ajax_duration(request): def ajax_question_update(request): if request.method == 'POST': qid = request.POST['question_id'] + title = request.POST['question_title'] body = request.POST['question_body'] question = get_object_or_404(Question, pk=qid) if question: - if question.uid == request.user.id: + if question.uid == request.user.id or request.user.id in admins: + question.title = title question.body = body question.save() return HttpResponse("saved") @csrf_exempt +def ajax_details_update(request): + if request.method == 'POST': + qid = request.POST['qid'] + category = request.POST['category'] + tutorial = request.POST['tutorial'] + minute_range = request.POST['minute_range'] + second_range = request.POST['second_range'] + question = get_object_or_404(Question, pk=qid) + if question: + if question.uid == request.user.id or request.user.id in admins: + question.category = category + question.tutorial = tutorial + question.minute_range = minute_range + question.second_range = second_range + question.save() + return HttpResponse("saved") + +@csrf_exempt def ajax_reply_update(request): if request.method == 'POST': rid = request.POST['reply_id'] body = request.POST['reply_body'] reply= get_object_or_404(Reply, pk=rid) if reply: - if reply.uid == request.user.id: + if reply.uid == request.user.id or request.user.id in admins: reply.body = body reply.save() return HttpResponse("saved") |