Esempio n. 1
0
def init_data(app, created_models, verbosity, **kwargs):
    from sphene.community.models import Group
    from sphene.sphboard.models import Category, ThreadInformation, Post
    if Category in created_models:
        group = Group.objects.get( name = 'DishNine' )
        category = Category( name = 'Example Category',
                             group = group,
                             description = 'This is just an example Category. You can modify categories in the django admin interface.',
                             )
        category.save()

    if ThreadInformation in created_models:
        # Synchronize ThreadInformation with all posts ..
        # (Required for backward compatibility)
        synchronize_threadinformation(verbosity)
Esempio n. 2
0
    def setUp(self):
        self.testuser = testutils.get_testuser()
        self.testgroup = testutils.get_testgroup()
        testutils.setup_threadlocals(self.testuser, self.testgroup)

        # Setup test role ..
        self.testrole = testutils.get_testrole()

        # Test category
        # Since we are testing permissions .. revoke all permissions
        self.c = Category(name = 'Simple Test Category',
                          allowview = 3,
                          allowreplies = 3,
                          allowthreads = 3,)
        self.c.save()
Esempio n. 3
0
    def get_or_create_for_object(self, model_instance):
        # Find a category associated with the given object
        model_type = ContentType.objects.get_for_model(model_instance)
        try:
            return self.filter(object_type__pk=model_type.id,
                               object_id=model_instance.pk).get()
        except CommentsCategoryConfig.DoesNotExist:
            # Find root category
            group = get_current_group()
            from sphene.sphcomments.categorytypes import CommentsCategoryType, CommentsOnObjectCategoryType
            if not group.id in root_category_id:
                try:
                    root_category_id[group.id] = Category.objects.get(
                        group=group,
                        category_type=CommentsCategoryType.name,
                    ).id
                except Category.DoesNotExist:
                    raise CommentsCategoryConfig.DoesNotExist(
                        'Please create a category of type "%s" (%s).' %
                        (CommentsCategoryType.label,
                         CommentsCategoryType.name))

            # create a new category ...
            # to copy preferences we need the root category ..
            root_category = Category.objects.get(pk=root_category_id[group.id])
            # TODO role permissions are currently not copied ..
            category = Category(
                name='comment category for "%s"' % str(model_instance),
                parent=root_category,
                group=group,
                category_type=CommentsOnObjectCategoryType.name,
                allowview=root_category.allowview,
                allowthreads=root_category.allowthreads,
                allowreplies=root_category.allowreplies,
                slug='comments-%s' % ''.join(
                    random.choices(string.ascii_uppercase + string.digits,
                                   k=5)))
            category.save()
            config = CommentsCategoryConfig(category=category,
                                            content_object=model_instance)
            config.save()
            return config
Esempio n. 4
0
    def setUp(self):
        """
            We have 2 categories cat1 and cat2 and 2 threads (total 4 posts):

              cat1/                  -- category cat1
                 cat1_p1             -- thread/post c1_p1 in category cat1
                   cat1_p2           -- post c1_p2 in thread cat1_p1
                   cat1_p3           -- post c1_p3 in thread cat1_p1
              cat2/                  -- category cat2
                 cat2_p1             -- thread/post cat2_p1 in category cat2
        """
        self.testuser = testutils.get_testuser()
        self.superuser = testutils.get_superuser()
        self.testgroup = testutils.get_testgroup()
        testutils.setup_threadlocals(self.testuser, self.testgroup)

        # Setup test role ..
        self.testrole = testutils.get_testrole()

        # Test category 1
        self.cat1 = Category(name='Category 1',
                             allowview=3,
                             allowreplies=3,
                             allowthreads=3,
                             group=self.testgroup)
        self.cat1.save()

        self.cat2 = Category(name='Category 2',
                             allowview=3,
                             allowreplies=3,
                             allowthreads=3,
                             group=self.testgroup)
        self.cat2.save()

        # create thread 1 in category c1
        self.cat1_p1 = Post(category=self.cat1,
                            subject='Post p1 in category c1',
                            body="post 1",
                            markup='bbcode',
                            author=self.testuser)
        self.cat1_p1.save()

        self.cat1_p2 = Post(category=self.cat1,
                            subject='Post p2 in category c1',
                            body="post 2",
                            markup='bbcode',
                            thread=self.cat1_p1,
                            author=self.testuser)
        self.cat1_p2.save()

        self.cat1_p3 = Post(category=self.cat1,
                            subject='Post p3 in category c1',
                            body="post 3",
                            markup='bbcode',
                            thread=self.cat1_p1,
                            author=self.testuser)
        self.cat1_p3.save()

        # create thread 2 in category cat2
        self.cat2_p1 = Post(category=self.cat2,
                            subject='Post p1 in category cat2',
                            body="post 1",
                            markup='bbcode',
                            author=self.testuser)
        self.cat2_p1.save()

        # log in the user
        logged_in = self.client.login(username='******',
                                      password='******')