Skip to content

Commit

Permalink
fix a migratedb issue with flask-login, fix the blog post list by tak…
Browse files Browse the repository at this point in the history
…ing out ill conceived "latest"
  • Loading branch information
jmoiron committed Jan 8, 2012
1 parent bfccddc commit 4bb496d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jmoiron/blog/views.py
Expand Up @@ -23,7 +23,7 @@ def show_page(num):
p.urlfunc = lambda num: url_for("blog.show_page", num=num)
if not p.exists:
abort(404)
posts = Post.latest()[p.slice()]
posts = Post.find({"is_published": True}).order_by("-timestamp")[p.slice()]
return render_template("blog/index.html", posts=posts, page=p)

@blog.route("/<slug>")
Expand Down
11 changes: 9 additions & 2 deletions manage.py
Expand Up @@ -46,6 +46,13 @@ def create_indexes():
@script.command
def migratedb(dumpfile=None):
"""Run a migration from an SQL database."""
# remove the flask-login context processor as it messes up rendering
# templates outside of a regular run-created context
from flaskext import login
procs = app.template_context_processors[None]
if login._user_context_processor in procs:
procs.remove(login._user_context_processor)

print 'Flushing current mongo database...'
flushdb()
if dumpfile:
Expand All @@ -65,7 +72,7 @@ def migratedb(dumpfile=None):
db['comment'].insert(comments['comments'])
db['banned_ip'].insert(comments['bannedips'])
print 'Resetting blog comments to use oids..'
from blog.models import Post
from jmoiron.blog.models import Post
mapping = dict([(c['id'], c['_id']) for c in db.comment.find()])
for post in Post.find({'comments': {'$ne': []}}):
post.comments = [mapping[c] for c in post['comments']]
Expand All @@ -81,7 +88,7 @@ def migratedb(dumpfile=None):
@script.command
def rerender_entries(source_tag=None):
"""Rerender stream entries."""
from stream.models import Entry
from jmoiron.stream.models import Entry
if source_tag:
entries = Entry.find({'source_tag': source_tag})
else:
Expand Down

0 comments on commit 4bb496d

Please sign in to comment.