# HG changeset patch # User Madhusudan.C.S # Date 1295177653 -19800 # Node ID e15749fab2e4d261306913c5cc82760ceed6b264 # Parent 5ed0362bd674dc742dd6f6c5a814c1089c2ef619 Restructured create form to use templatetags and use Javascript for autcomplete. diff -r 5ed0362bd674 -r e15749fab2e4 pytask/taskapp/urls.py --- a/pytask/taskapp/urls.py Sun Jan 16 17:02:02 2011 +0530 +++ b/pytask/taskapp/urls.py Sun Jan 16 17:04:13 2011 +0530 @@ -20,6 +20,7 @@ url(r'^submit/report/(?P\d+)$', 'submit_report', name='submit_report'), url(r'^browse/$', 'browse_tasks', name='browse_tasks'), + url(r'^suggest_tags/$', 'suggest_task_tags', name='suggest_task_tags'), ) # URL patterns specific to textbook projects. diff -r 5ed0362bd674 -r e15749fab2e4 pytask/taskapp/views.py --- a/pytask/taskapp/views.py Sun Jan 16 17:02:02 2011 +0530 +++ b/pytask/taskapp/views.py Sun Jan 16 17:04:13 2011 +0530 @@ -1,11 +1,12 @@ from datetime import datetime from django import shortcuts -from django.http import Http404 +from django import http from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.core.context_processors import csrf from django.core.urlresolvers import reverse +from django.utils import simplejson as json from pytask.views import show_msg @@ -46,7 +47,7 @@ 'task/create.html', context) else: form = taskapp_forms.CreateTaskForm() - context.update({'form':form}) + context.update({'form': form}) return shortcuts.render_to_response('task/create.html', context) else: return show_msg(user, 'You are not authorised to create a task.') @@ -176,7 +177,7 @@ is_creator = True if user == task.created_by else False can_edit = True if task.status == "UP" and is_creator else False if not can_edit: - raise Http404 + raise http.Http404 context = {"user": user, "profile": profile, @@ -207,7 +208,7 @@ task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) if profile.rights not in ["MG", "DC"] or task.status != "UP": - raise Http404 + raise http.Http404 context = {"user": user, "profile": profile, @@ -225,7 +226,7 @@ task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) if profile.rights not in ["MG", "DC"] or task.status != "UP": - raise Http404 + raise http.Http404 task.approved_by = user task.approval_datetime = datetime.now() @@ -250,7 +251,7 @@ can_mod_reviewers = True if profile.rights in ["MG", "DC"] else False if not can_mod_reviewers: - raise Http404 + raise http.Http404 context = {"user": user, "profile": profile, @@ -319,10 +320,8 @@ @login_required def view_report(request, report_id): - try: - report = taskapp_models.WorkReport.objects.get(pk=report_id) - except taskapp_models.WorkReport.DoesNotExist: - raise Http404 + report = shortcuts.get_object_or_404(taskapp_models.WorkReport, + pk=report_id) user = request.user context = {"report": report, @@ -348,7 +347,7 @@ old_reports = task.reports.all() if not task.status == "WR": - raise Http404 + raise http.Http404 can_upload = True if user in task.selected_users.all() else False @@ -396,7 +395,7 @@ can_create = True if profile.rights != "CT" else False if not can_create: - raise Http404 + raise http.Http404 context = {"user": user, "profile": profile, @@ -494,7 +493,7 @@ else False if not can_edit: - raise Http404 + raise http.Http404 context = {"user": user, "profile": profile, @@ -523,7 +522,7 @@ task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) if task.status == "UP": - raise Http404 + raise http.Http404 user = request.user profile = user.get_profile() @@ -631,7 +630,7 @@ return show_msg(user, 'There are no pending claims for this task', task_url, 'view the task') else: - raise Http404 + raise http.Http404 @login_required def approve_textbook(request, task_id): @@ -642,7 +641,7 @@ textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) if profile.rights not in ["MG", "DC"] or textbook.status != "UP": - raise Http404 + raise http.Http404 context = {"user": user, "profile": profile, @@ -660,7 +659,7 @@ textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) if profile.rights not in ["MG", "DC"] or textbook.status != "UP": - raise Http404 + raise http.Http404 textbook.approved_by = user textbook.approval_datetime = datetime.now() @@ -673,3 +672,12 @@ } return shortcuts.render_to_response("task/approved_textbook.html", context) + +def suggest_task_tags(request): + """Returns the tags matching the query for the AJAXy autocomplete + to get tags related to tasks. + """ + + taskapp_models.Task.objects.filter(tags) + json_response = json.dumps(['abc', 'bca', 'bowbow']) + return http.HttpResponse(json_response) diff -r 5ed0362bd674 -r e15749fab2e4 pytask/templates/base.html --- a/pytask/templates/base.html Sun Jan 16 17:02:02 2011 +0530 +++ b/pytask/templates/base.html Sun Jan 16 17:04:13 2011 +0530 @@ -1,8 +1,25 @@ {% block title %}PyTasks{% endblock %} - {% block js_script %} {% endblock %} + {% comment %}Load site wide CSS here. Additional styling must be + loaded in the block that follows{% endcomment %} + + {% block css %} + {% endblock %} + + {% comment %}Load site wide javascript here. Additional scripts must + be loaded in the block that follows{% endcomment %} + + + {% block js %} + {% endblock %} {% load user_tags %} diff -r 5ed0362bd674 -r e15749fab2e4 pytask/templates/task/create.html --- a/pytask/templates/task/create.html Sun Jan 16 17:02:02 2011 +0530 +++ b/pytask/templates/task/create.html Sun Jan 16 17:04:13 2011 +0530 @@ -1,8 +1,22 @@ -{% extends 'base.html' %} +{% extends "base.html" %} +{% load form_helpers %} +{% block css %} + + +{% endblock %} +{% block js %} + + +{% endblock %} + {% block content %} -
-{% csrf_token %} -{{form.as_p}} - -
+ {% as_div_form form "Create Task Form" csrf_token "" "Create" %} {% endblock %} diff -r 5ed0362bd674 -r e15749fab2e4 pytask/templates/task/create_textbook.html --- a/pytask/templates/task/create_textbook.html Sun Jan 16 17:02:02 2011 +0530 +++ b/pytask/templates/task/create_textbook.html Sun Jan 16 17:04:13 2011 +0530 @@ -1,8 +1,10 @@ {% extends 'base.html' %} +{% load form_helpers %} + {% block content %} -
-{% csrf_token %} -{{form.as_p}} - -
+
+ {% csrf_token %} + {% as_div_form form %} + +
{% endblock %} diff -r 5ed0362bd674 -r e15749fab2e4 pytask/templates/task/edit.html --- a/pytask/templates/task/edit.html Sun Jan 16 17:02:02 2011 +0530 +++ b/pytask/templates/task/edit.html Sun Jan 16 17:04:13 2011 +0530 @@ -1,8 +1,10 @@ {% extends 'base.html' %} +{% load form_helpers %} + {% block content %} -
+ {% csrf_token %} - {{form.as_p}} + {% as_div_form form %} -
+ {% endblock %}