from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

from zinnia.models import Entry

from astrobin.notifications import push_notification

class Command(BaseCommand):
    help = "Notifies all users about most recent blog entry."

    def handle(self, *args, **options):
        entry = Entry.objects.all()[0]
        push_notification(
            User.objects.all(),
            'new_blog_entry',
            {
                'object': entry.title,
                'object_url': entry.get_absolute_url()
            }
        )

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

import persistent_messages
from zinnia.models import Entry


class Command(BaseCommand):
    help = "Notifies all users about most recent blog entry."

    def handle(self, *args, **options):
        entry = Entry.objects.all()[0]
        for u in User.objects.all():
            m = persistent_messages.models.Message(
                user = u,
                from_user = User.objects.get(username = 'astrobin'),
                message = '<a href="' + entry.get_absolute_url() + '">New blog entry: <strong>' + entry.title + '</strong></a>',
                level = persistent_messages.INFO,
            )
            m.save()

Fix management command to send notification about new blog post.
Fix management command to send notification about new blog post.

  from django.core.management.base import BaseCommand
  from django.contrib.auth.models import User
  
+ import persistent_messages
  from zinnia.models import Entry
  
- from astrobin.notifications import push_notification
  
  class Command(BaseCommand):
      help = "Notifies all users about most recent blog entry."
  
      def handle(self, *args, **options):
          entry = Entry.objects.all()[0]
-         push_notification(
-             User.objects.all(),
+         for u in User.objects.all():
-             'new_blog_entry',
+             m = persistent_messages.models.Message(
+                 user = u,
+                 from_user = User.objects.get(username = 'astrobin'),
+                 message = '<a href="' + entry.get_absolute_url() + '">New blog entry: <strong>' + entry.title + '</strong></a>',
+                 level = persistent_messages.INFO,
-             {
+             )
+             m.save()
-                 'object': entry.title,
-                 'object_url': entry.get_absolute_url()
-             }
-         )
  
Fix management command to send notification about new blog post.
## Code Before:
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

from zinnia.models import Entry

from astrobin.notifications import push_notification

class Command(BaseCommand):
    help = "Notifies all users about most recent blog entry."

    def handle(self, *args, **options):
        entry = Entry.objects.all()[0]
        push_notification(
            User.objects.all(),
            'new_blog_entry',
            {
                'object': entry.title,
                'object_url': entry.get_absolute_url()
            }
        )

## Instruction:
Fix management command to send notification about new blog post.
## Code After:
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

import persistent_messages
from zinnia.models import Entry


class Command(BaseCommand):
    help = "Notifies all users about most recent blog entry."

    def handle(self, *args, **options):
        entry = Entry.objects.all()[0]
        for u in User.objects.all():
            m = persistent_messages.models.Message(
                user = u,
                from_user = User.objects.get(username = 'astrobin'),
                message = '<a href="' + entry.get_absolute_url() + '">New blog entry: <strong>' + entry.title + '</strong></a>',
                level = persistent_messages.INFO,
            )
            m.save()
