当前位置: 首页>>代码示例>>Python>>正文


Python CMSPlugin.set_base_attr方法代码示例

本文整理汇总了Python中cms.models.pluginmodel.CMSPlugin.set_base_attr方法的典型用法代码示例。如果您正苦于以下问题:Python CMSPlugin.set_base_attr方法的具体用法?Python CMSPlugin.set_base_attr怎么用?Python CMSPlugin.set_base_attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cms.models.pluginmodel.CMSPlugin的用法示例。


在下文中一共展示了CMSPlugin.set_base_attr方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete_with_plugins

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
    def test_delete_with_plugins(self):
        """
        Check that plugins and placeholders get correctly deleted when we delete
        a page!
        """
        home = create_page("home", "nav_playground.html", "en")
        page = create_page("page", "nav_playground.html", "en")
        page.rescan_placeholders() # create placeholders
        placeholder = page.placeholders.all()[0]
        plugin_base = CMSPlugin(
            plugin_type='TextPlugin',
            placeholder=placeholder,
            position=1,
            language=settings.LANGUAGES[0][0]
        )
        plugin_base.insert_at(None, position='last-child', save=False)

        plugin = Text(body='')
        plugin_base.set_base_attr(plugin)
        plugin.save()
        self.assertEqual(CMSPlugin.objects.count(), 1)
        self.assertEqual(Text.objects.count(), 1)
        self.assertTrue(Placeholder.objects.count() > 2)
        page.delete()
        home.delete()
        self.assertEqual(CMSPlugin.objects.count(), 0)
        self.assertEqual(Text.objects.count(), 0)
        self.assertEqual(Placeholder.objects.count(), 0)
        self.assertEqual(Page.objects.count(), 0)
开发者ID:360yln,项目名称:django-cms-2.4,代码行数:31,代码来源:page.py

示例2: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
    def add_plugin(self,
                   user=None,
                   page=None,
                   placeholder=None,
                   language='en',
                   body=''):
        if not placeholder:
            if page:
                placeholder = page.placeholders.get(
                    slot__iexact='Right-Column')
            else:
                placeholder = page.placeholders.get(
                    slot__iexact='Right-Column')

        plugin_base = CMSPlugin(
            plugin_type='TextPlugin',
            placeholder=placeholder,
            position=1,
            language=language)
        plugin_base.insert_at(None, position='last-child', commit=False)

        plugin = Text(body=body)
        plugin_base.set_base_attr(plugin)
        plugin.save()
        return plugin.pk
开发者ID:hedberg,项目名称:django-cms,代码行数:27,代码来源:testcases.py

示例3: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
def add_plugin(placeholder, plugin_type, language, position='last-child',
               target=None, **data):
    """
    Add a plugin to a placeholder
    
    See docs/extending_cms/api_reference.rst for more info
    """
    # validate placeholder
    assert isinstance(placeholder, Placeholder)
    
    # validate and normalize plugin type
    plugin_model, plugin_type = _verify_plugin_type(plugin_type)
        

    max_pos = CMSPlugin.objects.filter(language=language,
        placeholder=placeholder).aggregate(Max('position'))['position__max'] or 0

    plugin_base = CMSPlugin(
        plugin_type=plugin_type,
        placeholder=placeholder, 
        position=max_pos + 1,
        language=language
    )
    plugin_base.insert_at(target, position=position, save=False)
            
    plugin = plugin_model(**data)
    plugin_base.set_base_attr(plugin)
    plugin.save()
    return plugin
开发者ID:Polyconseil,项目名称:django-cms,代码行数:31,代码来源:api.py

示例4: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
def add_plugin(placeholder, plugin_type, language, position='last-child',
               **data):
    """
    Add a plugin to a placeholder
    
    See docs/extending_cms/api_reference.rst for more info
    """
    # validate placeholder
    assert isinstance(placeholder, Placeholder)
    
    # validate and normalize plugin type
    plugin_model, plugin_type = _verify_plugin_type(plugin_type)
        
    plugin_base = CMSPlugin(
        plugin_type=plugin_type,
        placeholder=placeholder, 
        position=1, 
        language=language
    )
    plugin_base.insert_at(None, position=position, save=False)
            
    plugin = plugin_model(**data)
    plugin_base.set_base_attr(plugin)
    plugin.save()
    return plugin
开发者ID:BeUnique,项目名称:django-cms,代码行数:27,代码来源:api.py

示例5: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
def add_plugin(placeholder, plugin_type, language, position='last-child', **data):
    """
    Taken from django-cms api (in newer versions)
    https://github.com/divio/django-cms/blob/b8633b42efcd137d96e1e3f42e004cb7595768fe/cms/api.py
    """
    assert isinstance(placeholder, Placeholder)
    plugin_model = plugin_type.model
    plugin_type = plugin_type.__name__
    plugin_base = CMSPlugin(
        plugin_type=plugin_type,
        placeholder=placeholder, 
        position=1,
        language=language
    )
    plugin_base.insert_at(None, position='last-child', commit=False)
    plugin = plugin_model(**data)
    plugin_base.set_base_attr(plugin)
    plugin.save()
    return plugin
开发者ID:unhookme,项目名称:pnwinsects-app,代码行数:21,代码来源:models.py

示例6: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
def add_plugin(placeholder, plugin_type, language, position='last-child',
               target=None, **data):
    """
    Add a plugin to a placeholder
    
    See docs/extending_cms/api_reference.rst for more info
    """
    # validate placeholder
    assert isinstance(placeholder, Placeholder)

    # validate and normalize plugin type
    plugin_model, plugin_type = _verify_plugin_type(plugin_type)
    if target:
        if position == 'last-child':
            new_pos = CMSPlugin.objects.filter(language=language, parent=target, tree_id=target.tree_id).count()
        elif position == 'first-child':
            new_pos = 0
        elif position == 'left':
            new_pos = target.position
        elif position == 'right':
            new_pos = target.position + 1
        else:
            raise Exception('position not supported: %s' % position)
        for pl in CMSPlugin.objects.filter(language=language, parent=target.parent_id, tree_id=target.tree_id, position__gte=new_pos):
            pl.position += 1
            pl.save()
    else:
        new_pos = CMSPlugin.objects.filter(language=language, parent__isnull=True, placeholder=placeholder).count()

    plugin_base = CMSPlugin(
        plugin_type=plugin_type,
        placeholder=placeholder,
        position=new_pos,
        language=language
    )
    plugin_base.insert_at(target, position=position, save=False)

    plugin = plugin_model(**data)
    plugin_base.set_base_attr(plugin)
    plugin.save()
    return plugin
开发者ID:Acidburn0zzz,项目名称:django-cms,代码行数:43,代码来源:api.py

示例7: test_11_copy_textplugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
    def test_11_copy_textplugin(self):
        """
        Test that copying of textplugins replaces references to copied plugins
        """
        
        page = self.create_page()
        
        placeholder = page.placeholders.get(slot='body')
        
        plugin_base = CMSPlugin(
            plugin_type='TextPlugin',
            placeholder=placeholder, 
            position=1, 
            language=self.FIRST_LANG)
        plugin_base.insert_at(None, position='last-child', commit=False)
                
        plugin = Text(body='')
        plugin_base.set_base_attr(plugin)
        plugin.save()
        
        plugin_ref_1_base = CMSPlugin(
            plugin_type='TextPlugin',
            placeholder=placeholder, 
            position=1, 
            language=self.FIRST_LANG)
        plugin_ref_1_base.insert_at(plugin_base, position='last-child', commit=False)    
        
        plugin_ref_1 = Text(body='')
        plugin_ref_1_base.set_base_attr(plugin_ref_1)
        plugin_ref_1.save()
        
        plugin_ref_2_base = CMSPlugin(
            plugin_type='TextPlugin',
            placeholder=placeholder, 
            position=2, 
            language=self.FIRST_LANG)
        plugin_ref_2_base.insert_at(plugin_base, position='last-child', commit=False)    
        
        plugin_ref_2 = Text(body='')
        plugin_ref_2_base.set_base_attr(plugin_ref_2)

        plugin_ref_2.save()
        
        plugin.body = plugin_tags_to_admin_html(' {{ plugin_object %s }} {{ plugin_object %s }} ' % (str(plugin_ref_1.pk), str(plugin_ref_2.pk)))
        plugin.save()
        self.assertEquals(plugin.pk, 1)
        page_data = self.get_new_page_data()

        #create 2nd language page
        page_data.update({
            'language': self.SECOND_LANG,
            'title': "%s %s" % (page.get_title(), self.SECOND_LANG),
        })
        response = self.client.post(URL_CMS_PAGE_CHANGE % page.pk + "?language=%s" % self.SECOND_LANG, page_data)
        self.assertRedirects(response, URL_CMS_PAGE)
        
        self.assertEquals(CMSPlugin.objects.filter(language=self.FIRST_LANG).count(), 3)
        self.assertEquals(CMSPlugin.objects.filter(language=self.SECOND_LANG).count(), 0)
        self.assertEquals(CMSPlugin.objects.count(), 3)
        self.assertEquals(Page.objects.all().count(), 1)
        
        copy_data = {
            'placeholder': placeholder.pk,
            'language': self.SECOND_LANG,
            'copy_from': self.FIRST_LANG,
        }
        response = self.client.post(URL_CMS_PAGE + "copy-plugins/", copy_data)
        self.assertEquals(response.status_code, 200)
        self.assertEqual(response.content.count('<li '), 3)
        # assert copy success
        self.assertEquals(CMSPlugin.objects.filter(language=self.FIRST_LANG).count(), 3)
        self.assertEquals(CMSPlugin.objects.filter(language=self.SECOND_LANG).count(), 3)
        self.assertEquals(CMSPlugin.objects.count(), 6)

        new_plugin = Text.objects.get(pk=6)
        self.assertEquals(plugin_tags_to_id_list(new_plugin.body), [u'4', u'5'])
开发者ID:42,项目名称:django-cms,代码行数:78,代码来源:plugins.py

示例8: convert

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]

#.........这里部分代码省略.........
                moved_items =[]     # a record of the items we migrated to placeholders

                # loop over each item in the class
                for item in actual_model.objects.all():

                    old_field_content = getattr(item, old_field)  # the old field we want to convert

                    # first get rid of junk content (change "<br />" to "")
                    if old_field_content == "<br />":
                        old_field_content = ""
                        setattr(item, old_field, "") # item.content = ""
                        if execute == "convert":
                            item.save()
                    
                    # now the serious business of converting the fields
            
                    # if the item lacks a placeholder, create the placeholder and the reference to it
                    if old_field_content and not getattr(item, new_field, None):

                        # check to see if it's worth converting
                        if len(old_field_content) > 60:

                            # create the placeholder
                            placeholder=Placeholder(slot=slot)
                            if execute == "convert":
                                placeholder.save()
        
                            # refer to the placeholder from the item
                            setattr(item, new_field, placeholder)
        
                            # I copied this from one of the test files
                            plugin_base = CMSPlugin(
                                plugin_type='TextPlugin',
                                placeholder=placeholder, 
                                position=1, 
                                language=settings.LANGUAGES[0][0]) # we assume the original field was in the first language
                            plugin_base.insert_at(None, position='last-child', commit=False)
        
                            # create a text plugin
                            plugin = Text(body='')
                            plugin_base.set_base_attr(plugin)
                            plugin.body = getattr(item, old_field)
                            if execute == "convert":
                                plugin.save()
        
                            # set the old field to ""
                            setattr(item, old_field, "")
                            if execute == "convert":
                                item.save()
                                item.status = "Converted to placeholder"
                            else:
                                item.status = "Unconverted"
                                        
                        else:
                            print "too short", old_field_content
                            # this item is so short it must be junk
                            if execute == "convert":
                                setattr(item, old_field, "")
                                item.status = "Junk field - too short; was deleted instead of converted:" + old_field_content
                                item.save()
                            else:    
                                item.status = "Junk field - too short; will be deleted instead of converted:" + old_field_content
                            # make a note that this was a junk item
                            junk_content.append(item)
                                # make a note that we moved this item

                        moved_items.append(item)    
 
                # information about junk content items
                if execute == "convert":
                    message = " ".join((str(len(junk_content)), "junk items not converted items"))
                else:
                    message = " ".join((str(len(junk_content)), "junk items found"))                    

                models_dictionary["messages"][mmodel][old_field]["Junk fields"]=message

                # information about items that have been/need to be converted
                if execute == "convert":
                    message = str(len(moved_items)) + " items were converted to placeholder " + new_field
                else:
                    message = str(len(moved_items)) + " items need to be converted to placeholder " + new_field
            
                models_dictionary["messages"][mmodel][old_field]["Conversions"]=message
            
                # list every item that was copied for the full report
                if execute == "convert":
                    action = "Fields that were copied"
                else:
                    action = "Fields to be copied"
                    
                models_dictionary["modules"][module]["models"][model]["actions"][action]=moved_items
                

    return shortcuts.render_to_response(
        "housekeeping/convert_to_placeholders.html", {
            "execute": execute,
            "converted": models_dictionary,
            },
        RequestContext(request),
        )
开发者ID:airtonix,项目名称:Arkestra,代码行数:104,代码来源:convert_to_placeholders.py

示例9: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import set_base_attr [as 别名]
def add_plugin(placeholder, plugin_type, language, position='last-child',
               target=None, **data):
    """
    Add a plugin to a placeholder

    See docs/extending_cms/api_reference.rst for more info
    """
    # validate placeholder
    assert isinstance(placeholder, Placeholder)

    # validate and normalize plugin type
    plugin_model, plugin_type = _verify_plugin_type(plugin_type)
    if target:
        if position == 'last-child':
            if CMSPlugin.node_order_by:
                position = 'sorted-child'
            new_pos = CMSPlugin.objects.filter(parent=target).count()
            parent_id = target.pk
        elif position == 'first-child':
            new_pos = 0
            if CMSPlugin.node_order_by:
                position = 'sorted-child'
            parent_id = target.pk
        elif position == 'left':
            new_pos = target.position
            if CMSPlugin.node_order_by:
                position = 'sorted-sibling'
            parent_id = target.parent_id
        elif position == 'right':
            new_pos = target.position + 1
            if CMSPlugin.node_order_by:
                position = 'sorted-sibling'
            parent_id = target.parent_id
        else:
            raise Exception('position not supported: %s' % position)
        if position == 'last-child' or position == 'first-child':
            qs = CMSPlugin.objects.filter(language=language, parent=target, position__gte=new_pos,
                                          placeholder=placeholder)
        else:
            qs = CMSPlugin.objects.filter(language=language, parent=target.parent_id, position__gte=new_pos,
                                          placeholder=placeholder)
        for pl in qs:
            pl.position += 1
            pl.save()
    else:
        if position == 'last-child':
            new_pos = CMSPlugin.objects.filter(language=language, parent__isnull=True, placeholder=placeholder).count()
        else:
            new_pos = 0
            for pl in CMSPlugin.objects.filter(language=language, parent__isnull=True, position__gte=new_pos,
                                               placeholder=placeholder):
                pl.position += 1
                pl.save()
        parent_id = None
    plugin_base = CMSPlugin(
        plugin_type=plugin_type,
        placeholder=placeholder,
        position=new_pos,
        language=language,
        parent_id=parent_id,
    )

    plugin_base = plugin_base.add_root(instance=plugin_base)

    if target:
        plugin_base = plugin_base.move(target, pos=position)
    plugin = plugin_model(**data)
    plugin_base.set_base_attr(plugin)
    plugin.save()
    return plugin
开发者ID:AllenYang0308,项目名称:django-cms,代码行数:72,代码来源:api.py


注:本文中的cms.models.pluginmodel.CMSPlugin.set_base_attr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。