--- 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)
--- 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),
)
--- 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
+
--- 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):
--- /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 %}
+ <h3>{{ textbook.name }}</h3>
+
+ {% if can_edit %}
+ <a href="/task/textbook/edit/tid={{textbook.uniq_key}}">Edit Text book</a>
+ {% endif %}
+
+ {% if can_approve %}
+ <a href="/task/textbook/approve/tid={{textbook.uniq_key}}">Approve Text book</a>
+ {% endif %}
+
+ <hr />created by <a href="/user/view/uid={{ textbook.created_by.id }}">{{ textbook.created_by.username }}</a>
+ on {{textbook.creation_datetime|date:"D d M Y"}} at {{textbook.creation_datetime|time:"H:i"}}<br />
+ <hr />
+
+ {% if textbook.tags.count %}
+ Tags:
+ {% for tag in textbook.tags %}
+ {{tag}}
+ {% endfor %}
+ <hr />
+ {% endif %}
+
+ Chapters: <br />
+ {% for chap in chapters %}
+ <ul>
+ <li><a href="/task/view/tid={{chap.uniq_key}}">{{chap.title}}</a> </li>
+ </ul>
+ {% endfor %}
+
+
+
+ <hr />
+ {% if comments %}
+ comments:<br /><br />
+ {% for comment in comments %}
+ <a href="/user/view/uid={{comment.commented_by.id}}">{{ comment.commented_by.username }}</a>
+ on {{ comment.comment_datetime|date:"D d M Y"}} at {{comment.comment_datetime|time:"H:i"}} wrote:<br />
+ {{ comment.data|linebreaksbr }}<br />
+ {% endfor %}
+ {% endif %}
+ <hr />
+
+ {% if can_comment %}
+ Add comment:<br />
+ <form action="" method="post">
+ {% csrf_token %}
+ {{form.as_p}}
+ <input type="submit" value="Submit">
+ </form>
+ {% endif %}
+
+{% endblock %}