def star_project(request, username, project): project = Project.retrieve(username, project, request.user) if is_following(request.user, project): unfollow(request.user, project) else: follow(request.user, project, actor_only=False) return HttpResponseRedirect(project.link())
def project_rights_delete(request, username, project, user): try: project = Project.retrieve(username, project, request.user, ADMIN_RIGHT) user = UserProfile.objects.get(user__username=user) project_right = ProjectRight.objects.get(user=user, project=project) project_right.delete() except: pass return HttpResponseRedirect(project.rights_link())
def edit_project(request, username, project): status = "edit" project = Project.retrieve(username, project, request.user, EDIT_RIGHT) if request.method == "POST": form = EditProjectForm(request.POST, instance=project) if form.is_valid(): try: form.save() status = "saved" except Exception: status = "error" else: form = EditProjectForm(instance=project) return render(request, "edit_project.html", {"project": project, "edit_form": form, "status": status})
def project(request, username, project): project = Project.retrieve(username, project, request.user) if request.method == "POST": box_form = BoxForm( request.POST, project=project, form_class="well", initial={"project": project}, action=project.link("boxes") ) if box_form.is_valid(): try: new_box = box_form.save() messages.success(request, "%s box successfully saved" % new_box.name) return HttpResponseRedirect(new_box.link()) except: messages.error(request, COMMON_ERROR_MSG) return HttpResponseRedirect(project.link()) else: box_form = BoxForm( project=project, form_class="well", initial={"project": project}, action=project.link("boxes") ) return render( request, "project.html", {"project": project, "box_error": request.method == "POST", "box_form": box_form} )
def project_rights(request, username, project): project = Project.retrieve(username, project, request.user, ADMIN_RIGHT) status = None if request.method == "POST": right = int(request.POST["right"]) if right in (VIEW_RIGHT, EDIT_RIGHT, ADMIN_RIGHT): status = "saved" try: user = UserProfile.objects.get(user__username=request.POST["username"]) if user != project.owner: project_right = ProjectRight.objects.get(user=user, project=project) project_right.right = right project_right.save() except UserProfile.DoesNotExist: status = "notexist" except ProjectRight.DoesNotExist: project_right = ProjectRight(project=project, user=user, right=right).save() except: status = "error" else: status = "error" return render(request, "manage_rights.html", {"project": project, "status": status})