Skip to content

Commit

Permalink
Merge commit 'django-friends/master'
Browse files Browse the repository at this point in the history
Conflicts:
	friends/forms.py
	friends/models.py
  • Loading branch information
alibrahim committed Jul 26, 2009
2 parents 4968768 + fa3b938 commit c4d75f5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -0,0 +1 @@
recursive-include friends/templates/notification *
41 changes: 22 additions & 19 deletions friends/forms.py
@@ -1,39 +1,42 @@
from django import forms

from django.conf import settings
from django.contrib.auth.models import User

from emailconfirmation.models import EmailAddress
from friends.models import *

try:
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
except ImportError:
else:
notification = None

if "emailconfirmation" in settings.INSTALLED_APPS:
from emailconfirmation.models import EmailAddress
else:
EmailAddress = None

class UserForm(forms.Form):

def __init__(self, user=None, *args, **kwargs):
self.user = user
super(UserForm, self).__init__(*args, **kwargs)


class JoinRequestForm(forms.Form):

email = forms.EmailField(label="Email", required=True, widget=forms.TextInput(attrs={'size':'30'}))
message = forms.CharField(label="Message", required=False, widget=forms.Textarea(attrs = {'cols': '30', 'rows': '5'}))
if EmailAddress:
class JoinRequestForm(forms.Form):

def clean_email(self):
# @@@ this assumes email-confirmation is being used
self.existing_users = EmailAddress.objects.get_users_for(self.cleaned_data["email"])
if self.existing_users:
raise forms.ValidationError(u"Someone with that email address is already here.")
return self.cleaned_data["email"]
email = forms.EmailField(label="Email", required=True, widget=forms.TextInput(attrs={'size':'30'}))
message = forms.CharField(label="Message", required=False, widget=forms.Textarea(attrs = {'cols': '30', 'rows': '5'}))

def save(self, user):
join_request = JoinInvitation.objects.send_invitation(user, self.cleaned_data["email"], self.cleaned_data["message"])
user.message_set.create(message="Invitation to join sent to %s" % join_request.contact.email)
return join_request
def clean_email(self):
# @@@ this assumes email-confirmation is being used
self.existing_users = EmailAddress.objects.get_users_for(self.cleaned_data["email"])
if self.existing_users:
raise forms.ValidationError(u"Someone with that email address is already here.")
return self.cleaned_data["email"]

def save(self, user):
join_request = JoinInvitation.objects.send_invitation(user, self.cleaned_data["email"], self.cleaned_data["message"])
user.message_set.create(message="Invitation to join sent to %s" % join_request.contact.email)
return join_request

class InviteFriendForm(UserForm):

Expand Down
10 changes: 5 additions & 5 deletions friends/management.py
@@ -1,18 +1,18 @@
from django.conf import settings
from django.db.models import signals

from django.utils.translation import ugettext_noop as _

try:
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification

def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type("friends_invite", _("Invitation Received"), _("you have received an invitation"), default=2)
notification.create_notice_type("friends_invite_sent", _("Invitation Sent"), _("you have sent an invitation"), default=1)
notification.create_notice_type("friends_accept", _("Acceptance Received"), _("an invitation you sent has been accepted"), default=2)
notification.create_notice_type("friends_accept_sent", _("Acceptance Sent"), _("you have accepted an invitation you received"), default=1)
notification.create_notice_type("friends_otherconnect", _("Other Connection"), _("one of your friends has a new connection"), default=2)
notification.create_notice_type("join_accept", _("Join Invitation Accepted"), _("an invitation you sent to join this site has been accepted"), default=2)

signals.post_syncdb.connect(create_notice_types, sender=notification)
except ImportError:
else:
print "Skipping creation of NoticeTypes as notification app not found"
35 changes: 24 additions & 11 deletions friends/models.py
Expand Up @@ -2,31 +2,29 @@
from random import random

from django.db import models

from django.template.loader import render_to_string
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.utils.hashcompat import sha_constructor

from django.db.models import signals
from django.conf import settings

# favour django-mailer but fall back to django.core.mail
try:
if "mailer" in settings.INSTALLED_APPS:
from mailer import send_mail
except ImportError:
else:
from django.core.mail import send_mail

try:
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
except ImportError:
else:
notification = None

# @@@ this assumes email-confirmation is being used
from emailconfirmation.models import EmailAddress

from django.conf import settings

if "emailconfirmation" in settings.INSTALLED_APPS:
from emailconfirmation.models import EmailAddress
else:
EmailAddress = None

class Contact(models.Model):
"""
Expand Down Expand Up @@ -205,6 +203,21 @@ def new_user(sender, instance, **kwargs):
# @@@ send notification
signals.post_save.connect(new_user, sender=EmailAddress)

if EmailAddress:
def new_user(sender, instance, **kwargs):
if instance.verified:
for join_invitation in JoinInvitation.objects.filter(contact__email=instance.email):
if join_invitation.status not in [5, 7]: # if not accepted or already marked as joined independently
join_invitation.status = 7
join_invitation.save()
# notification will be covered below
for contact in Contact.objects.filter(email=instance.email):
contact.users.add(instance.user)
# @@@ send notification

# only if django-email-notification is installed
signals.post_save.connect(new_user, sender=EmailAddress)

def delete_friendship(sender, instance, **kwargs):
friendship_invitations = FriendshipInvitation.objects.filter(to_user=instance.to_user, from_user=instance.from_user)
for friendship_invitation in friendship_invitations:
Expand Down
17 changes: 11 additions & 6 deletions setup.py
@@ -1,13 +1,13 @@
from setuptools import setup, find_packages

setup(
name='django-friends',
version='0.1.0',
version='0.1.1',
description='friendship, contact and invitation management for the Django web framework',
author='James Tauber',
author_email='jtauber@jtauber.com',
url='http://code.google.com/p/django-friends/',
packages=find_packages(),
url='http://github.com/jtauber/django-friends/',
packages=find_packages(exclude=['friendsdev']),
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Web Environment',
Expand All @@ -17,7 +17,12 @@
'Programming Language :: Python',
'Framework :: Django',
],
include_package_data=True,
include_package_data = True,
package_data = {
'friends': [
'templates/notification/*/*.html',
'templates/notification/*/*.txt',
]
},
zip_safe=False,
install_requires=['setuptools'],
)

0 comments on commit c4d75f5

Please sign in to comment.