taskapp/utilities/request.py
changeset 122 daee11bdfbaa
parent 100 2275886511df
child 132 ca88bf4ad362
--- a/taskapp/utilities/request.py	Fri Feb 26 16:17:45 2010 +0530
+++ b/taskapp/utilities/request.py	Fri Feb 26 17:49:26 2010 +0530
@@ -1,4 +1,5 @@
 from datetime import datetime
+
 from django.contrib.auth.models import User
 from pytask.taskapp.models import Request, Profile
 
@@ -29,3 +30,21 @@
         req.sent_to.add(sent_to)
     req.save()
 
+def get_request(rid, user):
+    """ see if the request is replied or if he can not view the request,
+    raise 404 error. else return request.
+    """
+
+    try:
+        request_obj = Request.objects.get(id=rid)
+    except Request.DoesNotExist:
+        return None
+
+    if request_obj.is_replied == True:
+        return None
+    else:
+        try:
+            request_obj.sent_to.get(id=user.id)
+        except User.DoesNotExist:
+            return None
+        return request_obj