def test_get_for_inbox_group_join(self):
        mod = self.create_user('mod', status='d')
        group = Group(name='grp', openness=Group.MODERATED)
        group.save()
        mod.join_group(group)

        simple = self.create_user('simple')
        simple.join_group(group)

        inbox_context = context.get_for_inbox(mod)

        self.assertEqual(inbox_context['re_count'], 0)
        self.assertEqual(inbox_context['group_join_requests_count'], 1)

        inbox_context = context.get_for_inbox(simple)
        values = set(inbox_context.values())
        self.assertEqual(values, set([0, 0]))
Exemple #2
0
    def test_get_for_inbox_group_join(self):
        mod = self.create_user('mod', status='d')
        group = Group(name='grp', openness=Group.MODERATED)
        group.save()
        mod.join_group(group)

        simple = self.create_user('simple')
        simple.join_group(group)

        inbox_context = context.get_for_inbox(mod)

        self.assertEqual(inbox_context['re_count'], 0)
        self.assertEqual(inbox_context['group_join_requests_count'], 1)

        inbox_context = context.get_for_inbox(simple)
        values = set(inbox_context.values())
        self.assertEqual(values, set([0, 0]))
Exemple #3
0
def user_responses(request, user, context):
    """
    We list answers for question, comments, and
    answer accepted by others for this user.
    as well as mentions of the user

    user - the profile owner

    the view has two sub-views - "forum" - i.e. responses
    and "flags" - moderation items for mods only
    """

    #0) temporary, till urls are fixed: update context
    #   to contain response counts for all sub-sections
    context.update(view_context.get_for_inbox(request.user))

    #1) select activity types according to section
    section = request.GET.get('section', 'forum')
    if section == 'flags' and not\
        (request.user.is_moderator() or request.user.is_administrator()):
        raise Http404

    if section == 'forum':
        activity_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
        activity_types += (const.TYPE_ACTIVITY_MENTION, )
    elif section == 'flags':
        activity_types = (const.TYPE_ACTIVITY_MARK_OFFENSIVE, )
        if askbot_settings.ENABLE_CONTENT_MODERATION:
            activity_types += (const.TYPE_ACTIVITY_MODERATED_NEW_POST,
                               const.TYPE_ACTIVITY_MODERATED_POST_EDIT)
    elif section == 'join_requests':
        return show_group_join_requests(request, user, context)
    elif section == 'messages':
        if request.user != user:
            raise Http404

        from group_messaging.views import SendersList, ThreadsList
        context.update(SendersList().get_context(request))
        context.update(ThreadsList().get_context(request))
        data = {
            'inbox_threads_count':
            context['threads_count'],  #a hackfor the inbox count
            'active_tab': 'users',
            'page_class': 'user-profile-page',
            'tab_name': 'inbox',
            'inbox_section': section,
            'tab_description': _('private messages'),
            'page_title': _('profile - messages')
        }
        context.update(data)
        if 'thread_id' in request.GET:
            from group_messaging.models import Message
            from group_messaging.views import ThreadDetails
            try:
                thread_id = request.GET['thread_id']
                context.update(ThreadDetails().get_context(request, thread_id))
                context['group_messaging_template_name'] = \
                    'group_messaging/home_thread_details.html'
            except Message.DoesNotExist:
                raise Http404
        else:
            context[
                'group_messaging_template_name'] = 'group_messaging/home.html'
            #here we take shortcut, because we don't care about
            #all the extra context loaded below
        return render(request, 'user_inbox/messages.html', context)
    else:
        raise Http404

    #2) load the activity notifications according to activity types
    #todo: insert pagination code here
    memo_set = request.user.get_notifications(activity_types)
    memo_set = memo_set.select_related(
        'activity',
        'activity__content_type',
        'activity__question__thread',
        'activity__user',
        'activity__user__gravatar',
    ).order_by('-activity__active_at')[:const.USER_VIEW_DATA_SIZE]

    #3) "package" data for the output
    response_list = list()
    for memo in memo_set:
        if memo.activity.content_object is None:
            continue  #a temp plug due to bug in the comment deletion
        response = {
            'id': memo.id,
            'timestamp': memo.activity.active_at,
            'user': memo.activity.user,
            'is_new': memo.is_new(),
            'response_url': memo.activity.get_absolute_url(),
            'response_snippet': memo.activity.get_snippet(),
            'response_title': memo.activity.question.thread.title,
            'response_type': memo.activity.get_activity_type_display(),
            'response_id': memo.activity.question.id,
            'nested_responses': [],
            'response_content': memo.activity.content_object.html,
        }
        response_list.append(response)

    #4) sort by response id
    response_list.sort(lambda x, y: cmp(y['response_id'], x['response_id']))

    #5) group responses by thread (response_id is really the question post id)
    last_response_id = None  #flag to know if the response id is different
    filtered_response_list = list()
    for i, response in enumerate(response_list):
        #todo: group responses by the user as well
        if response['response_id'] == last_response_id:
            original_response = dict.copy(
                filtered_response_list[len(filtered_response_list) - 1])
            original_response['nested_responses'].append(response)
            filtered_response_list[len(filtered_response_list) -
                                   1] = original_response
        else:
            filtered_response_list.append(response)
            last_response_id = response['response_id']

    #6) sort responses by time
    filtered_response_list.sort(
        lambda x, y: cmp(y['timestamp'], x['timestamp']))

    reject_reasons = models.PostFlagReason.objects.all().order_by('title')
    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-page',
        'tab_name': 'inbox',
        'inbox_section': section,
        'tab_description': _('comments and answers to others questions'),
        'page_title': _('profile - responses'),
        'post_reject_reasons': reject_reasons,
        'responses': filtered_response_list,
    }
    context.update(data)
    return render(request, 'user_inbox/responses_and_flags.html', context)
Exemple #4
0
def user_responses(request, user, context):
    """
    We list answers for question, comments, and
    answer accepted by others for this user.
    as well as mentions of the user

    user - the profile owner

    the view has two sub-views - "forum" - i.e. responses
    and "flags" - moderation items for mods only
    """

    #0) temporary, till urls are fixed: update context
    #   to contain response counts for all sub-sections
    context.update(view_context.get_for_inbox(request.user))

    #1) select activity types according to section
    section = request.GET.get('section', 'forum')

    if section == 'forum':
        activity_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
        activity_types += (const.TYPE_ACTIVITY_MENTION,)
    elif section == 'join_requests':
        return show_group_join_requests(request, user, context)
    elif section == 'messages':
        if request.user != user:
            if askbot_settings.ADMIN_INBOX_ACCESS_ENABLED == False:
                raise Http404
            elif not(request.user.is_moderator() or request.user.is_administrator()):
                raise Http404

        from group_messaging.views import SendersList, ThreadsList
        context.update(SendersList().get_context(request))
        context.update(ThreadsList().get_context(request, user))
        data = {
            'inbox_threads_count': context['threads_count'],#a hackfor the inbox count
            'active_tab':'users',
            'page_class': 'user-profile-page',
            'tab_name' : 'inbox',
            'inbox_section': section,
            'page_title' : _('profile - messages')
        }
        context.update(data)
        if 'thread_id' in request.GET:
            from group_messaging.models import Message
            from group_messaging.views import ThreadDetails
            try:
                thread_id = request.GET['thread_id']
                context.update(ThreadDetails().get_context(request, thread_id))
                context['group_messaging_template_name'] = \
                    'group_messaging/home_thread_details.html'
            except Message.DoesNotExist:
                raise Http404
        else:
            context['group_messaging_template_name'] = 'group_messaging/home.html'
            #here we take shortcut, because we don't care about
            #all the extra context loaded below
        return render(request, 'user_inbox/messages.html', context)
    else:
        raise Http404

    #2) load the activity notifications according to activity types
    #todo: insert pagination code here
    memo_set = request.user.get_notifications(activity_types)
    memo_set = memo_set.select_related(
                    'activity',
                    'activity__content_type',
                    'activity__question__thread',
                    'activity__user',
                    'activity__user__gravatar',
                ).order_by(
                    '-activity__active_at'
                )[:const.USER_VIEW_DATA_SIZE]

    #3) "package" data for the output
    response_list = list()
    for memo in memo_set:
        obj = memo.activity.content_object
        if obj is None:
            memo.activity.delete()
            continue#a temp plug due to bug in the comment deletion

        act = memo.activity
        act_user = act.user
        act_message = act.get_activity_type_display()
        act_type = 'edit'

        response = {
            'id': memo.id,
            'timestamp': act.active_at,
            'user': act_user,
            'is_new': memo.is_new(),
            'url': act.get_absolute_url(),
            'snippet': act.get_snippet(),
            'title': act.question.thread.title,
            'message_type': act_message,
            'memo_type': act_type,
            'question_id': act.question.id,
            'followup_messages': list(),
            'content': obj.html or obj.text,
        }
        response_list.append(response)

    #4) sort by response id
    response_list.sort(lambda x,y: cmp(y['question_id'], x['question_id']))

    #5) group responses by thread (response_id is really the question post id)
    last_question_id = None #flag to know if the question id is different
    filtered_message_list = list()
    for message in response_list:
        #todo: group responses by the user as well
        if message['question_id'] == last_question_id:
            original_message = dict.copy(filtered_message_list[-1])
            original_message['followup_messages'].append(message)
            filtered_message_list[-1] = original_message
        else:
            filtered_message_list.append(message)
            last_question_id = message['question_id']

    #6) sort responses by time
    filtered_message_list.sort(lambda x,y: cmp(y['timestamp'], x['timestamp']))

    reject_reasons = models.PostFlagReason.objects.all().order_by('title')
    data = {
        'active_tab':'users',
        'page_class': 'user-profile-page',
        'tab_name' : 'inbox',
        'inbox_section': section,
        'page_title' : _('profile - responses'),
        'post_reject_reasons': reject_reasons,
        'messages' : filtered_message_list,
    }
    context.update(data)
    template = 'user_inbox/responses.html'
    return render(request, template, context)
Exemple #5
0
 def test_get_for_inbox_anonymous(self):
     anon = AnonymousUser()
     inbox_context = context.get_for_inbox(anon)
     self.assertEqual(inbox_context, None)
Exemple #6
0
def user_responses(request, user, context):
    """
    We list answers for question, comments, and
    answer accepted by others for this user.
    as well as mentions of the user

    user - the profile owner

    the view has two sub-views - "forum" - i.e. responses
    and "flags" - moderation items for mods only
    """

    #0) temporary, till urls are fixed: update context
    #   to contain response counts for all sub-sections
    context.update(view_context.get_for_inbox(request.user))

    #1) select activity types according to section
    section = request.GET.get('section', 'forum')
    if section == 'flags' and not\
        (request.user.is_moderator() or request.user.is_administrator()):
        raise Http404

    if section == 'forum':
        activity_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
        activity_types += (const.TYPE_ACTIVITY_MENTION,)
    elif section == 'flags':
        activity_types = (const.TYPE_ACTIVITY_MARK_OFFENSIVE,)
        if askbot_settings.ENABLE_CONTENT_MODERATION:
            activity_types += (
                const.TYPE_ACTIVITY_MODERATED_NEW_POST,
                const.TYPE_ACTIVITY_MODERATED_POST_EDIT
            )
    elif section == 'join_requests':
        return show_group_join_requests(request, user, context)
    elif section == 'messages':
        if request.user != user:
            raise Http404
        #here we take shortcut, because we don't care about
        #all the extra context loaded below
        from group_messaging.views import SendersList, ThreadsList
        context.update(SendersList().get_context(request))
        context.update(ThreadsList().get_context(request))
        data = {
            'active_tab':'users',
            'page_class': 'user-profile-page',
            'tab_name' : 'inbox',
            'inbox_section': section,
            'tab_description' : _('private messages'),
            'page_title' : _('profile - messages')
        }
        context.update(data)
        return render_into_skin(
            'user_inbox/messages.html', context, request
        )
    else:
        raise Http404

    #2) load the activity notifications according to activity types
    #todo: insert pagination code here
    memo_set = request.user.get_notifications(activity_types)
    memo_set = memo_set.select_related(
                    'activity',
                    'activity__content_type',
                    'activity__question__thread',
                    'activity__user',
                    'activity__user__gravatar',
                ).order_by(
                    '-activity__active_at'
                )[:const.USER_VIEW_DATA_SIZE]

    #3) "package" data for the output
    response_list = list()
    for memo in memo_set:
        if memo.activity.content_object is None:
            continue#a temp plug due to bug in the comment deletion
        response = {
            'id': memo.id,
            'timestamp': memo.activity.active_at,
            'user': memo.activity.user,
            'is_new': memo.is_new(),
            'response_url': memo.activity.get_absolute_url(),
            'response_snippet': memo.activity.get_snippet(),
            'response_title': memo.activity.question.thread.title,
            'response_type': memo.activity.get_activity_type_display(),
            'response_id': memo.activity.question.id,
            'nested_responses': [],
            'response_content': memo.activity.content_object.html,
        }
        response_list.append(response)

    #4) sort by response id
    response_list.sort(lambda x,y: cmp(y['response_id'], x['response_id']))

    #5) group responses by thread (response_id is really the question post id)
    last_response_id = None #flag to know if the response id is different
    filtered_response_list = list()
    for i, response in enumerate(response_list):
        #todo: group responses by the user as well
        if response['response_id'] == last_response_id:
            original_response = dict.copy(filtered_response_list[len(filtered_response_list)-1])
            original_response['nested_responses'].append(response)
            filtered_response_list[len(filtered_response_list)-1] = original_response
        else:
            filtered_response_list.append(response)
            last_response_id = response['response_id']

    #6) sort responses by time
    filtered_response_list.sort(lambda x,y: cmp(y['timestamp'], x['timestamp']))

    reject_reasons = models.PostFlagReason.objects.all().order_by('title')
    data = {
        'active_tab':'users',
        'page_class': 'user-profile-page',
        'tab_name' : 'inbox',
        'inbox_section': section,
        'tab_description' : _('comments and answers to others questions'),
        'page_title' : _('profile - responses'),
        'post_reject_reasons': reject_reasons,
        'responses' : filtered_response_list,
    }
    context.update(data)
    return render_into_skin('user_inbox/responses_and_flags.html', context, request)
Exemple #7
0
def user_responses(request, user, context):
    """
    We list answers for question, comments, and
    answer accepted by others for this user.
    as well as mentions of the user

    user - the profile owner

    the view has two sub-views - "forum" - i.e. responses
    and "flags" - moderation items for mods only
    """

    # 0) temporary, till urls are fixed: update context
    #   to contain response counts for all sub-sections
    context.update(view_context.get_for_inbox(request.user))

    # 1) select activity types according to section
    section = request.GET.get("section", "forum")
    if section == "flags" and not (request.user.is_moderator() or request.user.is_administrator()):
        raise Http404

    if section == "forum":
        activity_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
        activity_types += (const.TYPE_ACTIVITY_MENTION,)
    elif section == "flags":
        activity_types = (const.TYPE_ACTIVITY_MARK_OFFENSIVE,)
        if askbot_settings.ENABLE_CONTENT_MODERATION:
            activity_types += (const.TYPE_ACTIVITY_MODERATED_NEW_POST, const.TYPE_ACTIVITY_MODERATED_POST_EDIT)
    elif section == "join_requests":
        return show_group_join_requests(request, user, context)
    elif section == "messages":
        if request.user != user:
            raise Http404

        from group_messaging.views import SendersList, ThreadsList

        context.update(SendersList().get_context(request))
        context.update(ThreadsList().get_context(request))
        data = {
            "inbox_threads_count": context["threads_count"],  # a hackfor the inbox count
            "active_tab": "users",
            "page_class": "user-profile-page",
            "tab_name": "inbox",
            "inbox_section": section,
            "tab_description": _("private messages"),
            "page_title": _("profile - messages"),
        }
        context.update(data)
        if "thread_id" in request.GET:
            from group_messaging.models import Message
            from group_messaging.views import ThreadDetails

            try:
                thread_id = request.GET["thread_id"]
                context.update(ThreadDetails().get_context(request, thread_id))
                context["group_messaging_template_name"] = "group_messaging/home_thread_details.html"
            except Message.DoesNotExist:
                raise Http404
        else:
            context["group_messaging_template_name"] = "group_messaging/home.html"
            # here we take shortcut, because we don't care about
            # all the extra context loaded below
        return render(request, "user_inbox/messages.html", context)
    else:
        raise Http404

    # 2) load the activity notifications according to activity types
    # todo: insert pagination code here
    memo_set = request.user.get_notifications(activity_types)
    memo_set = memo_set.select_related(
        "activity", "activity__content_type", "activity__question__thread", "activity__user", "activity__user__gravatar"
    ).order_by("-activity__active_at")[: const.USER_VIEW_DATA_SIZE]

    # 3) "package" data for the output
    response_list = list()
    for memo in memo_set:
        if memo.activity.content_object is None:
            continue  # a temp plug due to bug in the comment deletion
        response = {
            "id": memo.id,
            "timestamp": memo.activity.active_at,
            "user": memo.activity.user,
            "is_new": memo.is_new(),
            "response_url": memo.activity.get_absolute_url(),
            "response_snippet": memo.activity.get_snippet(),
            "response_title": memo.activity.question.thread.title,
            "response_type": memo.activity.get_activity_type_display(),
            "response_id": memo.activity.question.id,
            "nested_responses": [],
            "response_content": memo.activity.content_object.html,
        }
        response_list.append(response)

    # 4) sort by response id
    response_list.sort(lambda x, y: cmp(y["response_id"], x["response_id"]))

    # 5) group responses by thread (response_id is really the question post id)
    last_response_id = None  # flag to know if the response id is different
    filtered_response_list = list()
    for i, response in enumerate(response_list):
        # todo: group responses by the user as well
        if response["response_id"] == last_response_id:
            original_response = dict.copy(filtered_response_list[len(filtered_response_list) - 1])
            original_response["nested_responses"].append(response)
            filtered_response_list[len(filtered_response_list) - 1] = original_response
        else:
            filtered_response_list.append(response)
            last_response_id = response["response_id"]

    # 6) sort responses by time
    filtered_response_list.sort(lambda x, y: cmp(y["timestamp"], x["timestamp"]))

    reject_reasons = models.PostFlagReason.objects.all().order_by("title")
    data = {
        "active_tab": "users",
        "page_class": "user-profile-page",
        "tab_name": "inbox",
        "inbox_section": section,
        "tab_description": _("comments and answers to others questions"),
        "page_title": _("profile - responses"),
        "post_reject_reasons": reject_reasons,
        "responses": filtered_response_list,
    }
    context.update(data)
    return render(request, "user_inbox/responses_and_flags.html", context)
Exemple #8
0
def user_responses(request, user, context):
    """
    We list answers for question, comments, and
    answer accepted by others for this user.
    as well as mentions of the user

    user - the profile owner

    the view has two sub-views - "forum" - i.e. responses
    and "flags" - moderation items for mods only
    """

    # 0) temporary, till urls are fixed: update context
    #   to contain response counts for all sub-sections
    context.update(view_context.get_for_inbox(request.user))

    # 1) select activity types according to section
    section = request.GET.get('section', 'forum')

    if section == 'forum':
        activity_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
        activity_types += (const.TYPE_ACTIVITY_MENTION, )
    elif section == 'join_requests':
        return show_group_join_requests(request, user, context)
    elif section == 'messages':
        if request.user != user:
            if not askbot_settings.ADMIN_INBOX_ACCESS_ENABLED:
                raise Http404
            elif not (request.user.is_moderator()
                      or request.user.is_administrator()):
                raise Http404

        from group_messaging.views import SendersList, ThreadsList
        context.update(SendersList().get_context(request))
        context.update(ThreadsList().get_context(request, user))
        data = {
            'inbox_threads_count':
            context['threads_count'],  # a hackfor the inbox count
            'active_tab': 'users',
            'page_class': 'user-profile-page',
            'tab_name': 'inbox',
            'inbox_section': section,
            'page_title': _('profile - messages')
        }
        context.update(data)
        if 'thread_id' in request.GET:
            from group_messaging.models import Message
            from group_messaging.views import ThreadDetails
            try:
                thread_id = request.GET['thread_id']
                context.update(ThreadDetails().get_context(request, thread_id))
                context['group_messaging_template_name'] = \
                    'group_messaging/home_thread_details.jinja'
            except Message.DoesNotExist:
                raise Http404
        else:
            context[
                'group_messaging_template_name'] = 'group_messaging/home.jinja'
            # here we take shortcut, because we don't care about
            # all the extra context loaded below
        return render(request, 'user_inbox/messages.jinja', context)
    else:
        raise Http404

    # 2) load the activity notifications according to activity types
    # TODO: insert pagination code here
    memo_set = request.user.get_notifications(activity_types)
    memo_set = memo_set.select_related(
        'activity',
        'activity__content_type',
        'activity__question__thread',
        'activity__user',
        'activity__user__gravatar',
    ).order_by('-activity__active_at')[:const.USER_VIEW_DATA_SIZE]

    # 3) "package" data for the output
    response_list = list()
    for memo in memo_set:
        obj = memo.activity.content_object
        if obj is None:
            memo.activity.delete()
            continue  # a temp plug due to bug in the comment deletion

        act = memo.activity
        act_user = act.user
        act_message = act.get_activity_type_display()
        act_type = 'edit'

        response = {
            'id': memo.id,
            'timestamp': act.active_at,
            'user': act_user,
            'is_new': memo.is_new(),
            'url': act.get_absolute_url(),
            'snippet': act.get_snippet(),
            'title': act.question.thread.title,
            'message_type': act_message,
            'memo_type': act_type,
            'question_id': act.question.id,
            'followup_messages': list(),
            'content': obj.html or obj.text,
        }
        response_list.append(response)

    # 4) sort by response id
    response_list.sort(key=lambda ele: ele['question_id'], reverse=True)

    # 5) group responses by thread (response_id is really the question post id)
    last_question_id = None  # flag to know if the question id is different
    filtered_message_list = list()
    for message in response_list:
        # TODO: group responses by the user as well
        if message['question_id'] == last_question_id:
            original_message = dict.copy(filtered_message_list[-1])
            original_message['followup_messages'].append(message)
            filtered_message_list[-1] = original_message
        else:
            filtered_message_list.append(message)
            last_question_id = message['question_id']

    # 6) sort responses by time
    filtered_message_list.sort(key=lambda ele: ele['timestamp'], reverse=True)

    reject_reasons = models.PostFlagReason.objects.all().order_by('title')
    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-page',
        'tab_name': 'inbox',
        'inbox_section': section,
        'page_title': _('profile - responses'),
        'post_reject_reasons': reject_reasons,
        'messages': filtered_message_list,
    }
    context.update(data)
    template = 'user_inbox/responses.jinja'
    return render(request, template, context)