def toggle_tag_viewer(request, tag_id, user_id=False): """ Adds or removes a user's tag viewing rights for a selected tag. Arguments: tag_id - integer tag to remove rights from user_id - integer user ID to remove from the tag viewers. False triggers a search in the POST array for a username. Returns: a redirect back to the page the request originated from. """ tag = Tag.objects.get(id=tag_id) if ((request.user == tag.owner or request.user in tag.users.all())): if (not user_id): form = AddMemberForm(request.POST) form.is_valid() user = User.objects.get(username=form.cleaned_data['username']) else: user = User.objects.get(id=user_id) if (user in tag.viewers.all()): tag.viewers.remove(user) else: tag.viewers.add(user) tag.save() messages.info(request, "Updated " + str(user) + "'s tag viewer status.") return HttpResponseRedirect('/tags/' + str(tag_id))
def add_task_member(request, task_id): """ Adds a member (assignee) to a task Arguments: task_id - integer task ID user_id - integer user ID Returns: redirect back to the project view page """ task = ProjectTask.objects.get(id=task_id) if (request.method == "POST" and task.creator == request.user): form = AddMemberForm(request.POST) if (form.is_valid()): username = form.cleaned_data['username'] try: user = User.objects.get(username=username) if (user not in task.assigned.all()): task.assigned.add(user) task.save() messages.info( request, "Assigned " + user.username + " to task.") except: messages.error( request, "User " + username + " is not a valid user.") return HttpResponseRedirect('/projects/task/view/' + str(task_id) + "/")
def add_member(request, proj_id): """ Adds a member to a project """ project = Project.objects.get(id=proj_id) if (request.method == "POST" and project.manager == request.user): form = AddMemberForm(request.POST) if (form.is_valid()): username = form.cleaned_data['username'] try: user = User.objects.get(username=username) if (user not in project.members.all()): project.members.add(user) project.save() messages.info( request, "Assigned " + user.username + " to project.") except: messages.error( request, "User " + username + " is not a valid user.") return HttpResponseRedirect('/projects/view/' + str(proj_id) + "/")