# HG changeset patch # User Nishanth Amuluru # Date 1294747814 -19800 # Node ID 4252da60a4efc35e28b24f9f60a04805787bd4c1 # Parent daca865314e7f2b48cd6a0deb8e06bc83982ac58 submit report works fine diff -r daca865314e7 -r 4252da60a4ef pytask/taskapp/forms.py --- a/pytask/taskapp/forms.py Tue Jan 11 16:51:07 2011 +0530 +++ b/pytask/taskapp/forms.py Tue Jan 11 17:40:14 2011 +0530 @@ -130,5 +130,5 @@ class Meta: model = WorkReport - fields = ['remarks', 'attachment'] + fields = ['data', 'summary', 'attachment'] diff -r daca865314e7 -r 4252da60a4ef pytask/taskapp/models.py --- a/pytask/taskapp/models.py Tue Jan 11 16:51:07 2011 +0530 +++ b/pytask/taskapp/models.py Tue Jan 11 17:40:14 2011 +0530 @@ -91,7 +91,7 @@ approved_by = models.ForeignKey(User, null = True, blank = True, related_name = "approved_reports") - data = models.TextField() + data = models.TextField(verbose_name="Report") summary = models.CharField(max_length=100, verbose_name="Summary", help_text="A one line summary") attachment = models.FileField(upload_to = UPLOADS_DIR) diff -r daca865314e7 -r 4252da60a4ef pytask/taskapp/urls.py --- a/pytask/taskapp/urls.py Tue Jan 11 16:51:07 2011 +0530 +++ b/pytask/taskapp/urls.py Tue Jan 11 17:40:14 2011 +0530 @@ -4,7 +4,7 @@ select_user, edit_task, create_textbook, view_textbook, \ browse_tasks, edit_textbook, approve_task, approved_task,\ browse_textbooks, approve_textbook, approved_textbook, addreviewer,\ - view_report, view_work + view_report, view_work, submit_report from pytask.views import under_construction @@ -20,6 +20,7 @@ (r'^addreviewer/tid=(\w+)$', addreviewer), (r'^view/work/tid=(\w+)$', view_work), (r'^view/report/rid=(\w+)$', view_report), + (r'^submit/report/tid=(\w+)$', submit_report), (r'^browse/$', browse_tasks), (r'^textbook/create/$', create_textbook), diff -r daca865314e7 -r 4252da60a4ef pytask/taskapp/views.py --- a/pytask/taskapp/views.py Tue Jan 11 16:51:07 2011 +0530 +++ b/pytask/taskapp/views.py Tue Jan 11 17:40:14 2011 +0530 @@ -12,11 +12,12 @@ from pytask.utils import make_key from pytask.views import show_msg -from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook +from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook, \ + WorkReport from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ TaskCommentForm, ClaimTaskForm, \ ChoiceForm, EditTaskForm, CreateTextbookForm,\ - EditTextbookForm + EditTextbookForm, WorkReportForm from pytask.taskapp.utils import getTask, getTextBook from pytask.profile.utils import get_notification @@ -335,8 +336,75 @@ @login_required def view_report(request, rid): - pass + + try: + report = WorkReport.objects.get(uniq_key=rid) + except WorkReport.DoesNotExist: + raise Http404 + + user = request.user + context = {"report": report, + "user": user, + } + + if not user.is_authenticated(): + return render_to_response("task/view_report.html", context) + + profile = user.get_profile() + + context.update({"profile": profile}) + return render_to_response("task/view_report.html", context) + +@login_required +def submit_report(request, tid): + """ Check if the work is in WR state and the user is in assigned_users. + """ + + user = request.user + task = getTask(tid) + old_reports = task.reports.all() + + if not task.status == "WR": + raise Http404 + + can_upload = True if user in task.selected_users.all() else False + context = { + 'user': user, + 'task': task, + 'can_upload': can_upload, + } + + context.update(csrf(request)) + + if request.method == "POST": + if not can_upload: + return show_msg(user, "You are not authorised to upload data to this task", task_url, "view the task") + + form = WorkReportForm(request.POST, request.FILES) + + if form.is_valid(): + data = form.cleaned_data.copy() + data.update({"task":task, + "revision": old_reports.count(), + "uniq_key": make_key(WorkReport), + "submitted_by": user, + "submitted_at": datetime.now(), + }) + r = WorkReport(**data) + r.save() + + report_url = "/task/view/report/rid=%s"%r.uniq_key + return redirect(report_url) + + else: + context.update({"form":form}) + return render_to_response('task/submit_report.html', context) + + else: + form = WorkReportForm() + context.update({"form":form}) + return render_to_response('task/submit_report.html', context) @login_required def create_textbook(request): diff -r daca865314e7 -r 4252da60a4ef pytask/templates/task/submit_report.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/submit_report.html Tue Jan 11 17:40:14 2011 +0530 @@ -0,0 +1,12 @@ +{% extends 'base.html' %} +{% block title %} + {{task.title}} +{% endblock %} +{% block content %} +Submit a report:
+
+ {% csrf_token %} +{{ form.as_p }} + +
+{% endblock %} diff -r daca865314e7 -r 4252da60a4ef pytask/templates/task/view_report.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/view_report.html Tue Jan 11 17:40:14 2011 +0530 @@ -0,0 +1,12 @@ +{% extends 'base.html' %} +{% block content %} +Report for {{report.task.title}}
+ +
+Description:
+{{ report.data|linebreaksbr }} +
+Summary: {{ report.summary }}
+
+Attachment: {{report.attachment.name}} +{% endblock %}