Exemple #1
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)
Exemple #2
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)
def history_list(url):
    path = current_wiki.history_path(url)

    # get the page for this url, if it exists
    page = current_wiki.get(url)

    # no history or non-existent page, show the no history page
    if not os.path.exists(path) or page is None:
        return render_template("no_history.html", page_name=url)

    file_ids = []
    links = []
    link_names = []

    # locate all files in the history directory with .md extensions
    for filename in os.listdir(path):
        if filename.endswith(".md"):
            file_ids.append(get_history_id(filename))
            continue
        else:
            continue

    # show in reverse chronological order (most recent first)
    file_ids.reverse()

    # generate links and link names
    for file_id in file_ids:
        page_link = "/history_page/" + file_id + "/" + url
        links.append(page_link)

        link_name = format_history_id(file_id)
        link_names.append(link_name)

    return render_template('history_list.html', page=page, file_ids=file_ids, links=links, link_names=link_names)
Exemple #4
0
def home():
    read_timestamps()
    last_edited = get_timestamp('home')
    page = current_wiki.get('home')
    if page:
        return display('home')
    return render_template('home.html', last_edited=last_edited)
Exemple #5
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)
Exemple #6
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)
Exemple #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(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)
Exemple #8
0
def pdf(url):
    page = current_wiki.get(url)
    if page is None:
        return redirect(url_for('wiki.home'))
    path = page.get_path()
    pypandoc.convert_file(path,
                          'pdf',
                          outputfile="content/pdf/" + url + ".pdf")
    abspath = os.path.abspath("content/pdf/" + url + ".pdf")
    webbrowser.get(config.BROWSER_PATH).open_new_tab(abspath)
    return redirect(url_for('wiki.display', url=url))
Exemple #9
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)
Exemple #10
0
def export(url):
    page = current_wiki.get(url)
    md = current_wiki.get_md(url)
    filename = url+'.md'
    return Response(
        md,
        mimetype="application/md",
        headers={
            "Content-disposition": "attachment; filename=" + filename,
            "Content-type": "application/force-download"
        }
    )
Exemple #11
0
def versions(url):
    """
    @file: routes.py
    @author: Dustin Gulley
    @date: 04/08/2018
    Returns all page versions of a specified url
    'myfile_v1' -> [Page with 'path/to/myfile_v1.txt', Page with 'path/to/myfile_v2.txt']
    """
    page = current_wiki.get(url)
    all_pages = current_wiki.index()
    pages = Page.get_versions(page.path, all_pages)
    return render_template('versions.html', pages=pages)
Exemple #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)
        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)
Exemple #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)
        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"))
Exemple #14
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)
Exemple #15
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)
Exemple #16
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)
Exemple #17
0
def addpoll(url):
    page = current_wiki.get(url)
    form = PollForm()
    if form.is_submitted():
        options = [form.option1.data, form.option2.data]
        votes = [0, 0]
        if (form.option3.data):
            options.append(form.option3.data)
            votes.append(0)
        if (form.option4.data):
            options.append(form.option4.data)
            votes.append(0)
        print("Path: ")
        print(current_app.config['USER_DIR'])
        newPoll = current_poll_manager.add_poll(form.referenceName.data,
                                                form.title.data, options,
                                                votes)
        newPoll.save()
        print(options)
        print(votes)
        return redirect(url_for('wiki.poll', url=(form.referenceName.data)))
    print("Phase 4")
    return render_template('addpoll.html', form=form, page=page)
Exemple #18
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)
Exemple #19
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)
Exemple #20
0
def home():
    page = current_wiki.get('home')
    if page:
        return display('home')
    return render_template('home.html')
Exemple #21
0
def userpage():
    page = current_wiki.get('userpage')
    if page:
        return display('userpage')
    return render_template('userpage.html')
Exemple #22
0
def history():
    page = current_wiki.get('history')
    return render_template('history.html')
Exemple #23
0
def home():
    page = current_wiki.get('home')
    if page:
        return display('home')
    return render_template('home.html')