From 4cd7dfecfbe0d9d5cc5db944e47da8c058e55166 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Fri, 11 Feb 2022 19:30:19 -0500 Subject: add support for title, and ensure no js --- pastebin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pastebin.py') diff --git a/pastebin.py b/pastebin.py index ec79909..4d5c231 100644 --- a/pastebin.py +++ b/pastebin.py @@ -22,15 +22,17 @@ def check_user_status(): class Paste(db.Model): id = db.Column(db.Integer, primary_key=True) code = db.Column(db.Text) + title = db.Column(db.Text) pub_date = db.Column(db.DateTime) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) is_private = db.Column(db.Boolean) parent_id = db.Column(db.Integer, db.ForeignKey('paste.id')) parent = db.relationship('Paste', lazy=True, backref='children', uselist=False, remote_side=[id]) - def __init__(self, user, code, parent=None, is_private=False): + def __init__(self, user, code, title, parent=None, is_private=False): self.user = user self.code = code + self.title = title self.is_private = is_private self.pub_date = datetime.utcnow() self.parent = parent @@ -49,7 +51,10 @@ def new_paste(): parent = Paste.query.get(reply_to) if request.method == 'POST' and request.form['code']: is_private = bool(request.form.get('is_private')) - paste = Paste(g.user, request.form['code'], parent=parent, is_private=is_private) + title = "Untitled paste" + if request.form['pastetitle'] and request.form['pastetitle'] != "Enter title here": + title = request.form['pastetitle'] + paste = Paste(g.user, request.form['code'], title, parent=parent, is_private=is_private) db.session.add(paste) db.session.commit() sign = Signer(app.secret_key, salt='jackson').sign(str(paste.id)) \ -- cgit