Exemplo n.º 1
0
def edit(request, note_id):
    instance_data = Note.objects.get(id=note_id)
    form = NoteForm(data=request.POST or None, instance=instance_data)
    if form.is_valid():
        form.save()
        return redirect('/')
    return render(request, 'form.html', {'form': form})
Exemplo n.º 2
0
def edit(request, note_id):
    instance_data = Note.objects.get(id=note_id)
    form = NoteForm(data=request.POST or None, instance=instance_data)
    if form.is_valid():
        form.save()
        return redirect('/')
    return render(request, 'form.html', {'form': form})
Exemplo n.º 3
0
def update(request, id):    
    note = get_object_or_404(Note, pk=id, user=request.user)
    
    if request.method == 'GET':
        form = NoteForm(model_to_dict(note))
    elif request.method == 'POST':
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse(index))        
        
    return direct_to_template(request, 'note/details.html', {'form': form, 'note_id': note.id})
Exemplo n.º 4
0
def add_new_note(request, note_id=None):
    if request.method == 'POST':  # If the form has been submitted...
        form = NoteForm(request.POST)  # A form bound to the POST data
        if note_id:
            print note_id
            form = NoteForm(request.POST,
                            instance=get_object_or_404(Note, id=note_id))
        if form.is_valid():  # All validation rules pass
            note = form.save(commit=False)
            note.pub_date = datetime.now()
            note.owner = request.user
            note.save()
            return HttpResponseRedirect('/mysite/pynotes/')
        else:
            for field in form:
                if field.errors:
                    print str(field)
                    print field.label_tag
                    print field.errors

        # Redirect after POST

    type_list = NoteType.objects.all().order_by('desc')
    form = NoteForm()  # An unbound form
    return render(
        request, 'note_form.html', {
            'sezione': {
                'titolo': 'Edit Add Note '
            },
            'form': form,
            'type_list': type_list
        })
Exemplo n.º 5
0
def new(request):
    
    if request.method == 'GET':        
        form = NoteForm()
    elif request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.user = request.user
            note.order = 0
            note.save()
            return HttpResponseRedirect(reverse(index))
            
    return direct_to_template(request, 'note/details.html', {'form': form})
Exemplo n.º 6
0
def old_dashboard(request):
    if request.method == 'POST':
        tmp = request.POST.copy()
        tmp.update({'owner': request.user.id})
        form = NoteForm(tmp)
        if not form.is_valid():
            template = loader.get_template('dashboard.html')
            rc = RequestContext(request, {'form': form})
            return HttpResponse(template.render(rc))
        note = form.save(commit=False)
        note.owner = request.user
        note.save()
        return redirect('dashboard')
    else:
        template = loader.get_template('dashboard.html')
        rc = RequestContext(request, {'form': NoteForm()})
        return HttpResponse(template.render(rc))
Exemplo n.º 7
0
def dashboard_old(request):
	if request.method=="POST":
		#this is pulling a copy of the post
		d=request.POST.copy()
		#this will add the user id as the owner of the post
		d.update({'owner':request.user.id})
		form=NoteForm(d)
		if not form.is_valid():
		#if form is not valid return to the dashboard with errors
			template=loader.get_template("dashboard.html")
			rc=RequestContext(request,{'form':form})
			return HttpResponse(template.render(rc))
		note=form.save(commit=False)
		note.owner=request.user
		note.save()
		return redirect("dashboard")
	else:	
		template=loader.get_template("dashboard.html")
		rc=RequestContext(request,{"form":NoteForm()})
		return HttpResponse(template.render(rc))
def dashboard_old(request):
    if request.method == "POST":
        #this is pulling a copy of the post
        d = request.POST.copy()
        #this will add the user id as the owner of the post
        d.update({'owner': request.user.id})
        form = NoteForm(d)
        if not form.is_valid():
            #if form is not valid return to the dashboard with errors
            template = loader.get_template("dashboard.html")
            rc = RequestContext(request, {'form': form})
            return HttpResponse(template.render(rc))
        note = form.save(commit=False)
        note.owner = request.user
        note.save()
        return redirect("dashboard")
    else:
        template = loader.get_template("dashboard.html")
        rc = RequestContext(request, {"form": NoteForm()})
        return HttpResponse(template.render(rc))
Exemplo n.º 9
0
def dashboard_old(request):

    if request.method == "POST":
        d = request.POST.copy()
        d.update({"owner": request.user.id})
        form = NoteForm(d)
        if not form.is_valid():
            # if form is not valid, return the dashboard template with errors
            template = loader.get_template("dashboard.html")
            rc = RequestContext(request, {"form": form})
            return HttpResponse(template.render(rc))
        # save the note to database
        note = form.save(commit=False)
        note.owner = request.user
        note.save()
        return redirect("dashboard")
    else:
        template = loader.get_template("dashboard.html")
        rc = RequestContext(request, {"form": NoteForm()})
        return HttpResponse(template.render(rc))

        template = loader.get_template("dashboard.html")
        rc = RequestContext(request, {"form": NoteForm()})
        return HttpResponse(template.render(rc))
Exemplo n.º 10
0
def dashboard_old(request):
    if request.method=="POST":
        d=request.POST.copy()
        d.update({'owner':request.user.id})
        form=NoteForm(d)
        if not form.is_valid():
            # if form is not valid, return the dashboard template with errors
            template=loader.get_template("dashboard.html")
            rc=RequestContext(request,{'form':form})
            return HttpResponse(template.render(rc))
        # save the note to the database
        note=form.save(commit=False)
        note.owner=request.user
        note.save()
        return render_to_response("dashboard.html",
            {'notes':Note.objects.filter(owner=request.user),'form':form})
    else:
        template=loader.get_template("dashboard.html")
        from django.forms.models import modelformset_factory
        NoteFormSet=modelformset_factory(Note,can_delete=True,extra=0)
        formset=NoteFormSet(queryset=Note.objects.all())
        rc=RequestContext(request,{'form':NoteForm(),'formset':formset,
        'notes':Note.objects.filter(owner=request.user)})
        return HttpResponse(template.render(rc))
Exemplo n.º 11
0
def create(request):
    form = NoteForm(data=request.POST or None)
    if form.is_valid():
        form.save()
        return redirect('/')
    return render(request, 'form.html', {'form': form})
Exemplo n.º 12
0
def create(request):
    form = NoteForm(data=request.POST or None)
    if form.is_valid():
        form.save()
        return redirect('/')
    return render(request, 'form.html', {'form': form})