Beispiel #1
0
def index():
    if request.method == 'POST':
        form = NoteForm(request.form)

        if form.validate():
            note = Note(unique_word_count=count_unique_word(form.text.data),
                        short_description=form.text.data[:60],
                        text=form.text.data)

            db.session.add(note)
            db.session.commit()
            flash('Заметка №({}) успешно добавлена'.format(note.id), 'success')

            return redirect(url_for('index'))

        else:
            flash('Пожалуйста заполните форму', 'warning')
            return redirect(url_for('index'))

    if request.method == 'GET':
        form = NoteForm()
        return render_template('index.html',
                               title='Add Note',
                               form=form,
                               active_note_add=True)
Beispiel #2
0
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})
Beispiel #3
0
def new():
    pcfg = {"title": "New note"}

    form = NoteForm()

    if form.validate_on_submit():
        a = Note()
        a.title = form.title.data
        a.cat = form.cat.data
        a.note = form.note.data
        a.user_id = current_user.id

        db.session.add(a)
        db.session.commit()

        flash("Success updating note: {0}".format(a.title), "success")
        return redirect(url_for("bp_notes.notes"))

    logbooks = (db.session.query(Logbook.id, Logbook.name, func.count(
        Log.id)).join(Log).filter(Logbook.user_id == current_user.id).group_by(
            Logbook.id).all())
    return render_template("notes/new.jinja2",
                           pcfg=pcfg,
                           form=form,
                           logbooks=logbooks)
Beispiel #4
0
 def get(self, request):
     notes = Notes.objects.all()
     context = {
         'notes': notes,
         'new_note_form': NoteForm(),
     }
     return render(request, 'ajax_note/index.html', context)
Beispiel #5
0
def handle_add_notes(username):
    """ Display form to add notes for the logged in user.
        Add new note and redirect to user detail.
    """

    if session.get('user_id') != username:
        flash("You are not authorized to add notes to this user!")
        return redirect('/')

    form = NoteForm()

    if form.validate_on_submit():

        new_note = Note()
        form.populate_obj(new_note)
        new_note.owner = username

        db.session.add(new_note)
        db.session.commit()

        flash("Note has been added")

        return redirect(f"/users/{username}")
    else:
        return render_template("add_notes.html", form=form)
Beispiel #6
0
def edit_note(id):
    """
    Edit a role
    """

    add_note = False

    note = Note.query.get_or_404(id)
    form = NoteForm(obj=note)
    if form.validate_on_submit():
        note.title = form.title.data
        note.body = form.body.data
        db.session.add(note)
        db.session.commit()
        flash('You have successfully edited the note.')

        # redirect to the roles page
        return redirect(url_for('user.list_notes'))

    form.body.data = note.body
    form.title.data = note.title
    return render_template('user/note.html',
                           add_role=add_note,
                           form=form,
                           title="Edit Note")
Beispiel #7
0
def add_note():
    """
    Add a role to the database
    """
    add_note = True
    user = current_user
    form = NoteForm()
    if form.validate_on_submit():
        note = Note(title=form.title.data, body=form.body.data)

        try:
            # add role to the database
            user.notes.append(note)
            db.session.add(note)
            db.session.commit()
            flash('You have successfully added a new note to the user.')
        except:
            # in case role name already exists
            flash('Error: .')
        # redirect to the roles page
        return redirect(url_for('user.list_notes'))

    # load role template
    return render_template('user/note.html',
                           add_role=add_note,
                           form=form,
                           title='Add Note')
Beispiel #8
0
def add_notes_form(username):
    """ GET: Display a form to add notes.
        POST: Add a new note and redirect to /users/<username>
    """

    if CURRENT_USER not in session:
        flash("You are not authorized to view this page.")
        return redirect("/login")

    elif username != session[CURRENT_USER]:
        flash("You are not authorized to access another user's page.")
        logged_in_user = session[CURRENT_USER]
        return redirect(f"/users/{logged_in_user}")

    form = NoteForm()
    user = User.query.get_or_404(username)

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        note = Note(title=title, content=content)
        user.notes.append(note)

        db.session.commit()

        return redirect(f'/users/{username}')
    else:
        return render_template("new_note.html", user=user, form=form)
Beispiel #9
0
def update_notes_form(note_id):
    """ GET: Display a form to update notes.
        POST: update note and redirect to /users/<username>
    """
    note = Note.query.get_or_404(note_id)
    username = note.user.username
    form = NoteForm(obj=note)

    if CURRENT_USER not in session:
        flash("You are not authorized to view this page.")
        return redirect("/login")

    elif username != session[CURRENT_USER]:
        flash("You are not authorized to access another user's page.")
        logged_in_user = session[CURRENT_USER]
        return redirect(f"/users/{logged_in_user}")

    if form.validate_on_submit():
        note.title = form.title.data
        note.content = form.content.data

        db.session.commit()

        return redirect(f'/users/{username}')
    else:
        return render_template("update_note.html", form=form, note=note)
Beispiel #10
0
def add_note():
    """
    Add a note to the database
    """

    add_note = True

    form = NoteForm()
    if form.validate_on_submit():
        note = Note(user_id=current_user.id, text=form.noteText.data)
        try:
            # add note to the database
            db.session.add(note)
            db.session.commit()
            flash('You have successfully added a new note.')
        except:
            flash('Note cannot be added.')
            db.session.rollback()

        # redirect to notes page
        return redirect(url_for('home.list_notes'))

    # load note template
    return render_template('home/notes/note.html',
                           action="Add",
                           add_note=add_note,
                           form=form,
                           title="Add Note")
Beispiel #11
0
def edit_note(id):
    """
    Edit a note
    """

    add_note = False

    note = Note.query.get_or_404(id)
    form = NoteForm(obj=note)
    if form.validate_on_submit():
        note.user_id = current_user.id
        note.text = form.noteText.data
        db.session.commit()
        flash('You have successfully edited the note.')

        # redirect to the notes page
        return redirect(url_for('home.list_notes'))

    form.noteText.data = note.text
    # form.userEmail.data = note.user_id
    return render_template('home/notes/note.html',
                           action="Edit",
                           add_note=add_note,
                           form=form,
                           note=note,
                           title="Edit Note")
Beispiel #12
0
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
    })
Beispiel #13
0
def add_note(username):
    """
    If GET, displays a form to add a new note
    If POST, processes new note and redirects to user's info page
    """
    #fail fast
    #redirect and flash first
    user = User.query.get_or_404(username)

    if "username" not in session or username != session["username"]:
        flash("You cannot add a note from this user")
        return redirect("/")

    form = NoteForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        new_note = Note(title=title, content=content, owner=user.username)
        db.session.add(new_note)
        db.session.commit()
        return redirect(f"/users/{user.username}")

    else:
        return render_template("new_note_form.html", form=form)
Beispiel #14
0
def edit(note_id):
    pcfg = {"title": "Edit my notes"}

    a = Note.query.filter(Note.user_id == current_user.id,
                          Note.id == note_id).first()
    if not a:
        flash("Note not found", "error")
        return redirect(url_for("bp_notes.notes"))

    form = NoteForm(request.form, obj=a)

    if form.validate_on_submit():
        a.title = form.title.data
        a.cat = form.cat.data
        a.note = form.note.data

        db.session.commit()

        flash("Success saving note: {0}".format(a.title), "success")
        return redirect(url_for("bp_notes.notes"))

    logbooks = Logbook.query.filter(Logbook.user_id == current_user.id).all()

    return render_template("notes/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           note=a,
                           note_id=note_id,
                           logbooks=logbooks)
Beispiel #15
0
def addnote(language):
    '''
    Allows a logged in user add a note for a language.
    '''
    form = NoteForm()
    document_language = mongo.db.languages.find_one_or_404(
        {"language": language}, {"topics": 1})
    topics = document_language["topics"]
    form.topic.choices = [("", "-select-")] + [(topic, topic)
                                               for topic in topics]
    if form.validate_on_submit():
        mongo.db.notes.insert_one({
            "user_id": ObjectId(current_user.id),
            "language": language,
            "topic": form.topic.data,
            "note_name": form.name.data,
            "content": form.content.data
        })
        flash("Perfect - note added!")
        return redirect(url_for("notes", language=language))
    elif request.method == "GET":
        pass
    else:
        flash("Oops - check fields!", "error")
    return render_template("addnote.html",
                           form=form,
                           language=language,
                           sample1=session["sample1"],
                           sample2=session["sample2"],
                           sample3=session["sample3"],
                           sample4=session["sample4"],
                           quote=session["quote"])
Beispiel #16
0
def create_note():
    form = NoteForm()
    if form.validate_on_submit():
        flash('Success')
        return redirect(url_for('home'))

    return render_template('create_note.html', title='Create note', form=form)
def xss_stor():
    notes = get_notes_xss_stor()
    nf = NoteForm()
    if nf.validate_on_submit():
        add_note_xss_stor(nf.username.data, nf.note.data)
        flash('Note was added!')
        return redirect(url_for('xss_stor'))
    return render_template('xss_stor.html', form=nf, notes=notes)
Beispiel #18
0
def show_note(user_id, search_id):
    g.user = User.query.get_or_404(user_id)
    note = Search.query.get_or_404(search_id)
    word = note.word
    pos = note.pos.value
    if user_id != session['user_id']:
        flash('Access denied')
        return redirect('/')
    return render_template('home.html', word_to_search=word, pos=pos, form=NoteForm(obj=note))
Beispiel #19
0
def show_notes(user_id):
    g.user = User.query.get_or_404(user_id)
    form = NoteForm()
    if user_id != session['user_id']:
        flash('Access denied')
        return redirect('/')
    else:
        notes = g.user.searches
        return render_template('notes.html', notes=notes)
Beispiel #20
0
def add_note(request):
    if NoteForm(request.POST).is_valid():
        note = BeautifulSoup(request.POST['note']).get_text()
        date = datetime.datetime.now()
        obj = Note(note_text=note, pub_date=date)
        obj.save()
        return HttpResponseRedirect('/')
    else:
        return HttpResponseRedirect('/')
Beispiel #21
0
def add_note(request,classes,lecture_number):
    lectures = Lecture.objects.filter(slug=classes,
        lecture_number=lecture_number)
    if request.POST:
        noteform = NoteForm(request.POST)
        if noteform.is_valid():
            newnote = noteform.save(commit=False)
            newnote.author = User.objects.get(username=request.user)
            newnote.lecture = lectures[0]
            newnote.save()
            return HttpResponseRedirect('/notes/'+classes+'/'+lecture_number)
    else:
        noteform = NoteForm(request.POST)
    args = {}
    args.update(csrf(request))
    args['form'] = noteform
    args['classes'] = classes
    args['lecture_number'] = lecture_number
    return render_to_response('add_note.html', args)
Beispiel #22
0
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))
Beispiel #23
0
def add_note(request):
    if request.is_ajax():
        form = NoteForm(request.POST)
        print form
        folder_id = request.POST.get('folder_id')
        if form.is_valid():
            note = form.save(commit=False)
            note.folder = Folder.objects.get(pk=folder_id)
            note.save()
            return render(request, 'notes/note_entry.html', {'notes': [note]})
Beispiel #24
0
def note_list(request, username=None):
	try:
		author = User.objects.get(username=username)
		notes = Note.objects.filter(author_id=author.id)
		# add a new note
		if request.method == 'POST':
			title = request.POST['title']
			content = request.POST['content']
			content_excerpts = content[:200]
			note_initial = {
				'title': title, 
				'content': content,
			}
			# check title's length
			if len(title) > 128:
				note_form = NoteForm(initial=note_initial)
				context_dict = {'message': u'标题字数过多,请不要超过 128 个字符', 'form': note_form}
				return render(request, 'site/add_note.html', context_dict)
			else:
				# add a note
				note = Note(
					author_id = author.id,
					title = title,
					content = content,
					content_excerpts = content_excerpts,
				)
				note.save()
				return redirect('note_list', username=username)
		
		context_dict = {'notes': notes, 'author': author}
		return render(request, 'site/note_list.html', context_dict)

	except OperationalError:
		note_form = NoteForm(initial=note_initial)
		context_dict = {'message': u'对不起,你所输入的符号(如表情符号)暂不支持', 'form': note_form}
		return render(request, 'site/add_note.html', context_dict)

	except User.DoesNotExist:
		raise Http404("Not exists.")

	except Note.DoesNotExist:
		raise Http404("Not exists.")
Beispiel #25
0
def add_note():
    form = NoteForm()
    if form.validate_on_submit():
        user_id = current_user.id
        create_note(user_id, form.note.data)
        flash("You have successfully added a new note.")
        return redirect(url_for("notes"))
    return render_template("updateNote.html",
                           add_note=True,
                           form=form,
                           title="Add Note")
Beispiel #26
0
def update_note(note_id):
    """ Update note by noteid.
    """
    note = Note.query.get_or_404(note_id)
    form = NoteForm(obj=note)
    if form.validate_on_submit():
        note.title = form.title.data
        note.content = form.content.data
        db.session.commit()
        return redirect(f"/users/{note.owner}")
    return render_template("edit_note.html", form=form, note=note)
Beispiel #27
0
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))
Beispiel #28
0
def edit_note(note_id: int):
    user_id = current_user.id
    cur_note = get_note(user_id, note_id)
    form = NoteForm(obj=cur_note)
    if form.validate_on_submit():
        update_note(user_id, note_id, form.note.data)
        flash("You have successfully updated your note.")
        return redirect(url_for("notes"))
    return render_template("updateNote.html",
                           add_note=False,
                           form=form,
                           title="Edit Note")
Beispiel #29
0
def add_note():
    note_form = NoteForm()

    if note_form.validate_on_submit():
        title = note_form.title.data
        text = note_form.text.data
        file = note_form.file.data
        with sqlite3.connect(DB_NAME) as con:
            cur = con.cursor()
            cur.execute(f'''insert into Notes(title,text) values('{title}','{text}')''')
            con.commit()
    return render_template('add.html',form=note_form)
Beispiel #30
0
def update_note(request, username, note_id):
	# commit update
	try:
		if request.method == 'POST':
			new_title = request.POST['title']
			new_content = request.POST['content']
			new_content_excerpts = new_content[:200]
			# check title's length
			new_note_initial = {
				'title': new_title,
				'content': new_content,
			}
			if len(new_title) > 128:
				note_form = NoteForm(initial=new_note_initial)
				context_dict = {'message': u'标题字数过多,请不要超过 128 个字符', 'form': note_form}
				return render(request, 'site/edit_note.html', context_dict)
			
			else:
				Note.objects.filter(id=note_id).update(
					title = new_title,
					content = new_content,
					content_excerpts = new_content_excerpts,
				)
				return redirect('note', username=username, note_id=note_id)

		else:
			author = User.objects.get(username=username)
			note = Note.objects.get(id=note_id)
			note_initial = {
				'title': note.title,
				'content': note.content,
			}
			form = NoteForm(initial=note_initial)
			content_dict = {'note_id': note_id, 'form': form}
			return render(request, 'site/edit_note.html', content_dict)

	except OperationalError:
		note_form = NoteForm(initial=new_note_initial)
		context_dict = {'message': u'对不起,你所输入的符号(如表情符号)暂不支持', 'form': note_form}
		return render(request, 'site/edit_note.html', context_dict)