def edit_note(request, n_id): instance = Note.objects.get(id=n_id) form = NoteForm(request.POST or None, instance=instance) if form.is_valid(): form.save() return HttpResponseRedirect('/') return render(request, 'note_edit.html', {'form': form})
def note(request, booknr, chapternr, versnr): text = '' if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): # save note note = BibleVersNote.objects.filter(vers__bookNr__nr=booknr, vers__chapterNr=chapternr, vers__versNr=versnr, user=request.user) if note.count() <= 0: book = BibleBook.objects.filter(nr=booknr)[0] vers = BibleVers.objects.filter(versNr=versnr, chapterNr=chapternr, bookNr=book)[0] note = BibleVersNote(vers=vers, user=request.user, text=request.POST['note']) else: note = note[0] note.text = form.cleaned_data['note'] text = note.text note.save() else: # display error pass else: form = NoteForm() # retrieve content from db note = BibleVersNote.objects.filter(vers__bookNr__nr=booknr, vers__chapterNr=chapternr, vers__versNr=versnr, user=request.user) if note.count() > 0: text = note[0].text form.note = text verses1 = BibleText.objects.filter(vers__bookNr__nr=booknr, vers__chapterNr=chapternr, translationIdentifier__identifier=BIBLES_IN_VIEW[0]) verses2 = BibleText.objects.filter(vers__bookNr__nr=booknr, vers__chapterNr=chapternr, translationIdentifier__identifier=BIBLES_IN_VIEW[1]) verses3 = BibleText.objects.filter(vers__bookNr__nr=booknr, vers__chapterNr=chapternr, translationIdentifier__identifier=BIBLES_IN_VIEW[2]) verses4 = BibleText.objects.filter(vers__bookNr__nr=booknr, vers__chapterNr=chapternr, translationIdentifier__identifier=BIBLES_IN_VIEW[3]) # return render(request, 'strongs/editorbible.html', {'form': form, 'text': text, 'saveurl':'/note/' + booknr + '/' + chapternr + '/' + versnr + '/', 'vers': versnr, 'search': verses1[0].vers.bookNr.name + ' ' + str(chapternr), 'translation1': BIBLE_NAMES_IN_VIEW[0], 'translation2': BIBLE_NAMES_IN_VIEW[1], 'translation3': BIBLE_NAMES_IN_VIEW[2], 'translation4': BIBLE_NAMES_IN_VIEW[3], 'verses': izip_longest(verses1, verses2, verses3, verses4)}) return render(request, 'strongs/bibleNew.html', {'form': form, 'text': text, 'saveurl':'/note/' + booknr + '/' + chapternr + '/' + versnr + '/', 'vers': versnr, 'search': verses1[0].vers.bookNr.name + ' ' + str(chapternr), 'translation1': BIBLE_NAMES_IN_VIEW[0], 'translation2': BIBLE_NAMES_IN_VIEW[1], 'translation3': BIBLE_NAMES_IN_VIEW[2], 'translation4': BIBLE_NAMES_IN_VIEW[3], 'verses1': verses1, 'verses2': verses2, 'verses3': verses3, 'verses4': verses4, 'trOptions': BIBLE_NAMES_IN_VIEW})
def post_note(request): if request.method == 'POST': note = Note(author_id=request.user.id) form = NoteForm(request.POST, instance=note) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('microblog_home')) return render_to_response('microblog/note_list.html', context_instance=RequestContext(request, {'form': form}))
def get_task_note(request, t_l_id=None): if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): form.save() if t_l_id is None: return HttpResponseRedirect('/new_task/'+t_l_id) else: return HttpResponseRedirect('/new_task/') else: form = NoteForm() return render(request, "notes_add.html", { 'form' : form })
def add(request): if request.method == 'POST': form = NoteForm(request.POST, request.FILES) if form.is_valid(): form.save() if request.is_ajax(): return HttpResponse("success") else: return redirect('/') else: form = NoteForm() return render(request, 'add.html', {'form': form})
def new(request): #TODO: Replace this and similar instances with @require_POST decorator if not request.method == "POST": return HttpResponse(status=405) form = NoteForm(request.POST) if form.is_valid(): note = form.save(commit=False) note.author = request.user note.save() messages.info(request, "Your note has been added.") return HttpResponseRedirect(request.POST['next'])
def take_notes(request): if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): date = datetime.datetime.now() user = request.user note = Note(date=date, user=user, **form.cleaned_data) note.save() return HttpResponseRedirect(reverse('books:index')) else: form = NoteForm() books = Book.objects.all() return render(request, 'books/take_notes.html', {'form': form, 'books': books})
def take_note(request, id=''): content = Content.objects.get(id=id) user_num = request.user.id if request.method == 'CET': form = NoteForm() return render_to_responsen("read_page.html", {"content": content}, RequestContext(request, {"form": form, })) else: form = NoteForm(request.POST) if form.is_valid(): clean_data = form.clean() text_content = clean_data['content'] note = Note() note.add_note(user_num, content, text_content) return HttpResponseRedirect("/book/chapter/%d/" % (content.id)) else: return render_to_response("read_page.html", {"content": content}, RequestContext(request, {"form": form, }))
def update(request, id): note = Note.objects.get(id=id) if request.user == note.author: c = Context({'object': note}) if request.method == 'POST': form = NoteForm(request.POST, instance=note) if note.is_event: timeform = TimeForm(request.POST) c.update({'timeform': timeform}) if form.is_valid(): if not note.is_event: note.save() return HttpResponseRedirect(note.get_absolute_url()) else: if timeform.is_valid(): pprint.pprint(timeform.cleaned_data) note.end = datetime.datetime.combine( timeform.cleaned_data['end_date'], timeform.cleaned_data['end_time'] ) note.start = datetime.datetime.combine( timeform.cleaned_data['start_date'], timeform.cleaned_data['start_time'] ) note.save() return HttpResponseRedirect(note.get_absolute_url()) else: form = NoteForm(instance=note) if note.is_event: c.update({'timeform': TimeForm({ 'start_date': note.start.date(), 'start_time': note.start.time(), 'end_date': note.end.date(), 'end_time': note.end.time(), }) }) c.update({'form': form, 'is_event': note.is_event}) return render(request, "corkboard/note_form.html", c) else: return HttpResponseForbidden("Du har ikke tilladelse til at redigere dette opslag.")
def create(request, event): if request.user.is_authenticated(): c = {} if request.method == 'POST': form = NoteForm(request.POST) if event: timeform = TimeForm(request.POST) c.update({'timeform': timeform}) if form.is_valid(): note = form.save(commit=False) note.author = request.user note.pub_date = datetime.datetime.now() if not event: note.save() return HttpResponseRedirect(note.get_absolute_url()) else: #pprint.pprint(timeform.data) if timeform.is_valid(): #pprint.pprint(timeform.cleaned_data) note.end = datetime.datetime.combine( timeform.cleaned_data['end_date'], timeform.cleaned_data['end_time'] ) note.start = datetime.datetime.combine( timeform.cleaned_data['start_date'], timeform.cleaned_data['start_time'] ) note.is_event = True note.save() return HttpResponseRedirect(note.get_absolute_url()) else: form = NoteForm() if event: c.update({'timeform': TimeForm()}) c.update({'form': form, 'is_event': event}) return render(request, "corkboard/note_form.html", c) else: return redirect_to_login(request.path)
def add_note(request, bbl=None): lot = get_object_or_404(Lot, bbl=bbl) if request.method == 'POST': form = NoteForm(request.POST, user=request.user) if form.is_valid(): form.save() return redirect('lots.views.details', bbl=bbl) else: form = NoteForm(initial={ 'lot': lot, }, user=request.user) template = 'organize/add_note.html' return render_to_response(template, { 'form': form, 'lot': lot, }, context_instance=RequestContext(request))
def get_note(request, t_id=None): if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): temp=form.save(commit=True) # print form if t_id is not None: task=Task.objects.get(id=t_id) task.note.add(temp) # return HttpResponseRedirect('/notes/'+t_id) return HttpResponseRedirect('/') # return HttpResponseRedirect('/new_task/') return HttpResponseRedirect('/') else: print form.errors else: form = NoteForm() return render(request, "notes_add.html", { 'form' : form })
def add_note(request, bbl=None): lot = get_object_or_404(Lot, bbl=bbl) if request.method == 'POST': form = NoteForm(request.POST, user=request.user) if form.is_valid(): form.save() return redirect('lots.views.details', bbl=bbl) else: form = NoteForm(initial={ 'lot': lot, }, user=request.user) template = 'organize/add_note.html' return render_to_response(template, { 'form': form, 'lot': lot, }, context_instance=RequestContext(request))
def note_create(request): 'Non-Ajax view.' if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): new_note = form.save(commit=False) new_note.slug = find_slug_for(slugify(new_note.title)) new_note.tags = make_tags_uniform(new_note.tags) new_note.text = "Fill me in!" new_note.type = "plain" new_note.save() new_note.owners = [request.user] form.save_m2m() return HttpResponseRedirect(new_note.get_absolute_url()) else: form = NoteForm() extra = {'create_form':form} return render_to_response('codernote/note_create.html', extra, context_instance=RequestContext(request))
def post_note(request): """ つぶやき投稿用のビュー関数です。このままのコードで、GETメソッドで呼び出すとエラーが発生します(formを定義せずに利用することになるため) """ if request.method == 'POST': #ユーザをあらかじめ設定したNoteのインスタンスを作成します(まだデータベースに登録はされません) #request.userは入力値ではなくログイン情報からユーザを参照する方法です note = Note(author_id=request.user.id) #NoteFormはNoteモデルクラスから生成される検証フォームですが、ユーザを入力値として受け取らないように定義されています。 #そのため、デフォルト値としてユーザをあらかじめ設定したNoteのインスタンスをinstanceとして設定しています。 form = NoteForm(request.POST, instance=note) if form.is_valid(): #入力検証に問題がなければ、入力フォームから直にNoteデータをデータベースに登録します。 form.save() #データを登録後、urls.pyからmicroblog_homeという名前が設定されているURLConfを探しだし、URL化してリダイレクトしています return HttpResponseRedirect(reverse('microblog_home')) else: form = NoteForm() #GETメソッドで呼ばれた場合のためにformを空のNoteFormで初期化 return render_to_response('microblog/note_list.html', context_instance=RequestContext(request, {'form': form}))
def facilities_detail(request, facility_id,view_type='inventory'): try: f = Facility.objects.get(pk=facility_id) except Facility.DoesNotExist: raise Http404 products = Product.objects.all() breadcrumbs = [[f.parent.parent.name], [f.parent.name, ''], [f.name, ''], [_('Facility Detail')] ] product_counts = [] for product in Product.objects.all(): if view_type == 'inventory': product_counts.append([product.name, f.stock_on_hand(product.sms_code)]) elif view_type == 'months_of_stock': product_counts.append([product.name, f.months_of_stock(product.sms_code)]) if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): n = ServiceDeliveryPointNote() n.text = form.cleaned_data['text'] n.service_delivery_point = f n.contact_detail_id = request.user.ilsgatewayuser.id n.save() form = NoteForm() else: form = NoteForm() notes = f.servicedeliverypointnote_set.order_by('-created_at')[:3] contact_groups = [] contact_groups.append(['Facility', f.contactdetail_set.all().order_by('-role__id')]) contact_groups.append(['District', f.parent.contactdetail_set.all().order_by('-role__id')]) contact_groups.append(['Region', f.parent.parent.contactdetail_set.all().order_by('-role__id')]) return render_to_response('facilities_detail.html', {'facility': f, 'products': products, 'view_type': view_type, 'form': form, 'breadcrumbs': breadcrumbs, 'contact_groups': contact_groups, 'product_counts': product_counts, 'notes': notes}, context_instance=RequestContext(request),)
def new_note(request): if request.method == 'GET': context = {'suppress_menu':True} return render(request, 'cloud_notes/new.html', context) elif request.method == 'POST': if "cancel" in request.POST: return redirect('cloud_notes.views.list') else: form = NoteForm(request.POST) context = {'form':form} if form.is_valid(): # do stuff # ... if 'notes_folder' in request.session: fldr = Folder.objects.get(pk=request.session['notes_folder'], user=request.user) else: fldr = Folder.objects.get(name="Main", user=request.user) # Don't allow user to inadvertently create note in Trash if fldr.name == 'Trash': fldr = Folder.objects.get(name="Main", user=request.user) obj = Note() obj.title = form.cleaned_data['title'] obj.note = form.cleaned_data['note'] obj.post_type = 'note' obj.created_at = datetime.utcnow() obj.modified_at = datetime.utcnow() obj.user = request.user obj.folder = fldr obj.save() return redirect('cloud_notes.views.list') else: print form.errors return render(request, 'cloud_notes/new.html', context)
def test_shorter_10_symbols(self): form = NoteForm({"text": "Test"}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'text': [u'Do not allowed to post note shorter that 10 symbols.']})
def test_valid_form(self): form = NoteForm({"text": "TEST NOTE TEST NOTE"}) self.assertTrue(form.is_valid()) note = form.save() self.assertEqual(note.text, "TEST NOTE TEST NOTE")
def test_blank_form(self): form = NoteForm({}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'text': [u'This field is required.']})