Move all the content from create form to edit form for tasks.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Sun, 16 Jan 2011 20:54:42 +0530
changeset 427 42156890006d
parent 426 7b009bbd2bfc
child 428 c9d8cd54195e
Move all the content from create form to edit form for tasks.
pytask/taskapp/views.py
pytask/templates/task/edit.html
--- a/pytask/taskapp/views.py	Sun Jan 16 20:47:43 2011 +0530
+++ b/pytask/taskapp/views.py	Sun Jan 16 20:54:42 2011 +0530
@@ -420,11 +420,11 @@
             return shortcuts.redirect(textbook_url)
         else:
             context.update({"form": form})
-            return shortcuts.render_to_response("task/create_textbook.html", context)
+            return shortcuts.render_to_response("task/edit.html", context)
     else:
         form = taskapp_forms.CreateTextbookForm()
         context.update({"form": form})
-        return shortcuts.render_to_response("task/create_textbook.html", context)
+        return shortcuts.render_to_response("task/edit.html", context)
 
 def view_textbook(request, task_id):
 
@@ -509,11 +509,11 @@
             return shortcuts.redirect(textbook_url)
         else:
             context.update({"form": form})
-            return shortcuts.render_to_response("task/edit_textbook.html", context)
+            return shortcuts.render_to_response("task/edit.html", context)
     else:
         form = taskapp_forms.EditTextbookForm(instance=textbook)
         context.update({"form": form})
-        return shortcuts.render_to_response("task/edit_textbook.html", context)
+        return shortcuts.render_to_response("task/edit.html", context)
 
 @login_required
 def claim_task(request, task_id):
@@ -678,6 +678,21 @@
     to get tags related to tasks.
     """
 
+    term = request.GET.get('term', None)
+    response = []
+
+    if term:
+      tag_entities = Tag.objects.filter(name__icontains=term)
+      response = [tag.name for tag in tag_entities]
+
+    json_response = json.dumps(response)
+    return http.HttpResponse(json_response)
+
+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)
--- a/pytask/templates/task/edit.html	Sun Jan 16 20:47:43 2011 +0530
+++ b/pytask/templates/task/edit.html	Sun Jan 16 20:54:42 2011 +0530
@@ -1,10 +1,23 @@
-{% extends 'base.html' %}
+{% extends "base.html" %}
 {% load form_helpers %}
 
+{% block css %}
+  <style>
+    .ui-autocomplete-loading {
+      background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
+    }
+  </style>
+{% endblock %}
+
+{% block js %}
+    <script type="text/javascript"
+        src="/pytask/static/js/create_task_form.js">
+    </script>
+    <script type="text/javascript">
+      create_form("{% url suggest_task_tags %}");
+    </script>
+{% endblock %}
+
 {% block content %}
-  <form action="" method="post">
-    {% csrf_token %}
-    {% as_div_form form %}
-    <input type="submit" value="Update">
-  </form>
+  {% as_div_form form "Create Task Form" csrf_token "" "Submit" %}
 {% endblock %}