Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
4 friends/models.py
@@ -45,11 +45,11 @@ def accept(self):
signals.friendship_accepted.send(sender=self)
def decline(self):
- signals.friendship_declined.send(sender=self, cancelled=False)
+ signals.friendship_declined.send(sender=self)
self.delete()
def cancel(self):
- signals.friendship_declined.send(sender=self, cancelled=True)
+ signals.friendship_cancelled.send(sender=self)
self.delete()
View
5 friends/signals.py
@@ -4,7 +4,10 @@
friendship_accepted = Signal()
-friendship_declined = Signal(providing_args=['cancelled'])
+friendship_declined = Signal()
+
+
+friendship_cancelled = Signal()
def create_friendship_instance(sender, instance, created, raw, **kwargs):
View
99 friends/templatetags/friends_tags.py
@@ -7,22 +7,6 @@
@register.tag
-def friends_of(parser, token):
- tag_name, user_var = token.split_contents()
- return FriendsOfNode(user_var)
-
-
-class FriendsOfNode(template.Node):
- def __init__(self, user_var):
- self.user_var = template.Variable(user_var)
-
- def render(self, context):
- user = self.user_var.resolve(context)
- context.update({'friends': Friendship.objects.friends_of(user, True)})
- return u''
-
-
-@register.tag
def add_to_friends(parser, token):
bits = token.split_contents()
tag_name, bits = bits[0], bits[1:]
@@ -68,6 +52,52 @@ def render(self, context):
return u''
+def _get_user(value):
+ if isinstance(value, User):
+ return value
+ elif hasattr(value, 'user') and isinstance(value.user, User):
+ return value.user
+ else:
+ raise ValueError
+
+
+@register.filter
+def is_friends_with(value, arg):
+ try:
+ user = _get_user(value)
+ except ValueError:
+ raise template.TemplateSyntaxError('is_friends_with filter can only be ' \
+ 'applied to User\'s or objects ' \
+ 'with a `user` attribute.')
+ try:
+ target = _get_user(arg)
+ except ValueError:
+ raise template.TemplateSyntaxError('is_friends_with filter\'s argument ' \
+ 'must be a User or an object ' \
+ 'with a `user` attribute.')
+ return Friendship.objects.are_friends(user, target)
+
+
+@register.filter
+def blocked_by(value, arg):
+ try:
+ user = _get_user(value)
+ except ValueError:
+ raise template.TemplateSyntaxError('blocked_by filter can only be ' \
+ 'applied to User\'s or objects ' \
+ 'with a `user` attribute.')
+ try:
+ target = _get_user(arg)
+ except ValueError:
+ raise template.TemplateSyntaxError('blocked_by filter\'s argument ' \
+ 'must be a User or an object ' \
+ 'with a `user` attribute.')
+ if UserBlocks.objects.filter(user=target, blocks=user).count():
+ return True
+ else:
+ return False
+
+
@register.tag
def block_user(parser, token):
bits = token.split_contents()
@@ -110,30 +140,17 @@ def render(self, context):
return u''
-def _get_user(value):
- if isinstance(value, User):
- return value
- elif hasattr(value, 'user') and isinstance(value.user, User):
- return value.user
- else:
- raise ValueError
+@register.tag
+def friends_of(parser, token):
+ tag_name, user_var = token.split_contents()
+ return FriendsOfNode(user_var)
-@register.filter
-def blocked_by(value, arg):
- try:
- user = _get_user(value)
- except ValueError:
- raise template.TemplateSyntaxError('blocked_by filter can only be ' \
- 'applied to User\'s or objects ' \
- 'with a `user` attribute.')
- try:
- target = _get_user(arg)
- except ValueError:
- raise template.TemplateSyntaxError('blocked_by filter\'s argument ' \
- 'must be a User or an object ' \
- 'with a `user` attribute.')
- if UserBlocks.objects.filter(user=target, blocks=user).count():
- return True
- else:
- return False
+class FriendsOfNode(template.Node):
+ def __init__(self, user_var):
+ self.user_var = template.Variable(user_var)
+
+ def render(self, context):
+ user = self.user_var.resolve(context)
+ context.update({'friends': Friendship.objects.friends_of(user, True)})
+ return u''

No commit comments for this range

Something went wrong with that request. Please try again.