def addTodo(request) : if request.is_ajax and request.method == "POST": new_item = TodoItem(content = request.POST['content']) new_item.save() ser_instance = serializers.serialize('json', [ new_item, ]) return JsonResponse({"new_item": ser_instance}, status=200) else : return JsonResponse({"error": new_item.errors}, status=400)
def test_json(self): """Checking json serialization""" item = TodoItem(title='the title', order=2, done=False) result = item.to_json() self.assertEqual(result, { 'title': 'the title', 'order': 2, 'done': False })
def test_json(self): """Checking json serialization""" item = TodoItem( title='the title', order=2, done=False) result = item.to_json() self.assertEqual( result, {'title': 'the title', 'order': 2, 'done': False})
def test_post_get(self): saved = [] for pk in xrange(1, 6): item = TodoItem(title='Title %d' % pk, order=pk, done=False) self.client.post( reverse('todo_api:handle_rest_call'), data=json.dumps(item.to_json()), content_type='application/json') item.pk = pk saved.append(item) expected = json.dumps([item.to_json() for item in saved]) response = self.client.get(reverse('todo_api:handle_rest_call')) self.assertEqual(expected, response.content)
def addTodo(request, ): #取回post中的內容.. # if not request.POST.get('deadline') or not request.POST.get('rating') or not request.POST.get('hours'): new_item = TodoItem(content=request.POST['content']) # else: # new_item = TodoItem( # content = request.POST['content'], # deadline = request.POST.get('deadline'), # rating = request.POST.get('rating'), # hours = request.POST.get('hours'), # ) new_item.save() return HttpResponseRedirect('/todo/')
def create_todo(todolist, title, order, done, container=None): """ Create and return a TodoItem with given values. If container is passed, the item is saved and id is appended to container. """ item = TodoItem( todolist = todolist, title = title, order = order, done = done, ) if container is not None: item.save() container.append(item.id) return item
def createTodoItem(request, list_id): user_id = request.session.get('user_id') title = request.POST.get('title') try: if title is None: return HttpResponseBadRequest() # Make sure the user is authorized to make modifications to this list todo_list = TodoList.objects.get(pk=list_id) if not todo_list.collaborators.filter(pk=user_id).exists(): return HttpResponseForbidden() todo = TodoItem(title=title, todo_list=todo_list) todo.full_clean() todo.save() # If the request was accepted and successfully processed, broadcast a # 'item-added' message on the pusher channel for this list channel_name = 'presence-todoList' + list_id p[channel_name].trigger('item-added', todo.to_json()) except TodoList.DoesNotExist: return HttpResponseNotFound() except ValidationError as e: return HttpResponseBadRequest(content=e.message) return HttpResponse(content=todo_list.to_json(), content_type='application/json')
def edit(request, id=None): if id: action = 'edit' todo = get_object_or_404(TodoItem, pk=id) else: action = 'new' todo = TodoItem() if request.POST: form = TodoItemForm(request.POST, initial=todo) if form.is_valid(): todo.name = form.cleaned_data.get('name') todo.done = form.cleaned_data.get('done') todo.save() redirect_url = reverse(index) return HttpResponseRedirect(redirect_url) else: form = TodoItemForm(initial={'name': todo.name, 'done': todo.done }) context = { 'form': form, 'action': action, } return TemplateResponse(request, 'edit.html', context=context)
def item_create(request, todolist_id, **kwargs): if 'todolist' in kwargs.keys(): curr_list = kwargs['todolist'] else: curr_list = get_object_or_404(TodoList, pk=todolist_id) note = TodoItem() title = request.POST['title'] done = True if 'done' in request.POST.keys() else False try: order = int(request.POST['order']) except ValueError: order = None note.todolist = curr_list note.title = title note.order = order note.done = done note.save() return HttpResponseRedirect(reverse('todo:item_index', args=(todolist_id,)))
def addTodo(request): new_item = TodoItem(content=request.POST['content']) new_item.save() return HttpResponseRedirect('/todo/')
def addTodo(request): new_item = TodoItem(content=request.POST['content']) # send the data from user input to the database new_item.save() return HttpResponseRedirect('/todo/')
def additem(request): new_item = TodoItem(content=request.POST['add_item']) new_item.save() return redirect('/')
def new(request): form = NewForm(request.POST) newitem = form['item'].value() newtodo = TodoItem(item=newitem, item_status='new') newtodo.save() return redirect(to='index')
def updateTodo(request, todo_id): item_to_delete = TodoItem.objects.get(id=todo_id) item_to_delete.delete() new_item = TodoItem(content=request.POST['content']) new_item.save() return HttpResponseRedirect('/todo/')
def add_todo(req): new_item = TodoItem(content=req.POST['content']) new_item.save() return redirect('todoApp:indexUrl')