def get_queryset(self): category = self.prepared_context['category'] if category is None: if self.prepared_context['show_type'] != 'threads': # We are just showing the root categories, without any threads. return [] # Show the latest threads from all categories. allowed_categories = get_all_viewable_categories( self.group, self.request.user) if self.group is not None: thread_args = {'category__group': self.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 self.prepared_context['isShowLatest'] = True thread_list = ThreadInformation.objects.filter(**thread_args) else: thread_list = category.get_thread_list() if self.prepared_context['show_type'] != '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') return thread_list
def latest_posts_of_user_context(request, group, user): allowed_categories = get_all_viewable_categories( group, request.user ) post_list = Post.objects.filter( category__id__in = allowed_categories, author = user ) post_list = post_list.order_by( '-postdate' ) return { 'post_list': post_list, 'post_user': user, }
def latest_posts_of_user_context(request, group, user): allowed_categories = get_all_viewable_categories(group, request.user) post_list = Post.objects.filter(category__id__in=allowed_categories, author=user) post_list = post_list.order_by('-postdate') return { 'post_list': post_list, 'post_user': user, }
def move_post_1(request, group, post_id): """ Display list of categories where the post can be moved to. """ post = Post.objects.get(pk=post_id) if not post.allow_moving_post(): raise PermissionDenied() categories = get_all_viewable_categories(group, request.user) categories = Category.objects.filter(pk__in=categories) return render_to_response("sphene/sphboard/move_post_1.html", {'categories': categories, 'post': post}, context_instance = RequestContext(request))
def move_post_1(request, group, post_id): """ Display list of categories where the post can be moved to. """ post_obj = Post.objects.get(pk=post_id) if not post_obj.allow_moving_post(): raise PermissionDenied() categories = get_all_viewable_categories(group, request.user) categories = Category.objects.filter(pk__in=categories) return render(request, "sphene/sphboard/move_post_1.html", { 'categories': categories, 'post': post_obj })
def search_posts(query, category = None): group = get_current_group() user = get_current_user() #if group: # query = u''.join((u'+', u'group_id:', unicode(group.id), ' ', query)) categories = get_all_viewable_categories(group, user) if category is not None: prefix = u'category_id:%d' % category.id else: prefix = u' OR '.join([u'category_id:%d' % category for category in categories]) query = u'(%s) AND (%s)' % (prefix, query) logger.debug('Searching for: %s' % query) ret = PostFilter(post_index.search(query=query), categories) logger.debug('Searching done.') return ret
def search_posts(query, category=None): group = get_current_group() user = get_current_user() #if group: # query = u''.join((u'+', u'group_id:', unicode(group.id), ' ', query)) categories = get_all_viewable_categories(group, user) if category is not None: prefix = u'category_id:%d' % category.id else: prefix = u' OR '.join( [u'category_id:%d' % category for category in categories]) query = u'(%s) AND (%s)' % (prefix, query) logger.debug('Searching for: %s' % query) ret = PostFilter(post_index.search(query=query), categories) logger.debug('Searching done.') return ret
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