예제 #1
0
def create_notification(request, form):
    """Create a new notification for the post's author about new comment."""
    # validate comment user is not the same than post user
    post = form.cleaned_data.get('post')
    if request.user != User.objects.get(pk=post.user.id):
        notification = Notification()
        notification.origin_user = request.user
        notification.target_user = User.objects.get(pk=post.user.id)
        notification.message = f'@{request.user} ' + _(
            'commented in your post:') + f' {post.title}'
        notification.url = reverse('post', args=[post.id])
        notification.save()
예제 #2
0
def create_notification(user):
    """Notify a user about its new summary report."""

    notification = Notification()
    notification.target_user = user
    sr = ''
    if user.summary_reports == 'D':
        sr = 'Your daily summary report is here.'
    elif user.summary_reports == 'W':
        sr = 'Your weekly summary report is here.'
    elif user.summary_reports == 'M':
        sr = 'Your monthly summary report is here.'
    notification.message = sr
    notification.url = reverse('summary_report')
    notification.save()