示例#1
0
    def ready(self):

        # ensure that current LeprikonSite exists
        from .models.leprikonsite import LeprikonSite
        try:
            LeprikonSite.objects.get_current()
        except:
            pass

        # create leprikon page on first run
        from cms.api import create_page
        from cms.constants import TEMPLATE_INHERITANCE_MAGIC
        from menus.menu_pool import menu_pool
        from .conf import settings
        try:
            create_page(
                title='Leprikón',
                template=TEMPLATE_INHERITANCE_MAGIC,
                language=settings.LANGUAGE_CODE,
                slug='leprikon',
                apphook='LeprikonApp',
                apphook_namespace='leprikon',
                reverse_id='leprikon',
                in_navigation=True,
                navigation_extenders='LeprikonMenu',
                published=True,
            ).set_as_homepage()
            menu_pool.clear()
        except:
            pass
示例#2
0
 def test_15_home_not_in_menu(self):
     page1 = Page.objects.get(pk=self.get_page(1).pk)
     page1.in_navigation = False
     page1.save()
     page4 = Page.objects.get(pk=self.get_page(4).pk)
     page4.in_navigation = False
     page4.save()
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context)
     nodes = context['children']
     self.assertEqual(len(nodes), 1)
     self.assertEqual(
         nodes[0].get_absolute_url(),
         "%s%s/" % (self.get_pages_root(), self.get_page(2).get_slug()))
     self.assertEqual(
         nodes[0].children[0].get_absolute_url(),
         "%s%s/%s/" % (self.get_pages_root(), self.get_page(2).get_slug(),
                       self.get_page(3).get_slug()))
     page4 = Page.objects.get(pk=self.get_page(4).pk)
     page4.in_navigation = True
     page4.save()
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context)
     nodes = context['children']
     self.assertEqual(len(nodes), 2)
示例#3
0
 def setUp(self):
     super(BaseMenuTest, self).setUp()
     if not menu_pool.discovered:
         menu_pool.discover_menus()
     self.old_menu = menu_pool.menus
     menu_pool.menus = {'CMSMenu': self.old_menu['CMSMenu']}
     menu_pool.clear(settings.SITE_ID)
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    page = instance.page
    page_languages = page.get_languages()

    if not instance.language in page_languages:
        page_languages.append(instance.language)
        page.update_languages(page_languages)

    if not page.publisher_is_draft:
        menu_pool.clear(page.site_id)

    if instance.pk and not hasattr(instance, "tmp_path"):
        instance.tmp_path = None
        try:
            instance.tmp_path = Title.objects.filter(
                pk=instance.pk).values_list('path')[0][0]
        except IndexError:
            pass  # no Titles exist for this page yet
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
    apphook_pre_title_checker(instance, **kwargs)
示例#5
0
    def ready(self):

        # ensure that current LeprikonSite exists
        from .models.leprikonsite import LeprikonSite
        try:
            LeprikonSite.objects.get_current()
        except Exception:
            pass

        # create leprikon page on first run
        from cms.api import create_page
        from cms.constants import TEMPLATE_INHERITANCE_MAGIC
        from menus.menu_pool import menu_pool

        from .conf import settings
        try:
            create_page(
                title='Leprikón',
                template=TEMPLATE_INHERITANCE_MAGIC,
                language=settings.LANGUAGE_CODE,
                slug='leprikon',
                apphook='LeprikonApp',
                apphook_namespace='leprikon',
                reverse_id='leprikon',
                in_navigation=True,
                navigation_extenders='LeprikonMenu',
                published=True,
            ).set_as_homepage()
            menu_pool.clear()
        except Exception:
            pass
示例#6
0
 def process_request(self, request):
     """
     If we should show the toolbar for this request, put it on
     request.toolbar. Then call the request_hook on the toolbar.
     """
     if 'edit' in request.GET and not request.session.get('cms_edit', False):
         if not request.session.get('cms_edit', False):
             menu_pool.clear()
         request.session['cms_edit'] = True
         if request.session.get('cms_build', False):
             request.session['cms_build'] = False
     if 'edit_off' in request.GET and request.session.get('cms_edit', True):
         if request.session.get('cms_edit', True):
             menu_pool.clear()
         request.session['cms_edit'] = False
         if request.session.get('cms_build', False):
             request.session['cms_build'] = False
     if 'build' in request.GET and not request.session.get('cms_build', False):
         request.session['cms_build'] = True
     if request.user.is_staff:
         try:
             request.cms_latest_entry = LogEntry.objects.filter(
                 user=request.user,
                 action_flag__in=(ADDITION, CHANGE)
             ).only('pk').order_by('-pk')[0].pk
         except IndexError:
             request.cms_latest_entry = -1
     request.toolbar = CMSToolbar(request)
示例#7
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    if instance.page.languages:
        languages = instance.page.languages.split(',')
    else:
        languages = []
    if not instance.language in languages:
        languages.append(instance.language)
        instance.page.languages = ",".join(languages)
        instance.page._publisher_keep_state = True
        instance.page.save(no_signals=True)
    if not instance.page.publisher_is_draft:
        menu_pool.clear(instance.page.site_id)
    if instance.pk and not hasattr(instance, "tmp_path"):
        instance.tmp_path = None
        try:
            instance.tmp_path = Title.objects.filter(pk=instance.pk).values_list('path')[0][0]
        except IndexError:
            pass  # no Titles exist for this page yet
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
    apphook_pre_title_checker(instance, **kwargs)
示例#8
0
 def process_request(self, request):
     """
     If we should show the toolbar for this request, put it on
     request.toolbar. Then call the request_hook on the toolbar.
     """
     if 'edit' in request.GET and not request.session.get(
             'cms_edit', False):
         if not request.session.get('cms_edit', False):
             menu_pool.clear()
         request.session['cms_edit'] = True
         if request.session.get('cms_build', False):
             request.session['cms_build'] = False
     if 'edit_off' in request.GET and request.session.get('cms_edit', True):
         if request.session.get('cms_edit', True):
             menu_pool.clear()
         request.session['cms_edit'] = False
         if request.session.get('cms_build', False):
             request.session['cms_build'] = False
     if 'build' in request.GET and not request.session.get(
             'cms_build', False):
         request.session['cms_build'] = True
     if request.user.is_staff:
         request.session['cms_log_entries'] = LogEntry.objects.filter(
             user=request.user).count()
     request.toolbar = CMSToolbar(request)
示例#9
0
 def _reload_menus(self):
     menu_pool.clear(all=True)
     menu_pool.discover_menus()
     # All cms menu modifiers should be removed from menu_pool.modifiers
     # so that they do not interfere with our menu nodes
     menu_pool.modifiers = [m for m in menu_pool.modifiers if m.__module__.startswith("djangocms_blog")]
     self._reset_menus()
示例#10
0
 def set_status(self, new_status, all_producers=True, producers_id=None):
     if all_producers:
         now = timezone.now()
         self.is_updated_on = now
         self.status = new_status
         if self.highest_status < new_status:
             self.highest_status = new_status
         self.save(update_fields=['status', 'is_updated_on', 'highest_status'])
         invoice.CustomerInvoice.objects.filter(
             delivery_id=self.id
         ).order_by('?').update(
             status=new_status
         )
         purchase.Purchase.objects.filter(
             customer_invoice__delivery_id=self.id
         ).order_by('?').update(
             status=new_status)
         menu_pool.clear()
         cache.clear()
     else:
         purchase.Purchase.objects.filter(
             customer_invoice__delivery_id=self.id,
             producer__in=producers_id
         ).order_by('?').update(
             status=new_status
         )
示例#11
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    if instance.page.languages:
        languages = instance.page.languages.split(',')
    else:
        languages = []
    if not instance.language in languages:
        languages.append(instance.language)
        instance.page.languages = ",".join(languages)
        instance.page._publisher_keep_state = True
        instance.page.save(no_signals=True)
    if not instance.page.publisher_is_draft:
        menu_pool.clear(instance.page.site_id)
    if instance.pk and not hasattr(instance, "tmp_path"):
        instance.tmp_path = None
        try:
            instance.tmp_path = Title.objects.filter(
                pk=instance.pk).values_list('path')[0][0]
        except IndexError:
            pass  # no Titles exist for this page yet
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
    apphook_pre_title_checker(instance, **kwargs)
示例#12
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    page = instance.page
    page_languages = page.get_languages()

    if not instance.language in page_languages:
        page_languages.append(instance.language)
        page.update_languages(page_languages)

    if not page.publisher_is_draft:
        menu_pool.clear(page.site_id)

    if instance.pk and not hasattr(instance, "tmp_path"):
        instance.tmp_path = None
        try:
            instance.tmp_path = Title.objects.filter(pk=instance.pk).values_list("path")[0][0]
        except IndexError:
            pass  # no Titles exist for this page yet
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
    apphook_pre_title_checker(instance, **kwargs)
示例#13
0
 def test_15_home_not_in_menu(self):
     with SettingsOverride(CMS_MODERATOR=False):
 
         page1 = Page.objects.get(pk=self.page1.pk)
         page1.in_navigation = False
         page1.save()
         page4 = Page.objects.get(pk=self.page4.pk)
         page4.in_navigation = False
         page4.save()
         context = self.get_context()
         tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
         tpl.render(context) 
         nodes = context['children']
         self.assertEqual(len(nodes), 1)
         self.assertEqual(nodes[0].get_absolute_url(), "%s%s/" % (self.get_pages_root(), self.page2.get_slug()))
         self.assertEqual(nodes[0].children[0].get_absolute_url(), "%s%s/%s/" % (self.get_pages_root(), self.page2.get_slug(), self.page3.get_slug()))
         page4 = Page.objects.get(pk=self.page4.pk)
         page4.in_navigation = True
         page4.save()
         menu_pool.clear(settings.SITE_ID)
         context = self.get_context()
         tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
         tpl.render(context) 
         nodes = context['children']
         self.assertEqual(len(nodes), 2)
示例#14
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    
    menu_pool.clear(instance.page.site_id)
    
    instance.tmp_path = None
    instance.tmp_application_urls = None
    
    if instance.id:
        try:
            tmp_title = Title.objects.get(pk=instance.id)
            instance.tmp_path = tmp_title.path
            instance.tmp_application_urls = tmp_title.application_urls
        except:
            pass # no Titles exist for this page yet
    
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        parent_page = instance.page.parent
        slug = u'%s' % instance.slug
        
        instance.path = u'%s' % slug
        if parent_page:
            parent_title = Title.objects.get_title(parent_page, language=instance.language, language_fallback=True)
            if parent_title:
                instance.path = (u'%s/%s' % (parent_title.path, slug)).lstrip("/")
示例#15
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    
    menu_pool.clear(instance.page.site_id)
    
    instance.tmp_path = None
    instance.tmp_application_urls = None
    
    if instance.id:
        try:
            tmp_title = Title.objects.get(pk=instance.id)
            instance.tmp_path = tmp_title.path
            instance.tmp_application_urls = tmp_title.application_urls
        except:
            pass # no Titles exist for this page yet
    
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        parent_page = instance.page.parent
        slug = u'%s' % instance.slug
        
        instance.path = u'%s' % slug
        if parent_page:
            parent_title = Title.objects.get_title(parent_page, language=instance.language, language_fallback=True)
            if parent_title:
                instance.path = (u'%s/%s' % (parent_title.path, slug)).lstrip("/")
 def save_model(self, request, obj, form, change):
     """
     Clear menu cache when changing menu structure
     """
     if 'config.menu_structure' in form.changed_data:
         from menus.menu_pool import menu_pool
         menu_pool.clear(all=True)
     return super(BlogConfigAdmin, self).save_model(request, obj, form, change)
示例#17
0
def pre_delete_page(instance, **kwargs):
    menu_pool.clear(instance.site_id)
    for placeholder in instance.get_placeholders():
        for plugin in placeholder.cmsplugin_set.all().order_by('-depth'):
            plugin._no_reorder = True
            plugin.delete(no_mp=True)
        placeholder.delete()
    clear_permission_cache()
示例#18
0
 def test_incorrect_nav_extender_in_db(self):
     self._update_page(2, navigation_extenders="SomethingWrong")
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context["children"]
     self.assertEqual(len(nodes), 2)
示例#19
0
def pre_save_page(instance, **kwargs):
    instance.old_page = None
    try:
        instance.old_page = Page.objects.get(pk=instance.pk)
    except ObjectDoesNotExist:
        pass
    menu_pool.clear(instance.site_id)
    clear_permission_cache()
示例#20
0
def pre_delete_page(instance, **kwargs):
    menu_pool.clear(instance.site_id)
    for placeholder in instance.placeholders.all():
        for plugin in placeholder.cmsplugin_set.all():
            plugin._no_reorder = True
            plugin.delete()
        placeholder.delete()
    clear_permission_cache()
示例#21
0
def pre_delete_page(instance, **kwargs):
    menu_pool.clear(instance.site_id)
    for placeholder in instance.get_placeholders():
        for plugin in placeholder.get_plugins().order_by('-depth'):
            plugin._no_reorder = True
            plugin.delete(no_mp=True)
        placeholder.delete()
    clear_permission_cache()
示例#22
0
 def save_model(self, request, obj, form, change):
     """
     Clear menu cache when changing menu structure
     """
     if 'config.menu_structure' in form.changed_data:
         from menus.menu_pool import menu_pool
         menu_pool.clear(all=True)
     return super(BlogConfigAdmin, self).save_model(request, obj, form, change)
示例#23
0
 def test_incorrect_nav_extender_in_db(self):
     self._update_page(2, navigation_extenders="SomethingWrong")
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['children']
     self.assertEqual(len(nodes), 2)
示例#24
0
 def handle(self, *args, **options):
     permanence = Permanence.objects.filter(id=6).order_by('?').first()
     if PERMANENCE_PLANNED == permanence.status and permanence.highest_status == PERMANENCE_SEND:
         OfferItem.objects.filter(permanence_id=permanence.id).update(is_active=True)
         permanence.status = PERMANENCE_SEND
         permanence.save(update_fields=['status'])
         menu_pool.clear()
         cache.clear()
示例#25
0
def pre_save_page(instance, **kwargs):
    instance.old_page = None
    try:
        instance.old_page = Page.objects.get(pk=instance.pk)
    except ObjectDoesNotExist:
        pass
    menu_pool.clear(instance.site_id)
    clear_permission_cache()
示例#26
0
def pre_delete_page(instance, **kwargs):
    menu_pool.clear(instance.site_id)
    for placeholder in instance.placeholders.all():
        for plugin in placeholder.cmsplugin_set.all():
            plugin._no_reorder = True
            plugin.delete()
        placeholder.delete()
    clear_permission_cache()
示例#27
0
 def handle(self, *args, **options):
     permanence = Permanence.objects.filter(id=6).order_by('?').first()
     if PERMANENCE_PLANNED == permanence.status and permanence.highest_status == PERMANENCE_SEND:
         OfferItem.objects.filter(permanence_id=permanence.id).update(
             is_active=True)
         permanence.status = PERMANENCE_SEND
         permanence.save(update_fields=['status'])
         menu_pool.clear()
         cache.clear()
示例#28
0
 def test_extenders_on_root_child(self):
     self._update_page(4, navigation_extenders="TestMenu")
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context)
     nodes = context['children']
     self.assertEqual(len(nodes), 2)
     self.assertEqual(len(nodes[1].children), 4)
示例#29
0
 def test_extenders_on_root_child(self):
     self._update_page(4, navigation_extenders="TestMenu")
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context)
     nodes = context["children"]
     self.assertEqual(len(nodes), 2)
     self.assertEqual(len(nodes[1].children), 4)
示例#30
0
def pre_save_page(instance, raw, **kwargs):
    """Helper pre save signal, assigns old_page attribute, so we can still
    compare changes. Currently used only if CMS_PUBLISHER
    """
    menu_pool.clear(instance.site_id)
    instance.old_page = None
    try:
        instance.old_page = Page.objects.get(pk=instance.pk)
    except ObjectDoesNotExist:
        pass
示例#31
0
 def setUp(self):
     super(BaseMenuTest, self).setUp()
     u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
     u.set_password("test")
     u.save()
     self.login_user(u)
     if not menu_pool.discovered:
         menu_pool.discover_menus()
     self.old_menu = menu_pool.menus
     menu_pool.menus = {'CMSMenu':self.old_menu['CMSMenu']}
     menu_pool.clear(settings.SITE_ID)
    def process_request(self, request):
        """
        If we should show the toolbar for this request, put it on
        request.toolbar. Then call the request_hook on the toolbar.
        """

        if not self.is_cms_request(request):
            return

        edit_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
        edit_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF')
        build = get_cms_setting('CMS_TOOLBAR_URL__BUILD')
        disable = get_cms_setting('CMS_TOOLBAR_URL__DISABLE')
        anonymous_on = get_cms_setting('TOOLBAR_ANONYMOUS_ON')

        if disable in request.GET:
            request.session['cms_toolbar_disabled'] = True
        if edit_on in request.GET:  # If we actively enter edit mode, we should show the toolbar in any case
            request.session['cms_toolbar_disabled'] = False

        if not request.session.get('cms_toolbar_disabled', False) and (
                request.user.is_staff or
            (anonymous_on and request.user.is_anonymous())):
            if edit_on in request.GET and not request.session.get(
                    'cms_edit', False):
                if not request.session.get('cms_edit', False):
                    menu_pool.clear()
                request.session['cms_edit'] = True
                if request.session.get('cms_build', False):
                    request.session['cms_build'] = False
            if edit_off in request.GET and request.session.get(
                    'cms_edit', True):
                if request.session.get('cms_edit', True):
                    menu_pool.clear()
                request.session['cms_edit'] = False
                if request.session.get('cms_build', False):
                    request.session['cms_build'] = False
            if build in request.GET and not request.session.get(
                    'cms_build', False):
                request.session['cms_build'] = True
        else:
            if request.session.get('cms_build'):
                request.session['cms_build'] = False
            if request.session.get('cms_edit'):
                request.session['cms_edit'] = False
        if request.user.is_staff:
            try:
                request.cms_latest_entry = LogEntry.objects.filter(
                    user=request.user,
                    action_flag__in=(ADDITION,
                                     CHANGE)).only('pk').order_by('-pk')[0].pk
            except IndexError:
                request.cms_latest_entry = -1
        request.toolbar = CMSToolbar(request)
示例#33
0
 def setUp(self):
     super(BaseMenuTest, self).setUp()
     u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
     u.set_password("test")
     u.save()
     self.login_user(u)
     if not menu_pool.discovered:
         menu_pool.discover_menus()
     self.old_menu = menu_pool.menus
     menu_pool.menus = {'CMSMenu':self.old_menu['CMSMenu']}
     menu_pool.clear(settings.SITE_ID)
示例#34
0
 def setUp(self):
     settings.CMS_MODERATOR = False
     u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
     u.set_password("test")
     u.save()
     self.login_user(u)
     if not menu_pool.discovered:
         menu_pool.discover_menus()
     self.old_menu = menu_pool.menus
     menu_pool.menus = {'CMSMenu':self.old_menu['CMSMenu']}
     menu_pool.clear(settings.SITE_ID)
     self.create_some_nodes()
示例#35
0
 def setUp(self):
     settings.CMS_MODERATOR = False
     u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
     u.set_password("test")
     u.save()
     self.login_user(u)
     if not menu_pool.discovered:
         menu_pool.discover_menus()
     self.old_menu = menu_pool.menus
     menu_pool.menus = {'CMSMenu':self.old_menu['CMSMenu']}
     menu_pool.clear(settings.SITE_ID)
     self.create_some_nodes()
示例#36
0
 def setUp(self):
     
     with SettingsOverride(CMS_MODERATOR = False):
         u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
         u.set_password("test")
         u.save()
         self.login_user(u)
         menu_pool.clear(settings.SITE_ID)
         
         if not menu_pool.discovered:
             menu_pool.discover_menus()
         self.old_menu = menu_pool.menus
         menu_pool.menus = {'CMSMenu':self.old_menu['CMSMenu'], 'TestMenu':TestMenu()}
示例#37
0
    def tearDown(self):
        super(MenuTestCase, self).tearDown()

        # This is needed to ensure that Django CMS does not blow a fuse
        # when we load fixtures for the next test.
        from cms.utils.permissions import set_current_user
        set_current_user(None)

        # This resets the menu pool to pre-expansion values.
        from menus.menu_pool import menu_pool
        menu_pool.menus = self.saved_menus
        menu_pool._expanded = False
        menu_pool.clear()
示例#38
0
    def process_request(self, request):
        """
        If we should show the toolbar for this request, put it on
        request.toolbar. Then call the request_hook on the toolbar.
        """

        if not self.is_cms_request(request):
            return

        edit_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
        edit_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF')
        build = get_cms_setting('CMS_TOOLBAR_URL__BUILD')
        disable = get_cms_setting('CMS_TOOLBAR_URL__DISABLE')
        anonymous_on = get_cms_setting('TOOLBAR_ANONYMOUS_ON')

        if disable in request.GET:
            request.session['cms_toolbar_disabled'] = True
        if edit_on in request.GET:  # If we actively enter edit mode, we should show the toolbar in any case
            request.session['cms_toolbar_disabled'] = False

        if not request.session.get('cms_toolbar_disabled', False) and (
                request.user.is_staff or (anonymous_on and request.user.is_anonymous())
        ):
            if edit_on in request.GET and not request.session.get('cms_edit', False):
                if not request.session.get('cms_edit', False):
                    menu_pool.clear()
                request.session['cms_edit'] = True
                if request.session.get('cms_build', False):
                    request.session['cms_build'] = False
            if edit_off in request.GET and request.session.get('cms_edit', True):
                if request.session.get('cms_edit', True):
                    menu_pool.clear()
                request.session['cms_edit'] = False
                if request.session.get('cms_build', False):
                    request.session['cms_build'] = False
            if build in request.GET and not request.session.get('cms_build', False):
                request.session['cms_build'] = True
        else:
            if request.session.get('cms_build'):
                request.session['cms_build'] = False
            if request.session.get('cms_edit'):
                request.session['cms_edit'] = False
        if request.user.is_staff:
            try:
                request.cms_latest_entry = LogEntry.objects.filter(
                    user=request.user,
                    action_flag__in=(ADDITION, CHANGE)
                ).only('pk').order_by('-pk')[0].pk
            except IndexError:
                request.cms_latest_entry = -1
        request.toolbar = CMSToolbar(request)
示例#39
0
 def test_extenders_on_child(self):
     """
     TestMenu has 4 flat nodes
     """
     self._update_page(1, in_navigation=False)
     self._update_page(2, navigation_extenders="TestMenu")
     menu_pool.clear(settings.SITE_ID)
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context)
     nodes = context['children']
     self.assertEqual(len(nodes), 2)
     self.assertEqual(len(nodes[0].children), 4)
     self.assertEqual(nodes[0].children[1].get_absolute_url(), "/")
示例#40
0
 def test_extenders_on_child(self):
     """
     TestMenu has 4 flat nodes
     """
     self._update_page(1, in_navigation=False)
     self._update_page(2, navigation_extenders="TestMenu")
     menu_pool.clear(settings.SITE_ID)
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context)
     nodes = context["children"]
     self.assertEqual(len(nodes), 2)
     self.assertEqual(len(nodes[0].children), 4)
     self.assertEqual(nodes[0].children[1].get_absolute_url(), "/")
示例#41
0
 def test_extenders_on_root(self):
     self._update_page(1, navigation_extenders="TestMenu")
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     
     tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
     tpl.render(context) 
     nodes = context['children']
     self.assertEqual(len(nodes), 2)
     self.assertEqual(len(nodes[0].children), 4)
     self.assertEqual(len(nodes[0].children[3].children), 1)
     self._update_page(1, in_navigation=False)
     menu_pool.clear(settings.SITE_ID)
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context) 
     nodes = context['children']
     self.assertEqual(len(nodes), 5)
示例#42
0
    def test_02_extenders_on_root(self):
        Page.objects.filter(pk=1).update(navigation_extenders="TestMenu")
        menu_pool.clear(settings.SITE_ID)
        context = self.get_context()

        tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
        tpl.render(context)
        nodes = context["children"]
        self.assertEqual(len(nodes), 2)
        self.assertEqual(len(nodes[0].children), 4)
        self.assertEqual(len(nodes[0].children[3].children), 1)
        Page.objects.filter(pk=1).update(in_navigation=False)
        menu_pool.clear(settings.SITE_ID)
        tpl = Template("{% load menu_tags %}{% show_menu %}")
        tpl.render(context)
        nodes = context["children"]
        self.assertEqual(len(nodes), 5)
示例#43
0
    def setUp(self):
        super(MenuTest, self).setUp()
        self.cats = [self.category_1]
        cache.clear()
        for i, lang_data in enumerate(self._categories_data):
            cat = self._get_category(lang_data['en'])
            if 'it' in lang_data:
                cat = self._get_category(lang_data['it'], cat, 'it')
            self.cats.append(cat)

        activate('en')
        menu_pool.clear(all=True)
        menu_pool.discover_menus()
        # All cms menu modifiers should be removed from menu_pool.modifiers
        # so that they do not interfere with our menu nodes
        menu_pool.modifiers = [m for m in menu_pool.modifiers if m.__module__.startswith('djangocms_blog')]
        cache.clear()
示例#44
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    if not instance.page.publisher_is_draft:
        menu_pool.clear(instance.page.site_id)
    if instance.id and not hasattr(instance, "tmp_path"):
        instance.tmp_path = None
        try:
            instance.tmp_path = Title.objects.filter(pk=instance.id).values_list('path')[0][0]
        except IndexError:
            pass  # no Titles exist for this page yet

    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
示例#45
0
    def setUp(self):
        super(MenuTest, self).setUp()
        self.cats = [self.category_1]
        cache.clear()
        for i, lang_data in enumerate(self._categories_data):
            cat = self._get_category(lang_data['en'])
            if 'it' in lang_data:
                cat = self._get_category(lang_data['it'], cat, 'it')
            self.cats.append(cat)

        activate('en')
        menu_pool.clear(all=True)
        menu_pool.discover_menus()
        # All cms menu modifiers should be removed from menu_pool.modifiers
        # so that they do not interfere with our menu nodes
        menu_pool.modifiers = [m for m in menu_pool.modifiers if m.__module__.startswith('djangocms_blog')]
        cache.clear()
示例#46
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    if not instance.page.publisher_is_draft:
        menu_pool.clear(instance.page.site_id)
    if instance.id and not hasattr(instance, "tmp_path"):
        instance.tmp_path = None
        try:
            instance.tmp_path = Title.objects.filter(
                pk=instance.id).values_list('path')[0][0]
        except IndexError:
            pass  # no Titles exist for this page yet

    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
示例#47
0
    def setUp(self):

        with SettingsOverride(CMS_MODERATOR=False):
            u = User(username="******",
                     is_staff=True,
                     is_active=True,
                     is_superuser=True)
            u.set_password("test")
            u.save()
            self.login_user(u)
            menu_pool.clear(settings.SITE_ID)

            if not menu_pool.discovered:
                menu_pool.discover_menus()
            self.old_menu = menu_pool.menus
            menu_pool.menus = {
                'CMSMenu': self.old_menu['CMSMenu'],
                'TestMenu': TestMenu()
            }
示例#48
0
 def test_15_home_not_in_menu(self):
     page1 = Page.objects.get(pk=self.page1.pk)
     page1.in_navigation = False
     page1.save()
     page4 = Page.objects.get(pk=self.page4.pk)
     page4.in_navigation = False
     page4.save()
     context = self.get_context()
     nodes = show_menu(context, 0, 100, 100, 100)['children']
     self.assertEqual(len(nodes), 1)
     self.assertEqual(nodes[0].get_absolute_url(), "/%s/" % self.page2.get_slug())
     self.assertEqual(nodes[0].children[0].get_absolute_url(), "/%s/%s/" % (self.page2.get_slug(), self.page3.get_slug()))
     page4 = Page.objects.get(pk=self.page4.pk)
     page4.in_navigation = True
     page4.save()
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     nodes = show_menu(context, 0, 100, 100, 100)['children']
     self.assertEqual(len(nodes), 2)
示例#49
0
 def test_15_home_not_in_menu(self):
     page1 = Page.objects.get(pk=self.page1.pk)
     page1.in_navigation = False
     page1.save()
     page4 = Page.objects.get(pk=self.page4.pk)
     page4.in_navigation = False
     page4.save()
     context = self.get_context()
     nodes = show_menu(context, 0, 100, 100, 100)['children']
     self.assertEqual(len(nodes), 1)
     self.assertEqual(nodes[0].get_absolute_url(), "/%s/" % self.page2.get_slug())
     self.assertEqual(nodes[0].children[0].get_absolute_url(), "/%s/%s/" % (self.page2.get_slug(), self.page3.get_slug()))
     page4 = Page.objects.get(pk=self.page4.pk)
     page4.in_navigation = True
     page4.save()
     menu_pool.clear(settings.SITE_ID)
     context = self.get_context()
     nodes = show_menu(context, 0, 100, 100, 100)['children']
     self.assertEqual(len(nodes), 2)
示例#50
0
    def save(self, *args, **kwargs):

        # Invalidate the menu cache on creating/modifying objects
        menu_pool.clear(settings.SITE_ID, settings.LANGUAGE_CODE)
        
        if not self.pk:
            c = type(self).__name__
            if c == 'Typography':
                self.entry_type = 0
            elif c == 'Book':
                self.entry_type = 1

        e = self.get_first_in_type()

        # Auto-increment order
        if e and not self.pk:
            self.order = e.order + 1

        super(Entry, self).save(*args, **kwargs)
示例#51
0
    def process_request(self, request):
        """
        If we should show the toolbar for this request, put it on
        request.toolbar. Then call the request_hook on the toolbar.
        """

        edit_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
        edit_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF')
        build = get_cms_setting('CMS_TOOLBAR_URL__BUILD')

        if request.user.is_staff or request.user.is_anonymous():
            if edit_on in request.GET and not request.session.get(
                    'cms_edit', False):
                if not request.session.get('cms_edit', False):
                    menu_pool.clear()
                request.session['cms_edit'] = True
                if request.session.get('cms_build', False):
                    request.session['cms_build'] = False
            if edit_off in request.GET and request.session.get(
                    'cms_edit', True):
                if request.session.get('cms_edit', True):
                    menu_pool.clear()
                request.session['cms_edit'] = False
                if request.session.get('cms_build', False):
                    request.session['cms_build'] = False
            if build in request.GET and not request.session.get(
                    'cms_build', False):
                request.session['cms_build'] = True
        else:
            request.session['cms_build'] = False
            request.session['cms_edit'] = False
        if request.user.is_staff:
            try:
                request.cms_latest_entry = LogEntry.objects.filter(
                    user=request.user,
                    action_flag__in=(ADDITION,
                                     CHANGE)).only('pk').order_by('-pk')[0].pk
            except IndexError:
                request.cms_latest_entry = -1
        request.toolbar = CMSToolbar(request)
示例#52
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """
    
    menu_pool.clear(instance.page.site_id)
    
    instance.tmp_path = None
    instance.tmp_application_urls = None
    
    if instance.id:
        try:
            tmp_title = Title.objects.get(pk=instance.id)
            instance.tmp_path = tmp_title.path
            instance.tmp_application_urls = tmp_title.application_urls
        except:
            pass # no Titles exist for this page yet
    
    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
示例#53
0
 def process_request(self, request):
     """
     If we should show the toolbar for this request, put it on
     request.toolbar. Then call the request_hook on the toolbar.
     """
     if 'edit' in request.GET and not request.session.get('cms_edit', False):
         if not request.session.get('cms_edit', False):
             menu_pool.clear()
         request.session['cms_edit'] = True
         if request.session.get('cms_build', False):
             request.session['cms_build'] = False
     if 'edit_off' in request.GET and request.session.get('cms_edit', True):
         if request.session.get('cms_edit', True):
             menu_pool.clear()
         request.session['cms_edit'] = False
         if request.session.get('cms_build', False):
             request.session['cms_build'] = False
     if 'build' in request.GET and not request.session.get('cms_build', False):
         request.session['cms_build'] = True
     if request.user.is_staff:
         request.session['cms_log_entries'] = LogEntry.objects.filter(user=request.user).count()
     request.toolbar = CMSToolbar(request)
示例#54
0
def pre_save_title(instance, raw, **kwargs):
    """Save old state to instance and setup path
    """

    menu_pool.clear(instance.page.site_id)

    instance.tmp_path = None
    instance.tmp_application_urls = None

    if instance.id:
        try:
            tmp_title = Title.objects.get(pk=instance.id)
            instance.tmp_path = tmp_title.path
            instance.tmp_application_urls = tmp_title.application_urls
        except:
            pass  # no Titles exist for this page yet

    # Build path from parent page's path and slug
    if instance.has_url_overwrite and instance.path:
        instance.path = instance.path.strip(" /")
    else:
        update_title(instance)
示例#55
0
    def test_context_current_page(self):
        """
        Asserts the number of queries triggered by
        `cms.context_processors.cms_settings` and `cms.middleware.page`
        """
        from django.template import context

        page_template = "nav_playground.html"
        original_context = {'TEMPLATES': settings.TEMPLATES}
        page = self.create_homepage("page", page_template, "en", published=True)
        page_2 = create_page("page-2", page_template, "en", published=True,
                             parent=page)

        # Tests for standard django applications
        # 1 query is executed in get_app_patterns(), not related
        # to cms.context_processors.cms_settings.
        # Executing this oputside queries assertion context ensure
        # repetability
        self.client.get("/en/plain_view/")

        cache.clear()
        menu_pool.clear()
        context._standard_context_processors = None

        # Number of queries when context processor is enabled
        with self.settings(**original_context):
            with self.assertNumQueries(FuzzyInt(0, 17)):
                response = self.client.get("/en/plain_view/")
            # One query when determining current page
            with self.assertNumQueries(FuzzyInt(0, 1)):
                self.assertFalse(response.context['request'].current_page)
                self.assertFalse(response.context['request']._current_page_cache)
            # Zero more queries when determining the current template
            with self.assertNumQueries(0):
                # Template is the first in the CMS_TEMPLATES list
                template = Variable('CMS_TEMPLATE').resolve(response.context)
                self.assertEqual(template, get_cms_setting('TEMPLATES')[0][0])
        cache.clear()
        menu_pool.clear()

        # Number of queries when context processors is enabled
        with self.settings(**original_context):
            with self.assertNumQueries(FuzzyInt(13, 28)) as context:
                response = self.client.get("/en/page-2/")
                template = Variable('CMS_TEMPLATE').resolve(response.context)
                self.assertEqual(template, page_template)
                num_queries_page = len(context.captured_queries)
        cache.clear()
        menu_pool.clear()
        page_2.template = 'INHERIT'
        page_2.save()
        page_2.publish('en')
        with self.settings(**original_context):
            # One query more triggered as page inherits template from ancestor
            with self.assertNumQueries(num_queries_page + 1):
                response = self.client.get("/en/page-2/")
                template = Variable('CMS_TEMPLATE').resolve(response.context)
                self.assertEqual(template, page_template)
示例#56
0
    def test_context_current_page(self):
        """
        Asserts the number of queries triggered by
        `cms.context_processors.cms_settings` and `cms.middleware.page`
        """
        from django.template import context

        page_template = "nav_playground.html"
        original_context = {'TEMPLATES': settings.TEMPLATES}
        page = create_page("page", page_template, "en", published=True)
        page_2 = create_page("page-2", page_template, "en", published=True,
                             parent=page)

        # Tests for standard django applications
        # 1 query is executed in get_app_patterns(), not related
        # to cms.context_processors.cms_settings.
        # Executing this oputside queries assertion context ensure
        # repetability
        self.client.get("/en/plain_view/")

        cache.clear()
        menu_pool.clear()
        context._standard_context_processors = None

        # Number of queries when context processor is enabled
        with self.settings(**original_context):
            with self.assertNumQueries(FuzzyInt(0, 17)):
                response = self.client.get("/en/plain_view/")
            # One query when determining current page
            with self.assertNumQueries(FuzzyInt(0, 1)):
                self.assertFalse(response.context['request'].current_page)
                self.assertFalse(response.context['request']._current_page_cache)
            # Zero more queries when determining the current template
            with self.assertNumQueries(0):
                # Template is the first in the CMS_TEMPLATES list
                template = Variable('CMS_TEMPLATE').resolve(response.context)
                self.assertEqual(template, get_cms_setting('TEMPLATES')[0][0])
        cache.clear()
        menu_pool.clear()

        # Number of queries when context processors is enabled
        with self.settings(**original_context):
            with self.assertNumQueries(FuzzyInt(13, 25)) as context:
                response = self.client.get("/en/page-2/")
                template = Variable('CMS_TEMPLATE').resolve(response.context)
                self.assertEqual(template, page_template)
                num_queries_page = len(context.captured_queries)
        cache.clear()
        menu_pool.clear()
        page_2.template = 'INHERIT'
        page_2.save()
        page_2.publish('en')
        with self.settings(**original_context):
            # One query more triggered as page inherits template from ancestor
            with self.assertNumQueries(num_queries_page + 1):
                response = self.client.get("/en/page-2/")
                template = Variable('CMS_TEMPLATE').resolve(response.context)
                self.assertEqual(template, page_template)
示例#57
0
    def set_status(self, new_status, all_producers=True, producers_id=None):
        from repanier.models.invoice import CustomerInvoice
        from repanier.models.purchase import Purchase

        if all_producers:
            now = timezone.now()
            self.is_updated_on = now
            self.status = new_status
            if self.highest_status < new_status:
                self.highest_status = new_status
            self.save(
                update_fields=['status', 'is_updated_on', 'highest_status'])
            CustomerInvoice.objects.filter(
                delivery_id=self.id).order_by('?').update(status=new_status)
            Purchase.objects.filter(
                customer_invoice__delivery_id=self.id).order_by('?').update(
                    status=new_status)
            menu_pool.clear()
            cache.clear()
        else:
            Purchase.objects.filter(
                customer_invoice__delivery_id=self.id,
                producer__in=producers_id).order_by('?').update(
                    status=new_status)
示例#58
0
    def copy_page(self,
                  target,
                  site,
                  position='first-child',
                  copy_permissions=True,
                  copy_moderation=True,
                  public_copy=False):
        """
        copy a page [ and all its descendants to a new location ]
        Doesn't checks for add page permissions anymore, this is done in PageAdmin.
        
        Note: public_copy was added in order to enable the creation of a copy for creating the public page during
        the publish operation as it sets the publisher_is_draft=False.
        """
        from cms.utils.moderator import update_moderation_message

        page_copy = None

        if public_copy:
            # create a copy of the draft page - existing code loops through pages so added it to a list
            pages = [copy.copy(self)]
        else:
            pages = [self] + list(self.get_descendants().order_by('-rght'))

        if not public_copy:
            site_reverse_ids = Page.objects.filter(
                site=site, reverse_id__isnull=False).values_list('reverse_id',
                                                                 flat=True)

            if target:
                target.old_pk = -1
                if position == "first-child":
                    tree = [target]
                elif target.parent_id:
                    tree = [target.parent]
                else:
                    tree = []
            else:
                tree = []
            if tree:
                tree[0].old_pk = tree[0].pk

        first = True
        # loop over all affected pages (self is included in descendants)
        for page in pages:
            titles = list(page.title_set.all())
            # get all current placeholders (->plugins)
            placeholders = list(page.placeholders.all())
            origin_id = page.id
            # create a copy of this page by setting pk = None (=new instance)
            page.old_pk = page.pk
            page.pk = None
            page.level = None
            page.rght = None
            page.lft = None
            page.tree_id = None
            page.published = False
            page.moderator_state = Page.MODERATOR_CHANGED
            page.publisher_public_id = None
            # only set reverse_id on standard copy
            if not public_copy:
                if page.reverse_id in site_reverse_ids:
                    page.reverse_id = None
                if first:
                    first = False
                    if tree:
                        page.parent = tree[0]
                    else:
                        page.parent = None
                    page.insert_at(target, position)
                else:
                    count = 1
                    found = False
                    for prnt in tree:
                        if prnt.old_pk == page.parent_id:
                            page.parent = prnt
                            tree = tree[0:count]
                            found = True
                            break
                        count += 1
                    if not found:
                        page.parent = None
                tree.append(page)
            page.site = site

            # override default page settings specific for public copy
            if public_copy:
                page.published = True
                page.publisher_is_draft = False
                page.moderator_state = Page.MODERATOR_APPROVED
                # we need to set relate this new public copy to its draft page (self)
                page.publisher_public = self

                # code taken from Publisher publish() overridden here as we need to save the page
                # before we are able to use the page object for titles, placeholders etc.. below
                # the method has been modified to return the object after saving the instance variable
                page = self._publisher_save_public(page)
                page_copy = page  # create a copy used in the return
            else:
                # only need to save the page if it isn't public since it is saved above otherwise
                page.save()

            # copy moderation, permissions if necessary
            if settings.CMS_PERMISSION and copy_permissions:
                from cms.models.permissionmodels import PagePermission
                for permission in PagePermission.objects.filter(
                        page__id=origin_id):
                    permission.pk = None
                    permission.page = page
                    permission.save()
            if settings.CMS_MODERATOR and copy_moderation:
                from cms.models.moderatormodels import PageModerator
                for moderator in PageModerator.objects.filter(
                        page__id=origin_id):
                    moderator.pk = None
                    moderator.page = page
                    moderator.save()

            # update moderation message for standard copy
            if not public_copy:
                update_moderation_message(page, unicode(_('Page was copied.')))

            # copy titles of this page
            for title in titles:
                title.pk = None  # setting pk = None creates a new instance
                title.publisher_public_id = None
                title.published = False
                title.page = page

                # create slug-copy for standard copy
                if not public_copy:
                    title.slug = page_utils.get_available_slug(title)
                title.save()

            # copy the placeholders (and plugins on those placeholders!)
            for ph in placeholders:
                plugins = list(ph.cmsplugin_set.all().order_by(
                    'tree_id', '-rght'))
                try:
                    ph = page.placeholders.get(slot=ph.slot)
                except Placeholder.DoesNotExist:
                    ph.pk = None  # make a new instance
                    ph.save()
                    page.placeholders.add(ph)
                if plugins:
                    copy_plugins_to(plugins, ph)

        # invalidate the menu for this site
        menu_pool.clear(site_id=site.pk)
        return page_copy  # return the page_copy or None