예제 #1
0
def ajax_search():
	f = query_db("SELECT * FROM pastes WHERE title LIKE ? LIMIT 4 OFFSET ?", ["%"+FormParser.new(request.form).get('q',"0")+"%", 4*int(FormParser.new(request.form).get('page','0'))])
	if f == []: return "Keine Treffer auf Seite %s" % (str(int(FormParser.new(request.form).get('page','0'))+1))
	else:
		string = ""
		for match in f: # teffer
			for key in match: # dictionary treffer
				if key == "title": string += "<a style='text-decoration:none;' href='/paste/view/%s'><div class='smatch'><b>Titel</b>: %s<br/><b>ID</b>: %s<br /><b>Sprache</b>: %s<br /><i>%s</i></div></a><br />" % (match["id"], match[key], match["id"], match["syntaxhighlight"], match['text'][:40])
		return string + "<br /><br />Seiten: <a href='#x_page_back' id='back'>&laquo;</a> %s <a href='#x_page_forward' id='next'>&raquo;</a><input type='hidden' id='pageid' name='pageid' value='%s'>" % (str(int(FormParser.new(request.form).get('page',"0")) + 1), FormParser.new(request.form).get('page','0'))
예제 #2
0
def ajax_search():
    f = query_db("SELECT * FROM pastes WHERE title LIKE ? LIMIT 4 OFFSET ?", [
        "%" + FormParser.new(request.form).get('q', "0") + "%",
        4 * int(FormParser.new(request.form).get('page', '0'))
    ])
    if f == []:
        return "Keine Treffer auf Seite %s" % (
            str(int(FormParser.new(request.form).get('page', '0')) + 1))
    else:
        string = ""
        for match in f:  # teffer
            for key in match:  # dictionary treffer
                if key == "title":
                    string += "<a style='text-decoration:none;' href='/paste/view/%s'><div class='smatch'><b>Titel</b>: %s<br/><b>ID</b>: %s<br /><b>Sprache</b>: %s<br /><i>%s</i></div></a><br />" % (
                        match["id"], match[key], match["id"],
                        match["syntaxhighlight"], match['text'][:40])
        return string + "<br /><br />Seiten: <a href='#x_page_back' id='back'>&laquo;</a> %s <a href='#x_page_forward' id='next'>&raquo;</a><input type='hidden' id='pageid' name='pageid' value='%s'>" % (
            str(int(FormParser.new(request.form).get('page', "0")) + 1),
            FormParser.new(request.form).get('page', '0'))
예제 #3
0
def harald_pdfw():
	f = FormParser.new(request.form)
	id = f.get('id', '0')
	data = query_db("select * from pastes where id = ?", [id], one=True)
	try: Lexer = get_lexer_by_name(data["syntaxhighlight"].lower())
	except: Lexer = get_lexer_by_name("python")
	with open(os.path.join("static","pdf",id + ".rtf"), "w") as rtfc:
		rtfc.write(highlight(data["text"], Lexer, RtfFormatter()))
	
	if not os.path.isfile("rtf2pdf.sh"): return "Fehler! Harald nicht gefunden."
	convert(os.path.join("static","pdf", id + ".rtf"), os.path.join("static","pdf", id + ".pdf"))
	return "Ready"
예제 #4
0
def new_paste():
	f = FormParser.new(request.form)
	title = f.get('title', "Untitled")
	paste = f.get('paste', "")
	syntax_highlight = f.get('syntax_highlight', None)
	private = f.get('private', 0)
	if title != None and paste != "" and syntax_highlight != None and private != None:
		id = randomletters()
		while query_db('select * from pastes where id = ?', [id], one=True) is not None:
			id = randomletters()
		
		g.db.execute("insert into pastes (id, title, text, private, syntaxhighlight, ip, date) values (?,?,?,?,?,?,?)", [id, title, paste, private, syntax_highlight, request.environ["REMOTE_ADDR"], datetime.datetime.now().strftime("%d.%m.%Y - %H:%M")])
		g.db.commit()
		return redirect("/paste/view/%s" % (id))	
	else: return "False"
예제 #5
0
def harald_pdfw():
    f = FormParser.new(request.form)
    id = f.get('id', '0')
    data = query_db("select * from pastes where id = ?", [id], one=True)
    try:
        Lexer = get_lexer_by_name(data["syntaxhighlight"].lower())
    except:
        Lexer = get_lexer_by_name("python")
    with open(os.path.join("static", "pdf", id + ".rtf"), "w") as rtfc:
        rtfc.write(highlight(data["text"], Lexer, RtfFormatter()))

    if not os.path.isfile("rtf2pdf.sh"):
        return "Fehler! Harald nicht gefunden."
    convert(os.path.join("static", "pdf", id + ".rtf"),
            os.path.join("static", "pdf", id + ".pdf"))
    return "Ready"
예제 #6
0
def new_paste():
    f = FormParser.new(request.form)
    title = f.get('title', "Untitled")
    paste = f.get('paste', "")
    syntax_highlight = f.get('syntax_highlight', None)
    private = f.get('private', 0)
    if title != None and paste != "" and syntax_highlight != None and private != None:
        id = randomletters()
        while query_db('select * from pastes where id = ?', [id],
                       one=True) is not None:
            id = randomletters()

        g.db.execute(
            "insert into pastes (id, title, text, private, syntaxhighlight, ip, date) values (?,?,?,?,?,?,?)",
            [
                id, title, paste, private, syntax_highlight,
                request.environ["REMOTE_ADDR"],
                datetime.datetime.now().strftime("%d.%m.%Y - %H:%M")
            ])
        g.db.commit()
        return redirect("/paste/view/%s" % (id))
    else:
        return "False"