199 else: |
199 else: |
200 form = ClaimTaskForm() |
200 form = ClaimTaskForm() |
201 context.update({"form": form}) |
201 context.update({"form": form}) |
202 return render_to_response("task/claim.html", context) |
202 return render_to_response("task/claim.html", context) |
203 |
203 |
204 |
204 @login_required |
|
205 def select_user(request, tid): |
|
206 """ first get the status of the task and then select one of claimed users |
|
207 generate list of claimed users by passing it as an argument to a function. |
|
208 """ |
|
209 |
|
210 task_url = "/task/view/tid=%s"%tid |
|
211 |
|
212 user = request.user |
|
213 profile = user.get_profile() |
|
214 task = getTask(tid) |
|
215 |
|
216 context = {"user": user, |
|
217 "profile": profile, |
|
218 "task": task, |
|
219 } |
|
220 |
|
221 context.update(csrf(request)) |
|
222 |
|
223 task_claimed = True if claimed_users else False |
|
224 claimed_users = task.claimed_users.all() |
|
225 selected_users = task.selected_users.all() |
|
226 |
|
227 is_creator = True if user == task.created_by else False |
|
228 |
|
229 if ( is_creator or profile.rights in ["CR", "DC"] ) and \ |
|
230 task.status in ["OP", "WR"] and task_claimed: |
|
231 |
|
232 if claimed_users: |
|
233 |
|
234 user_list = ((user.id,user.username) for user in claimed_users) |
|
235 |
|
236 if request.method == "POST": |
|
237 form = ChoiceForm(user_list, request.POST) |
|
238 if form.is_valid(): |
|
239 uid = form.cleaned_data['choice'] |
|
240 selected_user = User.objects.get(id=uid) |
|
241 |
|
242 task.selected_users.add(user) |
|
243 task.claimed_users.remove(user) |
|
244 task.save() |
|
245 |
|
246 return redirect(task_url) |
|
247 else: |
|
248 context.update({"form": form}) |
|
249 return render_to_response('task/select_user.html', context) |
|
250 else: |
|
251 form = ChoiceForm(user_list) |
|
252 context.update({"form": form}) |
|
253 return render_to_response('task/select_user.html', context) |
|
254 else: |
|
255 return show_msg(user, 'There are no pending claims for this task', |
|
256 task_url, 'view the task') |
|
257 else: |
|
258 raise Http404 |
|
259 |