Ejemplo n.º 1
0
def toggle_follow_question(request):
    result = dict()

    if request.user.is_anonymous():
        msg = _('anonymous users cannot %(perform_action)s') % \
            {'perform_action': askbot_settings.WORDS_FOLLOW_QUESTIONS}
        raise exceptions.PermissionDenied(msg + ' ' + get_login_link())
    else:
        q_id = request.POST['question_id']
        question = get_object_or_404(models.Post, id=q_id)
        result['is_enabled'] = request.user.toggle_favorite_question(question)
        result['num_followers'] = models.FavoriteQuestion.objects.filter(thread=question.thread).count()
    return result
Ejemplo n.º 2
0
def toggle_follow_question(request):
    result = dict()

    if request.user.is_anonymous():
        msg = _('anonymous users cannot %(perform_action)s') % \
            {'perform_action': askbot_settings.WORDS_FOLLOW_QUESTIONS}
        raise exceptions.PermissionDenied(msg + ' ' + get_login_link())
    else:
        q_id = request.POST['question_id']
        question = get_object_or_404(models.Post, id=q_id)
        result['is_enabled'] = request.user.toggle_favorite_question(question)
        result['num_followers'] = models.FavoriteQuestion.objects.filter(
            thread=question.thread).count()
    return result
Ejemplo n.º 3
0
def mark_tag(request, **kwargs):  # tagging system
    if request.user.is_anonymous():
        msg = _('anonymous users cannot %(perform_action)s') % \
            {'perform_action': _('mark or unmark tags')}
        raise exceptions.PermissionDenied(msg + ' ' + get_login_link())

    action = kwargs['action']
    post_data = json.loads(request.raw_post_data)
    raw_tagnames = post_data['tagnames']
    reason = post_data['reason']
    assert reason in ('good', 'bad', 'subscribed')
    # separate plain tag names and wildcard tags
    tagnames, wildcards = forms.clean_marked_tagnames(raw_tagnames)

    if request.user.is_administrator() and 'user' in post_data:
        user = get_object_or_404(models.User, pk=post_data['user'])
    else:
        user = request.user

    cleaned_tagnames, cleaned_wildcards = user.mark_tags(
                                                     tagnames,
                                                     wildcards,
                                                     reason=reason,
                                                     action=action
                                                )

    # lastly - calculate tag usage counts
    tag_usage_counts = dict()
    for name in tagnames:
        if name in cleaned_tagnames:
            tag_usage_counts[name] = 1
        else:
            tag_usage_counts[name] = 0

    for name in wildcards:
        if name in cleaned_wildcards:
            tag_usage_counts[name] = models.Tag.objects.filter(
                                        name__startswith = name[:-1],
                                        language_code=translation.get_language()
                                    ).count()
        else:
            tag_usage_counts[name] = 0

    return tag_usage_counts
Ejemplo n.º 4
0
def mark_tag(request, **kwargs):  # tagging system

    if request.user.is_anonymous():
        msg = _("anonymous users cannot %(perform_action)s") % {"perform_action": _("mark or unmark tags")}
        raise exceptions.PermissionDenied(msg + " " + get_login_link())

    action = kwargs["action"]
    post_data = simplejson.loads(request.body)
    raw_tagnames = post_data["tagnames"]
    reason = post_data["reason"]
    assert reason in ("good", "bad", "subscribed")
    # separate plain tag names and wildcard tags
    if action == "remove":
        tagnames, wildcards = forms.classify_marked_tagnames(raw_tagnames)
    else:
        tagnames, wildcards = forms.clean_marked_tagnames(raw_tagnames)

    if request.user.is_administrator() and "user" in post_data:
        user = get_object_or_404(models.User, pk=post_data["user"])
    else:
        user = request.user

    cleaned_tagnames, cleaned_wildcards = user.mark_tags(tagnames, wildcards, reason=reason, action=action)

    # lastly - calculate tag usage counts
    tag_usage_counts = dict()
    for name in tagnames:
        if name in cleaned_tagnames:
            tag_usage_counts[name] = 1
        else:
            tag_usage_counts[name] = 0

    for name in wildcards:
        if name in cleaned_wildcards:
            tag_usage_counts[name] = models.Tag.objects.filter(
                name__startswith=name[:-1], language_code=translation.get_language()
            ).count()
        else:
            tag_usage_counts[name] = 0

    return tag_usage_counts
Ejemplo n.º 5
0
def mark_tag(request, **kwargs):  # tagging system
    if request.user.is_anonymous():
        msg = _('anonymous users cannot %(perform_action)s') % \
            {'perform_action': _('mark or unmark tags')}
        raise exceptions.PermissionDenied(msg + ' ' + get_login_link())

    action = kwargs['action']
    post_data = json.loads(request.raw_post_data)
    raw_tagnames = post_data['tagnames']
    reason = post_data['reason']
    assert reason in ('good', 'bad', 'subscribed')
    # separate plain tag names and wildcard tags
    tagnames, wildcards = forms.clean_marked_tagnames(raw_tagnames)

    if request.user.is_administrator() and 'user' in post_data:
        user = get_object_or_404(models.User, pk=post_data['user'])
    else:
        user = request.user

    cleaned_tagnames, cleaned_wildcards = user.mark_tags(tagnames,
                                                         wildcards,
                                                         reason=reason,
                                                         action=action)

    # lastly - calculate tag usage counts
    tag_usage_counts = dict()
    for name in tagnames:
        if name in cleaned_tagnames:
            tag_usage_counts[name] = 1
        else:
            tag_usage_counts[name] = 0

    for name in wildcards:
        if name in cleaned_wildcards:
            tag_usage_counts[name] = models.Tag.objects.filter(
                name__startswith=name[:-1],
                language_code=translation.get_language()).count()
        else:
            tag_usage_counts[name] = 0

    return tag_usage_counts