
from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

try:
    from notification import models as notification
except ImportError:
    notification = None

from announcements.models import Announcement

class AnnouncementAdminForm(forms.ModelForm):
    """
    A custom form for the admin of the Announcment model. Has an extra field
    called send_now that when checked will send out the announcment allowing
    the user to decide when that happens.
    """
    send_now = forms.BooleanField(required=False,
        help_text=_("Send out this announcement now."))
    
    class Meta:
        model = Announcement
    
    def save(self, commit=True):
        """
        Checks the send_now field in the form and when True sends out the
        announcement through notification if present.
        """
        announcement = super(AnnouncementAdminForm, self).save(commit)
        if self.cleaned_data["send_now"]:
            if notification:
                users = User.objects.all()
                notification.queue(users, "announcement", {
                    "announcement": announcement,
                }, on_site=False)
        return announcement


from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

try:
    from notification import models as notification
except ImportError:
    notification = None

from announcements.models import Announcement

class AnnouncementAdminForm(forms.ModelForm):
    """
    A custom form for the admin of the Announcment model. Has an extra field
    called send_now that when checked will send out the announcment allowing
    the user to decide when that happens.
    """
    send_now = forms.BooleanField(required=False,
        help_text=_("Send out this announcement now."))
    
    class Meta:
        model = Announcement
    
    def save(self, commit=True):
        """
        Checks the send_now field in the form and when True sends out the
        announcement through notification if present.
        """
        announcement = super(AnnouncementAdminForm, self).save(commit)
        if self.cleaned_data["send_now"]:
            if notification:
                users = User.objects.all()
                notification.send(users, "announcement", {
                    "announcement": announcement,
                }, on_site=False, queue=True)
        return announcement

Use the new interface to notification.send to explicitly override the default behavior and queue notifications for announcements.
Use the new interface to notification.send to explicitly override the default behavior and queue notifications for announcements.

git-svn-id: 0d26805d86c51913b6a91884701d7ea9499c7fc0@37 4e50ab13-fc4d-0410-b010-e1608ea6a288
