aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--config.cfg.tpl3
-rw-r--r--manage.py2
-rw-r--r--pastebin.py116
-rwxr-xr-xserve.sh3
-rw-r--r--static/pastebin.js16
-rw-r--r--static/small.css6
-rw-r--r--static/style.css11
-rw-r--r--templates/delete_paste.html11
-rw-r--r--templates/layout.html16
-rw-r--r--templates/my_pastes.html13
-rw-r--r--templates/new_paste.html2
-rw-r--r--templates/show_paste.html3
13 files changed, 51 insertions, 162 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..54bc12a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+export PYTHONWARNINGS?=ignore
+
+reloadgunicorn:
+ cat var/app.pid | xargs kill -HUP
+
+stopgunicorn:
+ cat var/app.pid | xargs kill -SIGTERM
+
+clean_pyc:
+ @find `pwd` \( -name '*.pyc' -o -name '*.ptlc' \) -type f -delete
+
diff --git a/config.cfg.tpl b/config.cfg.tpl
index b4daf07..d302210 100644
--- a/config.cfg.tpl
+++ b/config.cfg.tpl
@@ -1,4 +1,3 @@
DEBUG=False
SQLALCHEMY_DATABASE_URI='sqlite:///pastebin.db'
-SECRET_KEY='dev-key'
-JUGGERNAUT_DRIVER='http://localhost:8080/application.js'
+SECRET_KEY='development-key'
diff --git a/manage.py b/manage.py
index cab41eb..ccccf91 100644
--- a/manage.py
+++ b/manage.py
@@ -16,7 +16,7 @@ def dropdb():
"""Drops all database tables."""
db.drop_all()
-manager.add_command('server', Server(host='0.0.0.0', port=8000))
+manager.add_command('server', Server(host='0.0.0.0', port=9200))
if __name__ == '__main__':
diff --git a/pastebin.py b/pastebin.py
index 3824285..03ab9b8 100644
--- a/pastebin.py
+++ b/pastebin.py
@@ -1,26 +1,12 @@
from datetime import datetime
-from flask import Flask, request, url_for, redirect, g, session, flash, \
- abort, render_template
+from flask import (Flask, request, url_for, redirect, g,
+ render_template, session)
from flask.ext.sqlalchemy import SQLAlchemy
-from flask.ext.oauth import OAuth
-from juggernaut import Juggernaut
app = Flask(__name__)
app.config.from_pyfile('config.cfg')
db = SQLAlchemy(app)
-oauth = OAuth()
-jug = Juggernaut()
-
-facebook = oauth.remote_app('facebook',
- base_url='https://graph.facebook.com/',
- request_token_url=None,
- access_token_url='/oauth/access_token',
- authorize_url='https://www.facebook.com/dialog/oauth',
- consumer_key='188477911223606',
- consumer_secret='621413ddea2bcc5b2e83d42fc40495de',
- request_token_params={'scope': 'email'}
-)
def url_for_other_page(page):
@@ -30,6 +16,13 @@ def url_for_other_page(page):
app.jinja_env.globals['url_for_other_page'] = url_for_other_page
+@app.before_request
+def check_user_status():
+ g.user = None
+ if 'user_id' in session:
+ g.user = User.query.get(session['user_id'])
+
+
class Paste(db.Model):
id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.Text)
@@ -53,26 +46,6 @@ class User(db.Model):
pastes = db.relationship(Paste, lazy='dynamic', backref='user')
-def send_new_paste_notifications(paste, reply):
- """Notifies clients about new pastes."""
- user = None
- user_id = None
- if paste.user:
- user = paste.user.display_name
- user_id = paste.user.id
- data = {'paste_id': paste.id, 'reply_id': reply.id, 'user': user}
- jug.publish('paste-replies:%d' % paste.id, data)
- if user_id is not None:
- jug.publish('user-replies:%d' % user_id, data)
-
-
-@app.before_request
-def check_user_status():
- g.user = None
- if 'user_id' in session:
- g.user = User.query.get(session['user_id'])
-
-
@app.route('/', methods=['GET', 'POST'])
def new_paste():
parent = None
@@ -83,82 +56,13 @@ def new_paste():
paste = Paste(g.user, request.form['code'], parent=parent)
db.session.add(paste)
db.session.commit()
- if parent is not None:
- send_new_paste_notifications(parent, paste)
return redirect(url_for('show_paste', paste_id=paste.id))
return render_template('new_paste.html', parent=parent)
+@app.route('/<int:paste_id>/')
@app.route('/<int:paste_id>')
def show_paste(paste_id):
paste = Paste.query.options(db.eagerload('children')).get_or_404(paste_id)
return render_template('show_paste.html', paste=paste)
-
-@app.route('/<int:paste_id>/delete', methods=['GET', 'POST'])
-def delete_paste(paste_id):
- paste = Paste.query.get_or_404(paste_id)
- if g.user is None or g.user != paste.user:
- abort(401)
- if request.method == 'POST':
- if 'yes' in request.form:
- db.session.delete(paste)
- db.session.commit()
- flash('Paste was deleted')
- return redirect(url_for('new_paste'))
- else:
- return redirect(url_for('show_paste', paste_id=paste.id))
- return render_template('delete_paste.html', paste=paste)
-
-
-@app.route('/my-pastes/', defaults={'page': 1})
-@app.route('/my-pastes/page/<int:page>')
-def my_pastes(page):
- if g.user is None:
- return redirect(url_for('login', next=request.url))
- pagination = Paste.query.filter_by(user=g.user).paginate(page)
- return render_template('my_pastes.html', pagination=pagination)
-
-
-@app.route('/login')
-def login():
- return facebook.authorize(callback=url_for('facebook_authorized',
- next=request.args.get('next') or request.referrer or None,
- _external=True))
-
-
-@app.route('/logout')
-def logout():
- session.clear()
- flash('You were logged out')
- return redirect(url_for('new_paste'))
-
-
-@app.route('/login/authorized')
-@facebook.authorized_handler
-def facebook_authorized(resp):
- next_url = request.args.get('next') or url_for('new_paste')
- if resp is None:
- flash('You denied the login')
- return redirect(next_url)
-
- session['fb_access_token'] = (resp['access_token'], '')
-
- me = facebook.get('/me')
- user = User.query.filter_by(fb_id=me.data['id']).first()
- if user is None:
- user = User()
- user.fb_id = me.data['id']
- db.session.add(user)
-
- user.display_name = me.data['name']
- db.session.commit()
- session['user_id'] = user.id
-
- flash('You are now logged in as %s' % user.display_name)
- return redirect(next_url)
-
-
-@facebook.tokengetter
-def get_facebook_oauth_token():
- return session.get('fb_access_token')
diff --git a/serve.sh b/serve.sh
new file mode 100755
index 0000000..fbc0f55
--- /dev/null
+++ b/serve.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+gunicorn -D -w8 --bind unix:/tmp/flask-pastebin.sock pastebin:app -p var/app.pid --access-logfile var/out.log --error-logfile var/error.log
diff --git a/static/pastebin.js b/static/pastebin.js
index 8507726..4412595 100644
--- a/static/pastebin.js
+++ b/static/pastebin.js
@@ -1,11 +1,8 @@
(function() {
var global = this;
- var jug = new Juggernaut();
-
var lib = global.pastebin = {
urlRoot : '/',
- jug : jug,
autoHideFlashes : function() {
var flashes = $('p.flash:visible').hide();
@@ -38,19 +35,8 @@
if (reply.author)
msg.append($('<span></span>').text(' ' + reply.author))
lib.flash(msg);
- },
-
- subscribePaste : function(pasteID) {
- jug.subscribe('paste-replies:' + pasteID, function(data) {
- lib.onNewReply(data, 'paste');
- });
- },
-
- subscribeUser : function(userID) {
- jug.subscribe('user-replies:' + userID, function(data) {
- lib.onNewReply(data, 'user');
- });
}
+
};
diff --git a/static/small.css b/static/small.css
new file mode 100644
index 0000000..af50a92
--- /dev/null
+++ b/static/small.css
@@ -0,0 +1,6 @@
+pre {
+ font-size: 18px;
+ line-height: 1.8em;
+}
+
+.page { margin: 50px auto; width: 100%; }
diff --git a/static/style.css b/static/style.css
index 7b19c76..d58599a 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1,6 +1,6 @@
body { margin: 0; padding: 0; }
body, input { font-size: 16px; font-family: 'Helvetica Neue', sans-serif; }
-.page { margin: 50px auto; width: 740px; }
+.page { margin: 50px auto; width: 800px; }
h1 { margin: 0; font-weight: normal; color: #c00; }
a { color: black; }
a:hover { color: #c00; }
@@ -12,10 +12,11 @@ dl { overflow: auto; font-size: 14px; }
dl dt { font-weight: bold; width: 90px; float: left;
clear: left; }
dl dd { float: left; margin: 0; padding: 0; }
-pre, textarea { font-family: 'Consolas', monospace; font-size: 14px;
- background: #eee; padding: 0; margin: 0; }
-textarea { border: none; width: 720px; }
-.code, .flash { background: #eee; margin: 10px -30px; padding: 10px 30px; }
+pre, textarea { font-family: 'Consolas', monospace; font-size: 18px;
+ background: #eee; padding: 0; margin: 0; line-height: 2em;
+ word-break: break-word; white-space: pre-wrap;}
+textarea { border: none; width: 100%; }
+.code, .flash { background: #eee; padding: 20px; }
.pagination strong,
.pagination span.ellipsis,
.pagination a { border: 1px solid #d00; padding: 2px 6px; text-decoration: none; }
diff --git a/templates/delete_paste.html b/templates/delete_paste.html
deleted file mode 100644
index e258dae..0000000
--- a/templates/delete_paste.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{% extends "layout.html" %}
-{% block title %}Delete Paste #{{ paste.id }}{% endblock %}
-{% block body %}
- <h2>Delete Paste #{{ paste.id }}</h2>
- <form action="" method=post>
- <p>Are you sure you want to delete the paste? You cannot undo this.
- <p>
- <input type=submit name=yes value=Yes>
- <input type=submit name=no value=No>
- </form>
-{% endblock %}
diff --git a/templates/layout.html b/templates/layout.html
index 206f750..64298f2 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -1,25 +1,31 @@
<!doctype html>
<title>{% block title %}{% endblock %} | Flask Pastebin</title>
+<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
+<meta name="apple-mobile-web-app-capable" content="yes">
+<meta name="apple-mobile-web-app-status-bar-style" content="black">
+<meta name="format-detection" content="telephone=no">
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
-<script type=text/javascript src="{{ config.JUGGERNAUT_DRIVER }}"></script>
-<script type=text/javascript src="{{ url_for('static', filename='jquery.js') }}"></script>
+<link rel="stylesheet" media="screen and (max-width: 800px)"
+href="{{ url_for('static', filename='small.css') }}" />
+
+{#<script type=text/javascript src="{{ url_for('static', filename='jquery.js') }}"></script>
<script type=text/javascript src="{{ url_for('static', filename='pastebin.js') }}"></script>
<script type=text/javascript>
pastebin.urlRoot = {{ request.url_root|tojson|safe }};
-{%- if g.user %}
- pastebin.subscribeUser({{ g.user.id }});
-{%- endif %}
</script>
+#}
<div class=page>
<h1>Flask Pastebin</h1>
<ul class=nav>
<li><a href="{{ url_for('new_paste') }}">New Paste</a>
+ {#
{% if g.user %}
<li><a href="{{ url_for('my_pastes') }}">My Pastes</a>
<li><a href="{{ url_for('logout') }}">Sign out ({{ g.user.display_name }})</a>
{% else %}
<li><a href="{{ url_for('login') }}">Sign in with Facebook</a>
{% endif %}
+ #}
</ul>
{% for message in get_flashed_messages() %}
<p class=flash>{{ message }}
diff --git a/templates/my_pastes.html b/templates/my_pastes.html
deleted file mode 100644
index 64967ad..0000000
--- a/templates/my_pastes.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{% extends "layout.html" %}
-{% block title %}My Pastes{% endblock %}
-{% from '_pagination.html' import render_pagination %}
-{% block body %}
- <h2>My Pastes</h2>
- <ul>
- {% for paste in pagination.items %}
- <li><a href="{{ url_for('show_paste', paste_id=paste.id) }}">#{{ paste.id }}</a>
- from {{ paste.pub_date.strftime('%Y-%m-%d @ %H:%M') }}
- {% endfor %}
- </ul>
- {{ render_pagination(pagination) }}
-{% endblock %}
diff --git a/templates/new_paste.html b/templates/new_paste.html
index 31bf41a..658acfb 100644
--- a/templates/new_paste.html
+++ b/templates/new_paste.html
@@ -3,7 +3,7 @@
{% block body %}
<h2>New Paste</h2>
<form action="" method=post>
- <div class=code><textarea name=code cols=60 rows=18>{{ parent.code }}</textarea></div>
+ <div class=code><textarea name=code cols=60 rows=12>{{ parent.code }}</textarea></div>
<p><input type=submit value="New Paste">
</form>
{% endblock %}
diff --git a/templates/show_paste.html b/templates/show_paste.html
index 7eeaa4b..1c42e99 100644
--- a/templates/show_paste.html
+++ b/templates/show_paste.html
@@ -29,7 +29,4 @@
{% endif %}
</dl>
<div class=code><pre>{{ paste.code }}</pre></div>
- <script type=text/javascript>
- pastebin.subscribePaste({{ paste.id }});
- </script>
{% endblock %}
bgstack15