def delete(url): page = current_wiki.get_or_404(url) if "admin" in current_user.data.get('roles'): current_wiki.delete(url) flash('Page "%s" was deleted.' % page.title, 'success') else: flash('Unable to delete page. You do not have permission.', 'error') return redirect(url_for('wiki.home'))
def move(url): page = current_wiki.get_or_404(url) form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data current_wiki.move(url, newurl) return redirect(url_for('wiki.display', url=newurl)) return render_template('move.html', form=form, page=page)
def history(url): """ This route handles showing the pages history. :param url: The url of the page for which you want the history of :return: Show the history of the page """ page = current_wiki.get_or_404(url) return render_template('history.html', history=page.history, page=page)
def saveas(url): old_page = current_wiki.get_or_404(url) form = URLForm(obj=old_page) if form.validate_on_submit(): return redirect(url_for( 'wiki.copy', oldurl=form.clean_url(url), newurl=form.clean_url(form.url.data) )) return render_template('saveas.html', form=form)
def display(url): page = current_wiki.get_or_404(url) if page.owner: owning_user = current_users.get_user(page.owner) if page.owner == current_user.get_id(): return render_template('page.html', page=page, ou=owning_user) else: return render_template('page.html', page=page, flag='readonly', ou=owning_user) return render_template('page.html', page=page)
def display_version(url): """ @file: routes.py @author: Dustin Gulley @date: 04/08/2018 Similar to display but with only conditions applying to a previous version """ page = current_wiki.get_or_404(url) return render_template('versioned_page.html', page=page)
def md2pdf_multiple_page(pdf_template, select_template): links = current_wiki.index() if request.method == "POST": data = request.form.getlist('page') pages = [] for url in data: pages.append(current_wiki.get_or_404(url)) html = render_template(pdf_template, pages=pages) return render_pdf(HTML(string=html)) return render_template(select_template, pages=links)
def display(url): #open creators.json file and pass current url's attributes to page.html #so we can access it in base.html ######################################## data = creator_module.get_page_data(url) ######################################## page = current_wiki.get_or_404(url) return render_template('page.html', page=page, data=data)
def move(url): page = current_wiki.get_or_404(url) form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data current_wiki.move(url, newurl) move_history(url, newurl) add_history(newurl, 'WikiBot', 'Moved page to URL: ' + newurl, page.html, page.content, 'move') return redirect(url_for('wiki.display', url=newurl)) return render_template('move.html', form=form, page=page)
def delete(url): page = current_wiki.get_or_404(url) all_pages = current_wiki.index() pages = Page.get_versions(page.path, all_pages) for p in pages: current_wiki.delete(p.url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.home'))
def history_page(id, url): # build the url to the history page url = "history/" + url + "/" + id page = current_wiki.get_or_404(url) # modify the title to include that it is an archived version page.title = page.title + " (Old Revision: " + format_history_id(id) + ")" return render_template('history_page.html', page=page)
def delete(url): # check if we have an upload file or a page if url[0:6] == 'upload': # delete uploaded file current_wiki.deleteUpload(url) return redirect(url_for('wiki.upload')) else: # delete page page = current_wiki.get_or_404(url) current_wiki.delete(url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.home'))
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))
def delete(url): page = current_wiki.get_or_404(url) if page.owner: if current_user.get_id() == page.owner: current_wiki.delete(url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.home')) else: if page.owner == "admin": flash('This page is locked to editing by the site administrators.') else: flash('You must own this page to delete it', 'success') return redirect(url_for('wiki.display', url=url)) current_wiki.delete(url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.home'))
def display(url): page = current_wiki.get_or_404(url) form = TagForm(obj=page) if request.method == "POST": newTags = request.form['newTags'] if page.tags == '': page.tags = newTags else: page.tags = page.tags + "," + newTags page.tags = newTags page.save() return redirect(url_for('wiki.display', url=url)) return render_template('page.html', page=page, form=form)
def page_preview(): url = request.args.get('currentTag', 0) url = url.strip("/") is_delete = request.args.get('isDeleteBtn', 0) is_riki_tab = request.args.get('isRikiLink', 0) if is_normal_href_link(url) and is_delete == '' and is_riki_tab != ('Riki' and 'Cancel' and 'Wikielodeon'): page = current_wiki.get_or_404(url) data = {} processor = Processor(page.content) data['html'], data['body'], data['meta'] = processor.process() return jsonify(result=data['html']) return "None"
def move(url): page = current_wiki.get_or_404(url) form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data current_wiki.move(url, newurl) # Delete non-moved pages all_pages = current_wiki.index() pages = Page.get_versions(page.path, all_pages) for p in pages: current_wiki.delete(p.url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.display', url=newurl)) return render_template('move.html', form=form, page=page)
def pdf(url): page = current_wiki.get_or_404(url) abs_path = os.path.dirname(os.path.abspath(__file__)) directory = os.path.dirname(abs_path) dir_next = os.path.dirname(directory) file_path = os.path.join(dir_next, 'content', url + '.md') path_html = os.path.join(dir_next, 'content', url + '.html') path = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe' config = pdfkit.configuration(wkhtmltopdf=path) #web = 'http://127.0.0.1:5000/' + url + '/' #pdfkit.from_url(web, url + '.pdf', configuration=config) output_filename = url + '.pdf' #html_file = markdown.markdownFromFile(file_path) #f = open(os.path.join(dir_next, 'content', url + '.html'), "w+") markdown.markdownFromFile(file_path, path_html) #f.write(str(html_file)) #f.close() pdfkit.from_file(path_html, output_filename, configuration=config) return render_template('page.html', page=page)
def move(url): page = current_wiki.get_or_404(url) if page.owner: if current_user.get_id() == page.owner: form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data current_wiki.move(url, newurl) return redirect(url_for('wiki.display', url=newurl)) 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)) form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data current_wiki.move(url, newurl) return redirect(url_for('wiki.display', url=newurl)) return render_template('move.html', form=form, page=page)
def related(url): # get url page = current_wiki.get_or_404(url) # make list of tags about original article tags = page.tags tagslist = tags.split(", ") #blank list to hold other articles with the same tags tagged = [] for i in tagslist: # append tag category tagged.append(i.capitalize()) #check if list of articles is only the original article, if not then add the article if len(current_wiki.index_by_tag(i)) > 1: tagged += current_wiki.index_by_tag(i) #if there are no other articles other than the orignal article, append this statement else: tagged.append("No other wikis with this tag") return render_template('related.html', tags=tagslist, page = page, pages = tagged)
def export(url): page = current_wiki.get_or_404(url) form = URLForm(obj=page) if request.method == 'POST': if request.form['submit_button'] == 'PDF': html = page.html base_url = flask.request.host_url rendered = render_template('pdf_page_template.html', page=page, base_url=base_url) pdf = pdfkit.from_string(rendered, False) response = make_response(pdf) response.headers['Content-Type'] = 'application/pdf' response.headers[ 'Content-Disposition'] = 'inline; filename={}.pdf'.format( 'Test') return response else: pass return render_template('export.html', form=form, page=page)
def delete(url): page = current_wiki.get_or_404(url) current_wiki.delete(url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.home'))
def display(url): page = current_wiki.get_or_404(url) return render_template('page.html', page=page, is_archive_page=is_archived_page(page), archives=get_archived_pages(page))
def display(url): page = current_wiki.get_or_404(url) last_edited = get_timestamp(url) return render_template('page.html', page=page, last_edited=last_edited)
def favorite(url): page = current_wiki.get_or_404(url) current_wiki.favorite(url,page.title) return display(url)
def deleteFavorite(url): page = current_wiki.get_or_404(url) current_wiki.delete_favorite(url, page.title) return favorites()
def display(url): page = current_wiki.get_or_404(url) return render_template('page.html', page=page)
def history_user(url, name): """ This route handles displaying the additions and subtractions to the page that a user made. :param url: The url of the page that was edited :param name: The name of the user who edited the page :return: Show a page the highlights the differences between the current content and the previous content """ # get the page passed page = current_wiki.get_or_404(url) # The timestamp of the edit is passed as a query param # Use it to get the edit we're interested in current_entry = page.history.entries[request.args.get("time")] previous_entry = current_entry current_entry_idx = page.history.entryKeys.index(request.args.get("time")) # Get the most recent edit made before the current one if current_entry_idx + 1 < len(page.history.entryKeys): previous_entry_idx = current_entry_idx + 1 previous_entry_key = page.history.entryKeys[previous_entry_idx] previous_entry = page.history.entries[previous_entry_key] # Generate a difference highlighting the additions and subtractions from the content diff = ndiff(previous_entry["version"], current_entry["version"]) adding = False first_add = True subtracting = False first_subtract = True diff_length = len(list(diff)) edits = "" for i, s in enumerate( ndiff(previous_entry["version"], current_entry["version"])): if (s[0] != '+' or i + 1 == diff_length) and adding is True: adding = False first_add = True edits += "</span>" if (s[0] != '-' or i + 1 == diff_length) and subtracting is True: subtracting = False first_subtract = True edits += "</span>" if s[0] == '+': if first_add is True: edits += "<span class=addition>" first_add = False adding = True edits += s[2] if s[0] == '-': if first_subtract is True: edits += "<span class=subtraction>" first_subtract = False subtracting = True edits += s[2] if s[0] == ' ': edits += s[2] safe_edits = Markup(edits) return render_template('user_based_history.html', edits=safe_edits, page=page, user=name, time=request.args.get("time"))
def history(url): page = current_wiki.get_or_404(url) if not os.path.exists('./history/content/' + url + '.json'): add_history(url, 'WikiBot', 'History created!', page.html, page.content, 'edit') changes = get_history(url) return render_template('history.html', page=page, changes=changes)
def md2pdf_single_page(url, pdf_template): pages = [current_wiki.get_or_404(url)] html = render_template(pdf_template, pages=pages) return render_pdf(HTML(string=html))