from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from cms.toolbar_pool import toolbar_pool
from cms.toolbar_base import CMSToolbar

from aldryn_blog import request_post_identifier


@toolbar_pool.register
class BlogToolbar(CMSToolbar):
    def populate(self):
        if not (self.is_current_app and self.request.user.has_perm('aldryn_blog.add_post')):
            return
        menu = self.toolbar.get_or_create_menu('blog-app', _('Blog'))
        menu.add_modal_item(_('Add Blog Post'), reverse('admin:aldryn_blog_post_add') + '?_popup',
                            close_on_url=reverse('admin:aldryn_blog_post_changelist'))

        blog_entry = getattr(self.request, request_post_identifier, None)
        if blog_entry and self.request.user.has_perm('aldryn_blog.change_post'):
            menu.add_modal_item(_('Edit Blog Post'), reverse('admin:aldryn_blog_post_change', args=(
                blog_entry.pk,)) + '?_popup',
                close_on_url=reverse('admin:aldryn_blog_post_changelist'), active=True)

from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from cms.toolbar_pool import toolbar_pool
from cms.toolbar_base import CMSToolbar

from aldryn_blog import request_post_identifier


@toolbar_pool.register
class BlogToolbar(CMSToolbar):
    def populate(self):
        if not (self.is_current_app and self.request.user.has_perm('aldryn_blog.add_post')):
            return
        menu = self.toolbar.get_or_create_menu('blog-app', _('Blog'))
        menu.add_modal_item(_('Add Blog Post'), reverse('admin:aldryn_blog_post_add'),
                            close_on_url=reverse('admin:aldryn_blog_post_changelist'))

        blog_entry = getattr(self.request, request_post_identifier, None)
        if blog_entry and self.request.user.has_perm('aldryn_blog.change_post'):
            menu.add_modal_item(_('Edit Blog Post'), reverse('admin:aldryn_blog_post_change', args=(
                blog_entry.pk,)),
                close_on_url=reverse('admin:aldryn_blog_post_changelist'), active=True)

Remove '?_popup' from toolbar urls
Remove '?_popup' from toolbar urls

  from django.core.urlresolvers import reverse
  from django.utils.translation import ugettext_lazy as _
  
  from cms.toolbar_pool import toolbar_pool
  from cms.toolbar_base import CMSToolbar
  
  from aldryn_blog import request_post_identifier
  
  
  @toolbar_pool.register
  class BlogToolbar(CMSToolbar):
      def populate(self):
          if not (self.is_current_app and self.request.user.has_perm('aldryn_blog.add_post')):
              return
          menu = self.toolbar.get_or_create_menu('blog-app', _('Blog'))
-         menu.add_modal_item(_('Add Blog Post'), reverse('admin:aldryn_blog_post_add') + '?_popup',
+         menu.add_modal_item(_('Add Blog Post'), reverse('admin:aldryn_blog_post_add'),
                              close_on_url=reverse('admin:aldryn_blog_post_changelist'))
  
          blog_entry = getattr(self.request, request_post_identifier, None)
          if blog_entry and self.request.user.has_perm('aldryn_blog.change_post'):
              menu.add_modal_item(_('Edit Blog Post'), reverse('admin:aldryn_blog_post_change', args=(
-                 blog_entry.pk,)) + '?_popup',
+                 blog_entry.pk,)),
                  close_on_url=reverse('admin:aldryn_blog_post_changelist'), active=True)
  
Remove '?_popup' from toolbar urls
## Code Before:
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from cms.toolbar_pool import toolbar_pool
from cms.toolbar_base import CMSToolbar

from aldryn_blog import request_post_identifier


@toolbar_pool.register
class BlogToolbar(CMSToolbar):
    def populate(self):
        if not (self.is_current_app and self.request.user.has_perm('aldryn_blog.add_post')):
            return
        menu = self.toolbar.get_or_create_menu('blog-app', _('Blog'))
        menu.add_modal_item(_('Add Blog Post'), reverse('admin:aldryn_blog_post_add') + '?_popup',
                            close_on_url=reverse('admin:aldryn_blog_post_changelist'))

        blog_entry = getattr(self.request, request_post_identifier, None)
        if blog_entry and self.request.user.has_perm('aldryn_blog.change_post'):
            menu.add_modal_item(_('Edit Blog Post'), reverse('admin:aldryn_blog_post_change', args=(
                blog_entry.pk,)) + '?_popup',
                close_on_url=reverse('admin:aldryn_blog_post_changelist'), active=True)

## Instruction:
Remove '?_popup' from toolbar urls
## Code After:
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from cms.toolbar_pool import toolbar_pool
from cms.toolbar_base import CMSToolbar

from aldryn_blog import request_post_identifier


@toolbar_pool.register
class BlogToolbar(CMSToolbar):
    def populate(self):
        if not (self.is_current_app and self.request.user.has_perm('aldryn_blog.add_post')):
            return
        menu = self.toolbar.get_or_create_menu('blog-app', _('Blog'))
        menu.add_modal_item(_('Add Blog Post'), reverse('admin:aldryn_blog_post_add'),
                            close_on_url=reverse('admin:aldryn_blog_post_changelist'))

        blog_entry = getattr(self.request, request_post_identifier, None)
        if blog_entry and self.request.user.has_perm('aldryn_blog.change_post'):
            menu.add_modal_item(_('Edit Blog Post'), reverse('admin:aldryn_blog_post_change', args=(
                blog_entry.pk,)),
                close_on_url=reverse('admin:aldryn_blog_post_changelist'), active=True)
