def create(request): if request.method == 'POST': form = NewTaskForm(request.POST) if form.is_valid(): data = form.cleaned_data if len(data['title']) > 500: return returnErrors(request, 'Task title too long') elif len(data['description']) > 5000: return returnErrors(request, 'Task description too long') else: # makes a task with the submitted information and the current user task = Task(owner=request.user, title=data['title'], description=data['description']) task.save() # adds collaborators 1, 2 and 3 by finding the user associated with the submitted email for x in range(1, 4): if User.objects.filter(username=data['collaborator' + str(x)]).exists(): task.collaborators.add(User.objects.get(username=data['collaborator' + str(x)])) else: return returnErrors(request, 'Fill out all task information') return HttpResponseRedirect('/')
def add_task(request): context = RequestContext(request) # Get the context from the request. if request.method == 'POST':# A HTTP POST? form = NewTaskForm(request.POST) if form.is_valid(): # Have we been provided with a valid form? form.save(commit=True) # Save the new task to the database. print ('task saved') return HttpResponseRedirect('/') else: print ('form errors') print (form.errors) else: # If the request was not a POST, display the form to enter details. form = NewTaskForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render_to_response('social_todo/index.html', {'form': form}, context)
def add_task(request): context = RequestContext(request) # Get the context from the request. if request.method == 'POST': # A HTTP POST? form = NewTaskForm(request.POST) if form.is_valid(): # Have we been provided with a valid form? form.save(commit=True) # Save the new task to the database. print('task saved') return HttpResponseRedirect('/') else: print('form errors') print(form.errors) else: # If the request was not a POST, display the form to enter details. form = NewTaskForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render_to_response('social_todo/index.html', {'form': form}, context)