Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2.0 compat for example

  • Loading branch information...
commit 24220c813b7ffec569cef67acf9631d6f6ce8f3e 1 parent 54f1a11
@coleifer authored
Showing with 22 additions and 22 deletions.
  1. +3 −3 example/admin.py
  2. +7 −7 example/models.py
  3. +12 −12 example/views.py
View
6 example/admin.py
@@ -29,7 +29,7 @@ def create(self):
def get_context(self):
return {
- 'note_list': Note.select().order_by(('created_date', 'desc')).paginate(1, 3)
+ 'note_list': Note.select().order_by(Note.created_date.desc()).paginate(1, 3)
}
class UserStatsPanel(AdminPanel):
@@ -37,8 +37,8 @@ class UserStatsPanel(AdminPanel):
def get_context(self):
last_week = datetime.datetime.now() - datetime.timedelta(days=7)
- signups_this_week = User.filter(join_date__gt=last_week).count()
- messages_this_week = Message.filter(pub_date__gt=last_week).count()
+ signups_this_week = User.select().where(User.join_date > last_week).count()
+ messages_this_week = Message.select().where(Message.pub_date > last_week).count()
return {
'signups': signups_this_week,
'messages': messages_this_week,
View
14 example/models.py
@@ -20,18 +20,18 @@ def __unicode__(self):
def following(self):
return User.select().join(
- Relationship, on='to_user_id'
- ).where(from_user=self).order_by('username')
+ Relationship, on=Relationship.to_user
+ ).where(Relationship.from_user==self).order_by(User.username)
def followers(self):
return User.select().join(
- Relationship, on='from_user_id'
- ).where(to_user=self).order_by('username')
+ Relationship, on=Relationship.from_user
+ ).where(Relationship.to_user==self).order_by(User.username)
def is_following(self, user):
- return Relationship.filter(
- from_user=self,
- to_user=user
+ return Relationship.select().where(
+ Relationship.from_user==self,
+ Relationship.to_user==user
).exists()
def gravatar_url(self, size=80):
View
24 example/views.py
@@ -22,21 +22,21 @@ def private_timeline():
user = auth.get_logged_in_user()
messages = Message.select().where(
- user__in=user.following()
- ).order_by(('pub_date', 'desc'))
+ Message.user << user.following()
+ ).order_by(Message.pub_date.desc())
return object_list('private_messages.html', messages, 'message_list')
@app.route('/public/')
def public_timeline():
- messages = Message.select().order_by(('pub_date', 'desc'))
+ messages = Message.select().order_by(Message.pub_date.desc())
return object_list('public_messages.html', messages, 'message_list')
@app.route('/join/', methods=['GET', 'POST'])
def join():
if request.method == 'POST' and request.form['username']:
try:
- user = User.get(username=request.form['username'])
+ user = User.select().where(User.username==request.form['username']).get()
flash('That username is already taken')
except User.DoesNotExist:
user = User(
@@ -66,19 +66,19 @@ def followers():
@app.route('/users/')
def user_list():
- users = User.select().order_by('username')
+ users = User.select().order_by(User.username)
return object_list('user_list.html', users, 'user_list')
@app.route('/users/<username>/')
def user_detail(username):
- user = get_object_or_404(User, username=username)
- messages = user.message_set.order_by(('pub_date', 'desc'))
+ user = get_object_or_404(User, User.username==username)
+ messages = user.message_set.order_by(Message.pub_date.desc())
return object_list('user_detail.html', messages, 'message_list', person=user)
@app.route('/users/<username>/follow/', methods=['POST'])
@auth.login_required
def user_follow(username):
- user = get_object_or_404(User, username=username)
+ user = get_object_or_404(User, User.username==username)
Relationship.get_or_create(
from_user=auth.get_logged_in_user(),
to_user=user,
@@ -89,10 +89,10 @@ def user_follow(username):
@app.route('/users/<username>/unfollow/', methods=['POST'])
@auth.login_required
def user_unfollow(username):
- user = get_object_or_404(User, username=username)
+ user = get_object_or_404(User, User.username==username)
Relationship.delete().where(
- from_user=auth.get_logged_in_user(),
- to_user=user,
+ Relationship.from_user==auth.get_logged_in_user(),
+ Relationship.to_user==user,
).execute()
flash('You are no longer following %s' % user.username)
return redirect(url_for('user_detail', username=user.username))
@@ -115,7 +115,7 @@ def create():
@auth.login_required
def edit(message_id):
user = auth.get_logged_in_user()
- message = get_object_or_404(Message, user=user, id=message_id)
+ message = get_object_or_404(Message, Message.user==user, Message.id==message_id)
if request.method == 'POST' and request.form['content']:
message.content = request.form['content']
message.save()
Please sign in to comment.
Something went wrong with that request. Please try again.