--- a/taskapp/models.py Wed Feb 24 17:11:59 2010 +0530
+++ b/taskapp/models.py Wed Feb 24 19:17:28 2010 +0530
@@ -143,6 +143,10 @@
assigned_user = models.ForeignKey(User, related_name = "%(class)s_assigned_user", blank = True, null = True)
pynts = models.PositiveIntegerField(default=0)
+ def __unicode__(self):
+
+ return u"Request %s %s"%(self.by.username, self.role)
+
class Notification(models.Model):
to = models.ManyToManyField(User, related_name = "%(class)s_to", blank = False)
--- a/taskapp/views/user.py Wed Feb 24 17:11:59 2010 +0530
+++ b/taskapp/views/user.py Wed Feb 24 19:17:28 2010 +0530
@@ -1,13 +1,13 @@
import os
+
from django.http import HttpResponse, Http404
from django.shortcuts import redirect, render_to_response
-from pytask.taskapp.models import Task
-from pytask.taskapp.forms.user import UserProfileEditForm
-from pytask.taskapp.events.user import createUser, updateProfile
from django.contrib.auth.models import User
-from pytask.taskapp.models import Profile
from django.contrib.auth.decorators import login_required
+from pytask.taskapp.models import Task, Profile, Request
+from pytask.taskapp.events.user import createUser, updateProfile
+from pytask.taskapp.forms.user import UserProfileEditForm
def show_msg(message, redirect_url=None, url_desc=None):
""" simply redirect to homepage """
@@ -95,3 +95,51 @@
edit_profile_form = UserProfileEditForm(instance = profile)
return render_to_response('user/edit_profile.html',{'edit_profile_form' : edit_profile_form, 'user':request.user})
+@login_required
+def browse_requests(request):
+
+ user = request.user
+ active_reqs = user.request_to.filter(replied=False)
+ reqs = active_reqs.order_by('creation_date').reverse()
+ for pos, req in enumerate(reversed(reqs)):
+ req.pos = pos
+ context = {
+ 'user':user,
+ 'reqs':reqs,
+ }
+
+ return render_to_response('user/browse_requests.html', context)
+
+@login_required
+def view_request(request, rid):
+ """ please note that request variable in this method is that of django.
+ our app request is called user_request.
+ """
+
+ user = request.user
+ reqs = user.request_to.filter(replied=False).order_by('creation_date')
+ user_request = reqs[int(rid)]
+
+ context = {
+ 'user':user,
+ 'req':user_request,
+ 'sent_users':user_request.to.all()
+ }
+
+ return render_to_response('user/view_request.html', context)
+
+@login_required
+def process_request(request, rid, reply):
+ """ check if the method is post and then update the request.
+ if it is get, display a 404 error.
+ """
+
+ if request.method=="POST":
+ user = request.user
+ browse_request_url= '/user/requests'
+ reqs = user.request_to.filter(replied=False).order_by('creation_date')
+ user_request = reqs[int(rid)]
+
+ return show_msg("Your reply has been processed", browse_request_url, "view other requests")
+ else:
+ return show_msg("You are not authorised to do this", browse_request_url, "view other requests")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/user/browse_requests.html Wed Feb 24 19:17:28 2010 +0530
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% block content %}
+ {% for req in reqs %}
+ <form><a href="/user/requests/rid={{req.pos}}">{{req.by.username}}|{{req.role}}|
+ {% ifequal req.role "PY" %}
+ {{req.task.title}}
+ {% endifequal %}</a><br /></form>
+ {% endfor %}
+{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/user/view_request.html Wed Feb 24 19:17:28 2010 +0530
@@ -0,0 +1,24 @@
+{% extends 'base.html' %}
+{% block content %}
+ From: <a href=""/user/view/uid={{req.by.id}}"">{{req.by.username}}</a><br />
+ To:
+ {% for to_user in sent_users %}
+ <a href="/user/view/uid={{to_user.id}}">{{to_user.username}}</a>,
+ {% endfor %}
+ <br />
+ Message: <br />
+ {% ifequal "PY" req.role %}
+ <a href="/user/view/uid={{req.by.id}}">{{req.by.username}}</a> assigned {{req.pynts}} pynts to
+ <a href="/user/view/uid={{req.assigned_to.id}}">{{req.assigned_to.username}}</a> for the task
+ <a href="/task/view/tid={{req.task.id}}">{{req.task.title}}</a><br />
+ Please click yes/no<br />
+ <form action="yes/" method="post">
+ <input value="Yes" type="submit">
+ </form>
+ <form action="no/" method="post">
+ <input value="No" type="submit">
+ </form>
+ {% else %}
+ {% endifequal %}
+
+{% endblock %}
--- a/urls.py Wed Feb 24 17:11:59 2010 +0530
+++ b/urls.py Wed Feb 24 19:17:28 2010 +0530
@@ -40,5 +40,9 @@
(r'^user/view/uid=(\d+)$', userViews.view_my_profile),
(r'^user/edit/?$', userViews.edit_my_profile),
+
+ (r'^user/requests/$', userViews.browse_requests),
+ (r'^user/requests/rid=(\d+)/$', userViews.view_request),
+ (r'^user/requests/rid=(\d+)/(\w+)/$', userViews.process_request),
)