def project_add_typed(request, project_id=None, response_format='html'): "Project add to preselected parent project" parent_project = None if project_id: parent_project = get_object_or_404(Project, pk=project_id) if not request.user.get_profile().has_permission(parent_project, mode='x'): parent_project = None if request.POST: if not 'cancel' in request.POST: project = Project() form = ProjectForm(request.user.get_profile(), project_id, request.POST, instance=project) if form.is_valid(): project = form.save() project.set_user_from_request(request) return HttpResponseRedirect(reverse('projects_project_view', args=[project.id])) else: return HttpResponseRedirect(reverse('projects')) else: form = ProjectForm(request.user.get_profile(), project_id) context = _get_default_context(request) context.update({'form': form, 'project':parent_project}) return render_to_response('projects/project_add_typed', context, context_instance=RequestContext(request), response_format=response_format)
def project_add(request, response_format='html'): "New project form" if request.POST: if not 'cancel' in request.POST: project = Project() form = ProjectForm(request.user.get_profile(), None, request.POST, instance=project) if form.is_valid(): project = form.save() project.set_user_from_request(request) return HttpResponseRedirect(reverse('projects_project_view', args=[project.id])) else: return HttpResponseRedirect(reverse('projects')) else: form = ProjectForm(request.user.get_profile(), None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('projects/project_add', context, context_instance=RequestContext(request), response_format=response_format)
def project_edit(request, project_id, response_format='html'): "Project edit page" project = get_object_or_404(Project, pk=project_id) if not request.user.get_profile().has_permission(project, mode='w'): return user_denied(request, message="You don't have access to this Project") if request.POST: if not 'cancel' in request.POST: form = ProjectForm(request.user.get_profile(), None, request.POST, instance=project) if form.is_valid(): project = form.save() return HttpResponseRedirect(reverse('projects_project_view', args=[project.id])) else: return HttpResponseRedirect(reverse('projects_project_view', args=[project.id])) else: form = ProjectForm(request.user.get_profile(), None, instance=project) context = _get_default_context(request) context.update({'form': form, 'project': project}) return render_to_response('projects/project_edit', context, context_instance=RequestContext(request), response_format=response_format)