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


Python ModelBase.save方法代码示例

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


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

示例1: LocationAwarenessTestCase

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    class LocationAwarenessTestCase(unittest.TestCase):
        def setUp(self):
            country = Country(name="South Africa", country_code="ZA")
            country.save()
            self.ct = City(
                name="Cape Town",
                country=country,
                coordinates=fromstr('POINT(18.423218 -33.925839)', srid=4326)
            )
            self.ct.save()
            loc1 = Location(
                city=self.ct,
                country=country,
                coordinates=fromstr('POINT(18.41 -33.91)', srid=4326),
                name='loc1'
            )
            loc1.save()
            self.model = ModelBase(title="title1", location=loc1)
            self.model.save()

        def test_distance_calculation(self):
            qs = ModelBase.objects.distance(self.ct.coordinates)
            for obj in qs:
                if obj.distance is not None:
                    self.assertEqual(obj.location.coordinates.distance(self.ct.coordinates), obj.distance)
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: test_save_model

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_save_model(self):
        # setup mock objects
        admin_obj = ModelBaseAdmin(ModelBase, 1)
        request = RequestFactory()
        request.user = self.user

        # After admin save the object's owner should be the current user.
        obj = ModelBase()
        admin_obj.save_model(request, obj, admin_obj.form, 1)
        self.failUnless(obj.owner == self.user)
        obj.save()
开发者ID:,项目名称:,代码行数:13,代码来源:

示例3: test_vote_total

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_vote_total(self):
        # create object with some votes
        obj = ModelBase(title='title')
        obj.save()
        obj.add_vote("token1", 1)
        obj.add_vote("token2", -1)
        obj.add_vote("token3", 1)

        # vote_total should return an integer
        result = obj.vote_total
        self.failUnlessEqual(result.__class__, int)

        # vote total is calculated as total_upvotes - total_downvotes
        self.failUnlessEqual(result, 1)
开发者ID:pombredanne,项目名称:jmbo,代码行数:16,代码来源:tests.py

示例4: test_can_vote

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_can_vote(self):
        # create dummy request object
        request = type('Request', (object,), {})

        class User():
            def is_authenticated(self):
                return False
        request.user = User()
        request.secretballot_token = 'test_token'

        # return false when liking is closed
        obj = ModelBase(
            likes_enabled=True,
            likes_closed=True,
            anonymous_likes=True
        )
        obj.save()
        self.failIf(obj.can_vote(request)[0])

        # return false when liking is disabled
        obj = ModelBase(
            likes_enabled=False,
            likes_closed=False,
            anonymous_likes=True
        )
        obj.save()
        self.failIf(obj.can_vote(request)[0])

        # return false if anonymous and anonymous liking is disabled
        obj = ModelBase(
            likes_enabled=True,
            likes_closed=False,
            anonymous_likes=False
        )
        obj.save()
        self.failIf(obj.can_vote(request)[0])

        # return true if anonymous and anonymous liking is enabled
        obj = ModelBase(
            likes_enabled=True,
            likes_closed=False,
            anonymous_likes=True
        )
        obj.save()
        self.failUnless(obj.can_vote(request))

        # return false if vote already exist
        content_type = ContentType.objects.get(
            app_label="jmbo",
            model="modelbase"
        )
        Vote.objects.create(
            object_id=obj.id,
            token='test_token',
            content_type=content_type, vote=1
        )
        self.failIf(obj.can_vote(request)[0])
开发者ID:,项目名称:,代码行数:59,代码来源:

示例5: test_comment_count

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_comment_count(self):
        comment_model = comments.get_model()

        # Return 0 if no comments exist.
        obj = ModelBase()
        obj.save()
        self.failUnless(obj.comment_count == 0)

        # Return the number of comments if comments exist. Here it
        # should be 1 since we've created 1 comment.
        comment_obj = comment_model(content_object=obj, site_id=1)
        comment_obj.save()
        obj = ModelBase.objects.get(id=obj.id)
        self.failUnless(obj.comment_count == 1)

        # Return 0 if no comments exist.
        dummy_obj = DummyModel()
        dummy_obj.save()
        dummy_obj = ModelBase.objects.get(id=dummy_obj.id)
        self.failUnless(dummy_obj.comment_count == 0)

        # Return the number of comments if comments exist on the
        # ModelBase object. Here it should be 1 since we've created 1
        # comment on the ModelBase object.
        comment_obj = comment_model(
            content_object=dummy_obj.modelbase_obj,
            site_id=1
        )
        comment_obj.save()
        dummy_obj = ModelBase.objects.get(id=dummy_obj.id)
        self.failUnless(dummy_obj.modelbase_obj.comment_count == 1)

        # If a comment was made on the ModelBase object it should
        # still count for leaf class objects.
        self.failUnless(dummy_obj.comment_count == 1)

        # Add another comment on dummy object and make sure the count
        # is 2 for both the dummy object and its modelbase object.
        comment_obj = comment_model(content_object=dummy_obj, site_id=1)
        comment_obj.save()
        dummy_obj = ModelBase.objects.get(id=dummy_obj.id)
        self.failUnless(dummy_obj.comment_count == 2)
        self.failUnless(dummy_obj.modelbase_obj.comment_count == 2)

        # There should now only be 3 comment objects.
        self.failUnless(comment_model.objects.all().count() == 3)
开发者ID:,项目名称:,代码行数:48,代码来源:

示例6: test_can_comment

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_can_comment(self):
        # create dummy request object
        request = type('Request', (object,), {})

        class User():
            def is_authenticated(self):
                return False
        request.user = User()
        request.secretballot_token = 'test_token'

        # return false when commenting is closed
        obj = ModelBase(
            comments_enabled=True,
            comments_closed=True,
            anonymous_comments=True
        )
        obj.save()
        self.failIf(obj.can_comment(request)[0])

        # return false when commenting is disabled
        obj = ModelBase(
            comments_enabled=False,
            comments_closed=False,
            anonymous_comments=True
        )
        obj.save()
        self.failIf(obj.can_comment(request)[0])

        # return false if anonymous and anonymous commenting is disabled
        obj = ModelBase(
            comments_enabled=True,
            comments_closed=False,
            anonymous_comments=False
        )
        obj.save()
        self.failIf(obj.can_comment(request)[0])

        # return true if anonymous and anonymous commenting is enabled
        obj = ModelBase(
            comments_enabled=True,
            comments_closed=False,
            anonymous_comments=True
        )
        obj.save()
        self.failUnless(obj.can_comment(request)[0])
开发者ID:,项目名称:,代码行数:47,代码来源:

示例7: test_save

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_save(self):
        before_save = timezone.now()

        # created field should be set on save
        obj = ModelBase(title="title")
        obj.save()

        # created field should be set to current datetime on save
        after_save = timezone.now()
        self.failIf(obj.created > after_save or obj.created < before_save)

        # If a user supplies a created date use that
        # instead of the current datetime.
        test_datetime = timezone.make_aware(timezone.datetime(2008, 10, 10, 12, 12))
        obj = ModelBase(title="title", created=test_datetime)
        obj.save()
        self.failIf(obj.created != test_datetime)

        # modified should be set to current datetime on each save
        before_save = timezone.now()
        obj = ModelBase(title="title")
        obj.save()
        after_save = timezone.now()
        self.failIf(obj.modified > after_save or obj.modified < before_save)

        # leaf class content type should be set on save
        obj = DummyModel(title="title")
        obj.save()
        self.failUnless(obj.content_type == ContentType.objects.\
                get_for_model(DummyModel))

        # leaf class class name should be set on save
        self.failUnless(obj.class_name == DummyModel.__name__)

        # Correct leaf class content type should be retained
        # over base class" content type.
        base = obj.modelbase_ptr
        base.save()
        self.failUnless(
            base.content_type == ContentType.objects.get_for_model(DummyModel)
        )

        # Correct leaf class class name should be
        # retained over base class" class name.
        self.failUnless(base.class_name == DummyModel.__name__)
开发者ID:praekelt,项目名称:jmbo,代码行数:47,代码来源:test_modelbase.py

示例8: test_publish_retract

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_publish_retract(self):
        today = timezone.make_aware(timezone.datetime.today())
        yesterday = today - timezone.timedelta(days=1)
        tomorrow = today + timezone.timedelta(days=1)

        p1 = ModelBase(title="title", state="published")
        p1.save()
        p1.sites.add(self.web_site)
        p1.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failUnless(p1 in queryset)

        p2 = ModelBase(title="title", publish_on=today)
        p2.save()
        p2.sites.add(self.web_site)
        p2.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failUnless(p2 in queryset)

        p4 = ModelBase(title="title", publish_on=today, retract_on=tomorrow)
        p4.save()
        p4.sites.add(self.web_site)
        p4.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failUnless(p4 in queryset)

        p5 = ModelBase(title="title", publish_on=tomorrow)
        p5.save()
        p5.sites.add(self.web_site)
        p5.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failIf(p5 in queryset)

        p6 = ModelBase(title="title", publish_on=yesterday, retract_on=today)
        p6.save()
        p6.sites.add(self.web_site)
        p6.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failIf(p6 in queryset)

        p7 = ModelBase(title="title", publish_on=tomorrow, retract_on=tomorrow)
        p7.save()
        p7.sites.add(self.web_site)
        p7.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failIf(p7 in queryset)

        p8 = ModelBase(
            title="title", publish_on=yesterday, retract_on=yesterday
        )
        p8.save()
        p8.sites.add(self.web_site)
        p8.save()
        jmbo_publish.Command().handle()
        queryset = ModelBase.permitted.all()
        self.failIf(p8 in queryset)
开发者ID:praekelt,项目名称:jmbo,代码行数:64,代码来源:test_manager.py

示例9: test_get_queryset

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_get_queryset(self):
        # create unpublished item
        unpublished_obj = ModelBase(title="title", state="unpublished")
        unpublished_obj.save()
        unpublished_obj.sites.add(self.web_site)
        unpublished_obj.save()

        # create published item
        published_obj = ModelBase(title="title", state="published")
        published_obj.save()
        published_obj.sites.add(self.web_site)
        published_obj.save()

        # unpublished objects should not be available in queryset
        queryset = ModelBase.permitted.all()
        self.failIf(unpublished_obj in queryset)

        # published objects should always be available in queryset
        self.failUnless(published_obj in queryset)

        # queryset should only contain items for the current site
        published_obj_web = ModelBase(state="published")
        published_obj_web.save()
        published_obj_web.sites.add(self.web_site)
        published_obj_web.save()
        queryset = ModelBase.permitted.all()
        self.failUnless(published_obj_web in queryset)

        # queryset should not contain items for other sites
        published_obj_mobile = ModelBase(state="published")
        published_obj_mobile.save()
        published_obj_mobile.sites.add(self.mobile_site)
        published_obj_mobile.save()
        queryset = ModelBase.permitted.all()
        self.failIf(published_obj_mobile in queryset)

        # Publish to different layers. The current layer during this test run
        # is "web".
        with override_settings(LAYERS={"tree": ["basic", ["web"]], "current": "web"}):
            call_command("load_layers")
            obj_layer_basic = ModelBase.objects.create(state="published")
            obj_layer_basic.sites = Site.objects.all()
            obj_layer_basic.layers = [Layer.objects.get(name="basic")]
            obj_layer_basic.save()
            obj_layer_web = ModelBase.objects.create(state="published")
            obj_layer_web.sites = Site.objects.all()
            obj_layer_web.layers = [Layer.objects.get(name="web")]
            obj_layer_web.save()
            queryset = ModelBase.permitted.all()
            self.failIf(obj_layer_basic in queryset)
            self.failUnless(obj_layer_web in queryset)
开发者ID:praekelt,项目名称:jmbo,代码行数:53,代码来源:test_manager.py

示例10: test_get_query_set

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_get_query_set(self):
        # create unpublished item
        unpublished_obj = ModelBase(title='title', state='unpublished')
        unpublished_obj.save()
        unpublished_obj.sites.add(self.web_site)
        unpublished_obj.save()

        # create published item
        published_obj = ModelBase(title='title', state='published')
        published_obj.save()
        published_obj.sites.add(self.web_site)
        published_obj.save()

        # create staging item
        staging_obj = ModelBase(title='title', state='staging')
        staging_obj.save()
        staging_obj.sites.add(self.web_site)
        staging_obj.save()

        # unpublished objects should not be available in queryset
        queryset = ModelBase.permitted.all()
        self.failIf(unpublished_obj in queryset)

        # published objects should always be available in queryset
        self.failUnless(published_obj in queryset)

        # Staging objects should only be available on instances
        # that define settings.STAGING = True.
        from django.conf import settings
        settings.STAGING = False
        queryset = ModelBase.permitted.all()
        self.failIf(staging_obj in queryset)
        settings.STAGING = True
        queryset = ModelBase.permitted.all()
        self.failUnless(staging_obj in queryset)

        # queryset should only contain items for the current site
        published_obj_web = ModelBase(state='published')
        published_obj_web.save()
        published_obj_web.sites.add(self.web_site)
        published_obj_web.save()
        queryset = ModelBase.permitted.all()
        self.failUnless(published_obj_web in queryset)

        # queryset should not contain items for other sites
        mobile_site = Site(id=101, domain="mobi.address.com")
        mobile_site.save()
        published_obj_mobile = ModelBase(state='published')
        published_obj_mobile.save()
        published_obj_mobile.sites.add(mobile_site)
        published_obj_mobile.save()
        queryset = ModelBase.permitted.all()
        self.failIf(published_obj_mobile in queryset)
开发者ID:,项目名称:,代码行数:55,代码来源:

示例11: test_is_permitted

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_is_permitted(self):
        # create unpublished item
        unpublished_obj = ModelBase(title='title', state='unpublished')
        unpublished_obj.save()
        unpublished_obj.sites.add(self.web_site)
        unpublished_obj.save()

        # create published item
        published_obj = ModelBase(title='title', state='published')
        published_obj.save()
        published_obj.sites.add(self.web_site)
        published_obj.save()

        # create staging item
        staging_obj = ModelBase(title='title', state='staging')
        staging_obj.save()
        staging_obj.sites.add(self.web_site)
        staging_obj.save()

        # is_permitted should be False for unpublished objects
        self.failIf(unpublished_obj.is_permitted)

        # is_permitted should be True for published objects
        self.failUnless(published_obj.is_permitted)

        # Is_permitted should be True for otherwise published objects in
        # the staging state for instances that define settings.STAGING = True.
        from django.conf import settings
        settings.STAGING = False
        self.failIf(staging_obj.is_permitted)
        settings.STAGING = True
        self.failUnless(staging_obj.is_permitted)

        # Is_permitted should be True only if the object is
        # published for the current site.
        published_obj_web = ModelBase(state='published')
        published_obj_web.save()
        published_obj_web.sites.add(self.web_site)
        published_obj_web.save()
        self.failUnless(published_obj_web.is_permitted)

        # Is_permitted should be False if the object is
        # not published for the current site.
        mobile_site = Site(id=100, domain="mobi.address.com")
        mobile_site.save()
        published_obj_mobile = ModelBase(state='published')
        published_obj_mobile.save()
        published_obj_mobile.sites.add(mobile_site)
        published_obj_mobile.save()
        self.failIf(published_obj_mobile.is_permitted)
开发者ID:,项目名称:,代码行数:52,代码来源:

示例12: test_unique_slugs

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_unique_slugs(self):
        # create 2 sites
        site_1 = Site(id=201, domain="site1.example.com")
        site_1.save()
        site_2 = Site(id=202, domain="site2.example.com")
        site_2.save()

        # Create an object for site 1
        obj_1 = ModelBase(title='object for site 1')
        obj_1.save()
        obj_1.sites.add(site_1)
        obj_1.slug = 'generic_slug'
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title='object for site 2')
        obj_2.save()
        obj_2.sites.add(site_2)
        obj_2.slug = 'generic_slug'
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.sites.add(site_1)
            obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = 'generic_slug_2'
        obj_2.sites.add(site_1)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.slug = 'generic_slug'
            obj_2.save()
开发者ID:,项目名称:,代码行数:37,代码来源:

示例13: test_generate_slug

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_generate_slug(self):
        # on save a slug should be set
        obj = ModelBase(title='utils test case title')
        obj.save()
        self.failIf(obj.slug == '')

        # slug should become sluggified version of title
        obj = ModelBase(title='utils test case title 1')
        obj.save()
        self.failUnless(obj.slug == slugify(obj.title))

        # no two items should have the same slug
        obj = ModelBase(title='utils test case title 1')
        obj.save()

        # in case an object title is updated, the slug not be updated
        obj.title = "updated title"
        obj.save()
        self.failIf(obj.slug == slugify(obj.title))

        # In case an object is updated, without the title being changed
        # the slug should remain unchanged.
        orig_slug = obj.slug
        obj.save()
        self.failUnless(obj.slug == orig_slug)

        # make sure the slug is actually saved
        obj = ModelBase.objects.get(id=obj.id)
        self.failIf(obj.slug == '')

        # Empty slugs might trip up regex query.
        obj = ModelBase()
        obj.save()
        obj = ModelBase()
        obj.save()
        obj = ModelBase()
        obj.save()
开发者ID:,项目名称:,代码行数:39,代码来源:

示例14: test_is_permitted

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_is_permitted(self):
        # create unpublished item
        unpublished_obj = ModelBase(title="title", state="unpublished")
        unpublished_obj.save()
        unpublished_obj.sites.add(self.web_site)
        unpublished_obj.save()

        # create published item
        published_obj = ModelBase(title="title", state="published")
        published_obj.save()
        published_obj.sites.add(self.web_site)
        published_obj.save()

        # is_permitted should be False for unpublished objects
        self.failIf(unpublished_obj.is_permitted)

        # is_permitted should be True for published objects
        self.failUnless(published_obj.is_permitted)

        # Is_permitted should be True only if the object is
        # published for the current site.
        published_obj_web = ModelBase(state="published")
        published_obj_web.save()
        published_obj_web.sites.add(self.web_site)
        published_obj_web.save()
        self.failUnless(published_obj_web.is_permitted)

        # Is_permitted should be False if the object is
        # not published for the current site.
        published_obj_mobile = ModelBase(state="published")
        published_obj_mobile.save()
        published_obj_mobile.sites.add(self.mobile_site)
        published_obj_mobile.save()
        self.failIf(published_obj_mobile.is_permitted)
开发者ID:praekelt,项目名称:jmbo,代码行数:36,代码来源:test_modelbase.py

示例15: test_unique_slugs

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import save [as 别名]
    def test_unique_slugs(self):
        obj_1 = ModelBase(title="object for site 1")
        obj_1.save()
        obj_1.sites.add(self.web_site)
        obj_1.slug = "generic_slug"
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title="object for site 2")
        obj_2.save()
        obj_2.sites.add(self.mobile_site)
        obj_2.slug = "generic_slug"
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.sites.add(self.web_site)
                obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = "generic_slug_2"
        obj_2.sites.add(self.web_site)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.slug = "generic_slug"
                obj_2.save()
开发者ID:praekelt,项目名称:jmbo,代码行数:32,代码来源:test_modelbase.py


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