Permalink
Browse files

style changes

  • Loading branch information...
1 parent 7f97323 commit 9511d9db96f18059ec7b9f7d5a4335a718cafbba @brosner brosner committed Apr 13, 2010
Showing with 89 additions and 70 deletions.
  1. +4 −4 friends/admin.py
  2. +26 −15 friends/forms.py
  3. +2 −0 friends/managers.py
  4. +14 −13 friends/models.py
  5. +3 −1 friends/templatetags/friends_tags.py
  6. +20 −18 friends/views.py
  7. +20 −19 setup.py
View
@@ -4,17 +4,17 @@
class FriendshipAdmin(admin.ModelAdmin):
- list_display = ('id', 'from_user', 'to_user', 'added',)
+ list_display = ["id", "from_user", "to_user", "added"]
class FriendshipInvitationAdmin(admin.ModelAdmin):
- list_display = ('id', 'from_user', 'to_user', 'sent', 'status',)
+ list_display = ["id", "from_user", "to_user", "sent", "status"]
class FriendshipInvitationHistoryAdmin(admin.ModelAdmin):
- list_display = ('id', 'from_user', 'to_user', 'sent', 'status',)
+ list_display = ["id", "from_user", "to_user", "sent", "status"]
admin.site.register(Friendship, FriendshipAdmin)
admin.site.register(FriendshipInvitation, FriendshipInvitationAdmin)
-admin.site.register(FriendshipInvitationHistory, FriendshipInvitationHistoryAdmin)
+admin.site.register(FriendshipInvitationHistory, FriendshipInvitationHistoryAdmin)
View
@@ -12,55 +12,66 @@
class UserForm(forms.Form):
+
def __init__(self, user=None, *args, **kwargs):
self.user = user
super(UserForm, self).__init__(*args, **kwargs)
class InviteFriendForm(UserForm):
+
to_user = forms.CharField(widget=forms.HiddenInput)
- message = forms.CharField(label="Message", required=False,
- widget=forms.Textarea(attrs={'cols': '20', 'rows': '5'}))
+ message = forms.CharField(
+ label = "Message",
+ required = False,
+ widget = forms.Textarea(attrs={"cols": "20", "rows": "5"})
+ )
def clean_to_user(self):
to_username = self.cleaned_data["to_user"]
try:
User.objects.get(username=to_username)
except User.DoesNotExist:
raise forms.ValidationError(u"Unknown user.")
-
return self.cleaned_data["to_user"]
def clean(self):
to_user = User.objects.get(username=self.cleaned_data["to_user"])
previous_invitations_to = FriendshipInvitation.objects.invitations(
- to_user=to_user,
- from_user=self.user
+ to_user = to_user,
+ from_user = self.user,
)
if previous_invitations_to.count() > 0:
- raise forms.ValidationError(u"Already requested friendship with %s" %
- to_user.username)
+ raise forms.ValidationError(
+ u"Already requested friendship with %s" % to_user.username
+ )
# check inverse
previous_invitations_from = FriendshipInvitation.objects.invitations(
- to_user=self.user,
- from_user=to_user
+ to_user = self.user,
+ from_user = to_user,
)
if previous_invitations_from.count() > 0:
- raise forms.ValidationError(u"%s has already requested friendship with you" %
- to_user.username)
+ raise forms.ValidationError(
+ u"%s has already requested friendship with you" % to_user.username
+ )
return self.cleaned_data
def save(self):
to_user = User.objects.get(username=self.cleaned_data["to_user"])
message = self.cleaned_data["message"]
- invitation = FriendshipInvitation(from_user=self.user,
- to_user=to_user, message=message, status="2")
+ invitation = FriendshipInvitation(
+ from_user = self.user,
+ to_user = to_user,
+ message = message,
+ status = "2"
+ )
invitation.save()
if notification:
notification.send([to_user], "friends_invite", {"invitation": invitation})
notification.send([self.user], "friends_invite_sent", {
"invitation": invitation
})
- self.user.message_set.create(message="Friendship requested with %s" %
- to_user.username) # @@@ make link like notification
+ self.user.message_set.create(
+ message="Friendship requested with %s" % to_user.username
+ ) # @@@ make link like notification
return invitation
View
@@ -10,6 +10,7 @@
class FriendshipManager(models.Manager):
+
def friends_for_user(self, user):
friends = []
qs = self.filter(Q(from_user=user) | Q(to_user=user)).select_related(depth=1)
@@ -35,6 +36,7 @@ def remove(self, user1, user2):
class FriendshipInvitationManager(models.Manager):
+
def invitations(self, user):
return self.filter(Q(from_user=user) | Q(to_user=user)).exclude(status__in=(5, 6, 7))
View
@@ -29,7 +29,7 @@ class Friendship(models.Model):
objects = FriendshipManager()
class Meta:
- unique_together = (('to_user', 'from_user'),)
+ unique_together = [("to_user", "from_user")]
def friend_set_for(user):
@@ -97,8 +97,8 @@ class FriendshipInvitationHistory(models.Model):
def delete_friendship(sender, instance, **kwargs):
friendship_invitations = FriendshipInvitation.objects.filter(
- to_user=instance.to_user,
- from_user=instance.from_user
+ to_user = instance.to_user,
+ from_user = instance.from_user,
)
for friendship_invitation in friendship_invitations:
if friendship_invitation.status != 7:
@@ -109,21 +109,22 @@ def delete_friendship(sender, instance, **kwargs):
signals.pre_delete.connect(delete_friendship, sender=Friendship)
-# moves existing friendship invitation from user to user to FriendshipInvitationHistory before saving new invitation
+# moves existing friendship invitation from user to user to
+# FriendshipInvitationHistory before saving new invitation
def friendship_invitation(sender, instance, **kwargs):
friendship_invitations = FriendshipInvitation.objects.filter(
- to_user=instance.to_user,
- from_user=instance.from_user
+ to_user = instance.to_user,
+ from_user = instance.from_user,
)
for friendship_invitation in friendship_invitations:
FriendshipInvitationHistory.objects.create(
- from_user=friendship_invitation.from_user,
- to_user=friendship_invitation.to_user,
- message=friendship_invitation.message,
- sent=friendship_invitation.sent,
- status=friendship_invitation.status
- )
+ from_user = friendship_invitation.from_user,
+ to_user = friendship_invitation.to_user,
+ message = friendship_invitation.message,
+ sent = friendship_invitation.sent,
+ status = friendship_invitation.status,
+ )
friendship_invitation.delete()
-signals.pre_save.connect(friendship_invitation, sender=FriendshipInvitation)
+signals.pre_save.connect(friendship_invitation, sender=FriendshipInvitation)
@@ -7,6 +7,7 @@
class FriendshipStatusNode(template.Node):
+
def __init__(self, user1, user2, varname=None):
self.user1 = user1
self.user2 = user2
@@ -23,9 +24,10 @@ def render(self, context):
status = INVITE_STATUS[int(status)-1][1]
if self.varname:
context[self.varname] = status
- return ''
+ return ""
return status
+
@register.tag
def friendship_status(parser, token):
bits = token.split_contents()
View
@@ -1,10 +1,11 @@
-from django.contrib.auth.decorators import login_required
-from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.models import User
+
from friends.models import FriendshipInvitation
@@ -18,10 +19,13 @@ def find_friends(request):
"users": users,
}, context_instance=RequestContext(request))
+
@login_required
def respond_to_friendship_invitation(request, invitation_id, redirect_to_view=None):
- inv = get_object_or_404(FriendshipInvitation, to_user=request.user,
- pk=invitation_id)
+ inv = get_object_or_404(FriendshipInvitation,
+ to_user = request.user,
+ pk = invitation_id,
+ )
response = request.GET.get("response", "a")
if response == "a":
inv.accept()
@@ -34,17 +38,15 @@ def respond_to_friendship_invitation(request, invitation_id, redirect_to_view=No
return HttpResponseRedirect(request.META["HTTP_REFERER"])
-"""
-@login_required
-def add_friend(request):
- if request.method == "POST":
- form = AddFriendForm(request.POST)
- if form.is_valid():
- form.save()
- return HttpResponseRedirect(reverse(find_friends))
- else:
- form = AddFriendForm()
- return render_to_response("friends/add_fiend.html", {
- "form": form,
- })
-"""
+# @login_required
+# def add_friend(request):
+# if request.method == "POST":
+# form = AddFriendForm(request.POST)
+# if form.is_valid():
+# form.save()
+# return HttpResponseRedirect(reverse(find_friends))
+# else:
+# form = AddFriendForm()
+# return render_to_response("friends/add_fiend.html", {
+# "form": form,
+# })
View
@@ -1,28 +1,29 @@
from setuptools import setup, find_packages
+
setup(
- name='django-friends',
- version='0.2.dev1',
- description='friendship, contact and invitation management for the Django web framework',
- author='James Tauber',
- author_email='jtauber@jtauber.com',
- url='http://github.com/jtauber/django-friends/',
- packages=find_packages(),
- classifiers=[
- 'Development Status :: 3 - Alpha',
- 'Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: MIT License',
- 'Operating System :: OS Independent',
- 'Programming Language :: Python',
- 'Framework :: Django',
+ name = "django-friends",
+ version = "0.2.dev1",
+ description = "friendship, contact and invitation management for the Django web framework",
+ author = "James Tauber",
+ author_email = "jtauber@jtauber.com",
+ url = "http://github.com/jtauber/django-friends/",
+ packages = find_packages(),
+ classifiers = [
+ "Development Status :: 3 - Alpha",
+ "Environment :: Web Environment",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: MIT License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python",
+ "Framework :: Django",
],
include_package_data = True,
package_data = {
- 'friends': [
- 'templates/notification/*/*.html',
- 'templates/notification/*/*.txt',
+ "friends": [
+ "templates/notification/*/*.html",
+ "templates/notification/*/*.txt",
]
},
- zip_safe=False,
+ zip_safe = False,
)

0 comments on commit 9511d9d

Please sign in to comment.