Beispiel #1
0
            "slug": self.slug,
        })
        

class PostModerator(CommentModerator):
    akismet = True
    email_notification = True
    enable_field = "enable_comments"
    
    def email(self, comment, content_object):
        """
        Use django-mailer for mail delivery.
        """
        if self.email_notification and not comment.is_public:
            return
        recipient_list = [manager_tuple[1] for manager_tuple in settings.MANAGERS]
        t = loader.get_template("comment_utils/comment_notification_email.txt")
        ctx = Context({
            "comment": comment,
            "content_object": content_object,
            "site": Site.objects.get_current(),
        })
        subject = _('[%s] Comment: "%s"') % (
            Site.objects.get_current().name,
            content_object,
        )
        message = t.render(ctx)
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list)

moderator.register(Post, PostModerator)
Beispiel #2
0
    def save(self):
        if not self.id and self.post_elsewhere:
            import pydelicious
            try:
                pydelicious.add(settings.DELICIOUS_USER, settings.DELICIOUS_PASSWORD, smart_str(self.url), smart_str(self.title), smart_str(self.tags))
            except:
                pass # TODO: don't just silently quash a bad del.icio.us post
        if self.description:
            self.description_html = formatter(self.description)
        super(Link, self).save()
    
    def get_absolute_url(self):
        return ('coltrane_link_detail', (), { 'year': self.pub_date.strftime('%Y'),
                                              'month': self.pub_date.strftime('%b').lower(),
                                              'day': self.pub_date.strftime('%d'),
                                              'slug': self.slug })
    get_absolute_url = models.permalink(get_absolute_url)


class ColtraneModerator(CommentModerator):
    akismet = True
    auto_close_field = 'pub_date'
    email_notification = True
    enable_field = 'enable_comments'
    close_after = settings.COMMENTS_MODERATE_AFTER

moderator.register([Entry, Link], ColtraneModerator)

tagging.register(Entry, 'tag_set')
tagging.register(Link, 'tag_set')
    square_url      = property(lambda self: self.get_image_url('s'))
    thumbnail_url   = property(lambda self: self.get_image_url('t'))
    small_url       = property(lambda self: self.get_image_url('m'))
    large_url       = property(lambda self: self.get_image_url('b'))
    original_url    = property(lambda self: self.get_image_url('o'))
    
    def resized_image(self, size=(740,987)):
    	from PIL import Image, ImageOps
    	import urllib
    	import os
    	from django.conf import settings

    	if not os.path.exists('%s/images/resized/%s.jpg' % (settings.MEDIA_ROOT, self.slug)):
    		newimage = urllib.urlretrieve(str(self.original_url))
    		newimage = Image.open(newimage[0]) 
    		newimage.thumbnail(size, Image.ANTIALIAS)
    		newimage = newimage.convert("RGB") # Apparently PIL may throw errors without this
    		newimage.save('%s/images/resized/%s.jpg' % (settings.MEDIA_ROOT, self.slug), 'jpeg') 
    		
    	return '%s/images/resized/%s.jpg' % (settings.MEDIA_URL, self.slug)
    	
    def embed_video(self):
        return """<object type="application/x-shockwave-flash" width="640" height="480" data="http://www.flickr.com/apps/video/stewart.swf?v=66164" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="intl_lang=en-us&amp;photo_secret=%(s)s&amp;photo_id=%(i)s"></param> <param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=66164"></param> <param name="bgcolor" value="#000000"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=66164" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;photo_secret=%(s)s&amp;photo_id=%(i)s" height="480" width="640"></embed></object>""" % {"s": self.secret, "i": self.photo_id}
    
class PhotoModerator(CommentModerator):
    email_notification = True

try:
    moderator.register(Photo, PhotoModerator)
except AlreadyModerated:
    pass
Beispiel #4
0
        draft. Previous in this case means added *before*. None is
        this entry is the first one.
        """
        try:
            return self.get_previous_by_published(draft=False)
        except self.DoesNotExist:
            return None

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name_plural = _('Entries')
        verbose_name = _('Entry')
        get_latest_by = 'published'

try:
    moderator.register(Entry, AkismetModerator)
except AlreadyModerated:
    pass

class Image(models.Model):
    entry = models.ForeignKey(Entry)
    date = models.DateField(auto_now_add=True)
    image = models.ImageField(upload_to='uploads/%Y/%m/')

    class Meta:
        verbose_name = _('Image')
        verbose_name_plural = _('Images')

Beispiel #5
0
        return self.title
    
    def get_absolute_url(self):
        return ('texblog_category',(),{'slug':self.slug})
        

class Entry(CommonArticleInfo):
    categories = models.ManyToManyField(Category)
   
    class Meta:
        ordering = ['-pub_date']
        verbose_name_plural = "Entries"
    
    def get_media_url(self):
        """Retrun url to entry media"""
        return settings.MEDIA_URL + 'weblog/'+self.slug+'/'
 
    @permalink
    def get_absolute_url(self):
        return ('texblog_entry_detail',(),{ 'year': self.pub_date.strftime('%Y'),
                                            'month': self.pub_date.strftime('%b').lower(),
                                            'day': self.pub_date.strftime('%d'),
                                            'slug': self.slug })
                
class TexblogModerator(CommentModerator):
    akismet = True
    email_notification = True
    enable_field = 'enable_comments'
    
moderator.register(Entry,TexblogModerator)    
Beispiel #6
0
            'slug': self.slug,
            'year': self.published_at.year,
            'month': "%02d" % self.published_at.month,
            'day': "%02d" % self.published_at.day,
        })

    @models.permalink
    def get_comment_url(self):
        return('article_comments', (), {
            'section': self.section.full_path,
            'slug': self.slug,
            'year': self.published_at.year,
            'month': "%02d" % self.published_at.month,
            'day': "%02d" % self.published_at.day,
        })
moderator.register(Article, CourantModerator)
gettag.register(Article, name_field='heading')

class ArticleByline(ContentByline):
    """
    Associates a staffer with an article, including their position and the
    order to display this staffer among all staffers associated with the article.
    """
    article = models.ForeignKey(Article)


class ArticleMedia(ContentMedia):
    """
    Associates a media item with an article, including the order to display
    this media item among all media items associated with the article.
    """
    def get_previous(self):
        """
        Returns the previous Entry with "live" status by ``pub_date``,
        if there is one, or ``None`` if there isn't.

        """
        return self._next_previous_helper('previous')

    def _get_comment_count(self):
        ctype = ContentType.objects.get_for_model(self)
        return Comment.objects.filter(
                content_type__pk=smart_unicode(ctype.id),
                object_pk__exact=smart_unicode(self.id)).count()
    _get_comment_count.short_description = _(u'Number of comments')



BLOG_ENTRIES_COMMENTS_MODERATE_AFTER = getattr(settings, 'BLOG_ENTRIES_COMMENTS_MODERATE_AFTER', None)
class BlogEntriesModerator(CommentModerator):
    akismet = not settings.DEBUG
    auto_close_field = 'pub_date'
    email_notification = True
    enable_field = 'enable_comments'
    if BLOG_ENTRIES_COMMENTS_MODERATE_AFTER:
        close_after = BLOG_ENTRIES_COMMENTS_MODERATE_AFTER

moderator.register([Entry], BlogEntriesModerator)

tagging.register(Entry, 'tag_set')
Beispiel #8
0
            self.embed_code = self.get_embed_code()
        #self.pub_date = time_to_utc(self.pub_date)
        self._process_markup()
        super(Video, self).save()
    
    class Admin:
        date_hierarchy = 'pub_date'
        fields = (
            ('Upload your own', {'fields': ('path',), 'classes': 'collapse'}),
            ('Publication details', {'fields': ('pub_date', 'title', 'slug', 'description', 'commentary', 'tags', 'enable_comments',)}),
            ('Details', {'fields': ('url', 'video_id', 'source', 'embed_code', 'running_time', 'rating', 'nsfw',)}),
            ('Related Material', {'fields': ('videos', 'people', 'places',), 'classes': 'collapse'}),
        )
        
        list_display    = ('title', 'url', 'source', 'pub_date', 'enable_comments',)
        search_fields   = ['title', 'description', 'source', 'people', 'url', 'tags']
        date_hierarchy  = 'created_on'


class VideoModerator(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(Video, VideoModerator)


dispatcher.connect(create_tumblelog_item, sender=Video, signal=signals.post_save)
dispatcher.connect(kill_tumblelog_item, sender=Video, signal=signals.post_delete)
Beispiel #9
0
    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/blog/%s/%s/" % (
            self.date_created.strftime("%Y/%b/%d").lower(), self.slug)

    def save(self):
        import markdown
        self.body_html = markdown.markdown(self.body)
        j = xmlrpclib.Server('http://rpc.technorati.com/rpc/ping')
        reply = j.weblogUpdates.ping('Weather-O-Meter Update',
                                     'http://forecast.denverpost.com/')
        super(Article, self).save()
        try:
            ping_google()
        except Exception:
            # Bare 'except' because we could get a variety
            # of HTTP-related exceptions.
            pass


'''
class ArticleModerator(CommentModerator):
    akismet = True 
    email_notification = True
    enable_field = 'enable_comments'

moderator.register(Article, ArticleModerator)
'''
Beispiel #10
0
    
    def _process_markup(self):
        self.html_text =  typogrify(formatter(self.text))
    
    class Admin:
        list_display    = ('text', 'url', 'enable_comments')
        search_fields   = ['text', 'credit']


class QuoteModerator(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(Quote, QuoteModerator)


class Person(models.Model):
    created_on          = models.DateTimeField(auto_now_add=True)
    last_modified       = models.DateTimeField(auto_now=True)
    name                = models.CharField(max_length=255)
    slug                = models.SlugField(max_length=255, prepopulate_from=('name',), help_text=u'Automatically built from name', unique=True)
    bio                 = models.TextField(u'Biography', blank=True, help_text=u'Optional')
    url                 = models.URLField(u'URL', blank=True, help_text=u'Optional')
    
    def __unicode__(self):
        return u'%s' % self.name
    
    class Meta:
        verbose_name_plural = 'people'