# HG changeset patch # User nishanth # Date 1267019339 -19800 # Node ID 3e75ed940408fefc92c3d02bcce2700d452ef164 # Parent 7c38ff64aee77833dfacfbcbb8bde5f8ebb9486c# Parent fd2e1bd7af8213c962e6c934748731888b4bea4a merged. diff -r 7c38ff64aee7 -r 3e75ed940408 taskapp/models.py --- a/taskapp/models.py Wed Feb 24 19:11:43 2010 +0530 +++ b/taskapp/models.py Wed Feb 24 19:18:59 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) diff -r 7c38ff64aee7 -r 3e75ed940408 taskapp/views/user.py --- a/taskapp/views/user.py Wed Feb 24 19:11:43 2010 +0530 +++ b/taskapp/views/user.py Wed Feb 24 19:18:59 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") diff -r 7c38ff64aee7 -r 3e75ed940408 templates/user/browse_requests.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/user/browse_requests.html Wed Feb 24 19:18:59 2010 +0530 @@ -0,0 +1,9 @@ +{% extends 'base.html' %} +{% block content %} + {% for req in reqs %} +
{{req.by.username}}|{{req.role}}| + {% ifequal req.role "PY" %} + {{req.task.title}} + {% endifequal %}
+ {% endfor %} +{% endblock %} diff -r 7c38ff64aee7 -r 3e75ed940408 templates/user/view_request.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/user/view_request.html Wed Feb 24 19:18:59 2010 +0530 @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% block content %} + From:  {{req.by.username}}
+ To: + {% for to_user in sent_users %} + {{to_user.username}},  + {% endfor %} +
+ Message:
+ {% ifequal "PY" req.role %} + {{req.by.username}} assigned {{req.pynts}} pynts to + {{req.assigned_to.username}} for the task + {{req.task.title}}
+ Please click yes/no
+
+ +
+
+ +
+ {% else %} + {% endifequal %} + +{% endblock %} diff -r 7c38ff64aee7 -r 3e75ed940408 urls.py --- a/urls.py Wed Feb 24 19:11:43 2010 +0530 +++ b/urls.py Wed Feb 24 19:18:59 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), )