def get_absolute_url(self): return ('article-detail', None, {'year': self.publish.year, 'month': int(self.publish.strftime('%m').lower()), 'day': self.publish.day, 'slug': self.slug}) class Diary(models.Model): """Diary, that accepts comments.""" body = models.TextField('body') allow_comments = models.BooleanField('allow comments', default=True) publish = models.DateTimeField('publish', default=datetime.now) objects = PublicManager() class Meta: db_table = 'demo_diary' ordering = ('-publish',) class DiaryCommentModerator(XtdCommentModerator): email_notification = True enable_field = 'allow_comments' auto_moderate_field = 'publish' moderate_after = 2 removal_suggestion_notification = True moderator.register(Diary, DiaryCommentModerator)
ret = word[1:] if word.endswith('.') or word.endswith(','): ret = word[:-1] return ret lowcase_comment = comment.comment.lower() msg = dict([(clean(w), i) for i, w in enumerate(lowcase_comment.split())]) for badword in badwords: if isinstance(badword, str): if lowcase_comment.find(badword) > -1: return True else: lastindex = -1 for subword in badword: if subword in msg: if lastindex > -1: if msg[subword] == (lastindex + 1): lastindex = msg[subword] else: lastindex = msg[subword] else: break if msg.get(badword[-1]) and msg[badword[-1]] == lastindex: return True return super(PostUserCommentModerator, self).moderate(comment, content_object, request) moderator.register(Post, PostUserCommentModerator)
def __str__(self): return self.headline def get_absolute_url(self): return reverse( 'article-detail', kwargs={ 'year': self.publish_at.year, 'month': int(self.publish_at.strftime('%m').lower()), 'day': self.publish_at.day, 'slug': self.slug, }, ) class AuthorArticle(models.Model): # Django can create an automatic through table, but having it explicit # allows an easier time adding meta-data if necessary in the future. author = models.ForeignKey(Author, on_delete=models.CASCADE) article = models.ForeignKey(Article, on_delete=models.CASCADE) class ArticleCommentModerator(CommentModerator): def moderate(self, comment, content_object, request): if settings.ARTICLES_COMMENT_MODERATION_ANONYMOUS: return not request.user.is_authenticated return super(ArticleCommentModerator, self).moderate(comment, content_object, request) moderator.register(Article, ArticleCommentModerator)
for subword in badword: if subword in msg: if lastindex > -1: if msg[subword] == (lastindex + 1): lastindex = msg[subword] else: lastindex = msg[subword] else: break if msg.get(badword[-1]) and msg[badword[-1]] == lastindex: return True return super(PostCommentModerator, self).moderate(comment, content_object, request) moderator.register(Artwork, PostCommentModerator) class FeaturedVideo(models.Model): video_url = models.URLField(blank=False, null=False, verbose_name="Video URL") thumbnail_image = models.ImageField(upload_to='video_tumbnails/', max_length=500, blank=False, null=False) active = models.BooleanField(default=False) def __str__(self): return self.video_url def save(self, *args, **kwargs): if self.active: try: video = FeaturedVideo.objects.get(active=True) if self != video: video.active = False
# COMMENT MODERATOR CLASS & REGISTRATION # ··························································· class BlogPostModerator(CommentModerator): email_notification = True enable_field = 'has_comments_enabled' def moderate(self, comment, content_object, request): # moderate all messages unless superuser is posting if request.user.is_superuser: return False else: return True moderator.register(LegacyPost, BlogPostModerator) moderator.register(ModernPost, BlogPostModerator) # ··························································· # CUSTOM MEDIA CLASSES (for future use) # ··························································· class CustomImage(AbstractImage): # Add any extra fields to image here # eg. To add a caption field: # caption = models.CharField(max_length=255, blank=True) admin_form_fields = Image.admin_form_fields + ( # Then add the field names here to make them appear in the form:
'month': int(self.publish.strftime('%m').lower()), 'day': self.publish.day, 'slug': self.slug}) class BadWordsModerator(SpamModerator): def moderate(self, comment, content_object, request): # Make a dictionary where the keys are the words of the message and # the values are their relative position in the message. msg = dict([(w, i) for i, w in enumerate(comment.comment.split())]) for badword in badwords: if isinstance(badword, str): if badword in msg: return True else: lastindex = -1 for subword in badword: if subword in msg: if lastindex > -1: if msg[subword] == (lastindex + 1): lastindex = msg[subword] else: lastindex = msg[subword] else: break if msg.get(badword[-1]) and msg[badword[-1]] == lastindex: print("Comment shouldn't be public") return True moderator.register(Article, BadWordsModerator)
return reverse( 'article-detail', kwargs={'year': self.publish.year, 'month': int(self.publish.strftime('%m').lower()), 'day': self.publish.day, 'slug': self.slug}) class Diary(models.Model): """Diary, that accepts comments.""" body = models.TextField('body') allow_comments = models.BooleanField('allow comments', default=True) publish = models.DateTimeField('publish', default=datetime.now) objects = PublicManager() class Meta: db_table = 'demo_diary' ordering = ('-publish',) class DiaryCommentModerator(XtdCommentModerator): email_notification = True enable_field = 'allow_comments' auto_moderate_field = 'publish' moderate_after = 2 removal_suggestion_notification = True moderator.register(Diary, DiaryCommentModerator)
ret = word[1:] if word.endswith('.') or word.endswith(','): ret = word[:-1] return ret lowcase_comment = comment.comment.lower() msg = dict([(clean(w), i) for i, w in enumerate(lowcase_comment.split())]) for badword in badwords: if isinstance(badword, str): if lowcase_comment.find(badword) > -1: return True else: lastindex = -1 for subword in badword: if subword in msg: if lastindex > -1: if msg[subword] == (lastindex + 1): lastindex = msg[subword] else: lastindex = msg[subword] else: break if msg.get(badword[-1]) and msg[badword[-1]] == lastindex: return True return super(PostCommentModerator, self).moderate(comment, content_object, request) moderator.register(Tutorial, PostCommentModerator)
lastindex = -1 for subword in badword: if subword in msg: if lastindex > -1: if msg[subword] == (lastindex + 1): lastindex = msg[subword] else: lastindex = msg[subword] else: break if msg.get(badword[-1]) and msg[badword[-1]] == lastindex: return True return super(PostCommentModerator, self).moderate(comment, content_object, request) moderator.register(Content, PostCommentModerator) # when the person visits it for the first time store it in the below ip model and if it is not present than increase # the above field views by one if it is present than don't increase above view but increase below count def content_image_directory(instance, filename): # user_id/uploaded_in_topic/album_name/image_in_topic/created/images/filename # since here also there is no created in the path so even when saving the new image it will override the previous one # try it return 'user_%s/image/%s/%s' % (instance.user.username, instance.content.slug, filename) class ContentImage(models.Model): # from post save add this model
null=True, verbose_name=_('Application')) class Banner(SoftDeletableModel): title = models.CharField(verbose_name=_('Title'), max_length=100) description = models.TextField(verbose_name=_('Description'), blank=True, null=True) image = models.ImageField(upload_to='banners', verbose_name=_('Banner Image'), null=True, blank=True) link = models.CharField(verbose_name=_("Link"), max_length=200, null=True, blank=True) def __str__(self): return self.title class AppCommentModerator(XtdCommentModerator): removal_suggestion_notification = True email_notification = True moderator.register(MobileApp, AppCommentModerator) class PDFDoc(CommonApprovableModel): title = models.CharField(verbose_name=_('Title'), max_length=200, unique=True) description = models.TextField(verbose_name=_('Description'), blank=True, null=True) download_count = models.PositiveIntegerField(null=True, verbose_name=_('Download Count'), default=0) author = models.CharField(max_length=100, null=True, blank=True, verbose_name=_('Author')) publish_year = models.DateField(null=True, blank=True, verbose_name=_('Publish Year')) objects = models.Manager() exist_objects = SoftDeletableManager() approved_pdf = ApprovedManager() class Meta: ordering = ["-upload_time"]
"""Quote, that accepts comments.""" title = models.CharField('title', max_length=200) slug = models.SlugField('slug', unique_for_date='publish') quote = models.TextField('quote') author = models.CharField('author', max_length=255) url_source = models.URLField('url source', blank=True, null=True) allow_comments = models.BooleanField('allow comments', default=True) publish = models.DateTimeField('publish', default=timezone.now) objects = PublicManager() class Meta: db_table = 'comp_quotes' ordering = ('-publish', ) def __str__(self): return self.title def get_absolute_url(self): return reverse('quotes-quote-detail', kwargs={'slug': self.slug}) class QuoteCommentModerator(SpamModerator): email_notification = True auto_moderate_field = 'publish' moderate_after = 365 moderator.register(Quote, QuoteCommentModerator)
#!/usr/bin/env python # -*- coding: utf-8 -*- from django_comments_xtd.moderation import XtdCommentModerator, moderator from post.models import Post class BlogModerator(XtdCommentModerator): email_notification = True enable_field = 'is_commentable' moderator.register(Post, BlogModerator)