Browse files

Add an "unpublished" view for rapid publishing.

  • Loading branch information...
1 parent 209c848 commit 231fd986614be28c5e18b727658d233e2a3eb2da @spladug spladug committed May 10, 2012
View
4 postcards/static/postcards.css
@@ -41,6 +41,10 @@ td.empty {
border-collapse: collapse;
}
+#postcards form {
+ display: inline;
+}
+
#postcards th {
text-transform: uppercase;
}
View
BIN postcards/static/spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
36 postcards/templates/home.html
@@ -33,30 +33,6 @@
</script>
{% endblock %}
-{% macro render_pagination() -%}
-<nav class="pagination">
-<ol>
- {% if pagination.has_prev: %}
- <li class="prev arrow"><a href="{{ url_for(".home", page=pagination.prev_num) }}">&larr;</a></li>
- {% endif %}
- {%- for page in pagination.iter_pages(left_edge=1, left_current=2, right_current=3, right_edge=1): %}
- {% if page: %}
- {% if page != pagination.page: %}
- <li><a href="{{ url_for(".home", page=page) }}">{{ page }}</a></li>
- {% else: %}
- <li class="current">{{ page }}</li>
- {% endif %}
- {% else: %}
- <li class="ellipsis">&hellip;</li>
- {% endif %}
- {%- endfor %}
- {% if pagination.has_next: %}
- <li class="next arrow"><a href="{{ url_for(".home", page=pagination.next_num) }}">&rarr;</a></li>
- {% endif %}
-</ol>
-</nav>
-{%- endmacro %}
-
{% block content %}
<form action="/" method="GET">
@@ -72,7 +48,7 @@
</form>
<div id="postcardcontainer">
-{{ render_pagination() }}
+{% include "pagination.html" %}
<table id="postcards">
<thead>
@@ -88,7 +64,7 @@
</thead>
<tbody>
{% if pagination.total: %}
-{% for postcard in postcards: %}
+{% for postcard in pagination.items: %}
<tr>
{% if postcard.front %}
<td><a class="thumbnail" href="{{ url_base }}{{ postcard.front }}"><img src="{{ url_base }}{{ postcard.front_thumb or DEFAULT_THUMB }}"></a></td>
@@ -110,14 +86,12 @@
<td class="status-published" colspan="2">Publishing&hellip;</td>
{% else: %}
<td>
- <form method="POST" action="{{ url_for('.publish') }}">
- <input type="hidden" name="postcard-id" value="{{ postcard.id }}">
+ <form method="POST" action="{{ url_for('.publish', id=postcard.id) }}">
<input type="submit" value="publish">
</form>
</td>
<td>
- <form method="POST" action="{{ url_for('.delete') }}">
- <input type="hidden" name="postcard-id" value="{{ postcard.id }}">
+ <form method="POST" action="{{ url_for('.delete', id=postcard.id) }}">
<input type="submit" value="delete">
</form>
</td>
@@ -132,7 +106,7 @@
</tbody>
</table>
-{{ render_pagination() }}
+{% include "pagination.html" %}
</div>
View
21 postcards/templates/pagination.html
@@ -0,0 +1,21 @@
+<nav class="pagination">
+<ol>
+ {% if pagination.has_prev: %}
+ <li class="prev arrow"><a href="{{ url_for(current_page, page=pagination.prev_num) }}">&larr;</a></li>
+ {% endif %}
+ {%- for page in pagination.iter_pages(left_edge=1, left_current=2, right_current=3, right_edge=1): %}
+ {% if page: %}
+ {% if page != pagination.page: %}
+ <li><a href="{{ url_for(current_page, page=page) }}">{{ page }}</a></li>
+ {% else: %}
+ <li class="current">{{ page }}</li>
+ {% endif %}
+ {% else: %}
+ <li class="ellipsis">&hellip;</li>
+ {% endif %}
+ {%- endfor %}
+ {% if pagination.has_next: %}
+ <li class="next arrow"><a href="{{ url_for(current_page, page=pagination.next_num) }}">&rarr;</a></li>
+ {% endif %}
+</ol>
+</nav>
View
85 postcards/templates/unpublished.html
@@ -0,0 +1,85 @@
+{% extends "base.html" %}
+
+{% block scripts %}
+<script src="/static/lib/jquery-1.6.2.min.js"></script>
+<script>
+$(function () {
+ $("#postcards").delegate(
+ 'form',
+ 'submit',
+ function (e) {
+ var form = $(this)
+ var row = form.closest('tr')
+ var div = form.closest('div')
+ div.html('<img src="/static/spinner.gif" width="91" height="85">')
+
+ $.ajax({
+ type: 'POST',
+ url: form.attr('action'),
+ success: function (data, textStatus, jqXHR) {
+ row.fadeOut()
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ div.html('<span class="error">shit, something broke :(</span>')
+ }
+ });
+
+ return false;
+ }
+ );
+});
+</script>
+{% endblock %}
+
+{% block content %}
+<div id="postcardcontainer">
+{% include "pagination.html" %}
+
+<table id="postcards">
+<thead>
+<tr>
+ <th>details</th>
+ <th>front</th>
+ <th>back</th>
+</tr>
+</thead>
+<tbody>
+{% if pagination.total: %}
+{% for postcard in pagination.items: %}
+<tr data-id="{{ postcard.id }}">
+ <td>
+ <p><a href="http://www.reddit.com/user/{{ postcard.user }}">/u/{{ postcard.user }}</a></p>
+ <p>from {{ postcard.country }} on {{ postcard.date }}</p>
+
+ <div>
+ <form method="POST" action="{{ url_for('.publish', id=postcard.id) }}">
+ <input type="submit" value="publish">
+ </form>
+ <form method="POST" action="{{ url_for('.delete', id=postcard.id) }}">
+ <input type="submit" value="delete">
+ </form>
+ </div>
+ </td>
+ {% if postcard.front %}
+ <td><a class="thumbnail-large" href="{{ url_base }}{{ postcard.front }}"><img src="{{ url_base }}{{ postcard.front_thumb.get('filename', DEFAULT_THUMB) }}" width="{{ postcard.front_thumb.get('width', DEFAULT_THUMB_WIDTH) }}" height="{{ postcard.front_thumb.get('height', DEFAULT_THUMB_HEIGHT) }}"></a></td>
+ {% else %}
+ <td></td>
+ {% endif %}
+ {% if postcard.back %}
+ <td><a class="thumbnail-large" href="{{ url_base }}{{ postcard.back }}"><img src="{{ url_base }}{{ postcard.back_thumb.get('filename', DEFAULT_THUMB) }}" width="{{ postcard.back_thumb.get('width', DEFAULT_THUMB_WIDTH) }}" height="{{ postcard.back_thumb.get('height', DEFAULT_THUMB_HEIGHT) }}"></a></td>
+ {% else %}
+ <td></td>
+ {% endif %}
+</tr>
+{% endfor %}
+{% else %}
+<tr>
+ <td colspan="8" class="empty">there doesn't seem to be anything here</td>
+</tr>
+{% endif %}
+</tbody>
+</table>
+
+{% include "pagination.html" %}
+</div>
+{% endblock %}
View
70 postcards/views.py
@@ -1,3 +1,4 @@
+import json
import base64
import datetime
@@ -35,10 +36,18 @@ class PostcardForm(wtf.Form):
def add_site_nav():
return dict(site_nav=[
("home", "home"),
+ ("unpublished", "unpublished"),
("new_postcard_form", "add postcard"),
])
+def build_pagination(base_query):
+ page_number = int(request.args.get('page', 1))
+ page_size = int(request.args.get('count', 25))
+ pagination = base_query.paginate(page_number, per_page=page_size)
+ return pagination
+
+
@app.route('/')
def home():
base_query = (Postcard.query.filter(Postcard.deleted == False)
@@ -49,17 +58,15 @@ def home():
if search_query:
base_query = base_query.filter(Postcard.user.like("%" + search_query + "%"))
- page_number = int(request.args.get('page', 1))
- page_size = int(request.args.get('count', 25))
- pagination = base_query.paginate(page_number, per_page=page_size)
+ pagination = build_pagination(base_query)
return render_template(
'home.html',
- postcards=pagination.items,
url_base='http://' + app.config['S3_BUCKET'] + '.s3.amazonaws.com/',
DEFAULT_THUMB='noimage.png',
pagination=pagination,
search_query=search_query,
+ current_page=".home",
)
@app.route('/postcard/new', methods=['GET', 'POST'])
@@ -91,26 +98,58 @@ def new_postcard_form():
return render_template('postcard_new.html', form=form)
+@app.route('/unpublished', methods=['GET'])
+def unpublished():
+ base_query = (Postcard.query.filter(Postcard.deleted == False)
+ .filter(Postcard.published == False)
+ .options(db.subqueryload('tags'))
+ .order_by(db.desc(Postcard.date)))
+ pagination = build_pagination(base_query)
+
+ # patch in larger thumbnails
+ for postcard in pagination.items:
+ info = {}
+
+ jsoninfo = getattr(postcard, 'json_image_info')
+ if jsoninfo:
+ info = json.loads(jsoninfo).get('small', {})
+
+ postcard.front_thumb = info.get('front', {})
+ postcard.back_thumb = info.get('back', {})
+
+ return render_template(
+ 'unpublished.html',
+ url_base='http://' + app.config['S3_BUCKET'] + '.s3.amazonaws.com/',
+ DEFAULT_THUMB='noimage-large.png',
+ DEFAULT_THUMB_WIDTH=215,
+ DEFAULT_THUMB_HEIGHT=215,
+ pagination=pagination,
+ current_page=".unpublished",
+ )
+
+
@app.route('/upload', methods=['POST'])
def upload():
data = base64.b64decode(request.data)
return upload_image_to_s3(data)
-@app.route('/postcard/delete', methods=['POST', 'DELETE'])
-def delete():
- id = int(request.form['postcard-id'])
+@app.route('/postcard/delete/<int:id>', methods=['POST', 'DELETE'])
+def delete(id):
postcard = Postcard._byID(id)
if postcard.deleted or postcard.published:
abort(403)
postcard.deleted = True
db.session.commit()
- flash('postcard deleted!')
- return redirect('/')
-@app.route('/postcard/publish', methods=['POST'])
-def publish():
- id = int(request.form['postcard-id'])
+ if request.headers['X-Requested-With'] == 'XMLHttpRequest':
+ return 'success!'
+ else:
+ flash('postcard deleted!')
+ return redirect('/')
+
+@app.route('/postcard/publish/<int:id>', methods=['POST'])
+def publish(id):
postcard = Postcard._byID(id)
if postcard.deleted or postcard.published:
abort(403)
@@ -122,5 +161,8 @@ def publish():
send_gold_claim_message(postcard.id)
enflair_user(postcard.user)
- flash('postcard published!')
- return redirect('/')
+ if request.headers['X-Requested-With'] == 'XMLHttpRequest':
+ return 'success!'
+ else:
+ flash('postcard published!')
+ return redirect('/')

0 comments on commit 231fd98

Please sign in to comment.