# HG changeset patch # User nishanth # Date 1267019248 -19800 # Node ID fd2e1bd7af8213c962e6c934748731888b4bea4a # Parent 8917b190c4c44618c85cc98ebbf4f7839fc54b08 added accept_assign_credits request diff -r 8917b190c4c4 -r fd2e1bd7af82 taskapp/models.py --- 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) diff -r 8917b190c4c4 -r fd2e1bd7af82 taskapp/views/user.py --- 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") diff -r 8917b190c4c4 -r fd2e1bd7af82 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:17:28 2010 +0530 @@ -0,0 +1,9 @@ +{% extends 'base.html' %} +{% block content %} + {% for req in reqs %} +
+ {% endfor %} +{% endblock %} diff -r 8917b190c4c4 -r fd2e1bd7af82 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:17:28 2010 +0530 @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% block content %} + From: {{req.by.username}}