Skip to content

Commit

Permalink
finish delete page
Browse files Browse the repository at this point in the history
  • Loading branch information
fanzeyi committed Apr 6, 2012
1 parent 81e4d0a commit 37bcb1c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
15 changes: 14 additions & 1 deletion static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,18 @@ button, .btn{
}

.link {
margin-bottom: 20px;
padding-bottom: 20px;
}

.cmd {
margin-left: 3px;
display: none;
}

.cmd a {
color: #CCC;
}

.link:hover .cmd {
display: inline;
}
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<div class="link-meta">
<span class="link-title"><a href="{{ link.url }}">{{ link.title }}</a></span>
<span class="link-siteurl">{{ link.url | netloc }}</span>
<span class="cmd"><a href="/del/{{ link.id }}">del</a></span>
</div>
{% if link.comment %}
<div class="link-comment">
Expand Down
21 changes: 18 additions & 3 deletions wobbuffet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: wobbuffet.py
# CREATED: 15:57:06 06/04/2012
# MODIFIED: 17:59:34 06/04/2012
# MODIFIED: 18:39:12 06/04/2012

import datetime
import urlparse
from functools import wraps

from flask import Flask
from flask import flash
from flask import abort
from flask import request
from flask import Response
from flask import redirect
from flask import render_template
from flaskext.sqlalchemy import SQLAlchemy
from werkzeug.security import check_password_hash
Expand Down Expand Up @@ -58,10 +60,11 @@ def get_netloc(url):

@app.route("/")
def index():
page = request.args.get("p", 0, type=int)
# page = request.args.get("p", 0, type=int)
links = db.session.query(Link).order_by(Link.id.desc())
link_count = links.count()
links = links.limit(app.config["LINKS_PER_PAGE"]).offset(page * app.config["LINKS_PER_PAGE"]).all()
links = links.all()
# links = links.limit(app.config["LINKS_PER_PAGE"]).offset(page * app.config["LINKS_PER_PAGE"]).all()
return render_template("index.html", links = links)

@app.route("/add", methods=["POST", "GET"])
Expand Down Expand Up @@ -98,5 +101,17 @@ def button_show():
netloc = urlparse.urlparse(request.base_url).netloc
return render_template("button.html", netloc = netloc)

@app.route("/del/<int:link_id>")
@require_login
def del_link(link_id):
try:
link = db.session.query(Link).filter_by(id=link_id).one()
except Exception:
abort(404)
else:
db.session.delete(link)
db.session.commit()
return redirect(request.referrer or url_for('index'))

if __name__ == "__main__":
app.run(debug = True)

0 comments on commit 37bcb1c

Please sign in to comment.