aboutsummaryrefslogtreecommitdiff
path: root/stackbin.py
diff options
context:
space:
mode:
Diffstat (limited to 'stackbin.py')
-rw-r--r--stackbin.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/stackbin.py b/stackbin.py
index 2345d5f..b5f774a 100644
--- a/stackbin.py
+++ b/stackbin.py
@@ -114,7 +114,13 @@ class Paste(db.Model):
parent = db.relationship('Paste', lazy=True, backref='children', uselist=False, remote_side=[id])
def __init__(self, user, code, title, relative_expiration_seconds, parent=None, is_private=False):
- self.user = user
+ # add new user if necessary
+ if user and user != "None":
+ try:
+ found_user = User.query.filter_by(display_name=user).all()[0]
+ except:
+ found_user = User(display_name=user)
+ self.user = found_user
self.code = code
self.title = title
self.is_private = is_private
@@ -133,9 +139,14 @@ class Paste(db.Model):
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
display_name = db.Column(db.String(120))
- fb_id = db.Column(db.String(30), unique=True)
+ #fb_id = db.Column(db.String(30), unique=True)
pastes = db.relationship(Paste, lazy='dynamic', backref='user')
+ def __init__(self, display_name = None):
+ self.display_name = display_name
+ db.session.add(self)
+ db.session.commit()
+
@app.route('/', methods=['GET', 'POST'])
def new_paste():
parent = None
@@ -146,7 +157,7 @@ def new_paste():
except:
parent = Paste.query.get(reply_to)
if request.method == 'POST' and request.form['code']:
- is_private = bool(request.form.get('is_private'))
+ is_private = bool(request.form.get('is_private') or False)
title = "Untitled paste"
if request.form['pastetitle'] and request.form['pastetitle'] != "Enter title here":
title = request.form['pastetitle']
@@ -285,13 +296,16 @@ def get_all_pastes():
private = None
if p1.is_private:
private = get_signed(p1.id, salt=app.config['SALT'])
+ user_id = ""
+ if p1.user_id:
+ user_id = User.query.get(p1.user_id).display_name
p2 = {
"id": p1.id,
"title": p1.title,
"pub_date": p1.pub_date,
"exp_date": p1.exp_date,
"private": private,
- "user_id": p1.user_id,
+ "user": user_id,
"is_private": p1.is_private,
"parent": (parent_id, parent_title),
"children": children,
bgstack15