Пример #1
0
        date_hierarchy = 'pub_date'
        fields = (
            ('Publication details', {'fields': ('pub_date', 'headline', 'slug', 'geography')}),
            ('Author', {'fields': ('author',)}),
            ('Article Activity', {'fields': ('status', 'enable_comments',)}),
            ('Categorization', {'fields': ('categories', 'tags', 'featured',)}),
            ('Brief', {'fields': ('summary', 'teaser', 'pull_quote',)}),
            ('Entry', {'fields': ('body',)}),
            ('Related Material', {'fields': ('articles', 'links', 'videos', 'quotes',), 'classes': 'collapse'}),
            ('Images', {'fields': ('lead_image', 'remove_lead', 'lead_caption', 'sidebar_image', 'remove_sidebar', 'sidebar_caption', 'inline_image', 'remove_inline', 'inline_caption',), 'classes': 'collapse'}),
            ('Relevant People, Sources', {'fields': ('people', 'sources',), 'classes': 'collapse'}),
        )
        
        list_display    = ('headline', 'pub_date', 'last_modified', 'status', 'enable_comments', 'author')
        list_filter     = ['pub_date', 'author', 'status', 'categories', 'featured']
        search_fields   = ['headline', 'summary', 'body']
        date_hierarchy  = 'pub_date'


class ArticleModerator(CommentModerator):
    akismet = settings.COMMENTS_AKISMET
    auto_moderate_field = 'pub_date'
    moderate_after = settings.COMMENTS_MODERATE_AFTER
    email_notification = settings.COMMENTS_EMAIL
    enable_field = settings.COMMENTS_ENABLE_FIELD
moderator.register(Article, ArticleModerator)


#dispatcher.connect(create_tumblelog_item, sender=Article, signal=signals.post_save)
#dispatcher.connect(kill_tumblelog_item, sender=Article, signal=signals.post_delete)
Пример #2
0
    location            = models.CharField(max_length=50, blank=True, null=True)
    name                = models.CharField(max_length=50, blank=True, null=True)
    thumbnail_url       = models.URLField()
    url                 = models.URLField(blank=True, null=True)
    friends             = models.ManyToManyField('TwitterUser', related_name='friends_user_set', blank=True, null=True)
    followers           = models.ManyToManyField('TwitterUser', related_name='followers_user_set', blank=True, null=True)
    
    def numFriends(self):
        return self.friends.count()
    
    def numFollowers(self):
        return self.followers.count()
    
    def __unicode__(self):
        return self.screen_name
    
    class Admin:
        list_display = ('screen_name', 'name', 'location', 'numFriends', 'numFollowers')


class TweetModerator(CommentModerator):
    akismet = settings.COMMENTS_AKISMET
    auto_moderate_field = 'pub_time'
    moderate_after = settings.COMMENTS_MODERATE_AFTER
    email_notification = settings.COMMENTS_EMAIL
    enable_field = settings.COMMENTS_ENABLE_FIELD
moderator.register(Tweet, TweetModerator)

dispatcher.connect(create_tumblelog_item, sender=Tweet, signal=signals.post_save)
dispatcher.connect(kill_tumblelog_item, sender=Tweet, signal=signals.post_delete)
Пример #3
0
    def test_freethreadedcomment(self):

        ###########################
        ### FreeThreadedComment ###
        ###########################

        fcomment1 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            comment='This is fun!  This is very fun!',
        )
        fcomment2 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            comment='This is stupid!  I hate it!',
        )
        fcomment3 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment2,
            comment='I agree, the first comment was wrong and you are right!',
        )
        fcomment4 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            website="http://www.eflorenzano.com/",
            email="*****@*****.**",
            comment='What are we talking about?',
        )
        fcomment5 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment3,
            comment="I'm a fanboy!",
        )
        fcomment6 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment1,
            comment="What are you talking about?",
        )

        moderator.register(TestModel, Moderator1)

        fcomment7 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            comment="Post moderator addition.  Does it still work?",
        )

        topic.is_public = False
        topic.save()

        fcomment8 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment7,
            comment="This should not appear, due to enable_field",
        )

        moderator.unregister(TestModel)

        fcomment9 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            comment="This should appear again, due to unregistration",
        )

        self.assertEquals(len(mail.outbox), 0)

        moderator.register(TestModel, Moderator2)

        fcomment10 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            comment=
            "This should not appear again, due to registration with a new manager.",
        )

        topic.is_public = True
        topic.save()

        fcomment11 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment1,
            comment="This should appear again.",
        )

        self.assertEquals(len(mail.outbox), 1)

        mail.outbox = []

        topic.date = topic.date - datetime.timedelta(days=20)
        topic.save()

        fcomment12 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment7,
            comment="This shouldn't appear, due to close_after=15.",
        )

        topic.date = topic.date + datetime.timedelta(days=20)
        topic.save()

        moderator.unregister(TestModel)
        moderator.register(TestModel, Moderator3)

        fcomment13 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment7,
            comment="This shouldn't appear because it has more than 10 chars.",
        )

        fcomment14 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment7,
            comment="<10chars",
        )

        moderator.unregister(TestModel)

        class Moderator5(CommentModerator):
            allowed_markup = [
                REST,
            ]
            max_depth = 3

        moderator.register(TestModel, Moderator5)

        fcomment15 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment7,
            comment="INVALID Markup.  Should not show up.",
            markup=TEXTILE)

        fcomment16 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=None,
            comment="VALID Markup.  Should show up.",
            markup=REST)

        fcomment17 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment16,
            comment="Building Depth...Should Show Up.",
            markup=REST)

        fcomment18 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment17,
            comment="More Depth...Should Show Up.",
            markup=REST)

        fcomment19 = FreeThreadedComment.objects.create_for_object(
            topic,
            name="Eric",
            ip_address='127.0.0.1',
            parent=fcomment18,
            comment="Too Deep..Should NOT Show UP",
            markup=REST)

        moderator.unregister(TestModel)

        tree = FreeThreadedComment.public.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    <10chars
This should appear again, due to unregistration
VALID Markup.  Should show up.
    Building Depth...Should Show Up.
        More Depth...Should Show Up.
""".lstrip())

        tree = FreeThreadedComment.objects.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    This shouldn't appear because it has more than 10 chars.
    <10chars
This should appear again, due to unregistration
VALID Markup.  Should show up.
    Building Depth...Should Show Up.
        More Depth...Should Show Up.
""".lstrip())

        tree = FreeThreadedComment.objects.get_tree(topic, root=comment2)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())

        tree = FreeThreadedComment.objects.get_tree(topic, root=comment2.id)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())
Пример #4
0
            os.remove(filename)
        except OSError:
            # most likely that image doesn't exist
            pass
        if self.image_caption:
            self.image_caption, self.html_image_caption = '', ''
        self.image = None
        self.remove_image = False
        return self
    
    class Meta:
        ordering = ('-saved_date',)
        get_latest_by = 'saved_date'
        
    class Admin:
        list_display = ('description', 'saved_date', 'extended_info', 'enable_comments')
        search_fields = ['description', 'extended_info']
        date_hierarchy = 'saved_date'

class BookmarkModerator(CommentModerator):
    akismet = settings.COMMENTS_AKISMET
    auto_moderate_field = 'saved_date'
    moderate_after = settings.COMMENTS_MODERATE_AFTER
    email_notification = settings.COMMENTS_EMAIL
    enable_field = settings.COMMENTS_ENABLE_FIELD
moderator.register(Bookmark, BookmarkModerator)


dispatcher.connect(create_tumblelog_item, sender=Bookmark, signal=signals.post_save)
dispatcher.connect(kill_tumblelog_item, sender=Bookmark, signal=signals.post_delete)
Пример #5
0
    def test_threadedcomment(self):
        topic = TestModel.objects.create(name="Test")
        user = User.objects.create_user('user',
                                        '*****@*****.**',
                                        password='******')
        user2 = User.objects.create_user('user2',
                                         '*****@*****.**',
                                         password='******')

        comment1 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            comment='This is fun!  This is very fun!',
        )
        comment2 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            comment='This is stupid!  I hate it!',
        )
        comment3 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment2,
            comment='I agree, the first comment was wrong and you are right!',
        )
        comment4 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            comment='What are we talking about?',
        )
        comment5 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment3,
            comment="I'm a fanboy!",
        )
        comment6 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment1,
            comment="What are you talking about?",
        )

        class Moderator1(CommentModerator):
            enable_field = 'is_public'
            auto_close_field = 'date'
            close_after = 15

        moderator.register(TestModel, Moderator1)

        comment7 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            comment="Post moderator addition.  Does it still work?",
        )

        topic.is_public = False
        topic.save()

        comment8 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment7,
            comment="This should not appear, due to enable_field",
        )

        moderator.unregister(TestModel)

        comment9 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            comment="This should appear again, due to unregistration",
        )

        self.assertEquals(len(mail.outbox), 0)

        ##################

        class Moderator2(CommentModerator):
            enable_field = 'is_public'
            auto_close_field = 'date'
            close_after = 15
            akismet = False
            email_notification = True

        moderator.register(TestModel, Moderator2)

        comment10 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            comment=
            "This should not appear again, due to registration with a new manager.",
        )

        topic.is_public = True
        topic.save()

        comment11 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment1,
            comment="This should appear again.",
        )

        self.assertEquals(len(mail.outbox), 1)
        mail.outbox = []

        topic.date = topic.date - datetime.timedelta(days=20)
        topic.save()

        comment12 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment7,
            comment="This shouldn't appear, due to close_after=15.",
        )

        topic.date = topic.date + datetime.timedelta(days=20)
        topic.save()

        moderator.unregister(TestModel)

        class Moderator3(CommentModerator):
            max_comment_length = 10

        moderator.register(TestModel, Moderator3)

        comment13 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment7,
            comment="This shouldn't appear because it has more than 10 chars.",
        )

        comment14 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment7,
            comment="<10chars",
        )

        moderator.unregister(TestModel)

        class Moderator4(CommentModerator):
            allowed_markup = [
                REST,
            ]

        moderator.register(TestModel, Moderator4)

        comment15 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment7,
            comment="INVALID Markup.  Should not show up.",
            markup=TEXTILE)

        comment16 = ThreadedComment.objects.create_for_object(
            topic,
            user=user,
            ip_address='127.0.0.1',
            parent=comment7,
            comment="VALID Markup.  Should show up.",
            markup=REST)

        moderator.unregister(TestModel)

        tree = ThreadedComment.public.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    <10chars
    VALID Markup.  Should show up.
This should appear again, due to unregistration
""".lstrip())

        tree = ThreadedComment.objects.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    This shouldn't appear because it has more than 10 chars.
    <10chars
    VALID Markup.  Should show up.
This should appear again, due to unregistration
""".lstrip())

        tree = ThreadedComment.objects.get_tree(topic, root=comment2)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())

        tree = ThreadedComment.objects.get_tree(topic, root=comment2.id)
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals(
            "\n".join(output), """
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())
Пример #6
0
    def test_freethreadedcomment(self):
        
        ###########################
        ### FreeThreadedComment ###
        ###########################
        
        fcomment1 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1',
            comment = 'This is fun!  This is very fun!',
        )
        fcomment2 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1',
            comment = 'This is stupid!  I hate it!',
        )
        fcomment3 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment2,
            comment = 'I agree, the first comment was wrong and you are right!',
        )
        fcomment4 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', 
            website="http://www.eflorenzano.com/", email="*****@*****.**",
            comment = 'What are we talking about?',
        )
        fcomment5 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment3,
            comment = "I'm a fanboy!",
        )
        fcomment6 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment1,
            comment = "What are you talking about?",
        )
        
        moderator.register(TestModel, Moderator1)
        
        fcomment7 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1',
            comment = "Post moderator addition.  Does it still work?",
        )
        
        topic.is_public = False
        topic.save()
        
        fcomment8 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
            comment = "This should not appear, due to enable_field",
        )
        
        moderator.unregister(TestModel)
        
        fcomment9 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1',
            comment = "This should appear again, due to unregistration",
        )
        
        self.assertEquals(len(mail.outbox), 0)

        moderator.register(TestModel, Moderator2)
        
        fcomment10 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1',
            comment = "This should not appear again, due to registration with a new manager.",
        )
        
        topic.is_public = True
        topic.save()
        
        fcomment11 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment1,
            comment = "This should appear again.",
        )
        
        self.assertEquals(len(mail.outbox), 1)
        
        mail.outbox = []
        
        topic.date = topic.date - datetime.timedelta(days = 20)
        topic.save()
        
        fcomment12 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
            comment = "This shouldn't appear, due to close_after=15.",
        )
        
        topic.date = topic.date + datetime.timedelta(days = 20)
        topic.save()
        
        moderator.unregister(TestModel)
        moderator.register(TestModel, Moderator3)
        
        fcomment13 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
            comment = "This shouldn't appear because it has more than 10 chars.",
        )
        
        fcomment14 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
            comment = "<10chars",
        )
        
        moderator.unregister(TestModel)
        class Moderator5(CommentModerator):
            allowed_markup = [REST,]
            max_depth = 3
        moderator.register(TestModel, Moderator5)
        
        fcomment15 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
            comment = "INVALID Markup.  Should not show up.", markup=TEXTILE
        )
        
        fcomment16 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = None,
            comment = "VALID Markup.  Should show up.", markup=REST
        )
        
        fcomment17 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment16,
            comment = "Building Depth...Should Show Up.", markup=REST
        )
        
        fcomment18 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment17,
            comment = "More Depth...Should Show Up.", markup=REST
        )
        
        fcomment19 = FreeThreadedComment.objects.create_for_object(
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment18,
            comment = "Too Deep..Should NOT Show UP", markup=REST
        )
        
        moderator.unregister(TestModel)
        
        tree = FreeThreadedComment.public.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    <10chars
This should appear again, due to unregistration
VALID Markup.  Should show up.
    Building Depth...Should Show Up.
        More Depth...Should Show Up.
""".lstrip())
        
        tree = FreeThreadedComment.objects.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    This shouldn't appear because it has more than 10 chars.
    <10chars
This should appear again, due to unregistration
VALID Markup.  Should show up.
    Building Depth...Should Show Up.
        More Depth...Should Show Up.
""".lstrip())
        
        tree = FreeThreadedComment.objects.get_tree(topic, root=comment2)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())
        
        tree = FreeThreadedComment.objects.get_tree(topic, root=comment2.id)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())
Пример #7
0
    def test_threadedcomment(self):
        topic = TestModel.objects.create(name = "Test")
        user = User.objects.create_user('user', '*****@*****.**', password='******')
        user2 = User.objects.create_user('user2', '*****@*****.**', password='******')
        
        comment1 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1',
            comment = 'This is fun!  This is very fun!',
        )
        comment2 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1',
            comment = 'This is stupid!  I hate it!',
        )
        comment3 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment2,
            comment = 'I agree, the first comment was wrong and you are right!',
        )
        comment4 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1',
            comment = 'What are we talking about?',
        )
        comment5 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment3,
            comment = "I'm a fanboy!",
        )
        comment6 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment1,
            comment = "What are you talking about?",
        )
        
        class Moderator1(CommentModerator):
            enable_field = 'is_public'
            auto_close_field = 'date'
            close_after = 15
        moderator.register(TestModel, Moderator1)
        
        comment7 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1',
            comment = "Post moderator addition.  Does it still work?",
        )
        
        topic.is_public = False
        topic.save()
        
        comment8 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
            comment = "This should not appear, due to enable_field",
        )
        
        moderator.unregister(TestModel)
        
        comment9 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1',
            comment = "This should appear again, due to unregistration",
        )

        self.assertEquals(len(mail.outbox), 0)
        
        ##################
        
        class Moderator2(CommentModerator):
            enable_field = 'is_public'
            auto_close_field = 'date'
            close_after = 15
            akismet = False
            email_notification = True
        moderator.register(TestModel, Moderator2)
        
        comment10 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1',
            comment = "This should not appear again, due to registration with a new manager.",
        )
        
        topic.is_public = True
        topic.save()
        
        comment11 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment1,
            comment = "This should appear again.",
        )
        
        self.assertEquals(len(mail.outbox), 1)
        mail.outbox = []
        
        topic.date = topic.date - datetime.timedelta(days = 20)
        topic.save()
        
        comment12 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
            comment = "This shouldn't appear, due to close_after=15.",
        )
        
        topic.date = topic.date + datetime.timedelta(days = 20)
        topic.save()
        
        moderator.unregister(TestModel)
        
        class Moderator3(CommentModerator):
            max_comment_length = 10
        moderator.register(TestModel, Moderator3)
        
        comment13 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
            comment = "This shouldn't appear because it has more than 10 chars.",
        )
        
        comment14 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
            comment = "<10chars",
        )
        
        moderator.unregister(TestModel)
        
        class Moderator4(CommentModerator):
            allowed_markup = [REST,]
        moderator.register(TestModel, Moderator4)
        
        comment15 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
            comment = "INVALID Markup.  Should not show up.", markup=TEXTILE
        )
        
        comment16 = ThreadedComment.objects.create_for_object(
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
            comment = "VALID Markup.  Should show up.", markup=REST
        )
        
        moderator.unregister(TestModel)
        
        tree = ThreadedComment.public.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    <10chars
    VALID Markup.  Should show up.
This should appear again, due to unregistration
""".lstrip())

        tree = ThreadedComment.objects.get_tree(topic)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is fun!  This is very fun!
    What are you talking about?
    This should appear again.
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
What are we talking about?
Post moderator addition.  Does it still work?
    This shouldn't appear because it has more than 10 chars.
    <10chars
    VALID Markup.  Should show up.
This should appear again, due to unregistration
""".lstrip())
        
        tree = ThreadedComment.objects.get_tree(topic, root=comment2)
        output = []
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())
        
        tree = ThreadedComment.objects.get_tree(topic, root=comment2.id)
        for comment in tree:
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
        self.assertEquals("\n".join(output),
"""
This is stupid!  I hate it!
    I agree, the first comment was wrong and you are right!
        I'm a fanboy!
""".lstrip())
Пример #8
0
from django.contrib import admin
from django.db.models import get_model

# Markdown editor
admin.autodiscover()

Post = get_model('blog','post')
PostAdmin = type(admin.site._registry[Post])

class NewPostAdmin(PostAdmin):
    class Media:
        js = ('js/wmd/wmd.js',)

admin.site.unregister(Post)
admin.site.register(Post, NewPostAdmin)

# Comment Moderator

from threadedcomments.moderation import moderator, CommentModerator

class PostModerator(CommentModerator):
    akismet = True
    enable_field = 'allow_comments'
    allowed_markup = (1,) #Markdown
    email_notification = True

moderator.register(Post, PostModerator)
Пример #9
0
    
    class Admin:
        list_display = ('owner', 'sync_date', 'numPhotos')


class PhotoSet(models.Model):
    flickr_id           = models.CharField(max_length=50)
    owner               = models.CharField(max_length=50)
    title               = models.CharField(max_length=200)
    description         = models.CharField(max_length=250)
    photos              = models.ManyToManyField('Photo')
    
    def numPhotos(self):
        return len(self.photos.objects.all())
    
    def __unicode__(self):
        return u"%s photo set by %s" % (self.title, self.owner)
    
    class Admin:
        list_display = ('flickr_id', 'owner', 'title')

class PhotoModerator(CommentModerator):
    akismet = settings.COMMENTS_AKISMET
    auto_moderate_field = 'taken_date'
    moderate_after = settings.COMMENTS_MODERATE_AFTER
    email_notification = settings.COMMENTS_EMAIL
    enable_field = settings.COMMENTS_ENABLE_FIELD
moderator.register(Photo, PhotoModerator)
        
dispatcher.connect(create_tumblelog_item, sender=Photo, signal=signals.post_save)
dispatcher.connect(kill_tumblelog_item, sender=Photo, signal=signals.post_delete)