Пример #1
0
def rating(url):
    page = current_wiki.get(url)
    form = RatingForm()
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        page.save()
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('page.html', form=form, page=page)
Пример #2
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        page.save()
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #3
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        page.save(session["user_id"])
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #4
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        author = session['user_id'] if 'user_id' in session else 'anonymouse'
        page.save(current_wiki, author=author)
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #5
0
def copy(oldurl, newurl):
    old_page = current_wiki.get(oldurl)
    new_page = current_wiki.get(newurl)
    form = EditorForm(obj=old_page)
    if form.validate_on_submit():
        if not new_page:
            new_page = current_wiki.get_bare(newurl)
        form.populate_obj(new_page)
        new_page.save()
        flash('"%s" was saved.' % new_page.title, 'success')
        return redirect(url_for('wiki.display', url=newurl))
    return render_template('copyeditor.html', form=form, page=old_page, url=newurl)
Пример #6
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        author = session['user_id'] if 'user_id' in session else 'anonymouse'
        page.save(current_wiki, author=author)
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #7
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        page.save()
        flash('"%s" was saved.' % page.title, 'success')
        update_timestamp(url)
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html',
                           form=form,
                           page=page,
                           date=datetime.now().strftime("%c"))
Пример #8
0
def recover(url):
    """
    @file: routes.py
    @author: Dustin Gulley
    @date: 04/08/2018
    Sets the page corresponding to the url as the newest version
    """
    page = current_wiki.get_or_404(url)
    form = EditorForm(obj=page)
    if not page:
        page = current_wiki.get_bare(url)
    form.populate_obj(page)
    page.save()
    flash('"%s" was saved.' % page.title, 'success')
    return redirect(url_for('wiki.display', url=url))
Пример #9
0
def edit(url):
    page = current_wiki.get(url)
    old_page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
            old_page = page
        form.populate_obj(page)
        page.save()
        if old_page != page:
            current_history.add_history(current_user.name, url, old_page, page)
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #10
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        is_new_page = False
        if not page:
            page = current_wiki.get_bare(url)
            is_new_page = True

        original_page = deepcopy(page)
        form.populate_obj(page)
        if not is_new_page and (original_page.body != page.body or original_page.title != page.title):
            archive(original_page.path)
        page.save()
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #11
0
def profile(user_id):
    page = current_wiki.get(user_id)
    if page:
        if page.owner:
            if current_user.get_id() == page.owner:
                return redirect(url_for('wiki.display', url=user_id))
            else:
                flash("Sorry, you can't access another user's profile.", 'success')
                return render_template('home.html')
        else:
            return redirect(url_for('wiki.display', url=user_id))
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        page = current_wiki.get_bare(user_id)
        form.populate_obj(page)
        page.owner = current_user.get_id()
        page.save()
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=user_id))
    return render_template('editor.html', form=form, page=page, uid=user_id)
Пример #12
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        form.populate_obj(page)
        page.save()
        new_path = Page.get_highest_version_of_file_path(page.path)
        pages = current_wiki.index()
        new_page = None

        for p in pages:
            if p.path == new_path:
                new_page = p

        if new_page is None:
            new_page = page

        flash('"%s" was saved.' % new_page.title, 'success')
        return redirect(url_for('wiki.display', url=new_page.url))
    return render_template('editor.html', form=form, page=page)
Пример #13
0
def edit(url):
    page = current_wiki.get(url)
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)

            # added
            add_history(url, 'WikiBot', 'Page created!', '<p>No content to show!</p>',
                        'title: \ntags: \n\nNo content to show!', 'create')

        # added
        if not os.path.exists('./history/content/' + url + '.json'):
            add_history(url, 'WikiBot', 'History created!', page.hmtl, page.content, 'edit')

        form.populate_obj(page)
        page.save()
        flash('"%s" was saved.' % page.title, 'success')

        # added
        add_history(url, form.author._value(), form.message._value(), page.html, page.content, 'edit')

        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)
Пример #14
0
def edit(url):
    page = current_wiki.get(url)
    if page:
        if page.owner:
            if page.owner == current_user.get_id():
                form = EditorForm(obj=page)
                if form.validate_on_submit():
                    if not page:
                        page = current_wiki.get_bare(url)
                    if form.image.data:
                        directory = "wiki/web/static/picture/{}".format(url)
                        if not os.path.exists(directory):
                            os.makedirs(directory)
                        f = request.files['image']
                        sfname = "{}/{}".format(directory, str(secure_filename(f.filename)))
                        f.save(sfname)
                        form.body.data = form.body.data + "\n![{}](/static/picture/{}/{})".format(f.filename, url,
                                                                                                  f.filename)
                    form.populate_obj(page)
                    page.save()
                    flash('"%s" was saved.' % page.title, 'success')
                    return redirect(url_for('wiki.display', url=url))
                return render_template('editor.html', form=form, page=page)
            else:
                if page.owner == "admin":
                    flash('This page is locked to editing by the site administrators.')
                else:
                    flash('You must own this page to move it', 'success')
                return redirect(url_for('wiki.display', url=url))
        else:
            form = EditorForm(obj=page)
            if form.validate_on_submit():
                if not page:
                    page = current_wiki.get_bare(url)
                if form.image.data:
                    directory = "wiki/web/static/picture/{}".format(url)
                    if not os.path.exists(directory):
                        os.makedirs(directory)
                    f = request.files['image']
                    sfname = "{}/{}".format(directory, str(secure_filename(f.filename)))
                    f.save(sfname)
                    form.body.data = form.body.data + "\n![{}](/static/picture/{}/{})".format(f.filename, url,
                                                                                              f.filename)
                form.populate_obj(page)
                page.save()
                flash('"%s" was saved.' % page.title, 'success')
                return redirect(url_for('wiki.display', url=url))
    else:
        form = EditorForm(obj=page)
        if form.validate_on_submit():
            if not page:
                page = current_wiki.get_bare(url)
            if form.image.data:
                directory = "wiki/web/static/picture/{}".format(url)
                if not os.path.exists(directory):
                    os.makedirs(directory)
                f = request.files['image']
                sfname = "{}/{}".format(directory, str(secure_filename(f.filename)))
                f.save(sfname)
                form.body.data = form.body.data + "\n![{}](/static/picture/{}/{})".format(f.filename, url, f.filename)
            form.populate_obj(page)
            page.save()
            flash('"%s" was saved.' % page.title, 'success')
            return redirect(url_for('wiki.display', url=url))
    form = EditorForm(obj=page)
    if form.validate_on_submit():
        if not page:
            page = current_wiki.get_bare(url)
        if form.image.data:
            directory = "wiki/web/static/picture/{}".format(url)
            if not os.path.exists(directory):
                os.makedirs(directory)
            f = request.files['image']
            sfname = "{}/{}".format(directory,str(secure_filename(f.filename)))
            f.save(sfname)
            form.body.data = form.body.data + "\n![{}](/static/picture/{}/{})".format(f.filename,url,f.filename)
        form.populate_obj(page)
        page.save()
        flash('"%s" was saved.' % page.title, 'success')
        return redirect(url_for('wiki.display', url=url))
    return render_template('editor.html', form=form, page=page)