Example #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})
Example #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})
Example #3
0
def note_add(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    if request.method == 'POST': # If the form has been submitted...
        form = NoteForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            note = Note(event=event, user=request.user, note = form.cleaned_data['note'])
            note.save()
            messages.success(request, _("Saved note"))
    return HttpResponseRedirect(reverse('event', args=[event.id]))
Example #4
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})
Example #5
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
        })
Example #6
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})
Example #7
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))
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))
Example #9
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))
Example #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))
Example #11
0
def note_form(request, note_id=None):
    type_list = NoteType.objects.all().order_by('desc')

    if note_id:
        note = Note.objects.get(id=note_id)
        data = {
            'id': note.id,
            'title': note.title,
            'body': note.body,
            'type': note.type
        }
        form = NoteForm(initial=data)
    else:
        form = NoteForm()

    return render(
        request, "note_form.html", {
            'sezione': {
                'titolo': 'Edit Add Note '
            },
            'type_list': type_list,
            'form': form,
            'note_id': note_id
        })
Example #12
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))
Example #13
0
def dashboard(request):
    from django.forms.models import inlineformset_factory
    noteformset = inlineformset_factory(User, Note, can_delete=True, 
                                        fields='__all__', extra=1)
    if request.method == 'POST':
        formset = noteformset(request.POST, request.FILES,
                              instance=request.user)
        if formset.is_valid():
            formset.save()
        return redirect('dashboard')
    else:
        formset = noteformset(instance=request.user)
        # import pdb;pdb.set_trace()
        return render_to_response(
            'dashboard.html',
            {'form': NoteForm(), 'formset': formset}, RequestContext(request))
def dashboard(request):
    from django.forms.models import inlineformset_factory
    # InlineFormSet with parent_model=User and model=Note
    NoteFormSet = inlineformset_factory(User,
                                        Note,
                                        can_delete=True,
                                        extra=1,
                                        form=NoteForm)
    if request.method == "POST":
        formset = NoteFormSet(request.POST,
                              request.FILES,
                              instance=request.user)
        if formset.is_valid():
            # updates and deletes Note objects based on user inputs
            formset.save()
        return redirect("dashboard")
    else:
        formset = NoteFormSet(instance=request.user)
        return render_to_response("dashboard.html", {
            'form': NoteForm(),
            'formset': formset
        }, RequestContext(request))
Example #15
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})
Example #16
0
from sprox.formbase import EditableForm


class NoteForm(TableForm):
    # This WidgetsList is just a container
    class fields(WidgetsList):
        title = TextField(validator=NotEmpty)
        author = TextField(validator=NotEmpty)
        description = TextArea(attrs=dict(rows=3, cols=25))
        date_taken = CalendarDatePicker(validator=DateConverter())
        subject_list = ((1, "Philosophy"), (2, "Maths"), (3, "Literature"),
                        (4, "History"), (5, "Politics"), (6, "Sociology"))
        subject = SingleSelectField(options=subject_list)


note_add_form = NoteForm("create_note_form")


class NoteEditForm(EditableForm):
    __model__ = Note
    __omit_fields__ = ['note_id']


note_edit_form = NoteEditForm(DBSession)

########NEW FILE########
__FILENAME__ = appadmin
# -*- coding: utf-8 -*-

# ##########################################################
# ## make sure administrator is on localhost
Example #17
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})