예제 #1
0
    def test_get_or_create(self):
        post_1, created_1 = get_or_create(Post, title='foo', short_text='bar')
        db.session.add(post_1)
        db.session.commit()
        post_2, created_2 = get_or_create(Post, title='foo', short_text='bar')

        self.assertTrue(created_1)
        self.assertFalse(created_2)
        self.assertEqual(post_1, post_2)
예제 #2
0
    def __setitem__(self, key, value):
        setting, created = get_or_create(Setting, key=key)
        setting.value = value
        setting.save()

        # Delete the Setting dictionary cache
        cache.delete_memoized(Setting.as_dict)
예제 #3
0
    def save(self, set_author=False):
        """
        Saves the Post object.

        Args:
            set_author: If True, the author of the post is set to the current user.

        Returns:
            The Post object

        """

        if set_author:
            self.post.author = current_user

        self.populate_obj(self.post)
        self.post.tags = [get_or_create(Tag, name=tag)[0] for tag in set(self.tags.data)]

        return self.post.save()