added saving of attachments
authorNishanth Amuluru <nishanth@fossee.in>
Thu, 06 Jan 2011 11:42:49 +0530
changeset 224 c41e38f36299
parent 223 b592ed0b12b1
child 225 042dabb73a22
added saving of attachments
taskapp/forms/task.py
taskapp/models.py
taskapp/views/task.py
templates/task/report.html
--- a/taskapp/forms/task.py	Thu Jan 06 10:05:58 2011 +0530
+++ b/taskapp/forms/task.py	Thu Jan 06 11:42:49 2011 +0530
@@ -104,3 +104,4 @@
     class Meta:
         model = WorkReport
         fields = ['remarks', 'attachment']
+
--- a/taskapp/models.py	Thu Jan 06 10:05:58 2011 +0530
+++ b/taskapp/models.py	Thu Jan 06 11:42:49 2011 +0530
@@ -171,11 +171,11 @@
     
 class WorkReport(models.Model):
 
-    attachment = models.FileField(upload_to = UPLOADS_DIR, blank = False)
+    attachment = models.FileField(upload_to=UPLOADS_DIR)
     remarks = models.TextField()
     revision = models.PositiveIntegerField(default=0)
     task = models.ForeignKey(Task, related_name = "%(class)s_report")
-    submitted_by = models.ForeignKey(Task, related_name = "%(class)s_submitted_by")
+    submitted_by = models.ForeignKey(User, related_name = "%(class)s_submitted_by")
 
     created_at = models.DateTimeField()
 
--- a/taskapp/views/task.py	Thu Jan 06 10:05:58 2011 +0530
+++ b/taskapp/views/task.py	Thu Jan 06 11:42:49 2011 +0530
@@ -66,7 +66,24 @@
         if not can_upload:
             return show_msg(user, "You are not authorised to upload data to this task", task_url, "view the task")
 
-        pass
+        form = WorkReportForm(request.POST, request.FILES)
+
+        if form.is_valid():
+            r = WorkReport(attachment = form.cleaned_data['remarks'],
+                           remarks = form.cleaned_data['remarks'],
+                           revision = old_reports.count(),
+                           task = task,
+                           submitted_by = user,
+                           created_at = datetime.now(),
+                          )
+
+            r.save()
+            return redirect(task_url)
+
+        else:
+            context.update({"form":form})
+            return render_to_response('task/report.html', context)
+
     else:
         form = WorkReportForm()
         context.update({"form":form})
--- a/templates/task/report.html	Thu Jan 06 10:05:58 2011 +0530
+++ b/templates/task/report.html	Thu Jan 06 11:42:49 2011 +0530
@@ -15,6 +15,7 @@
 Submit a report: <br />
 <form action='' method=post enctype="multipart/form-data">
 {{ form.as_p }}
+<input type=submit value=submit />
 </form>
 {% endif %}
 {% endblock %}