def project_api(request, project=None): """Handle listing groups and creating new ones""" if request.method == "GET": group = request.GET.get('group') projects = api.projects.list(group=group) d = {'objects': [p.to_dict() for p in projects]} return respond_json(d) elif request.method == "POST": form = ProjectForm(request.POST) if form.is_valid(): try: project = api.projects.create(user=request.user, **form.cleaned_data) except: logger.exception("Error saving key") return respond_json({'errorMsg': "Unknown error"}) return respond_json(project.to_dict()) return respond_json({'errorMsg': ajax_errors(form)}) elif request.method == 'DELETE': project = api.projects.get(project) project.delete() return respond_json({'message': "project deleted"}) raise HttpResponseNotAllowed()
def create_project(request): group = api.groups.get(request.GET['group']) if not request.user.has_perm('add', obj=group): raise HttpResponseForbidden( "You do not have permission to add projects.") if request.method == "POST": form = ProjectForm(request.POST) if form.is_valid(): # Create the project try: project = api.projects.create(user=request.user, group=group, **form.cleaned_data) return HttpResponseRedirect( reverse('project-details', args=[group.name, project.name])) except DuplicateObject: form._errors["name"] = form.error_class( ['Project by that name already exists']) else: form = ProjectForm() return render_to_response( 'cannula/form.html', RequestContext(request, { 'title': "Create Project for %s" % group, 'form': form, }))
def create_project(request): group = api.groups.get(request.GET['group']) if not request.user.has_perm('add', obj=group): raise HttpResponseForbidden("You do not have permission to add projects.") if request.method == "POST": form = ProjectForm(request.POST) if form.is_valid(): # Create the project try: project = api.projects.create(user=request.user, group=group, **form.cleaned_data) return HttpResponseRedirect(reverse('project-details', args=[group.name, project.name])) except DuplicateObject: form._errors["name"] = form.error_class(['Project by that name already exists']) else: form = ProjectForm() return render_to_response('cannula/form.html', RequestContext(request, { 'title': "Create Project for %s" % group, 'form': form, }) )
def group_details(request, group): group = api.groups.get(group) if not request.user.has_perm('read', obj=group): raise HttpResponseForbidden("You do not have access to this page.") return render_to_response( 'cannula/projectgroup_detail.html', RequestContext( request, { 'title': unicode(group), 'group': group, 'form': ProjectForm(), 'now': datetime.datetime.now(), 'logs': api.log.list(group=group) }))