# HG changeset patch # User Nishanth Amuluru # Date 1294686263 -19800 # Node ID 014d812e625e0f018ec6b9f40641f8033be6c7c7 # Parent 563fe356947d3bdb56a025f230fe9f4ccde8bcaa edit textbook works fine diff -r 563fe356947d -r 014d812e625e pytask/taskapp/forms.py --- a/pytask/taskapp/forms.py Tue Jan 11 00:23:47 2011 +0530 +++ b/pytask/taskapp/forms.py Tue Jan 11 00:34:23 2011 +0530 @@ -92,6 +92,12 @@ model = TextBook fields = ['name', 'chapters', 'tags_field'] +class EditTextbookForm(forms.ModelForm): + + class Meta: + model = TextBook + fields = ['name', 'chapters', 'tags_field'] + def AddReviewerForm(choices,instance=None): """ return a form object with appropriate choices """ diff -r 563fe356947d -r 014d812e625e pytask/taskapp/urls.py --- a/pytask/taskapp/urls.py Tue Jan 11 00:23:47 2011 +0530 +++ b/pytask/taskapp/urls.py Tue Jan 11 00:34:23 2011 +0530 @@ -2,7 +2,7 @@ from pytask.taskapp.views import create_task, view_task, claim_task, \ select_user, edit_task, create_textbook, view_textbook, \ - browse_textbooks + browse_textbooks, edit_textbook from pytask.views import under_construction @@ -17,6 +17,7 @@ (r'^textbook/create/$', create_textbook), (r'^textbook/view/tid=(\w+)/$', view_textbook), + (r'^textbook/edit/tid=(\w+)/$', edit_textbook), (r'^textbook/browse/$', browse_textbooks), ) diff -r 563fe356947d -r 014d812e625e pytask/taskapp/views.py --- a/pytask/taskapp/views.py Tue Jan 11 00:23:47 2011 +0530 +++ b/pytask/taskapp/views.py Tue Jan 11 00:34:23 2011 +0530 @@ -15,7 +15,8 @@ from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ TaskCommentForm, ClaimTaskForm, \ - ChoiceForm, EditTaskForm, CreateTextbookForm + ChoiceForm, EditTaskForm, CreateTextbookForm,\ + EditTextbookForm from pytask.taskapp.utils import getTask, getTextBook from pytask.profile.utils import get_notification @@ -270,6 +271,41 @@ return render_to_response("task/browse_textbooks.html", context) @login_required +def edit_textbook(request, tid): + + user = request.user + profile = user.get_profile() + + textbook = getTextBook(tid) + textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key + + can_edit = True if user == textbook.created_by and textbook.status == "UP"\ + else False + + if not can_edit: + raise Http404 + + context = {"user": user, + "profile": profile, + "textbook": textbook, + } + + context.update(csrf(request)) + + if request.method == "POST": + form = EditTextbookForm(request.POST, instance=textbook) + if form.is_valid(): + form.save() + return redirect(textbook_url) + else: + context.update({"form": form}) + return render_to_response("task/edit_textbook.html", context) + else: + form = EditTextbookForm(instance=textbook) + context.update({"form": form}) + return render_to_response("task/edit_textbook.html", context) + +@login_required def claim_task(request, tid): task_url = "/task/view/tid=%s"%tid diff -r 563fe356947d -r 014d812e625e pytask/templates/task/edit_textbook.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/edit_textbook.html Tue Jan 11 00:34:23 2011 +0530 @@ -0,0 +1,8 @@ +{% extends 'base.html' %} +{% block content %} +
+ {% csrf_token %} + {{form.as_p}} + +
+{% endblock %}