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 handleMacroCall(self, doc, params): from sphene.sphboard.models import Category category = params['category'] try: categoryObj = Category.objects.get( pk = category, ) except Category.DoesNotExist: return HTML( 'Category %s does not exist.' % category ) url = categoryObj.get_absolute_url_rss_latest_threads() add_rss_feed( url, 'RSS Feed of latest threads' ) return HTML( '<a href="%(url)s"><img src="%(media_url)ssphene/community/icons/feed-icon-14x14.png" border="0" alt="RSS Feed of latest threads" title="RSS Feed of latest threads" /></a>' % { 'url': url, 'media_url': settings.STATIC_URL } )
def blogindex(request, group, category_id=None, category_slug=None, page=1, year=None, month=None): """ shows a blog posts list. year and month parameters are used for archive functionality. """ category_info = get_category_info(category_id=category_id, category_slug=category_slug, group=group) if not category_info: return render_to_response('sphene/sphblog/nocategory.html', {}, context_instance=RequestContext(request)) context_variables = {} if year: context_variables['archive_year'] = year year = int(year) if month: context_variables['archive_month'] = month month = int(month) threads = get_posts_queryset(group, category_info[0], year, month) paged_threads = get_paged_objects(threads, page) allowpostcategories = filter(Category.has_post_thread_permission, category_info[0]) #blog_feed_url = reverse('sphblog-feeds', urlconf=get_current_urlconf(), args = ('latestposts',), kwargs = { 'groupName': group.name }) blog_feed_url = sph_reverse('sphblog-feeds') #, kwargs = { 'url': 'latestposts' }) add_rss_feed(blog_feed_url, 'Blog RSS Feed') all_tags = get_tags_for_categories(category_info[0]) context_variables.update({ 'allowpostcategories': allowpostcategories, 'threads': paged_threads, 'blog_feed_url': blog_feed_url, 'all_tags': all_tags, 'category': category_info[1], 'categories': category_info[0], 'group': group, }) return render_to_response('sphene/sphblog/blogindex.html', context_variables, context_instance=RequestContext(request))
def handleMacroCall(self, doc, params): from sphene.sphboard.models import Category category = params['category'] try: categoryObj = Category.objects.get(pk=category, ) except Category.DoesNotExist: return HTML('Category %s does not exist.' % category) url = categoryObj.get_absolute_url_rss_latest_threads() add_rss_feed(url, 'RSS Feed of latest queries') return HTML( '<a href="%(url)s"><img src="%(media_url)ssphene/community/icons/feed-icon-14x14.png" border="0" alt="RSS Feed of latest queries" title="RSS Feed of latest queries" /></a>' % { 'url': url, 'media_url': settings.MEDIA_URL })
def blogindex(request, group, category_id = None, category_slug = None, page = 1, year=None, month=None): """ shows a blog posts list. year and month parameters are used for archive functionality. """ category_info = get_category_info(category_id = category_id, category_slug = category_slug, group = group) if not category_info: return render_to_response('sphene/sphblog/nocategory.html', {}, context_instance = RequestContext(request)) context_variables = {} if year: context_variables['archive_year'] = year year = int(year) if month: context_variables['archive_month'] = month month = int(month) threads = get_posts_queryset(group, category_info[0], year, month) paged_threads = get_paged_objects(threads, page) allowpostcategories = filter(Category.has_post_thread_permission, category_info[0]) #blog_feed_url = reverse('sphblog-feeds', urlconf=get_current_urlconf(), args = ('latestposts',), kwargs = { 'groupName': group.name }) blog_feed_url = sph_reverse('sphblog-feeds');#, kwargs = { 'url': 'latestposts' }) add_rss_feed( blog_feed_url, 'Blog RSS Feed' ) all_tags = get_tags_for_categories( category_info[0] ) context_variables.update({'allowpostcategories': allowpostcategories, 'threads': paged_threads, 'blog_feed_url': blog_feed_url, 'all_tags': all_tags, 'category': category_info[1], 'categories': category_info[0], 'group': group, }) return render_to_response( 'sphene/sphblog/blogindex.html', context_variables, context_instance = RequestContext(request) )
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
def showCategory(request, group, category_id=None, showType=None, slug=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. We no longer support having no group !! """ 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 = sph_reverse("sphboard-feeds", kwargs={"url": "latest/%s" % categoryObject.id}) add_rss_feed(blog_feed_url, "Latest Threads in %s RSS Feed" % categoryObject.name) if sphdata != None: sphdata["subtitle"] = categoryObject.name elif sphdata is not None: sphdata["subtitle"] = ugettext("Forum Overview") 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
def showCategory(request, group, category_id=None, showType=None, slug=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. We no longer support having no group !! """ 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 = sph_reverse('sphboard-feeds', kwargs={'category_id': categoryObject.id}) add_rss_feed(blog_feed_url, 'Latest Threads in %s RSS Feed' % categoryObject.name) if sphdata != None: sphdata['subtitle'] = categoryObject.name elif sphdata is not None: sphdata['subtitle'] = ugettext('Forum Overview') 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 thread_args['root_post__is_hidden'] = 0 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') thread_list = thread_list.select_related('root_post', 'latest_post', 'root_post__category', 'root_post__author', 'latest_post__author') 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
def get(self, request, group=None, category_id=0, show_type=None, *args, **kwargs): category_id = category_id and int(category_id) or 0 self.group = group self.request = request if group is None: raise Http404 query_args = {'group': group, 'parent__isnull': True} sphdata = get_current_sphdata() categories = [] category = None if category_id: query_args['parent__isnull'] = False query_args['parent'] = category_id category = get_object_or_404(Category, pk=category_id) if not category.has_view_permission(request.user): raise PermissionDenied() category.touch(request.session, request.user) blog_feed_url = sph_reverse('sphboard-feeds', kwargs={'category_id': category.id}) add_rss_feed(blog_feed_url, 'Latest Threads in %s RSS Feed' % category.name) if sphdata is not None: sphdata['subtitle'] = category.name elif sphdata is not None: sphdata['subtitle'] = ugettext('Forum Overview') if show_type != 'threads': categories = Category.sph_objects.filter( group=group) # filter_for_group( args['group'] ) if category: categories = categories.filter(parent=category) else: categories = categories.filter(parent__isnull=True) categories = [ category for category in categories if category.has_view_permission(request.user) ] self.prepared_context = { 'rootCategories': categories, 'category': category, 'allowPostThread': category and category.allowPostThread(request.user), 'category_id': category_id, 'show_type': show_type, } try: self.prepared_context['search_posts_url'] = sph_reverse( 'sphsearchboard_posts') except: pass return super(CategoryList, self).get(request, *args, **kwargs)