def generateTestData(request): """ Not really a view - generate test data for a system. """ projects = {} for name in ("Psi", "GTD", "Housework", "Inventing"): project = Project(name=name, user=request.user) project.save() projects[name] = project contexts = {} for name in ("Home", "Work", "On the road", "Shopping"): context = Context(name=name, user=request.user) context.save() contexts[name] = context stuff = {'Do stuff':None, 'Do Psi stuff':projects['Psi'], 'Wash dishes':projects['Housework']} for name in stuff: task = Task(name=name, project=stuff[name], user=request.user) task.save() return HttpResponse("Done")
def createTask(request): name = request.POST.get('name', None) projectId = request.POST.get('project', None) contextId = request.POST.get('context', None) if not user_request_okay(request.user, projectId=projectId, contextId=contextId): return render_to_response("%s/pagenotfound.html", mergeStandardDict(request, {}, '')) if projectId: taskProject = Project.objects.get(id=int(projectId)) else: taskProject = None if contextId: taskContext = Context.objects.get(id=int(contextId)) else: taskContext = None newTask = Task(name=name, project=taskProject, context=taskContext, user=request.user) newTask.save() redirectPath = "%s%d" % (request.POST.get('newtask_path', "/"), newTask.id) return HttpResponseRedirect(redirectPath)