本文整理汇总了Python中apps.widgets.notifications.models.UserNotification类的典型用法代码示例。如果您正苦于以下问题:Python UserNotification类的具体用法?Python UserNotification怎么用?Python UserNotification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserNotification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notify_commitment_end
def notify_commitment_end():
"""Notify the user of the end of a commitment period and award their points."""
members = ActionMember.objects.filter(completion_date=datetime.date.today(),
action__type="commitment",
award_date__isnull=True)
# try and load the notification template.
template = None
try:
template = NoticeTemplate.objects.get(notice_type="commitment-ready")
except NoticeTemplate.DoesNotExist:
pass
for member in members:
if template:
message = template.render({"COMMITMENT": member.action})
else:
message = "Your commitment <a href='%s'>%s</a> has ended." % (
reverse("activity_task",
args=(member.action.type, member.action.slug)),
member.action.title)
message += "You can click on the link to claim your points."
UserNotification.create_info_notification(member.user, message,
display_alert=True,
content_object=member)
print "created commitment end notification for %s : %s" % (
member.user, member.action.slug)
示例2: _handle_activity_notification
def _handle_activity_notification(self, status):
"""Creates a notification for rejected or approved tasks.
This also creates an email message if it is configured.
"""
# don't create notification if the action is the SETUP_WIZARD_ACTIVITY
# that is used in the setup wizard.
if self.action.slug == SETUP_WIZARD_ACTIVITY:
return
# Construct the message to be sent.
status_nicely = 'not approved' if status != 'approved' else status
message = 'Your response to <a href="%s#action-details">"%s"</a> %s was %s.' % (
reverse("activity_task", args=(self.action.type, self.action.slug,)),
self.action.title,
# The below is to tell the javascript to convert into a pretty date.
# See the prettyDate function in media/js/makahiki.js
'<span class="rejection-date" title="%s"></span>' % self.submission_date.isoformat(),
status_nicely,
)
if status != 'approved':
message += " You can still get points by clicking on the link and trying again."
UserNotification.create_error_notification(self.user, message, display_alert=True,
content_object=self)
else:
points = self.points_awarded if self.points_awarded else self.action.point_value
message += " You earned %d points!" % points
UserNotification.create_success_notification(self.user, message, display_alert=True,
content_object=self)
示例3: notify_round_started
def notify_round_started():
"""Notify the user of a start of a round."""
if not challenge_mgr.in_competition():
return
today = datetime.datetime.today()
current_round = None
previous_round = None
rounds = challenge_mgr.get_all_round_info()["rounds"]
for key in rounds.keys():
# We're looking for a round that ends today and another that starts
# today (or overall)
start = rounds[key]["start"]
end = rounds[key]["end"]
# Check yesterday's round and check for the current round.
if start < (today - datetime.timedelta(days=1)) < end:
previous_round = key
if start < today < end:
current_round = key
print "Previous Round: %s" % previous_round
print "Current Round: %s" % current_round
if current_round and previous_round and current_round != previous_round:
print "Sending out round transition notices."
template = NoticeTemplate.objects.get(notice_type="round-transition")
message = template.render({"PREVIOUS_ROUND": previous_round, "CURRENT_ROUND": current_round})
for user in User.objects.all():
UserNotification.create_info_notification(user, message, display_alert=True)
示例4: send
def send(self):
"""
Sends a reminder email to the user.
"""
if not self.sent:
challenge = challenge_mgr.get_challenge()
subject = "[%s] Reminder for %s" % (challenge.name, self.action.title)
message = render_to_string(
"email/activity_reminder.txt",
{
"action": self.action,
"user": self.user,
"COMPETITION_NAME": challenge.name,
"domain": challenge.domain,
},
)
html_message = render_to_string(
"email/activity_reminder.html",
{
"action": self.action,
"user": self.user,
"COMPETITION_NAME": challenge.name,
"domain": challenge.domain,
},
)
UserNotification.create_email_notification(self.email_address, subject, message, html_message)
self.sent = True
self.save()
示例5: testAlertNotifications
def testAlertNotifications(self):
"""Test alert."""
alert = UserNotification(recipient=self.user, contents="Alert notification",
display_alert=True)
alert.save()
response = self.client.get(reverse("home_index"))
self.assertContains(response, "notification-dialog", msg_prefix="Alert should be shown")
response = self.client.get(reverse("help_index"))
self.assertNotContains(response, "notification-dialog",
msg_prefix="Dialog should not be displayed")
示例6: _send_winner_notification
def _send_winner_notification(self, prize, leader):
"""send notification."""
if leader and not self._notification_exists(prize, leader):
# Notify winner using the template.
template = NoticeTemplate.objects.get(notice_type='prize-winner')
message = template.render({'PRIZE': prize})
UserNotification.create_info_notification(leader.user, message, True, prize)
challenge = challenge_mgr.get_challenge()
subject = "[%s] Congratulations, you won a prize!" % challenge.name
UserNotification.create_email_notification(
leader.user.email, subject, message, message)
示例7: testAjaxReadNotifications
def testAjaxReadNotifications(self):
"""Test that notifications can be marked as read via AJAX."""
notification = UserNotification(recipient=self.user, contents="Test notification")
notification.save()
response = self.client.post(reverse("notifications_read", args=(notification.pk,)), {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.failUnlessEqual(response.status_code, 200)
response = self.client.get(reverse("home_index"))
self.assertNotContains(response, "Test notification",
msg_prefix="Notification should be read")
示例8: action_feedback
def action_feedback(request, action_type, slug):
"""Handle feedback for an action."""
_ = action_type
action = smartgrid.get_action(slug=slug)
user = request.user
profile = request.user.get_profile()
form = ActionFeedbackForm(request.POST)
if form.is_valid():
#print form.cleaned_data
# should do something ??
pass
feedback, created = ActionFeedback.objects.get_or_create(action=action, user=user)
has_comment = False
has_score = False
if 'Score' in request.POST:
feedback.rating = request.POST['Score']
has_score = True
else:
feedback.rating = 0
if 'comments' in request.POST:
feedback.comment = request.POST['comments']
if len(feedback.comment.strip()) > 0: # ignore pure whitespace comments
has_comment = True
else:
feedback.comment = ""
feedback.changed = datetime.datetime.now()
if has_comment or has_score:
feedback.save() # only save if they provided any feedback
else:
if created:
feedback.delete() # remove the feedback
created = False # reset created for giving points
if created:
# Give the user points for providing feedback
profile.add_points(score_mgr.feedback_points(),
datetime.datetime.today(),
"{0}: {1} (Provide feedback)"\
.format(action.type.capitalize(), action.title), action)
if score_mgr.feedback_points() > 0:
message = "Thank you for your feedback on {0}: {1} you've earned {2} points"\
.format(action.type.capitalize(), action.title, score_mgr.feedback_points())
else:
message = "Thank you for your feedback on {0}: {1}"\
.format(action.type.capitalize(), action.title)
UserNotification.create_info_notification(user, message,
display_alert=True,
content_object=action)
# Take them back to the action page.
return HttpResponseRedirect(reverse("activity_task", args=(action.type, action.slug,)))
示例9: notify_winner
def notify_winner(request):
"""Sends an email to the user notifying them that they are a winner."""
_ = request
round_name = challenge_mgr.get_round_name()
prizes = RafflePrize.objects.filter(round__name=round_name)
for prize in prizes:
if prize.winner:
# Notify winner using the template.
template = NoticeTemplate.objects.get(notice_type='raffle-winner')
message = template.render({'PRIZE': prize})
UserNotification.create_info_notification(prize.winner, message, True, prize)
return HttpResponseRedirect("/admin/raffle/raffleprize/")
示例10: notify_winner
def notify_winner(self, request, queryset):
"""pick winner."""
_ = request
for obj in queryset:
if obj.winner and not self.notice_sent(obj):
# Notify winner using the template.
template = NoticeTemplate.objects.get(notice_type="raffle-winner")
message = template.render({"PRIZE": obj})
UserNotification.create_info_notification(obj.winner, message, True, obj)
challenge = challenge_mgr.get_challenge()
subject = "[%s] Congratulations, you won a prize!" % challenge.name
UserNotification.create_email_notification(obj.winner.email, subject, message, message)
self.message_user(request, "Winners notification sent.")
示例11: save
def save(self, *args, **kwargs):
"""custom save method."""
message = "Congratulations, You have been awarded the {0} badge. ".format(self.badge.name)
message += "<div class=\"badge-theme-{0}-small\"><p>{1}</p></div>".format(self.badge.theme,
self.badge.label)
message += "Check out your badges <a href= %s >here</a>" % "/profile/?ref=dialog"
UserNotification.create_info_notification(
self.profile.user,
message,
True,
content_object=self
)
message = "Badge: %s" % self.badge.name
self.profile.add_points(self.badge.points, self.awarded_at, message, self)
super(BadgeAward, self).save(args, kwargs)
示例12: possibly_completed_quests
def possibly_completed_quests(user):
"""Check if the user may have completed one of their quests.
Returns an array of the completed quests."""
user_quests = user.quest_set.filter(questmember__completed=False, questmember__opt_out=False)
completed = []
for quest in user_quests:
if quest.completed_quest(user):
member = QuestMember.objects.get(user=user, quest=quest)
member.completed = True
member.save()
completed.append(quest)
# Create quest notification.
message = "Congratulations! You completed the '%s' quest." % quest.name
UserNotification.create_success_notification(user, message, display_alert=True)
return completed
示例13: testShowNotifications
def testShowNotifications(self):
"""
Test that we can show notifications to the user.
"""
for i in range(0, 3):
notification = UserNotification(recipient=self.user,
contents="Test notification %i" % i)
notification.save()
response = self.client.get(reverse("home_index"))
self.assertNotContains(response, "The following item(s) need your attention",
msg_prefix="Alert should not be shown"
)
for i in range(0, 3):
self.assertContains(response, "Test notification %i" % i,
msg_prefix="Notification %i is not shown" % i
)
示例14: notify_winner
def notify_winner(self, request, queryset):
"""pick winner."""
_ = request
for obj in queryset:
leader = obj.leader()
if leader and obj.award_to in ('individual_overall', 'individual_team')\
and not self.notice_sent(obj):
# Notify winner using the template.
template = NoticeTemplate.objects.get(notice_type='prize-winner')
message = template.render({'PRIZE': obj})
UserNotification.create_info_notification(leader.user, message, True, obj)
challenge = challenge_mgr.get_challenge()
subject = "[%s] Congratulations, you won a prize!" % challenge.competition_name
UserNotification.create_email_notification(
leader.user.email, subject, message, message)
self.message_user(request, "Winners notification sent.")
示例15: notify_round_started
def notify_round_started():
"""Notify the user of a start of a round."""
if not challenge_mgr.in_competition():
return
today = datetime.datetime.today()
current_round = None
previous_round = None
all_round_info = challenge_mgr.get_all_round_info()
rounds = all_round_info["rounds"]
for key in rounds.keys():
# We're looking for a round that ends today and another that starts
# today (or overall)
start = rounds[key]["start"]
end = rounds[key]["end"]
# Check yesterday's round and check for the current round.
if start < (today - datetime.timedelta(days=1)) < end:
previous_round = key
if start < today < end:
current_round = key
print 'Previous Round: %s' % previous_round
print 'Current Round: %s' % current_round
if current_round and previous_round and current_round != previous_round:
# only carry over the scoreboard entry if the round don't need to be reset
if not rounds[current_round]["round_reset"]:
print "carry over scoreboard entry to new round."
score_mgr.copy_scoreboard_entry(previous_round, current_round)
# if there is a gap, previous_round is null, check if it is not out of round
if current_round and current_round != previous_round and\
all_round_info["competition_start"] <= today <= all_round_info["competition_end"]:
print 'Sending out round transition notices.'
template = NoticeTemplate.objects.get(notice_type="round-transition")
message = template.render({"PREVIOUS_ROUND": previous_round,
"CURRENT_ROUND": current_round, })
for user in User.objects.all():
UserNotification.create_info_notification(user, message,
display_alert=True,)