def add_note(request): if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): form.save() return redirect('home') else: form = NoteForm() return render(request, 'notes/add_note.html', {'form': form})
def note_edit(request, note_id): note = get_object_or_404(Note, pk=note_id) if request.method=='POST': form = NoteForm(request.POST, instance=note) if form.is_valid(): form.save() return redirect('note_detail', note_id) else: form = NoteForm(instance=note) return render_to_response('notes/note_edit.html', {'form': form}, context_instance=RequestContext(request))
def note_edit(request, note_id): note = get_object_or_404(Note, pk=note_id) if request.method == 'POST': form = NoteForm(request.POST, instance=note) if form.is_valid(): form.save() return redirect('note_detail', note_id) else: form = NoteForm(instance=note) return render_to_response('notes/note_edit.html', {'form': form}, context_instance=RequestContext(request))
def note_edit(request, id=None): instance = Notes.objects.get(id=id, author=auth.get_user(request).id) form = NoteForm(request.POST or None, instance=instance) if form.is_valid(): form.save() return redirect('/') args = { 'title': instance.title, 'instance': instance, 'form': form, 'category_all': Category.objects.all(), } return render(request, "note_edit.html", args)
def add_note(request): """Shows form to add note and processes its POST product.""" if request.method == "POST": form = NoteForm(data=request.POST, files=request.FILES) if form.is_valid(): form.save() if request.is_ajax(): return render(request, "ajax_success.html", {"form": NoteForm()}) return HttpResponseRedirect(reverse("index")) if request.is_ajax(): return render(request, "ajax_fail.html", {"form": form}) return render(request, "add_note.html", {"form": form}) form = NoteForm() return render(request, "add_note.html", {"form": form})
def add_note(request): id = request.GET.get('id', None) if id is not None: note = get_object_or_404(Notes, id=id) else: note = None if request.method == 'POST': if request.POST.get('control') == 'delete': note.delete() messages.add_message(request, messages.INFO, 'Note Deleted!') return HttpResponseRedirect(reverse('notes:index')) form = NoteForm(request.POST, instance=note) if form.is_valid(): obj = form.save(commit=False) obj.owner = request.user obj.save() messages.add_message(request, messages.INFO, 'Note Added!') return HttpResponseRedirect(reverse('notes:index')) else: form = NoteForm(instance=note) return render(request, 'addNote.html', {'form': form, 'note': note})
def test_form_save(self): data = {'title': 'Note Title', 'body': 'Note body', 'tags': ''} form = NoteForm(data=data) self.assertTrue(form.is_valid()) user = User.objects.create_user(email='*****@*****.**', password='******') form.instance.owner = user note = form.save() self.assertEqual(note, Note.objects.first())
def addnote(request): if request.method == 'POST': form = NoteForm(request.POST) error = None if form.is_valid(): form.save() return HttpResponseRedirect(reverse('viewnotes')) else: return render(request, 'notes/addnote.html', { 'form': form, 'error': error }) else: form = NoteForm() return render(request, 'notes/addnote.html', { 'form': form, })
def index(request): all_notes = Note.all_notes.all() unresolved_notes = Note.unresolved_notes.all() urgent_notes = Note.urgent_notes.all() queued_invoices = Invoice.queued_invoices.all() running_invoices = Invoice.running_invoices.all() note_form = NoteForm(request.POST) is_admin = request.user.groups.filter(name='Admin') updates = Update.objects.all() if note_form.is_valid(): note_form.save() return note_form form = InvoiceForm(request.POST) if form.is_valid(): form.save() return form #return render(request, 'invoices/add_job.html', {'form': form}) return render_to_response('index.html', {'all_notes': all_notes, 'unresolved_notes': unresolved_notes, 'urgent_notes': urgent_notes, 'queued_invoices': queued_invoices, 'running_invoices': running_invoices, 'note_form': note_form, 'is_admin': is_admin, 'updates': updates, 'form': form}, context_instance=RequestContext(request))
def edit_n(request, Note_id): if request.POST: form = NoteForm(request.POST, instance=Note.objects.get(pk=Note_id)) if form.is_valid(): form.save() return HttpResponseRedirect('/notes/'+ Note_id +'/open_n') else: notebook_list = Notebook.objects.order_by('-name') STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/' n = Note.objects.get(pk=Note_id) form = NoteForm(request.POST) args = {'n': n, 'notebook_list': notebook_list, 'notes_count': Ncount(request.user.id), 'all_notebook_count': aNBcount(request.user.id), 'STATIC_URL': STATIC_URL} args.update(csrf(request)) args['form'] = form return render_to_response('notes/edit_n.html', args)
def test_form_save(self): user = User.objects.create_user(email='*****@*****.**') form_data = {'title': 'title', 'content': 'content'} post_data = {'is_public': 'off', 'tags': 'python, django'} form = NoteForm(data=form_data) form.instance.user = user note = form.save(post_data) self.assertEqual(note.title, 'title') self.assertEqual(note.content, 'content') self.assertEqual(len(note.tags), 2) self.assertEqual(note.is_public, False)
def edit_n(request, Note_id): if request.POST: form = NoteForm(request.POST, instance=Note.objects.get(pk=Note_id)) if form.is_valid(): form.save() return HttpResponseRedirect('/notes/' + Note_id + '/open_n') else: notebook_list = Notebook.objects.order_by('-name') STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/' n = Note.objects.get(pk=Note_id) form = NoteForm(request.POST) args = { 'n': n, 'notebook_list': notebook_list, 'notes_count': Ncount(request.user.id), 'all_notebook_count': aNBcount(request.user.id), 'STATIC_URL': STATIC_URL } args.update(csrf(request)) args['form'] = form return render_to_response('notes/edit_n.html', args)
def add_book(request): template_name = 'books/create_note.html' book = get_or_create_book(request) form = NoteForm(request.POST) if request.method == 'POST' and form.is_valid(): note = form.save(commit=False) note.user = request.user note.save() book.notes.add(note.pk) return redirect('books:book') return render(request, template_name, { 'form': form, })
def add_note(request): id = request.GET.get('id', None) if id is not None: note = get_object_or_404(Note, id=id) else: note = None if request.method == 'POST': if request.POST.get('control') == 'delete': note.delete() messages.add_message(request, messages.INFO, 'Note Deleted!') return HttpResponseRedirect(reverse('notes:index')) form = NoteForm(request.POST, instance=note) if form.is_valid(): form.save() messages.add_message(request, messages.INFO, 'Note Added!') return HttpResponseRedirect(reverse('notes:index')) else: form = NoteForm(instance=note) return render(request, 'notes/addnote.html', {'form':form, 'note':note})
def note_create(request): args = { 'username': auth.get_user(request).username, 'category_all': Category.objects.all(), 'form': NoteForm(initial={'category': Category.objects.get(name=u'Заметка')}), } args.update(csrf(request)) if request.POST: new_form = NoteForm(request.POST) if new_form.is_valid(): note = new_form.save(commit=False) note.author = request.user note.save() return redirect('/') else: args['form'] = new_form return render_to_response('create.html', args)
def test_filter(self): print(self.title) self.assertEqual(print(Notes.objects.get(title=self.title)), print(self.title)) self.assertEqual(print(Category.objects.get(name=self.category_name)), print(self.category_name)) form = NoteForm({ 'title': self.title, 'text': self.text, 'publish': True, }) self.assertTrue(form.is_valid()) comment = form.save() self.assertEqual(comment.title, self.title) self.assertEqual(comment.text, self.text) self.assertEqual(print(Notes.objects.get(publish=True)), print(self.title))
def edit_note(request, note_id): """Edit a note. This creates a new revision and bump the head to this new one""" # get the old note old_note = get_object_or_404(Note, note_id) if request.method == "POST": # get the new one from the form form = NoteForm(data=request.POST) if form.is_valid(): new_note = form.save(commit=False) new_note.save_as_revision_of(old_note) return redirect("notes:list") else: form = NoteForm(initial=old_note) return render("edit_note.html", { "form": form, }, request)
def note_create(request): if not request.user: # todo должно быть and raise Http404 args = { 'category_all': Category.objects.all(), 'form': NoteForm(initial={'category': Category.objects.get(name=u'Заметка')}), } args.update(csrf(request)) if request.POST: new_form = NoteForm(request.POST) if new_form.is_valid(): note = new_form.save(commit=False) note.author = request.user note.save() return redirect('/') else: args['form'] = new_form return render(request, 'create.html', args)
def add_note(request): """Add a note - GET request display the form - POST request create the note and redirect if the add is successful """ note = None if request.POST: form = NoteForm(request.POST) if form.is_valid(): note = form.save() else: form = NoteForm() return render("add_note.html", { "form": form, "note": note, })
def add_note(request): note = None if request.POST: form = NoteForm(request.POST) if form.is_valid(): # get the new instance from the model, and save it as a new one. try: note = form.save(commit=False) note.save_as_new() return redirect('notes:list') except ResourceConflict: form.errors['title'] = _("The title must be unique. Please choose another one") else: form = NoteForm() return render("add_note.html", { "form": form, "note": note }, request)
def new(request, slug): employee = get_object_or_404(Employee, slug=slug) if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): note = form.save(commit=False) note.employee = employee note.user = request.user note.updated = timezone.now() note.save() messages.success(request, 'Note created') return HttpResponseRedirect(reverse('employees.views.notes', args=[employee.slug])) form = NoteForm() d = { 'employee': employee, 'form' : form, 'title' : 'New Note', } return render_to_response('shared/new.html', add_csrf(request, d), context_instance=RequestContext(request))
def add_note(request): #fetch note by id to manipulate posted notes and pass the instance of posted note to form id = request.GET.get('id', None) if id is not None: note = get_object_or_404(Note, id=id) else: note = None # get the logged in user author = request.user if request.method == 'POST': # delete note # is there a variable named delete in html file if request.POST.get('control') == 'delete': note.delete() messages.add_message(request, messages.INFO, 'Note Deleted!') return HttpResponseRedirect(reverse('notes:index')) # new note form = NoteForm(request.POST, instance=note) if form.is_valid(): # create, but don't save instance new_author = form.save(commit=False) # add author new_author.author = author # save instance new_author.save() # save many-to-many-data for the form form.save_m2m() messages.add_message(request, messages.INFO, 'Note Added') return HttpResponseRedirect(reverse('notes:index')) else: form = NoteForm(instance=note) context = { 'form': form, 'note': note } return render(request, 'notes/addnote.html', context)
def station(request, slug): """Add a note for a station.""" station = get_object_or_404(Station, slug=slug) if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): note = form.save(commit=False) note.station = station note.user = request.user note.updated = timezone.now() note.save() messages.success(request, 'Note created') return HttpResponseRedirect(reverse('stations.views.detail', args=[station.slug])) form = NoteForm() d = { 'form': form, 'station': station, 'title': 'New Note', } return render_to_response('shared/new.html', add_csrf(request, d), context_instance=RequestContext(request))
def new_n(request): notebook_list = Notebook.objects.order_by('-name') STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/' if request.POST: form = NoteForm(request.POST) if form.is_valid(): newnote = form.save(commit=False) newnote.owner = request.user.id newnote.save() return HttpResponseRedirect('/notes/') else: form = NoteForm() args = {'notebook_list': notebook_list, 'notes_count': Ncount(request.user.id), 'user_username': request.user.username, 'user_id': request.user.id, 'all_notebook_count': aNBcount(request.user.id), 'STATIC_URL': STATIC_URL } args.update(csrf(request)) args['form'] = form return render_to_response('notes/new_n.html', args)
def edit(request, pk): note = get_object_or_404(Note, pk=pk) if request.method == 'POST': form = NoteForm(request.POST, instance=note) if form.is_valid(): note = form.save(commit=False) note.updated = timezone.now() note.save() messages.success(request, 'Note updated') if note.employee: return HttpResponseRedirect(reverse('employees.views.notes', args=[note.employee.slug])) elif note.station: return(HttpResponseRedirect(reverse('stations.views.detail', args=[note.station.slug]))) form = NoteForm(instance=note) d = { 'employee': note.employee, 'form' : form, 'station' : note.station, 'title' : 'Edit Note', } return render_to_response('shared/new.html', add_csrf(request, d), context_instance=RequestContext(request))
def new_n(request): notebook_list = Notebook.objects.order_by('-name') STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/' if request.POST: form = NoteForm(request.POST) if form.is_valid(): newnote = form.save(commit=False) newnote.owner = request.user.id newnote.save() return HttpResponseRedirect('/notes/') else: form = NoteForm() args = { 'notebook_list': notebook_list, 'notes_count': Ncount(request.user.id), 'user_username': request.user.username, 'user_id': request.user.id, 'all_notebook_count': aNBcount(request.user.id), 'STATIC_URL': STATIC_URL } args.update(csrf(request)) args['form'] = form return render_to_response('notes/new_n.html', args)