forked from pinax/pinax-notifications
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added notice model and increased medium length
- Loading branch information
Showing
9 changed files
with
254 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
from django.template.loader import render_to_string | ||
from django.utils.translation import ugettext | ||
|
||
from .base import BaseBackend | ||
|
||
|
||
class EmailBackend(BaseBackend): | ||
spam_sensitivity = 2 | ||
|
||
def can_send(self, user, notice_type, scoping): | ||
can_send = super(EmailBackend, self).can_send(user, notice_type, scoping) | ||
if can_send and user.email: | ||
return True | ||
return False | ||
|
||
def deliver(self, recipient, sender, notice_type, extra_context): | ||
# TODO: require this to be passed in extra_context | ||
|
||
context = self.default_context() | ||
context.update({ | ||
"recipient": recipient, | ||
"sender": sender, | ||
"notice": ugettext(notice_type.display), | ||
}) | ||
context.update(extra_context) | ||
|
||
messages = self.get_formatted_messages(( | ||
"short.txt", | ||
"full.txt" | ||
), notice_type.label, context) | ||
|
||
context.update({ | ||
"message": messages["short.txt"], | ||
}) | ||
subject = "".join(render_to_string("pinax/notifications/email_subject.txt", context).splitlines()) | ||
|
||
context.update({ | ||
"message": messages["full.txt"] | ||
}) | ||
body = render_to_string("pinax/notifications/email_body.txt", context) | ||
|
||
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [recipient.email]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
from django.template.loader import render_to_string | ||
from django.utils.translation import ugettext | ||
|
||
from .base import BaseBackend | ||
|
||
|
||
class EmailBackend(BaseBackend): | ||
spam_sensitivity = 2 | ||
|
||
def can_send(self, user, notice_type, scoping): | ||
can_send = super(EmailBackend, self).can_send(user, notice_type, scoping) | ||
if can_send and user.email: | ||
return True | ||
return False | ||
|
||
def deliver(self, recipient, sender, notice_type, extra_context): | ||
# TODO: require this to be passed in extra_context | ||
|
||
context = self.default_context() | ||
context.update({ | ||
"recipient": recipient, | ||
"sender": sender, | ||
"notice": ugettext(notice_type.display), | ||
}) | ||
context.update(extra_context) | ||
|
||
messages = self.get_formatted_messages(( | ||
"short.txt", | ||
"full.txt" | ||
), notice_type.label, context) | ||
|
||
context.update({ | ||
"message": messages["short.txt"], | ||
}) | ||
subject = "".join(render_to_string("pinax/notifications/email_subject.txt", context).splitlines()) | ||
|
||
context.update({ | ||
"message": messages["full.txt"] | ||
}) | ||
body = render_to_string("pinax/notifications/email_body.txt", context) | ||
|
||
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [recipient.email]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
from django.conf import settings | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('pinax_notifications', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Notice', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('message', models.TextField(verbose_name='message')), | ||
('added', models.DateTimeField(default=django.utils.timezone.now, verbose_name='added', db_index=True)), | ||
('unseen', models.BooleanField(default=True, db_index=True, verbose_name='unseen')), | ||
('archived', models.BooleanField(default=False, verbose_name='archived')), | ||
('on_site', models.BooleanField(default=False, verbose_name='on site')), | ||
('notice_type', models.ForeignKey(verbose_name='notice type', to='pinax_notifications.NoticeType')), | ||
('recipient', models.ForeignKey(related_name='received_notices', verbose_name='recipient', to=settings.AUTH_USER_MODEL)), | ||
('sender', models.ForeignKey(related_name='sent_notices', verbose_name='sender', to=settings.AUTH_USER_MODEL, null=True)), | ||
], | ||
options={ | ||
'verbose_name': 'notice', | ||
'verbose_name_plural': 'notices', | ||
}, | ||
), | ||
migrations.AlterField( | ||
model_name='noticesetting', | ||
name='medium', | ||
field=models.CharField(max_length=100, verbose_name='medium', choices=[(0, 'email')]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32ecab7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the changes that were not merged at the time from pinax#36 and brought back the Notice model from https://github.com/jtauber-archive/django-notification/blob/d50bdfb97a58529662d911fcbeb216083cee8879/notification/models.py that basically works as a log for sent notifications.