Example #1
0
def notify_user(user, message, url, trigger=None, formats=None, sender=None,
                update_user=True):
    from misago.notifications.models import Notification

    message_escaped = escape(message)
    if formats:
        final_formats = {}
        for format, replace in formats.items():
            final_formats[format] = '<strong>%s</strong>' % escape(replace)
        message_escaped = message_escaped % final_formats

    new_notification = Notification(user=user,
                                    trigger=hash_trigger(trigger or message),
                                    url=url,
                                    message=message_escaped)

    if sender:
        new_notification.sender = sender
        new_notification.sender_username = sender.username
        new_notification.sender_slug = sender.slug

    new_notification.save()

    update_checksum(new_notification)
    new_notification.save(update_fields=['checksum'])

    user.new_notifications = F('new_notifications') + 1
    if update_user:
        user.save(update_fields=['new_notifications'])
    return new_notification
Example #2
0
def notify_user(user,
                message,
                url,
                trigger=None,
                formats=None,
                sender=None,
                update_user=True):
    from misago.notifications.models import Notification

    message_escaped = escape(message)
    if formats:
        final_formats = {}
        for format, replace in formats.items():
            final_formats[format] = '<strong>%s</strong>' % escape(replace)
        message_escaped = message_escaped % final_formats

    new_notification = Notification(user=user,
                                    trigger=hash_trigger(trigger or message),
                                    url=url,
                                    message=message_escaped)

    if sender:
        new_notification.sender = sender
        new_notification.sender_username = sender.username
        new_notification.sender_slug = sender.slug

    new_notification.save()

    update_checksum(new_notification)
    new_notification.save(update_fields=['checksum'])

    user.new_notifications = F('new_notifications') + 1
    if update_user:
        user.save(update_fields=['new_notifications'])
    return new_notification
Example #3
0
def _real_read_user_notification(user, trigger):
    trigger_hash = hash_trigger(trigger)
    update_qs = user.misago_notifications.filter(is_new=True)
    update_qs = update_qs.filter(trigger=trigger_hash)
    updated = update_qs.update(is_new=False)

    if updated:
        user.new_notifications -= updated
        if user.new_notifications < 0:
            # Cos no. of changed rows returned via update()
            # isn't always accurate
            user.new_notifications = 0
        user.save(update_fields=['new_notifications'])
Example #4
0
def _real_read_user_notification(user, trigger):
    trigger_hash = hash_trigger(trigger)
    update_qs = user.misago_notifications.filter(is_new=True)
    update_qs = update_qs.filter(trigger=trigger_hash)
    updated = update_qs.update(is_new=False)

    if updated:
        user.new_notifications -= updated
        if user.new_notifications < 0:
            # Cos no. of changed rows returned via update()
            # isn't always accurate
            user.new_notifications = 0
        user.save(update_fields=['new_notifications'])