当前位置: 首页>>代码示例>>Python>>正文


Python context.get_for_tag_editor函数代码示例

本文整理汇总了Python中askbot.views.context.get_for_tag_editor函数的典型用法代码示例。如果您正苦于以下问题:Python get_for_tag_editor函数的具体用法?Python get_for_tag_editor怎么用?Python get_for_tag_editor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_for_tag_editor函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_email_subscriptions

def user_email_subscriptions(request, user, context):

    logging.debug(get_request_info(request))
    if request.method == 'POST':
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _('changes saved')
            if 'save' in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _('changes saved')
            elif 'stop_email' in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _('email updates canceled')
    else:
        #user may have been created by some app that does not know
        #about the email subscriptions, in that case the call below
        #will add any subscription settings that are missing
        #using the default frequencies
        user.add_missing_askbot_subscriptions()

        #initialize the form
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        'active_tab': 'users',
        'subscribed_tag_names': user.get_marked_tag_names('subscribed'),
        'page_class': 'user-profile-page',
        'tab_name': 'email_subscriptions',
        'page_title': _('profile - email subscriptions'),
        'email_feeds_form': email_feeds_form,
        'tag_filter_selection_form': tag_filter_form,
        'action_status': action_status,
        'user_languages': user.languages.split()
    }
    context.update(data)
    #todo: really need only if subscribed tags are enabled
    context.update(view_context.get_for_tag_editor())
    return render(
        request,
        'user_profile/user_email_subscriptions.html',
        context
    )
开发者ID:Cgruppo,项目名称:askbot-devel,代码行数:54,代码来源:users.py

示例2: ask


#.........这里部分代码省略.........
            if request.user.is_authenticated():
                drafts = models.DraftQuestion.objects.filter(author=request.user)
                drafts.delete()
                user = form.get_post_user(request.user)
            elif request.user.is_anonymous() and askbot_settings.ALLOW_ASK_UNREGISTERED:
                user = models.get_or_create_anonymous_user()
                ask_anonymously = True
            else:
                user = None

            if user:
                try:
                    question = user.post_question(
                        title=title,
                        body_text=text,
                        tags=tagnames,
                        wiki=wiki,
                        is_anonymous=ask_anonymously,
                        is_private=post_privately,
                        timestamp=timestamp,
                        group_id=group_id,
                        language=language,
                        ip_addr=request.META.get('REMOTE_ADDR')
                    )
                    signals.new_question_posted.send(None,
                        question=question,
                        user=user,
                        form_data=form.cleaned_data
                    )
                    return HttpResponseRedirect(question.get_absolute_url())
                except exceptions.PermissionDenied as e:
                    request.user.message_set.create(message = unicode(e))
                    return HttpResponseRedirect(reverse('index'))

            else:
                session_key=request.session.session_key
                if session_key is None:
                    return HttpResponseForbidden()

                models.AnonymousQuestion.objects.create(
                    session_key=session_key,
                    title=title,
                    tagnames=tagnames,
                    wiki=wiki,
                    is_anonymous=ask_anonymously,
                    text=text,
                    added_at=timestamp,
                    ip_addr=request.META.get('REMOTE_ADDR'),
                )
                return HttpResponseRedirect(url_utils.get_login_url())

    if request.method == 'GET':
        form = forms.AskForm(user=request.user)
        #session key used only to enable anonymous asking
        #as django will autodelete empty sessions
        request.session['askbot_write_intent'] = True

    draft_title = ''
    draft_text = ''
    draft_tagnames = ''
    if request.user.is_authenticated():
        drafts = models.DraftQuestion.objects.filter(author=request.user)
        if len(drafts) > 0:
            draft = drafts[0]
            draft_title = draft.title
            draft_text = draft.get_text()
            draft_tagnames = draft.tagnames

    form.initial = {
        'ask_anonymously': request.REQUEST.get('ask_anonymously', False),
        'tags': request.REQUEST.get('tags', draft_tagnames),
        'text': request.REQUEST.get('text', draft_text),
        'title': request.REQUEST.get('title', draft_title),
        'post_privately': request.REQUEST.get('post_privately', False),
        'language': get_language(),
        'wiki': request.REQUEST.get('wiki', False),
    }
    if 'group_id' in request.REQUEST:
        try:
            group_id = int(request.GET.get('group_id', None))
            form.initial['group_id'] = group_id
        except Exception:
            pass

    editor_is_folded = (askbot_settings.QUESTION_BODY_EDITOR_MODE=='folded' and \
                        askbot_settings.MIN_QUESTION_BODY_LENGTH==0 and \
                        form.initial['text'] == '')

    data = {
        'active_tab': 'ask',
        'page_class': 'ask-page',
        'form' : form,
        'editor_is_folded': editor_is_folded,
        'mandatory_tags': models.tag.get_mandatory_tags(),
        'email_validation_faq_url':reverse('faq') + '#validate',
        'category_tree_data': askbot_settings.CATEGORY_TREE,
        'tag_names': forms.split_tags(form.initial['tags'])
    }
    data.update(context.get_for_tag_editor())
    return render(request, 'ask.html', data)
开发者ID:ASKBOT,项目名称:askbot-devel,代码行数:101,代码来源:writers.py

示例3: edit_question

def edit_question(request, id):
    """edit question view
    """
    question = get_object_or_404(models.Post, id=id)

    if askbot_settings.READ_ONLY_MODE_ENABLED:
        return HttpResponseRedirect(question.get_absolute_url())

    revision = question.get_latest_revision()
    revision_form = None

    try:
        request.user.assert_can_edit_question(question)
        if request.method == "POST":
            if request.POST["select_revision"] == "true":
                # revert-type edit - user selected previous revision
                revision_form = forms.RevisionForm(question, revision, request.POST)
                if revision_form.is_valid():
                    # Replace with those from the selected revision
                    rev_id = revision_form.cleaned_data["revision"]
                    revision = question.revisions.get(revision=rev_id)
                    form = forms.EditQuestionForm(question=question, user=request.user, revision=revision)
                else:
                    form = forms.EditQuestionForm(
                        request.POST, question=question, user=question.user, revision=revision
                    )
            else:  # new content edit
                # Always check modifications against the latest revision
                form = forms.EditQuestionForm(request.POST, question=question, revision=revision, user=request.user)
                revision_form = forms.RevisionForm(question, revision)
                if form.is_valid():
                    if form.has_changed():
                        if form.cleaned_data["reveal_identity"]:
                            question.thread.remove_author_anonymity()

                        is_anon_edit = form.cleaned_data["stay_anonymous"]
                        is_wiki = form.cleaned_data.get("wiki", question.wiki)
                        post_privately = form.cleaned_data["post_privately"]
                        suppress_email = form.cleaned_data["suppress_email"]

                        user = form.get_post_user(request.user)

                        user.edit_question(
                            question=question,
                            title=form.cleaned_data["title"],
                            body_text=form.cleaned_data["text"],
                            revision_comment=form.cleaned_data["summary"],
                            tags=form.cleaned_data["tags"],
                            wiki=is_wiki,
                            edit_anonymously=is_anon_edit,
                            is_private=post_privately,
                            suppress_email=suppress_email,
                            ip_addr=request.META.get("REMOTE_ADDR"),
                        )

                        if "language" in form.cleaned_data:
                            question.thread.set_language_code(form.cleaned_data["language"])

                    return HttpResponseRedirect(question.get_absolute_url())
        else:
            # request type was "GET"
            revision_form = forms.RevisionForm(question, revision)
            initial = {
                "language": question.thread.language_code,
                "post_privately": question.is_private(),
                "wiki": question.wiki,
            }
            form = forms.EditQuestionForm(question=question, revision=revision, user=request.user, initial=initial)

        data = {
            "page_class": "edit-question-page",
            "active_tab": "questions",
            "question": question,
            "revision": revision,
            "revision_form": revision_form,
            "mandatory_tags": models.tag.get_mandatory_tags(),
            "form": form,
            "tag_names": question.thread.get_tag_names(),
            "category_tree_data": askbot_settings.CATEGORY_TREE,
        }
        data.update(context.get_for_tag_editor())
        return render(request, "question_edit.html", data)

    except exceptions.PermissionDenied, e:
        request.user.message_set.create(message=unicode(e))
        return HttpResponseRedirect(question.get_absolute_url())
开发者ID:Grahack,项目名称:askbot-devel,代码行数:86,代码来源:writers.py

示例4: questions


#.........这里部分代码省略.........
            },
            'paginator': paginator_html,
            'question_counter': question_counter,
            'faces': [],#[extra_tags.gravatar(contributor, 48) for contributor in contributors],
            'feed_url': context_feed_url,
            'query_string': search_state.query_string(),
            'page_size' : search_state.page_size,
            'questions': questions_html.replace('\n',''),
            'non_existing_tags': meta_data['non_existing_tags'],
        }

        related_tags_tpl = get_template('widgets/related_tags.html')
        related_tags_data = {
            'tags': related_tags,
            'tag_list_type': tag_list_type,
            'query_string': search_state.query_string(),
            'search_state': search_state,
            'language_code': translation.get_language(),
        }
        if tag_list_type == 'cloud':
            related_tags_data['font_size'] = extra_tags.get_tag_font_size(related_tags)

        ajax_data['related_tags_html'] = related_tags_tpl.render(
            RequestContext(request, related_tags_data)
        )

        #here we add and then delete some items
        #to allow extra context processor to work
        ajax_data['tags'] = related_tags
        ajax_data['interesting_tag_names'] = None
        ajax_data['threads'] = page
        extra_context = context.get_extra(
                                    'ASKBOT_QUESTIONS_PAGE_EXTRA_CONTEXT',
                                    request,
                                    ajax_data
                                )
        del ajax_data['tags']
        del ajax_data['interesting_tag_names']
        del ajax_data['threads']

        ajax_data.update(extra_context)

        return HttpResponse(simplejson.dumps(ajax_data), mimetype = 'application/json')

    else: # non-AJAX branch

        template_data = {
            'active_tab': 'questions',
            'author_name' : meta_data.get('author_name',None),
            'contributors' : contributors,
            'context' : paginator_context,
            'is_unanswered' : False,#remove this from template
            'interesting_tag_names': meta_data.get('interesting_tag_names', None),
            'ignored_tag_names': meta_data.get('ignored_tag_names', None),
            'subscribed_tag_names': meta_data.get('subscribed_tag_names', None),
            'language_code': translation.get_language(),
            'name_of_anonymous_user' : models.get_name_of_anonymous_user(),
            'page_class': 'main-page',
            'page_size': search_state.page_size,
            'query': search_state.query,
            'threads' : page,
            'questions_count' : paginator.count,
            'reset_method_count': reset_method_count,
            'scope': search_state.scope,
            'show_sort_by_relevance': conf.should_show_sort_by_relevance(),
            'search_tags' : search_state.tags,
            'sort': search_state.sort,
            'tab_id' : search_state.sort,
            'tags' : related_tags,
            'tag_list_type' : tag_list_type,
            'font_size' : extra_tags.get_tag_font_size(related_tags),
            'display_tag_filter_strategy_choices': conf.get_tag_display_filter_strategy_choices(),
            'email_tag_filter_strategy_choices': conf.get_tag_email_filter_strategy_choices(),
            'query_string': search_state.query_string(),
            'search_state': search_state,
            'feed_url': context_feed_url
        }

        extra_context = context.get_extra(
                                    'ASKBOT_QUESTIONS_PAGE_EXTRA_CONTEXT',
                                    request,
                                    template_data
                                )

        template_data.update(extra_context)
        template_data.update(context.get_for_tag_editor())

        #and one more thing:) give admin user heads up about
        #setting the domain name if they have not done that yet
        #todo: move this out to a separate middleware
        if request.user.is_authenticated() and request.user.is_administrator():
            if domain_is_bad():
                url = askbot_settings.get_setting_url(('QA_SITE_SETTINGS', 'APP_URL'))
                msg = _(
                    'Please go to Settings -> %s '
                    'and set the base url for your site to function properly'
                ) % url
                request.user.message_set.create(message=msg)

        return render(request, 'main_page.html', template_data)
开发者ID:bemall,项目名称:askbot-devel,代码行数:101,代码来源:readers.py

示例5: question


#.........这里部分代码省略.........
    page_objects = objects_list.page(show_page)

    # count visits
    signals.question_visited.send(None, request=request, question=question_post)

    paginator_data = {
        'is_paginated': (objects_list.count > const.ANSWERS_PAGE_SIZE),
        'pages': objects_list.num_pages,
        'current_page_number': show_page,
        'page_object': page_objects,
        'base_url': request.path + '?sort=%s&' % answer_sort_method,
    }
    paginator_context = functions.setup_paginator(paginator_data)

    # TODO: maybe consolidate all activity in the thread
    # for the user into just one query?
    favorited = thread.has_favorite_by_user(request.user)

    is_cacheable = True
    if show_page != 1:
        is_cacheable = False
    elif (show_comment_position or 0) > askbot_settings.MAX_COMMENTS_TO_SHOW:
        is_cacheable = False

    # maybe load draft
    initial = {}
    if request.user.is_authenticated():
        # TODO: refactor into methor on thread
        drafts = DraftAnswer.objects.filter(author=request.user, thread=thread)
        if drafts.count() > 0:
            initial['text'] = drafts[0].text

    custom_answer_form_path = getattr(django_settings, 'ASKBOT_NEW_ANSWER_FORM', None)
    if custom_answer_form_path:
        answer_form_class = load_module(custom_answer_form_path)
    else:
        answer_form_class = AnswerForm

    answer_form = answer_form_class(initial=initial, user=request.user)

    user_can_post_comment = (request.user.is_authenticated() and request.user.can_post_comment(question_post))

    new_answer_allowed = True
    previous_answer = None
    if request.user.is_authenticated():
        if askbot_settings.LIMIT_ONE_ANSWER_PER_USER:
            for answer in answers:
                if answer.author_id == request.user.pk:
                    new_answer_allowed = False
                    previous_answer = answer
                    break

    if request.user.is_authenticated() and askbot_settings.GROUPS_ENABLED:
        group_read_only = request.user.is_read_only()
    else:
        group_read_only = False

    data = {
        'active_tab': 'questions',
        'answer': answer_form,
        'answers': page_objects.object_list,
        'answer_count': thread.get_answer_count(request.user),
        'blank_comment': MockPost(post_type='comment', author=request.user),  # data for the js comment template
        'category_tree_data': askbot_settings.CATEGORY_TREE,
        'editor_is_unfolded': answer_form.has_data(),
        'favorited': favorited,
        'group_read_only': group_read_only,
        'is_cacheable': False,  # is_cacheable, # temporary, until invalidation fix
        'language_code': translation.get_language(),
        'long_time': const.LONG_TIME,  # "forever" caching
        'new_answer_allowed': new_answer_allowed,
        'oldest_answer_id': thread.get_oldest_answer_id(request.user),
        'page_class': 'question-page',
        'paginator_context': paginator_context,
        'previous_answer': previous_answer,
        'published_answer_ids': published_answer_ids,
        'question': question_post,
        'show_comment': show_comment,
        'show_comment_position': show_comment_position,
        'show_post': show_post,
        'similar_threads': thread.get_similar_threads(),
        'tab_id': answer_sort_method,
        'thread': thread,
        'thread_is_moderated': thread.is_moderated(),
        'user_is_thread_moderator': thread.has_moderator(request.user),
        'user_votes': user_votes,
        'user_post_id_list': user_post_id_list,
        'user_can_post_comment': user_can_post_comment,  # in general
    }

    # shared with ...
    if askbot_settings.GROUPS_ENABLED:
        data['sharing_info'] = thread.get_sharing_info()

    data.update(context.get_for_tag_editor())

    extra = context.get_extra('ASKBOT_QUESTION_PAGE_EXTRA_CONTEXT', request, data)
    data.update(extra)

    return render(request, 'question.jinja', data)
开发者ID:allieus,项目名称:askbot3,代码行数:101,代码来源:readers.py

示例6: edit_exercise

def edit_exercise(request, id):
    """edit exercise view
    """
    exercise = get_object_or_404(models.Post, id=id)
    revision = exercise.get_latest_revision()
    revision_form = None
    try:
        request.user.assert_can_edit_exercise(exercise)
        if request.method == 'POST':
            if request.POST['select_revision'] == 'true':
                #revert-type edit - user selected previous revision
                revision_form = forms.RevisionForm(
                                                exercise,
                                                revision,
                                                request.POST
                                            )
                if revision_form.is_valid():
                    # Replace with those from the selected revision
                    rev_id = revision_form.cleaned_data['revision']
                    revision = exercise.revisions.get(revision = rev_id)
                    form = forms.EditExerciseForm(
                                            exercise = exercise,
                                            user = request.user,
                                            revision = revision
                                        )
                else:
                    form = forms.EditExerciseForm(
                                            request.POST,
                                            exercise = exercise,
                                            user = request.user,
                                            revision = revision
                                        )
            else:#new content edit
                # Always check modifications against the latest revision
                form = forms.EditExerciseForm(
                                        request.POST,
                                        exercise = exercise,
                                        revision = revision,
                                        user = request.user,
                                    )
                revision_form = forms.RevisionForm(exercise, revision)
                if form.is_valid():
                    if form.has_changed():

                        if form.cleaned_data['reveal_identity']:
                            exercise.thread.remove_author_anonymity()

                        is_anon_edit = form.cleaned_data['stay_anonymous']
                        is_wiki = form.cleaned_data.get('wiki', exercise.wiki)
                        post_privately = form.cleaned_data['post_privately']

                        user = form.get_post_user(request.user)

                        user.edit_exercise(
                            exercise = exercise,
                            title = form.cleaned_data['title'],
                            body_text = form.cleaned_data['text'],
                            revision_comment = form.cleaned_data['summary'],
                            tags = form.cleaned_data['tags'],
                            wiki = is_wiki,
                            edit_anonymously = is_anon_edit,
                            is_private = post_privately
                        )
                    return HttpResponseRedirect(exercise.get_absolute_url())
        else:
            #request type was "GET"
            revision_form = forms.RevisionForm(exercise, revision)
            initial = {
                'post_privately': exercise.is_private(),
                'wiki': exercise.wiki
            }
            form = forms.EditExerciseForm(
                                    exercise = exercise,
                                    revision = revision,
                                    user = request.user,
                                    initial = initial
                                )

        data = {
            'page_class': 'edit-exercise-page',
            'active_tab': 'exercises',
            'exercise': exercise,
            'revision': revision,
            'revision_form': revision_form,
            'mandatory_tags': models.tag.get_mandatory_tags(),
            'form' : form,
            'tag_names': exercise.thread.get_tag_names(),
            'category_tree_data': askbot_settings.CATEGORY_TREE
        }
        data.update(context.get_for_tag_editor())
        return render_into_skin('exercise_edit.html', data, request)

    except exceptions.PermissionDenied, e:
        request.user.message_set.create(message = unicode(e))
        return HttpResponseRedirect(exercise.get_absolute_url())
开发者ID:maxwward,项目名称:SCOPEBak,代码行数:95,代码来源:writers.py

示例7: ask


#.........这里部分代码省略.........
            group_id = form.cleaned_data.get('group_id', None)
            language = form.cleaned_data.get('language', None)

            if request.user.is_authenticated():
                drafts = models.DraftQuestion.objects.filter(author=request.user)
                drafts.delete()
                user = form.get_post_user(request.user)
            elif request.user.is_anonymous() and askbot_settings.ALLOW_ASK_UNREGISTERED:
                user = models.get_or_create_anonymous_user()
                ask_anonymously = True
            else:
                user = None

            if user:
                try:
                    question = user.post_question(
                        title=title,
                        body_text=text,
                        tags=tagnames,
                        wiki=wiki,
                        is_anonymous=ask_anonymously,
                        is_private=post_privately,
                        timestamp=timestamp,
                        group_id=group_id,
                        language=language,
                        ip_addr=request.META.get('REMOTE_ADDR')
                    )
                    signals.new_question_posted.send(
                        None,
                        question=question,
                        user=user,
                        form_data=form.cleaned_data)
                    return redirect(question)
                except exceptions.PermissionDenied as e:
                    traceback.print_exc()
                    # request.user.message_set.create(message=force_text(e))
                    django_messages.info(request, force_text(e))
                    return redirect('index')
            else:
                request.session.flush()
                session_key = request.session.session_key
                models.AnonymousQuestion.objects.create(
                    session_key=session_key,
                    title=title,
                    tagnames=tagnames,
                    wiki=wiki,
                    is_anonymous=ask_anonymously,
                    text=text,
                    added_at=timestamp,
                    ip_addr=request.META.get('REMOTE_ADDR'),
                )
                return redirect(url_utils.get_login_url())

    if request.method == 'GET':
        form = forms.AskForm(user=request.user)

    draft_title = ''
    draft_text = ''
    draft_tagnames = ''
    if request.user.is_authenticated():
        drafts = models.DraftQuestion.objects.filter(author=request.user)
        if len(drafts) > 0:
            draft = drafts[0]
            draft_title = draft.title
            draft_text = draft.text
            draft_tagnames = draft.tagnames

    form.initial = {
        'ask_anonymously': request.REQUEST.get('ask_anonymously', False),
        'tags': request.REQUEST.get('tags', draft_tagnames),
        'text': request.REQUEST.get('text', draft_text),
        'title': request.REQUEST.get('title', draft_title),
        'post_privately': request.REQUEST.get('post_privately', False),
        'language': get_language(),
        'wiki': request.REQUEST.get('wiki', False),
    }
    if 'group_id' in request.REQUEST:
        try:
            group_id = int(request.GET.get('group_id', None))
            form.initial['group_id'] = group_id
        except Exception:
            pass

    editor_is_folded = \
        askbot_settings.QUESTION_BODY_EDITOR_MODE == 'folded' and \
        askbot_settings.MIN_QUESTION_BODY_LENGTH == 0 and \
        form.initial['text'] == ''

    data = {
        'active_tab': 'ask',
        'page_class': 'ask-page',
        'form': form,
        'editor_is_folded': editor_is_folded,
        'mandatory_tags': models.tag.get_mandatory_tags(),
        'email_validation_faq_url': reverse('faq') + '# validate',
        'category_tree_data': askbot_settings.CATEGORY_TREE,
        'tag_names': list(),  # need to keep context in sync with edit_question for tag editor
    }
    data.update(context.get_for_tag_editor())
    return render(request, 'ask.jinja', data)
开发者ID:allieus,项目名称:askbot3,代码行数:101,代码来源:writers.py


注:本文中的askbot.views.context.get_for_tag_editor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。