def save_post(self, newpost, data):
        super(BlogCategoryType, self).save_post(newpost, data)
        if newpost.thread is not None:
            return
        try:
            ext = newpost.blogpostextension_set.get()
        except BlogPostExtension.DoesNotExist:
            ext = BlogPostExtension( post = newpost, )


        ext.slug = data['slug']
        ext.status = data['status']
        ext.save()

        tag_set_labels( newpost, data['tags'] )

        if newpost.is_new_post:
            try:
                config = BlogCategoryConfig.objects.get( \
                    category = self.category)

                if config.enable_googleblogping:
                    # If enabled, ping google blogsearch.
                    import urllib
                    url = self.category.group.get_baseurl()
                    blog_feed_url = reverse('sphblog-feeds', urlconf=get_current_urlconf(), kwargs = { 'url': 'latestposts/%s' % self.category.id })
                    pingurl = 'http://blogsearch.google.com/ping?%s' % \
                        urllib.urlencode( \
                        { 'name': self.category.name,
                          'url': ''.join((url, self.category.get_absolute_url()),),
                          'changesURL': ''.join((url, blog_feed_url),) } )
                    urllib.urlopen( pingurl )

            except BlogCategoryConfig.DoesNotExist:
                pass
Esempio n. 2
0
def blogindex(request, group, category_id = None):
    categories = get_board_categories(group)
    if category_id is not None:
        category_id = int(category_id)
        categories = [category for category in categories \
                          if category.id == category_id]
    if not categories:
        return render_to_response( 'sphene/sphblog/nocategory.html',
                                   { },
                                   context_instance = RequestContext(request) )

    threads = get_posts_queryset(group, categories)

    allowpostcategories = filter(Category.has_post_thread_permission, categories)
    #blog_feed_url = reverse('sphblog-feeds', urlconf=get_current_urlconf(), args = ('latestposts',), kwargs = { 'groupName': group.name })
    blog_feed_url = reverse('sphblog-feeds', urlconf=get_current_urlconf(), kwargs = { 'url': 'latestposts' })
    add_rss_feed( blog_feed_url, 'Blog RSS Feed' )
    all_tags = get_tags_for_categories( categories )
    return render_to_response( 'sphene/sphblog/blogindex.html',
                               { 'allowpostcategories': allowpostcategories,
                                 'threads': threads,
                                 'blog_feed_url': blog_feed_url,
                                 'all_tags': all_tags,
                                 },
                               context_instance = RequestContext(request) )
    def save_post(self, newpost, data):
        super(BlogCategoryType, self).save_post(newpost, data)
        if newpost.thread is not None:
            return
        try:
            ext = newpost.blogpostextension_set.get()
        except BlogPostExtension.DoesNotExist:
            ext = BlogPostExtension(post=newpost, )

        ext.slug = data['slug']
        ext.status = data['status']
        ext.save()

        tag_set_labels(newpost, data['tags'])

        if newpost.is_new_post:
            try:
                config = BlogCategoryConfig.objects.get( \
                    category = self.category)

                if config.enable_googleblogping:
                    # If enabled, ping google blogsearch.
                    import urllib
                    url = self.category.group.get_baseurl()
                    blog_feed_url = sph_reverse(
                        'sphblog-feeds',
                        urlconf=get_current_urlconf(),
                        kwargs={'category_id': self.category.id})
                    pingurl = 'http://blogsearch.google.com/ping?%s' % \
                        urllib.urlencode( \
                        { 'name': self.category.name,
                          'url': ''.join((url, self.category.get_absolute_url()),),
                          'changesURL': ''.join((url, blog_feed_url),) } )
                    urllib.urlopen(pingurl)

            except BlogCategoryConfig.DoesNotExist:
                pass
Esempio n. 4
0
def showCategory(request, group = None, category_id = None, showType = None):
    """
    displays either all root categories, or the contents of a category.
    the contents of a category could be other categories or forum threads.

    TODO: clean this mess up - sorry for everyone who trys to understand
    this function - this is is probably the oldest and ugliest in 
    the whole SCT source.
    """
    args = {
        'group__isnull': True,
        'parent__isnull': True,
        }
    categoryObject = None
    
    sphdata = get_current_sphdata()
    
    if category_id != None and category_id != '0':
        args['parent__isnull'] = False
        args['parent'] = category_id
        categoryObject = get_object_or_404(Category, pk = category_id)
        if not categoryObject.has_view_permission( request.user ):
            raise PermissionDenied()
        categoryObject.touch(request.session, request.user)
        blog_feed_url = reverse('sphboard-feeds', urlconf=get_current_urlconf(), args = (), kwargs = { 'url': 'latest/2' })
        add_rss_feed( blog_feed_url, 'Latest Threads in %s RSS Feed' % categoryObject.name )

        if sphdata != None: sphdata['subtitle'] = categoryObject.name
        
    if group != None:
        args['group__isnull'] = False
        args['group'] = group

    if showType == 'threads':
        categories = []
    else:
        if 'group' in args:
            categories = Category.sph_objects.filter( group = args['group'] )#filter_for_group( args['group'] )
            if 'parent' in args:
                categories = categories.filter( parent = category_id )
            else:
                categories = categories.filter( parent__isnull = True )
            categories = [ category for category in categories if category.has_view_permission( request.user ) ]
        else:
            categories = Category.objects.filter( **args )
    
    context = { 'rootCategories': categories,
                'category': categoryObject,
                'allowPostThread': categoryObject and categoryObject.allowPostThread( request.user ),
                'category_id': category_id, }

    try:
        context['search_posts_url'] = sph_reverse('sphsearchboard_posts')
    except:
        pass

    templateName = 'sphene/sphboard/listCategories.html'
    if categoryObject == None:
        if showType != 'threads':
            return render_to_response( templateName, context,
                                       context_instance = RequestContext(request) )
        
        ## Show the latest threads from all categories.
        allowed_categories = get_all_viewable_categories( group, request.user )
        
        if group != None: thread_args = { 'category__group': group }
        else: thread_args = { 'category__group__isnull': True }
        #thread_args[ 'thread__isnull'] = True
        thread_args[ 'category__id__in'] = allowed_categories
        context['isShowLatest'] = True
        thread_list = ThreadInformation.objects.filter( **thread_args )
    else:
        category_type = categoryObject.get_category_type()
        templateName = category_type.get_threadlist_template()
        thread_list = categoryObject.get_thread_list()

    #thread_list = thread_list.extra( select = { 'latest_postdate': 'SELECT MAX(postdate) FROM sphboard_post AS postinthread WHERE postinthread.thread_id = sphboard_post.id OR postinthread.id = sphboard_post.id', 'is_sticky': 'status & %d' % POST_STATUSES['sticky'] } )
    if showType != 'threads':
        thread_list = thread_list.order_by( '-sticky_value', '-thread_latest_postdate' )
    else:
        thread_list = thread_list.order_by( '-thread_latest_postdate' )

    res =  object_list( request = request,
                        queryset = thread_list,
                        template_name = templateName,
                        extra_context = context,
                        template_object_name = 'thread',
                        allow_empty = True,
                        paginate_by = 10,
                        )
    
    res.sph_lastmodified = True
    return res
Esempio n. 5
0
def showCategory(request, group=None, category_id=None, showType=None):
    """
    displays either all root categories, or the contents of a category.
    the contents of a category could be other categories or forum threads.

    TODO: clean this mess up - sorry for everyone who trys to understand
    this function - this is is probably the oldest and ugliest in 
    the whole SCT source.
    """
    args = {
        'group__isnull': True,
        'parent__isnull': True,
    }
    categoryObject = None

    sphdata = get_current_sphdata()

    if category_id != None and category_id != '0':
        args['parent__isnull'] = False
        args['parent'] = category_id
        categoryObject = get_object_or_404(Category, pk=category_id)
        if not categoryObject.has_view_permission(request.user):
            raise PermissionDenied()
        categoryObject.touch(request.session, request.user)
        blog_feed_url = reverse('sphboard-feeds',
                                urlconf=get_current_urlconf(),
                                args=(),
                                kwargs={'url': 'latest/2'})
        add_rss_feed(blog_feed_url,
                     'Latest Threads in %s RSS Feed' % categoryObject.name)

        if sphdata != None: sphdata['subtitle'] = categoryObject.name

    if group != None:
        args['group__isnull'] = False
        args['group'] = group

    if showType == 'threads':
        categories = []
    else:
        if 'group' in args:
            categories = Category.sph_objects.filter(
                group=args['group'])  #filter_for_group( args['group'] )
            if 'parent' in args:
                categories = categories.filter(parent=category_id)
            else:
                categories = categories.filter(parent__isnull=True)
            categories = [
                category for category in categories
                if category.has_view_permission(request.user)
            ]
        else:
            categories = Category.objects.filter(**args)

    context = {
        'rootCategories':
        categories,
        'category':
        categoryObject,
        'allowPostThread':
        categoryObject and categoryObject.allowPostThread(request.user),
        'category_id':
        category_id,
    }

    try:
        context['search_posts_url'] = sph_reverse('sphsearchboard_posts')
    except:
        pass

    templateName = 'sphene/sphboard/listCategories.html'
    if categoryObject == None:
        if showType != 'threads':
            return render_to_response(templateName,
                                      context,
                                      context_instance=RequestContext(request))

        ## Show the latest threads from all categories.
        allowed_categories = get_all_viewable_categories(group, request.user)

        if group != None: thread_args = {'category__group': group}
        else: thread_args = {'category__group__isnull': True}
        #thread_args[ 'thread__isnull'] = True
        thread_args['category__id__in'] = allowed_categories
        context['isShowLatest'] = True
        thread_list = ThreadInformation.objects.filter(**thread_args)
    else:
        category_type = categoryObject.get_category_type()
        templateName = category_type.get_threadlist_template()
        thread_list = categoryObject.get_thread_list()

    #thread_list = thread_list.extra( select = { 'latest_postdate': 'SELECT MAX(postdate) FROM sphboard_post AS postinthread WHERE postinthread.thread_id = sphboard_post.id OR postinthread.id = sphboard_post.id', 'is_sticky': 'status & %d' % POST_STATUSES['sticky'] } )
    if showType != 'threads':
        thread_list = thread_list.order_by('-sticky_value',
                                           '-thread_latest_postdate')
    else:
        thread_list = thread_list.order_by('-thread_latest_postdate')

    res = object_list(
        request=request,
        queryset=thread_list,
        template_name=templateName,
        extra_context=context,
        template_object_name='thread',
        allow_empty=True,
        paginate_by=10,
    )

    res.sph_lastmodified = True
    return res