From 35d68cc0769f2f3c8fb0d63f85fc780b856a8209 Mon Sep 17 00:00:00 2001 From: ofshellohicy Date: Fri, 18 Jul 2014 14:50:32 +0800 Subject: remove useless feature --- pastebin.py | 1 + static/pastebin.js | 16 +--------------- static/small.css | 4 ++++ static/style.css | 9 +++++---- templates/layout.html | 16 +++++++++++----- templates/show_paste.html | 3 --- 6 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 static/small.css diff --git a/pastebin.py b/pastebin.py index 3824285..1a54812 100644 --- a/pastebin.py +++ b/pastebin.py @@ -89,6 +89,7 @@ def new_paste(): return render_template('new_paste.html', parent=parent) +@app.route('//') @app.route('/') def show_paste(paste_id): paste = Paste.query.options(db.eagerload('children')).get_or_404(paste_id) 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($('').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..4ed0712 --- /dev/null +++ b/static/small.css @@ -0,0 +1,4 @@ +pre { + font-size: 18px; + line-height: 1.8em; +} diff --git a/static/style.css b/static/style.css index 7b19c76..7905a59 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: 100%; } h1 { margin: 0; font-weight: normal; color: #c00; } a { color: black; } a:hover { color: #c00; } @@ -13,9 +13,10 @@ 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; } + background: #eee; padding: 0; margin: 0; + 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/layout.html b/templates/layout.html index 206f750..229644d 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -1,25 +1,31 @@ {% block title %}{% endblock %} | Flask Pastebin - - + + + + + + +{# +#}

Flask Pastebin

{% for message in get_flashed_messages() %}

{{ message }} 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 %}

{{ paste.code }}
- {% endblock %} -- cgit From 60ab734aa13c69687c19aed839e3c2e25a25bf8a Mon Sep 17 00:00:00 2001 From: ofshellohicy Date: Fri, 18 Jul 2014 15:05:30 +0800 Subject: continue to remove useless feature --- config.cfg | 1 - pastebin.py | 115 ++++---------------------------------------- templates/delete_paste.html | 11 ----- templates/my_pastes.html | 13 ----- 4 files changed, 9 insertions(+), 131 deletions(-) delete mode 100644 templates/delete_paste.html delete mode 100644 templates/my_pastes.html diff --git a/config.cfg b/config.cfg index 50cc812..d302210 100644 --- a/config.cfg +++ b/config.cfg @@ -1,4 +1,3 @@ DEBUG=False SQLALCHEMY_DATABASE_URI='sqlite:///pastebin.db' SECRET_KEY='development-key' -JUGGERNAUT_DRIVER='http://localhost:8080/application.js' diff --git a/pastebin.py b/pastebin.py index 1a54812..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,8 +56,6 @@ 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) @@ -95,71 +66,3 @@ 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('//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/') -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/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 %} -

Delete Paste #{{ paste.id }}

-
-

Are you sure you want to delete the paste? You cannot undo this. -

- - -

-{% endblock %} 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 %} -

My Pastes

-
    - {% for paste in pagination.items %} -
  • #{{ paste.id }} - from {{ paste.pub_date.strftime('%Y-%m-%d @ %H:%M') }} - {% endfor %} -
- {{ render_pagination(pagination) }} -{% endblock %} -- cgit From a15f0ed6c2904fb7bc0345012301f57682581855 Mon Sep 17 00:00:00 2001 From: ofshellohicy Date: Wed, 23 Jul 2014 11:35:41 +0800 Subject: update layout tmpl --- templates/layout.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/layout.html b/templates/layout.html index 229644d..64298f2 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -1,12 +1,12 @@ {% block title %}{% endblock %} | Flask Pastebin - - + + {# -- cgit From bbc403b4534d4e93b446959791466c9d55239afc Mon Sep 17 00:00:00 2001 From: ofshellohicy Date: Wed, 10 Sep 2014 11:42:21 +0800 Subject: misc updates --- Makefile | 11 +++++++++++ serve.sh | 3 +++ static/small.css | 2 ++ static/style.css | 6 +++--- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100755 serve.sh 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/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/small.css b/static/small.css index 4ed0712..af50a92 100644 --- a/static/small.css +++ b/static/small.css @@ -2,3 +2,5 @@ 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 7905a59..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: 100%; } +.page { margin: 50px auto; width: 800px; } h1 { margin: 0; font-weight: normal; color: #c00; } a { color: black; } a:hover { color: #c00; } @@ -12,8 +12,8 @@ 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; +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; } -- cgit