Example #1
0
def question_list(
    request,
    initial,
    list_description=_("questions"),
    base_path=None,
    page_title=_("All Questions"),
    allowIgnoreTags=True,
    feed_url=None,
    paginator_context=None,
    show_summary=None,
    feed_sort=("-added_at",),
    feed_req_params_exclude=(_("page"), _("pagesize"), _("sort")),
    extra_context={},
):

    if show_summary is None:
        show_summary = bool(settings.SHOW_SUMMARY_ON_QUESTIONS_LIST)

    questions = initial.filter_state(deleted=False)

    if request.user.is_authenticated() and allowIgnoreTags:
        questions = questions.filter(~Q(tags__id__in=request.user.marked_tags.filter(user_selections__reason="bad")))

    if page_title is None:
        page_title = _("Questions")

    if request.GET.get("type", None) == "rss":
        if feed_sort:
            questions = questions.order_by(*feed_sort)
        return RssQuestionFeed(request, questions, page_title, list_description)(request)

    keywords = ""
    if request.GET.get("q"):
        keywords = request.GET.get("q").strip()

    # answer_count = Answer.objects.filter_state(deleted=False).filter(parent__in=questions).count()
    # answer_description = _("answers")

    if not feed_url:
        req_params = generate_uri(request.GET, feed_req_params_exclude)

        if req_params:
            req_params = "&" + req_params

        feed_url = request.path + "?type=rss" + req_params

    context = {
        "questions": questions.distinct(),
        "questions_count": questions.count(),
        "keywords": keywords,
        "list_description": list_description,
        "base_path": base_path,
        "page_title": page_title,
        "tab": "questions",
        "feed_url": feed_url,
        "show_summary": show_summary,
    }
    context.update(extra_context)

    return pagination.paginated(request, ("questions", paginator_context or QuestionListPaginatorContext()), context)
Example #2
0
def question_list(request, initial,
                  list_description=_('questions'),
                  base_path=None,
                  page_title=_("All Questions"),
                  allowIgnoreTags=True,
                  feed_url=None,
                  paginator_context=None,
                  show_summary=None,
                  feed_sort=('-added_at',),
                  feed_req_params_exclude=(_('page'), _('pagesize'), _('sort')),
                  extra_context={}):

    if show_summary is None:
        show_summary = bool(settings.SHOW_SUMMARY_ON_QUESTIONS_LIST)

    questions = initial.filter_state(deleted=False)

    if request.user.is_authenticated() and allowIgnoreTags:
        questions = questions.filter(~Q(tags__id__in = request.user.marked_tags.filter(user_selections__reason = 'bad')))

    if page_title is None:
        page_title = _("Questions")

    if request.GET.get('type', None) == 'rss':
        if feed_sort:
            questions = questions.order_by(*feed_sort)
        return RssQuestionFeed(request, questions, page_title, list_description)(request)

    keywords =  ""
    if request.GET.get("q"):
        keywords = request.GET.get("q").strip()

    #answer_count = Answer.objects.filter_state(deleted=False).filter(parent__in=questions).count()
    #answer_description = _("answers")

    if not feed_url:
        req_params = generate_uri(request.GET, feed_req_params_exclude)

        if req_params:
            req_params = '&' + req_params

        feed_url = request.path + "?type=rss" + req_params

    context = {
        'questions' : questions.distinct(),
        'questions_count' : questions.count(),
        'keywords' : keywords,
        'list_description': list_description,
        'base_path' : base_path,
        'page_title' : page_title,
        'tab' : 'questions',
        'feed_url': feed_url,
        'show_summary' : show_summary,
    }
    context.update(extra_context)

    return pagination.paginated(request,
                               ('questions', paginator_context or QuestionListPaginatorContext()), context)
Example #3
0
def question_list(request, initial,
                  list_description=_('questions'),
                  base_path=None,
                  page_title=_("All Questions"),
                  allowIgnoreTags=True,
                  feed_url=None,
                  paginator_context=None,
                  show_summary=None,
                  feed_sort=('-added_at',),
                  feed_req_params_exclude=(_('page'), _('pagesize'), _('sort')),
                  extra_context={}):

    if show_summary is None:
        show_summary = bool(settings.SHOW_SUMMARY_ON_QUESTIONS_LIST)

    questions = initial.filter_state(deleted=False)

    if request.user.is_authenticated() and allowIgnoreTags:
        questions = questions.filter(~Q(tags__id__in = request.user.marked_tags.filter(user_selections__reason = 'bad')))

    if page_title is None:
        page_title = _("Questions")

    if request.GET.get('type', None) == 'rss':
        if feed_sort:
            questions = questions.order_by(*feed_sort)
        return RssQuestionFeed(request, questions, page_title, list_description)(request)

    keywords =  ""
    if request.GET.get("q"):
        keywords = request.GET.get("q").strip()

    #answer_count = Answer.objects.filter_state(deleted=False).filter(parent__in=questions).count()
    #answer_description = _("answers")

    if not feed_url:
        req_params = generate_uri(request.GET, feed_req_params_exclude)

        if req_params:
            req_params = '&' + req_params

        feed_url = request.path + "?type=rss" + req_params

    context = {
        'questions' : questions.distinct(),
        'questions_count' : questions.count(),
        'keywords' : keywords,
        'list_description': list_description,
        'base_path' : base_path,
        'page_title' : page_title,
        'tab' : 'questions',
        'feed_url': feed_url,
        'show_summary' : show_summary,
    }
    context.update(extra_context)

    return pagination.paginated(request,
                               ('questions', paginator_context or QuestionListPaginatorContext()), context)
Example #4
0
def question_list(request,
                  initial,
                  list_description=_('questions'),
                  base_path=None,
                  page_title=_("All Questions"),
                  allowIgnoreTags=True,
                  feed_url=None,
                  paginator_context=None,
                  isIndex=None):

    questions = initial.filter_state(deleted=False)

    if request.user.is_authenticated() and allowIgnoreTags:
        questions = questions.filter(~Q(
            tags__id__in=request.user.marked_tags.filter(
                user_selections__reason='bad')))

    if page_title is None:
        page_title = _("Questions")

    if request.GET.get('type', None) == 'rss':
        questions = questions.order_by('-added_at')
        return RssQuestionFeed(request, questions, page_title,
                               list_description)(request)

    keywords = ""
    if request.GET.get("q"):
        keywords = request.GET.get("q").strip()

    #answer_count = Answer.objects.filter_state(deleted=False).filter(parent__in=questions).count()
    #answer_description = _("answers")

    if not feed_url:
        req_params = generate_uri(request.GET,
                                  (_('page'), _('pagesize'), _('sort')))
        if req_params:
            req_params = '&' + req_params

        feed_url = request.path + "?type=rss" + req_params

    return pagination.paginated(
        request,
        ('questions', paginator_context or QuestionListPaginatorContext()), {
            "questions": questions.distinct(),
            "questions_count": questions.count(),
            "keywords": keywords,
            "list_description": list_description,
            "base_path": base_path,
            "page_title": page_title,
            "tab": "index" if isIndex else "questions",
            'feed_url': feed_url,
        })
Example #5
0
def question_list(request, initial,
                  list_description=_('questions'),
                  base_path=None,
                  page_title=_("All Questions"),
                  allowIgnoreTags=True,
                  feed_url=None,
                  paginator_context=None,
                  is_home_page=False,
                  tag = None,
                  known_tip = None):

    questions = initial.filter_state(deleted=False)

    if request.user.is_authenticated() and allowIgnoreTags:
        questions = questions.filter(~Q(tags__id__in = request.user.marked_tags.filter(user_selections__reason = 'bad')))

    if page_title is None:
        page_title = _("Questions")

    if request.GET.get('type', None) == 'rss':
        questions = questions.order_by('-added_at')
        return RssQuestionFeed(request, questions, page_title, list_description)(request)

    keywords =  ""
    if request.GET.get("q"):
        keywords = request.GET.get("q").strip()

    #answer_count = Answer.objects.filter_state(deleted=False).filter(parent__in=questions).count()
    #answer_description = _("answers")

    if not feed_url:
        req_params = "&".join(generate_uri(request.GET, (_('page'), _('pagesize'), _('sort'))))
        if req_params:
            req_params = '&' + req_params

        feed_url = mark_safe(escape(request.path + "?type=rss" + req_params))

    return pagination.paginated(request, ('questions', paginator_context or QuestionListPaginatorContext()), {
    "questions" : questions.distinct(),
    "questions_count" : len(questions),
    "keywords" : keywords,
    "list_description": list_description,
    "base_path" : base_path,
    "page_title" : page_title,
    "tab" : "questions",
    'feed_url': feed_url,
    'is_home_page' : is_home_page,
    'tag' : tag,
    'known_tip' : known_tip,
    })
Example #6
0
    def __init__(self, request, question_list, title, description):
        url = request.path + "&" + generate_uri(request.GET, (_('page'), _('pagesize'), _('sort')))
        super(RssQuestionFeed, self).__init__(request, title, description, url)

        self._question_list = question_list
Example #7
0
def node_management(request):
    if request.POST:
        params = pagination.generate_uri(request.GET, ('page',))

        if "save_filter" in request.POST:
            filter_name = request.POST.get('filter_name', _('filter'))
            params = pagination.generate_uri(request.GET, ('page',))
            current_filters = settings.NODE_MAN_FILTERS.value
            current_filters.append((filter_name, params))
            settings.NODE_MAN_FILTERS.set_value(current_filters)

        elif r"execute" in request.POST:
            selected_nodes = request.POST.getlist('_selected_node')

            if selected_nodes and request.POST.get('action', None):
                action = request.POST['action']
                selected_nodes = Node.objects.filter(id__in=selected_nodes)

                message = _("No action performed")

                if action == 'delete_selected':
                    for node in selected_nodes:
                        if node.node_type in ('question', 'answer', 'comment') and (not node.nis.deleted):
                            DeleteAction(user=request.user, node=node, ip=request.META['REMOTE_ADDR']).save()

                    message = _("All selected nodes marked as deleted")

                if action == 'undelete_selected':
                    for node in selected_nodes:
                        if node.node_type in ('question', 'answer', 'comment') and (node.nis.deleted):
                            node.nstate.deleted.cancel(ip=request.META['REMOTE_ADDR'])

                    message = _("All selected nodes undeleted")

                if action == "close_selected":
                    for node in selected_nodes:
                        if node.node_type == "question" and (not node.nis.closed):
                            CloseAction(node=node.leaf, user=request.user, extra=_("bulk close"), ip=request.META['REMOTE_ADDR']).save()

                    message = _("Selected questions were closed")

                if action == "hard_delete_selected":
                    ids = [n.id for n in selected_nodes]

                    for id in ids:
                        try:
                            node = Node.objects.get(id=id)
                            node.delete()
                        except:
                            pass

                    message = _("All selected nodes deleted")

                request.user.message_set.create(message=message)

                params = pagination.generate_uri(request.GET, ('page',))
                
            return HttpResponseRedirect(reverse("admin_tools", kwargs={'name': 'nodeman'}) + "?" + params)


    nodes = Node.objects.all()

    text = request.GET.get('text', '')
    text_in = request.GET.get('text_in', 'body')

    authors = request.GET.getlist('authors')
    tags = request.GET.getlist('tags')

    type_filter = request.GET.getlist('node_type')
    state_filter = request.GET.getlist('state_type')
    state_filter_type = request.GET.get('state_filter_type', 'any')

    if type_filter:
        nodes = nodes.filter(node_type__in=type_filter)

    state_types = NodeState.objects.filter(node__in=nodes).values_list('state_type', flat=True).distinct('state_type')
    state_filter = [s for s in state_filter if s in state_types]

    if state_filter:
        if state_filter_type == 'all':
            nodes = nodes.all_states(*state_filter)
        else:
            nodes = nodes.any_state(*state_filter)

    if (authors):
        nodes = nodes.filter(author__id__in=authors)
        authors = User.objects.filter(id__in=authors)

    if (tags):
        nodes = nodes.filter(tags__id__in=tags)
        tags = Tag.objects.filter(id__in=tags)

    if text:
        text_in = request.GET.get('text_in', 'body')
        filter = None

        if text_in == 'title' or text_in == 'both':
            filter = models.Q(title__icontains=text)

        if text_in == 'body' or text_in == 'both':
            sec_filter = models.Q(body__icontains=text)
            if filter:
                filter = filter | sec_filter
            else:
                filter = sec_filter

        if filter:
            nodes = nodes.filter(filter)

    node_types = [(k, n.friendly_name) for k, n in NodeMetaClass.types.items()]

    return ('osqaadmin/nodeman.html', pagination.paginated(request, ("nodes", NodeManagementPaginatorContext()), {
    'nodes': nodes,
    'text': text,
    'text_in': text_in,
    'type_filter': type_filter,
    'state_filter': state_filter,
    'state_filter_type': state_filter_type,
    'node_types': node_types,
    'state_types': state_types,
    'authors': authors,
    'tags': tags,
    'hide_menu': True
    }))
Example #8
0
    def __init__(self, request, question_list, title, description):
        url = request.path + "?" + generate_uri(request.GET, (_('page'), _('pagesize'), _('sort')))
        super(RssQuestionFeed, self).__init__(request, title, description, url)

        self._question_list = question_list
Example #9
0
def question_list(request,
                  initial,
                  list_description=_('questions'),
                  base_path=None,
                  page_title=_("All Questions"),
                  allowIgnoreTags=True,
                  feed_url=None,
                  paginator_context=None,
                  show_summary=None,
                  feed_sort=('-added_at', ),
                  feed_req_params_exclude=(_('page'), _('pagesize'),
                                           _('sort')),
                  extra_context={}):

    if show_summary is None:
        show_summary = bool(settings.SHOW_SUMMARY_ON_QUESTIONS_LIST)

    questions = initial.filter_state(deleted=False)

    if request.user.is_authenticated() and allowIgnoreTags:
        questions = questions.filter(~Q(
            tags__id__in=request.user.marked_tags.filter(
                user_selections__reason='bad')))

    if page_title is None:
        page_title = _("Questions")

    # Added custom code to OSQA to make it more useful for Magnate
    # Only show those questions that are linked to a given Zinnia entry
    # BEGIN
    if request.GET.get('entry', None):
        from zinnia.models.entry import Entry
        try:
            entry_pk = int(request.GET.get('entry'))
            entry = Entry.objects.get(pk=entry_pk)  # make sure it exists
            if entry.is_public():
                questions = questions.filter(about_entries__entry__pk=entry_pk)
                page_title = _(unicode(page_title) + " about " + entry.title)
        except (ValueError, Entry.DoesNotExist) as e:
            # If the entry id is not integer, ignore ?entry
            # If there is no such entry, ignore ?entry
            # If there is, but it is not public, ignore ?entry
            # If it is public, show related entries and change the title
            pass
    # END

    if request.GET.get('type', None) == 'rss':
        if feed_sort:
            questions = questions.order_by(*feed_sort)
        return RssQuestionFeed(request, questions, page_title,
                               list_description)(request)

    keywords = ""
    if request.GET.get("q"):
        keywords = request.GET.get("q").strip()

    #answer_count = Answer.objects.filter_state(deleted=False).filter(parent__in=questions).count()
    #answer_description = _("answers")

    if not feed_url:
        req_params = generate_uri(request.GET, feed_req_params_exclude)

        if req_params:
            req_params = '&' + req_params

        feed_url = request.path + "?type=rss" + req_params

    context = {
        'questions': questions.distinct(),
        'questions_count': questions.count(),
        'keywords': keywords,
        'list_description': list_description,
        'base_path': base_path,
        'page_title': page_title,
        'tab': 'questions',
        'feed_url': feed_url,
        'show_summary': show_summary,
    }
    context.update(extra_context)

    return pagination.paginated(
        request,
        ('questions', paginator_context or QuestionListPaginatorContext()),
        context)
Example #10
0
def node_management(request):
    if request.POST:
        params = pagination.generate_uri(request.GET, ("page",))

        if "save_filter" in request.POST:
            filter_name = request.POST.get("filter_name", _("filter"))
            params = pagination.generate_uri(request.GET, ("page",))
            current_filters = settings.NODE_MAN_FILTERS.value
            current_filters.append((filter_name, params))
            settings.NODE_MAN_FILTERS.set_value(current_filters)

        elif r"execute" in request.POST:
            selected_nodes = request.POST.getlist("_selected_node")

            if selected_nodes and request.POST.get("action", None):
                action = str(request.POST["action"])
                selected_nodes = Node.objects.filter(id__in=selected_nodes)

                message = _("No action performed")

                if action == "delete_selected":
                    for node in selected_nodes:
                        if node.node_type in ("question", "answer", "comment") and (not node.nis.deleted):
                            DeleteAction(user=request.user, node=node, ip=request.META["REMOTE_ADDR"]).save()

                    message = _("All selected nodes marked as deleted")

                if action == "undelete_selected":
                    for node in selected_nodes:
                        if node.node_type in ("question", "answer", "comment") and (node.nis.deleted):
                            node.nstate.deleted.cancel(ip=request.META["REMOTE_ADDR"])

                    message = _("All selected nodes undeleted")

                if action == "close_selected":
                    for node in selected_nodes:
                        if node.node_type == "question" and (not node.nis.closed):
                            CloseAction(
                                node=node.leaf, user=request.user, extra=_("bulk close"), ip=request.META["REMOTE_ADDR"]
                            ).save()

                    message = _("Selected questions were closed")

                if action == "hard_delete_selected":
                    ids = [n.id for n in selected_nodes]

                    for id in ids:
                        try:
                            node = Node.objects.get(id=id)
                            node.delete()
                        except:
                            pass

                    message = _("All selected nodes deleted")

                request.user.message_set.create(message=message)

                params = pagination.generate_uri(request.GET, ("page",))

            return HttpResponseRedirect(reverse("admin_tools", kwargs={"name": "nodeman"}) + "?" + params)

    nodes = Node.objects.all()

    text = request.GET.get("text", "")
    text_in = request.GET.get("text_in", "body")

    authors = request.GET.getlist("authors")
    tags = request.GET.getlist("tags")

    type_filter = request.GET.getlist("node_type")
    state_filter = request.GET.getlist("state_type")
    state_filter_type = request.GET.get("state_filter_type", "any")

    if type_filter:
        nodes = nodes.filter(node_type__in=type_filter)

    state_types = NodeState.objects.filter(node__in=nodes).values_list("state_type", flat=True).distinct("state_type")
    state_filter = [s for s in state_filter if s in state_types]

    if state_filter:
        if state_filter_type == "all":
            nodes = nodes.all_states(*state_filter)
        else:
            nodes = nodes.any_state(*state_filter)

    if authors:
        nodes = nodes.filter(author__id__in=authors)
        authors = User.objects.filter(id__in=authors)

    if tags:
        nodes = nodes.filter(tags__id__in=tags)
        tags = Tag.objects.filter(id__in=tags)

    if text:
        text_in = request.GET.get("text_in", "body")
        filter = None

        if text_in == "title" or text_in == "both":
            filter = models.Q(title__icontains=text)

        if text_in == "body" or text_in == "both":
            sec_filter = models.Q(body__icontains=text)
            if filter:
                filter = filter | sec_filter
            else:
                filter = sec_filter

        if filter:
            nodes = nodes.filter(filter)

    node_types = [(k, n.friendly_name) for k, n in NodeMetaClass.types.items()]

    return (
        "podporaadmin/nodeman.html",
        pagination.paginated(
            request,
            ("nodes", NodeManagementPaginatorContext()),
            {
                "nodes": nodes,
                "text": text,
                "text_in": text_in,
                "type_filter": type_filter,
                "state_filter": state_filter,
                "state_filter_type": state_filter_type,
                "node_types": node_types,
                "state_types": state_types,
                "authors": authors,
                "tags": tags,
                "hide_navigation": True,
            },
        ),
    )