コード例 #1
0
def add_or_update_task(request, pk=None):
    task = get_object_or_404(Todo, pk=pk) if pk else None
    form = TodoForm(request.user, request.POST or None, instance=task)
    if form.is_valid():
        form.save()
        return redirect(reverse('todo:home'))
    return render(request, 'todo/task_form.html', {'form': form})
コード例 #2
0
def todoedit(request, pk):
    todo = get_object_or_404(Todo, pk=pk)
    todoform = TodoForm(request.POST or None, instance=todo)
    if todoform.is_valid():
        todoform.save()
        return redirect('todolist')
    return render(request, 'todoadd.html', {'form': todoform})
コード例 #3
0
ファイル: views.py プロジェクト: Spashev/todo_django
def todo_create(request):
    if request.method == "POST":
        form = TodoForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('todo_list')
    form = TodoForm()
    return render(request, 'todo/edit.html', {'form': form})
コード例 #4
0
ファイル: views.py プロジェクト: andymckay/zoomy
def add(request):
    form = TodoForm(request.POST or None)
    if form.is_valid():
        form.save()
        return http.HttpResponseRedirect(reverse('todo.list'))
    
    return render_to_response('add.html', {'form':form},
                              context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: andymckay/zoomy
def add(request):
    form = TodoForm(request.POST or None)
    if form.is_valid():
        form.save()
        return http.HttpResponseRedirect(reverse('todo.list'))

    return render_to_response('add.html', {'form': form},
                              context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: Vishwasrr/Todo-app
    def post(self, request, pk):
        task = get_object_or_404(self.model, pk=pk)
        form = TodoForm(request.POST, instance=blog)
        if not form.is_valid():
            ctx = {'task': task.name, 'desc': task.desc}
            return render(request, self.template, ctx)

        form.save()
        return redirect(self.success_url)
コード例 #7
0
ファイル: views.py プロジェクト: andymckay/zoomy
def edit(request, pk):
    instance = get_object_or_404(Todo, pk=pk)
    form = TodoForm(request.POST or None, instance=instance)
    if form.is_valid():
        form.save()
        return http.HttpResponseRedirect(reverse('todo.list'))
    
    return render_to_response('edit.html', {'form':form},
                              context_instance=RequestContext(request))
コード例 #8
0
ファイル: views.py プロジェクト: andymckay/zoomy
def edit(request, pk):
    instance = get_object_or_404(Todo, pk=pk)
    form = TodoForm(request.POST or None, instance=instance)
    if form.is_valid():
        form.save()
        return http.HttpResponseRedirect(reverse('todo.list'))

    return render_to_response('edit.html', {'form': form},
                              context_instance=RequestContext(request))
コード例 #9
0
def create_todo(request):
    if request.method == 'GET':
        form = TodoForm(user=request.user)
    elif request.method == 'POST':
        form = TodoForm(request.POST, user=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    return render(request, "todo_form.html", {'form': form})
コード例 #10
0
def todo_edit(request, pk):
    todo = List.objects.get(user=request.user, pk=pk)
    if request.method == "POST":
        form = TodoForm(request.POST, instance=todo)
        if form.is_valid():
            form.save()
            return redirect('todo_view', todo.pk)
    else:
        form = TodoForm(instance=todo)
    return render(request, 'todo/edit.html', {'menu': 'list', 'form': form, 'pk': pk})
コード例 #11
0
def view_todo(request, todo_id):
    todo = get_object_or_404(Todo, pk=todo_id, user=request.user)
    context = {"todo": todo}
    if request.method == "POST":
        try:
            form = TodoForm(request.POST, instance=todo)
            form.save()
            return redirect('currenttodos')
        except Exception:
            context["error"] = "Something bad happen. Please try again"
    context["form"] = TodoForm(instance=todo)
    return render(request, "todo/view-todo.html", context=context)
コード例 #12
0
ファイル: views.py プロジェクト: vinit-modi/Django-ToDo-List
def viewtodo(request, todo_pk):
    todo = get_object_or_404(Todo, pk=todo_pk, user=request.user)
    if request.method == 'GET':
        form = TodoForm(instance=todo)
        return render(request,'todo/viewtodo.html',{'todo':todo, 'form':form})
    else:
        try:
            form = TodoForm(request.POST, instance=todo)
            form.save()
            return redirect('currenttodos')
        except ValueError:
            return render(request,'todo/viewtodo.html',{'todo':todo, 'form':form, 'error':'Too many data input. Please try again.'})
コード例 #13
0
def viewtodo(request, todo_pk):
    todo = get_object_or_404(Todo, pk=todo_pk, user=request.user)
    if request.method == 'GET':
        form = TodoForm(instance=todo)
        return render(request, 'todo/viewtodo.html', {
            'todo': todo,
            'form': form
        })
    else:
        form = TodoForm(request.POST, instance=todo)
        form.save()
        return redirect('currenttodos')
コード例 #14
0
ファイル: views.py プロジェクト: armeo/django-quickstart
def new_todo(request):
    if not request.method == 'POST':
        return redirect('home')
    todo_form = TodoForm(request.POST)
    if todo_form.is_valid():
        todo_form.save()
        messages.add_message(request, messages.SUCCESS,
                             'Item has been added.')
    else:
        messages.add_message(request, messages.ERROR,
                             'You need to enter a name.')
    return redirect('home')
コード例 #15
0
def update(request, id):
    if request.method == 'POST':
        todo = get_object_or_404(Todo, pk=id)
        todoForm = TodoForm(request.POST,instance=todo)
        if todoForm.is_valid():
            todoForm.save()

    context = {
        'message': 'Update article ' + str(id),
        'todo': todo,
    }
    return HttpResponseRedirect('/todo/',context)
コード例 #16
0
def add_todo(request):
    """Add a new todo. Should be invoked via POST method."""
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            # should log the action
            form.save()
            messages.success(request,
                             f"Added \"{request.POST['description']}\"")
            return redirect('todo:index')
    else:  # GET /add/ should be handled by the main index
        return redirect('todo:index')
    return render(request, 'todo/add.html', {'form': form})
コード例 #17
0
ファイル: views.py プロジェクト: annabananana7/GitHub
def addItem(request):
    t = Todo()
    t.text = request.POST.get('todo_text', '')
    t.save()
    
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
        #Item.objects.create(text=request.POST['item_text'])
        #return redirect('/')

    else:
        return render(request, 'todo/create.html', {'form': form})
コード例 #18
0
def edit_task(request, task_id):
    if request.method == "POST":
        task = TodoList.objects.get(pk=task_id)
        form = TodoForm(request.POST or None, instance=task)
        if form.is_valid():
            form.save()
        messages.success(request, ("Task Edited!"))
        return redirect('addTodo')
    else:
        form = TodoForm()
        # for checking status of task
        task_obj = TodoList.objects.get(pk=task_id)
        return render(request, 'edit.html', {
            'task_obj': task_obj,
            'form': form
        })
コード例 #19
0
ファイル: views.py プロジェクト: Autodidactas/TodoList
def index(request):

    # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032
    class RequiredFormSet(BaseFormSet):
        def __init__(self, *args, **kwargs):
            super(RequiredFormSet, self).__init__(*args, **kwargs)
            for form in self.forms:
                form.empty_permitted = False

                # si se fija aca le puse extra 3 para que me pinte 3 formularios de tareas al mismo tiempo
                # si se lo quito pues pone solo uno prueben

    TodoArticuloFormSet = formset_factory(TodoArticuloForm, extra=3, max_num=10, formset=RequiredFormSet)

    if request.method == "POST":

        todo_form = TodoForm(request.POST)
        todo_articulo_formset = TodoArticuloFormSet(request.POST, request.FILES)

        if todo_form.is_valid() and todo_articulo_formset.is_valid():
            todo_lista = todo_form.save()
            for form in todo_articulo_formset.forms:
                todo_item = form.save(commit=False)
                todo_item.fktodo = todo_lista
                todo_item.save()

            return HttpResponseRedirect("/")
    else:
        todo_form = TodoForm()
        todo_articulo_formset = TodoArticuloFormSet()

    todo = Todo.objects.all().order_by("id")  # Select * from Todo ;
    return render_to_response("index.html", locals(), RequestContext(request))
コード例 #20
0
ファイル: views.py プロジェクト: johnsi15/Python-Django
def index(request):

	# See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032
	class RequiredFormSet(BaseFormSet):
		def __init__(self, *args, **kwargs):
			super(RequiredFormSet, self).__init__(*args, **kwargs)
			for form in self.forms:
				form.empty_permitted = False

	#si se fija aca le puse extra 3 para que me pinte 3 formularios de tareas al mismo tiempo
	#si se lo quito pues pone solo uno prueben 
	TodoArticuloFormSet = formset_factory(TodoArticuloForm, extra=3, max_num=10, formset=RequiredFormSet)
	

	if request.method == 'POST':

		todo_form = TodoForm(request.POST)
		todo_articulo_formset = TodoArticuloFormSet(request.POST, request.FILES)

		if todo_form.is_valid() and todo_articulo_formset.is_valid():
			todo_lista = todo_form.save()
			for form in todo_articulo_formset.forms:
				todo_item = form.save(commit=False)
				todo_item.fktodo = todo_lista
				todo_item.save()

			return HttpResponseRedirect('/')
	else:
		todo_form = TodoForm()
		todo_articulo_formset = TodoArticuloFormSet()

	todo = Todo.objects.all().order_by('id') #Select * from Todo ;
	return  render_to_response('index.html', locals(),
								RequestContext(request))
コード例 #21
0
def edit_todo(request, todo_id):
    response = {}
    status = 400
    if request.method == 'POST':
        instance = TodoItem.objects.get(pk=todo_id)
        form = TodoForm(request.POST, user=request.user, instance=instance)
        if form.is_valid():
            form.save()
            status = 200
        else:
            print(form.errors.items())
            response['errors'] = dict(form.errors.items())
    if request.method == 'DELETE':
        model = TodoItem.objects.get(pk=todo_id)
        model.delete()
        status = 200
    return json_response(response, status)
コード例 #22
0
ファイル: views.py プロジェクト: anupriyan9/Anupriyan
def todoadd(request):
    todoform=TodoForm(request.POST or None)
    if todoform.is_valid():
        todo = todoform.save()
        todo.user = request.user
        todo.save()
        return redirect('todolist')
    return render(request,'todoadd.html',{'form':todoform})
コード例 #23
0
def createtodo(request):
    if request.method == "GET":
        return render(request, 'todo/createtodo.html', {'form': TodoForm()})
    else:
        form = TodoForm(request.POST)
        newtodo = form.save(commit=False)
        newtodo.user = request.user
        newtodo.save()
        return redirect('currenttodos')
コード例 #24
0
def add(request):
    if request.user.is_authenticated:
        user = request.user
    form = TodoForm(request.POST)
    if form.is_valid():
        todo = form.save(commit=False)
        todo.user = user
        todo.save()
        return redirect('home')
    else:
        return render(request, 'todo/home.html', context={'form': form})
コード例 #25
0
ファイル: views.py プロジェクト: hsintali/todoList-Project
def tododetail(request, todo_pk):
    todo = get_object_or_404(Todo, pk=todo_pk, user=request.user)
    if request.method == 'GET':
        form = TodoForm(instance=todo)
        return render(request, 'todo/tododetail.html', {
            'todo': todo,
            'form': form
        })
    else:
        try:
            form = TodoForm(request.POST, instance=todo)
            form.save()
            return redirect('usertodos')
        except ValueError:
            error = 'Bad data passed in.'
            return render(request, 'todo/tododetail.html', {
                'todo': todo(),
                'form': form,
                'error': error
            })
コード例 #26
0
def todoView(request):
    if request.method == "POST":
        form = TodoForm(request.POST)
        if form.is_valid():
            item = form.save(commit=False)
            item.createUser = request.user.username
            item.save()

    items = Todo.objects.filter(createUser=request.user.username).reverse()
    form = TodoForm()
    return render(request, 'todo.html', {'items': items, 'form': form})
コード例 #27
0
def todo_add(request):
    if request.method == 'POST':
        form = TodoForm(request.POST, request.FILES)
        if form.is_valid():
            todo = form.save()
            return redirect('todo_detail', pk=todo.pk)
    form = TodoForm()
    context = {
        'form': form,
    }
    return render(request, 'todo/todo_create.html', context)
コード例 #28
0
def todo_create(request):
    if request.method == "POST":
        form = TodoForm(request.POST)
        if form.is_valid():
            todo = form.save(commit=False)
            todo.user = request.user
            todo.save()
            return redirect('todo_view', todo.pk)
    else:
        form = TodoForm()
    return render(request, 'todo/edit.html', {'menu': 'list', 'form': form})
コード例 #29
0
ファイル: views.py プロジェクト: vinit-modi/Django-ToDo-List
def createtodo(request):
    if request.method == 'GET':
        return render(request,'todo/createtodo.html',{'form':TodoForm()})
    else:
        try:
            form = TodoForm(request.POST)
            newtodo = form.save(commit=False)
            newtodo.user = request.user
            newtodo.save()
            return redirect('currenttodos')
        except ValueError:
            return render(request,'todo/createtodo.html',{'form':TodoForm(), 'error':'Too many data input. Please try again.'})
コード例 #30
0
def AddTodo(request):
    if not request.user.is_authenticated():
        return redirect('accounts:login')
    if request.method == "POST":
        form = TodoForm(request.POST)
        if form.is_valid():
            todo = form.save(commit=False)
            todo.user = request.user
            todo.save()
            return IndexView(request)
    else:
        form = TodoForm()
    return render(request, 'addtodo.html', {'form': form})
コード例 #31
0
def viewtodo(request, todo_pk):
    if request.user.is_superuser:
        todo_object = get_object_or_404(Todo, pk=todo_pk)
    else:
        todo_object = get_object_or_404(Todo, pk=todo_pk, user=request.user)
    if request.method == 'GET':
        form = TodoForm(instance=todo_object)
        return render(request, 'todo/viewtodo.html', {
            'todo': todo_object,
            'form': form
        })
    elif request.method == 'POST':
        try:
            form = TodoForm(request.POST, instance=todo_object)
            form.save()
            return redirect('currenttodos')
        except ValueError:
            return render(request, 'todo/viewtodo.html', {
                'todo': todo_object,
                'form': form,
                'error': 'Bad info.'
            })
コード例 #32
0
def addTodo(request):
    if request.method == "POST":
        form = TodoForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()

        messages.success(request, ('New Task Added!'))
        return redirect('addTodo')
    else:
        form = TodoForm()
        all_tasks = TodoList.objects.all()
        # define paginator on object all_tasks
        paginator = Paginator(all_tasks, 5)
        page = request.GET.get('pg')
        # Gets page with page no in page and retrieves all contents in that page.
        all_tasks = paginator.get_page(page)

        return render(request, 'todo.html', {
            'all_tasks': all_tasks,
            'form': form,
            'now1': datetime.now()
        })
コード例 #33
0
def create_todo(request):
    context = {}
    if request.method == "POST":
        try:
            todo = TodoForm(request.POST)
            new_todo = todo.save(commit=False)
            new_todo.user = request.user
            new_todo.save()
            return redirect('currenttodos')
        except Exception:
            context["error"] = "Something bad happen. Please try again"

    context["form"] = TodoForm()
    return render(request, "todo/create-todo.html", context=context)
コード例 #34
0
ファイル: views.py プロジェクト: shobberlyridge/cyprus
def add_todo(request):
	form = TodoForm()
	if request.method == 'POST':
		print("Post")
		form = TodoForm(request.POST)
		# Have we been provided with a valid form?
		if form.is_valid():
			print(form.is_valid())
			# Save the new item to the database.
			form.save(commit=True)
			print("balh")
			# Now that the category is saved
			# We could give a confirmation message
			# But since the most recent category added is on the index page
			# Then we can direct the user back to the index page.
			return index(request)
		else:
			# The supplied form contained errors -
			# just print them to the terminal.
			print(form.errors)
			# Will handle the bad form, new form, or no form supplied cases.
		# Render the form with error messages (if any).
	return render(request, 'todo/add_todo.html', {'form': form})
コード例 #35
0
def view_todo(request, todo_pk):
    """ Отображение конкретного """

    context = {}

    todo = get_object_or_404(Todo, pk=todo_pk, user=request.user)
    context['todo'] = todo

    if request.method == 'GET':
        context['form'] = TodoForm(instance=todo)

        return render(request, 'todo/view_todo.html', context)
    else:
        try:
            form = TodoForm(request.POST, instance=todo)
            form.save()
            return redirect('todo:current-todos')

        except ValueError:
            context['form'] = form
            context[
                'error'] = 'Что-то пошло не так... Попробуйте заполнить поля заново'
            return render(request, 'todo/viewtodo.html', context)
コード例 #36
0
ファイル: views.py プロジェクト: vuzDylan/django_basic
def create_todo(request):
    args = {}
    args.update(csrf(request))
    args['user'] = request.user
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            todo = form.save(commit=False)
            todo.user = request.user
            todo.save()
            return HttpResponseRedirect('/todo/all')
    else:
        form = TodoForm()
    args['form'] = form
    return render_to_response('create_todo.html', args)
コード例 #37
0
ファイル: views.py プロジェクト: kashiro/todomvc-django
 def _update(self, data):
     todo = Todo.get_todos(data.get('id'))
     data.update({'completed': json.loads(data.get('completed'))})
     form = TodoForm(data, instance=todo)
     if form.is_valid():
         form.save()
コード例 #38
0
ファイル: views.py プロジェクト: kashiro/todomvc-django
 def _post(self, request):
     form = TodoForm(request.POST, instance=Todo())
     if form.is_valid():
         # get data from form
         # form.cleaned_data.get('title')
         form.save()