# HG changeset patch # User Nishanth Amuluru # Date 1294684248 -19800 # Node ID 1be4a3c09a474dc929acb0a74d40cb75db5b1dc8 # Parent 602a909e9e164187d691fa8f71b15d7a59efb6be view textbook works fine diff -r 602a909e9e16 -r 1be4a3c09a47 pytask/taskapp/models.py --- a/pytask/taskapp/models.py Sun Jan 09 20:33:08 2011 +0530 +++ b/pytask/taskapp/models.py Tue Jan 11 00:00:48 2011 +0530 @@ -149,3 +149,4 @@ approval_datetime = models.DateTimeField(blank = True, null = True) tagging.register(Task) +tagging.register(TextBook) diff -r 602a909e9e16 -r 1be4a3c09a47 pytask/taskapp/urls.py --- a/pytask/taskapp/urls.py Sun Jan 09 20:33:08 2011 +0530 +++ b/pytask/taskapp/urls.py Tue Jan 11 00:00:48 2011 +0530 @@ -1,7 +1,7 @@ from django.conf.urls.defaults import * from pytask.taskapp.views import create_task, view_task, claim_task, \ - select_user, edit_task, create_textbook + select_user, edit_task, create_textbook, view_textbook from pytask.views import under_construction @@ -14,6 +14,7 @@ (r'^select/tid=(\w+)$', select_user), (r'^browse/$', under_construction), - (r'^textbook/create/$', create_textbook) + (r'^textbook/create/$', create_textbook), + (r'^textbook/view/tid=(\w+)/$', view_textbook), ) diff -r 602a909e9e16 -r 1be4a3c09a47 pytask/taskapp/utils.py --- a/pytask/taskapp/utils.py Sun Jan 09 20:33:08 2011 +0530 +++ b/pytask/taskapp/utils.py Tue Jan 11 00:00:48 2011 +0530 @@ -1,4 +1,4 @@ -from pytask.taskapp.models import Task +from pytask.taskapp.models import Task, TextBook from django.http import Http404 def getTask(tid): @@ -9,3 +9,11 @@ except Task.DoesNotExist: raise Http404 +def getTextBook(tid): + + try: + task = TextBook.objects.get(uniq_key=tid) + return task + except TextBook.DoesNotExist: + raise Http404 + diff -r 602a909e9e16 -r 1be4a3c09a47 pytask/taskapp/views.py --- a/pytask/taskapp/views.py Sun Jan 09 20:33:08 2011 +0530 +++ b/pytask/taskapp/views.py Tue Jan 11 00:00:48 2011 +0530 @@ -16,7 +16,7 @@ from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ TaskCommentForm, ClaimTaskForm, \ ChoiceForm, EditTaskForm, CreateTextbookForm -from pytask.taskapp.utils import getTask +from pytask.taskapp.utils import getTask, getTextBook from pytask.profile.utils import get_notification @@ -208,7 +208,7 @@ new_textbook.chapters = form.cleaned_data['chapters'] - textbook_url = "/task/textbook/tid=%s"%new_textbook.uniq_key + textbook_url = "/task/textbook/view/tid=%s"%new_textbook.uniq_key return redirect(textbook_url) else: context.update({"form": form}) @@ -218,6 +218,37 @@ context.update({"form": form}) return render_to_response("task/create_textbook.html", context) +def view_textbook(request, tid): + + textbook = getTextBook(tid) + textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key + + user = request.user + if not user.is_authenticated(): + return render_to_response("task/view_textbook.html") + + profile = user.get_profile() + + context = {"user": user, + "profile": profile, + "textbook": textbook, + } + + context.update(csrf(request)) + + chapters = Task.objects.filter(status="UP") + + can_edit = True if user == textbook.created_by and textbook.status == "UP"\ + else False + + can_approve = True if profile.rights in ["MG", "DC"] and \ + textbook.status == "UP" else False + + context.update({"chapters": chapters, + "can_edit": can_edit, + "can_approve": can_approve}) + return render_to_response("task/view_textbook.html", context) + @login_required def claim_task(request, tid): diff -r 602a909e9e16 -r 1be4a3c09a47 pytask/templates/task/view_textbook.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/view_textbook.html Tue Jan 11 00:00:48 2011 +0530 @@ -0,0 +1,57 @@ +{% extends 'base.html' %} +{% block title %} + {{textbook.name}} +{% endblock %} +{% block content %} +

{{ textbook.name }}

+ + {% if can_edit %} + Edit Text book + {% endif %} + + {% if can_approve %} + Approve Text book + {% endif %} + +
created by {{ textbook.created_by.username }} + on {{textbook.creation_datetime|date:"D d M Y"}} at {{textbook.creation_datetime|time:"H:i"}}
+
+ + {% if textbook.tags.count %} + Tags: + {% for tag in textbook.tags %} + {{tag}} + {% endfor %} +
+ {% endif %} + + Chapters:
+ {% for chap in chapters %} + + {% endfor %} + + + +
+ {% if comments %} + comments:

+ {% for comment in comments %} + {{ comment.commented_by.username }} + on {{ comment.comment_datetime|date:"D d M Y"}} at {{comment.comment_datetime|time:"H:i"}} wrote:
+ {{ comment.data|linebreaksbr }}
+ {% endfor %} + {% endif %} +
+ + {% if can_comment %} + Add comment:
+
+ {% csrf_token %} + {{form.as_p}} + +
+ {% endif %} + +{% endblock %}