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


Python context.Context方法代码示例

本文整理汇总了Python中django.template.context.Context方法的典型用法代码示例。如果您正苦于以下问题:Python context.Context方法的具体用法?Python context.Context怎么用?Python context.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.context的用法示例。


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

示例1: send_letter_email

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def send_letter_email(request, grad_slug, letter_slug):
    letter = get_object_or_404(Letter, slug=letter_slug)
    grad = get_object_or_404(GradStudent, person=letter.student.person, slug=grad_slug, program__unit__in=request.units)
    if request.method == 'POST':
        form = LetterEmailForm(request.POST)
        if form.is_valid():
            letter.set_email_body(form.cleaned_data['email_body'])
            letter.set_email_subject(form.cleaned_data['email_subject'])
            if 'email_cc' in form.cleaned_data:
                letter.set_email_cc(form.cleaned_data['email_cc'])
            letter.set_email_sent(timezone_today())
            letter.save()
            return _send_letter(request, grad_slug, letter)

    else:
        email_template = letter.template.email_body()
        temp = Template(email_template)
        ls = grad.letter_info()
        text = temp.render(Context(ls))
        form = LetterEmailForm(initial={'email_body': text, 'email_subject': letter.template.email_subject()})
    return render(request, 'grad/select_letter_email_text.html', {'form': form, 'grad': grad, 'letter': letter}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:23,代码来源:send_letter_email.py

示例2: submit_row

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def submit_row(context):
    """
    Display the row of buttons for delete and save.
    """
    change = context['change']
    is_popup = context['is_popup']
    save_as = context['save_as']
    show_save = context.get('show_save', True)
    show_save_and_continue = context.get('show_save_and_continue', True)
    ctx = Context(context)
    ctx.update({
        'show_delete_link': (
            not is_popup and context['has_delete_permission'] and
            change and context.get('show_delete', True)
        ),
        'show_save_as_new': not is_popup and change and save_as,
        'show_save_and_add_another': (
            context['has_add_permission'] and not is_popup and
            (not save_as or context['add'])
        ),
        'show_save_and_continue': not is_popup and context['has_change_permission'] and show_save_and_continue,
        'show_save': show_save,
    })
    return ctx 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:26,代码来源:admin_modify.py

示例3: write_response

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def write_response(self, response):
        if isinstance(response, RedirectResponse):
            result = HttpResponseRedirect(response.url, status=response.status)
        elif isinstance(response, OptionalJSONResponse) and isinstance(response.data, HttpResponseBase):
            result = response.data
        elif isinstance(response, TemplateResponse):
            template_path = os.path.join(base_settings.BASE_DIR, 'templates', response.template)
            with open(template_path, 'r') as file:
                template = file.read()
                template = template.replace('{% end %}', '{% endif %}')
                context = Context(response.data)
                content = Template(template).render(context)
                result = HttpResponse(content, status=response.status)
        else:
            result = HttpResponse(response.render(), status=response.status)

        for name, value in self.view.default_headers().items():
            result[name] = value

        for name, value in response.header_items():
            result[name] = value

        return result 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:25,代码来源:route_view.py

示例4: submit_row

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def submit_row(context):
    """
    Displays the row of buttons for delete and save.
    """
    change = context['change']
    is_popup = context['is_popup']
    save_as = context['save_as']
    show_save = context.get('show_save', True)
    show_save_and_continue = context.get('show_save_and_continue', True)
    ctx = Context(context)
    ctx.update({
        'show_delete_link': (
            not is_popup and context['has_delete_permission'] and
            change and context.get('show_delete', True)
        ),
        'show_save_as_new': not is_popup and change and save_as,
        'show_save_and_add_another': (
            context['has_add_permission'] and not is_popup and
            (not save_as or context['add'])
        ),
        'show_save_and_continue': not is_popup and context['has_change_permission'] and show_save_and_continue,
        'show_save': show_save,
    })
    return ctx 
开发者ID:Yeah-Kun,项目名称:python,代码行数:26,代码来源:admin_modify.py

示例5: get_memo_text

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def get_memo_text(request, userid, event_slug, memo_template_id):
    """ Get the text from memo template """
    person, member_units = _get_faculty_or_404(request.units, userid)
    event = _get_event_or_404(units=request.units, slug=event_slug, person=person)
    lt = get_object_or_404(MemoTemplate, id=memo_template_id, unit__in=Unit.sub_units(request.units))
    temp = Template(lt.template_text)
    ls = event.memo_info()
    text = temp.render(Context(ls))

    return HttpResponse(text, content_type='text/plain') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:12,代码来源:views.py

示例6: get_letter_text

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def get_letter_text(request, grad_slug, letter_template_id):
    """ Get the text from letter template """
    grad = get_object_or_404(GradStudent, slug=grad_slug, program__unit__in=request.units)
    lt = get_object_or_404(LetterTemplate, id=letter_template_id, unit__in=request.units)
    temp = Template(lt.content)
    ls = grad.letter_info()
    text = temp.render(Context(ls))
    #print ls

    return HttpResponse(text, content_type='text/plain') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:12,代码来源:get_letter_text.py

示例7: render

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def render(self, context=None, request=None):
        # A deprecation path is required here to cover the following usage:
        # >>> from django.template import Context
        # >>> from django.template.loader import get_template
        # >>> template = get_template('hello.html')
        # >>> template.render(Context({'name': 'world'}))
        # In Django 1.7 get_template() returned a django.template.Template.
        # In Django 1.8 it returns a django.template.backends.django.Template.
        # In Django 1.10 the isinstance checks should be removed. If passing a
        # Context or a RequestContext works by accident, it won't be an issue
        # per se, but it won't be officially supported either.
        if isinstance(context, RequestContext):
            if request is not None and request is not context.request:
                raise ValueError(
                    "render() was called with a RequestContext and a request "
                    "argument which refer to different requests. Make sure "
                    "that the context argument is a dict or at least that "
                    "the two arguments refer to the same request.")
            warnings.warn(
                "render() must be called with a dict, not a RequestContext.",
                RemovedInDjango110Warning, stacklevel=2)

        elif isinstance(context, Context):
            warnings.warn(
                "render() must be called with a dict, not a Context.",
                RemovedInDjango110Warning, stacklevel=2)

        else:
            context = make_context(context, request)

        return self.template.render(context) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:django.py

示例8: submit_row

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def submit_row(context):
    """
    Display the row of buttons for delete and save.
    """
    add = context['add']
    change = context['change']
    is_popup = context['is_popup']
    save_as = context['save_as']
    show_save = context.get('show_save', True)
    show_save_and_continue = context.get('show_save_and_continue', True)
    has_add_permission = context['has_add_permission']
    has_change_permission = context['has_change_permission']
    has_view_permission = context['has_view_permission']
    has_editable_inline_admin_formsets = context['has_editable_inline_admin_formsets']
    can_save = (has_change_permission and change) or (has_add_permission and add) or has_editable_inline_admin_formsets
    can_save_and_continue = not is_popup and can_save and has_view_permission and show_save_and_continue
    can_change = has_change_permission or has_editable_inline_admin_formsets
    ctx = Context(context)
    ctx.update({
        'can_change': can_change,
        'show_delete_link': (
            not is_popup and context['has_delete_permission'] and
            change and context.get('show_delete', True)
        ),
        'show_save_as_new': not is_popup and has_change_permission and change and save_as,
        'show_save_and_add_another': (
            has_add_permission and not is_popup and
            (not save_as or add) and can_save
        ),
        'show_save_and_continue': can_save_and_continue,
        'show_save': show_save and can_save,
        'show_close': not(show_save and can_save)
    })
    return ctx 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:36,代码来源:admin_modify.py

示例9: _evaluate_row_action_in

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def _evaluate_row_action_in(action: models.Action, context: Mapping):
    """Evaluate an action_in in the given context.

    Given an action IN object and a row index:
    1) Create the form and the context
    2) Run the template with the context
    3) Return the resulting object (HTML?)

    :param action: Action object.
    :param context: Dictionary with pairs name/value
    :return: String with the HTML content resulting from the evaluation
    """
    # Get the active columns attached to the action
    tuples = [
        column_condition_pair
        for column_condition_pair in action.column_condition_pair.all()
        if column_condition_pair.column.is_active
    ]

    col_values = [context[colcon_pair.column.name] for colcon_pair in tuples]

    form = forms.EnterActionIn(
        None,
        tuples=tuples,
        context=context,
        values=col_values)

    # Render the form
    return Template(
        """<div align="center">
             <p class="lead">{{ description_text }}</p>
             {% load crispy_forms_tags %}{{ form|crispy }}
           </div>""",
    ).render(Context(
        {
            'form': form,
            'description_text': action.description_text,
        },
    )) 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:41,代码来源:preview.py

示例10: render

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def render(self, context=None, request=None):
        # A deprecation path is required here to cover the following usage:
        # >>> from django.template import Context
        # >>> from django.template.loader import get_template
        # >>> template = get_template('hello.html')
        # >>> template.render(Context({'name': 'world'}))
        # In Django 1.7 get_template() returned a django.template.Template.
        # In Django 1.8 it returns a django.template.backends.django.Template.
        # In Django 1.10 the isinstance checks should be removed. If passing a
        # Context or a RequestContext works by accident, it won't be an issue
        # per se, but it won't be officially supported either.
        if isinstance(context, RequestContext):
            if request is not None and request is not context.request:
                raise ValueError(
                    "render() was called with a RequestContext and a request "
                    "argument which refer to different requests. Make sure "
                    "that the context argument is a dict or at least that "
                    "the two arguments refer to the same request.")
            warnings.warn(
                "render() must be called with a dict, not a RequestContext.",
                RemovedInDjango110Warning, stacklevel=2)

        elif isinstance(context, Context):
            warnings.warn(
                "render() must be called with a dict, not a Context.",
                RemovedInDjango110Warning, stacklevel=2)

        else:
            context = make_context(context, request)

        try:
            return self.template.render(context)
        except TemplateDoesNotExist as exc:
            reraise(exc, self.backend) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:36,代码来源:django.py

示例11: content

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def content(self):
        """ Content of the panel when it's displayed in full screen. """
        toolbars = OrderedDict()
        for id, toolbar in DebugToolbar._store.items():
            content = {}
            for panel in toolbar.panels:
                panel_id = None
                nav_title = ''
                nav_subtitle = ''
                try:
                    panel_id = panel.panel_id
                    nav_title = panel.nav_title
                    nav_subtitle = panel.nav_subtitle() if isinstance(
                        panel.nav_subtitle, Callable) else panel.nav_subtitle
                except Exception:
                    logger.debug('Error parsing panel info:', exc_info=True)
                if panel_id is not None:
                    content.update({
                        panel_id: {
                            'panel_id': panel_id,
                            'nav_title': nav_title,
                            'nav_subtitle': nav_subtitle,
                        }
                    })
            toolbars[id] = {
                'toolbar': toolbar,
                'content': content
            }
        return get_template().render(Context({
            'toolbars': OrderedDict(reversed(list(toolbars.items()))),
            'trunc_length': get_config().get('RH_POST_TRUNC_LENGTH', 0)
        })) 
开发者ID:djsutho,项目名称:django-debug-toolbar-request-history,代码行数:34,代码来源:request_history.py

示例12: __str__

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def __str__(self):
        tpl = get_template(self.template)
        return mark_safe(tpl.render(Context(self.get_context()))) 
开发者ID:madre,项目名称:devops,代码行数:5,代码来源:filters.py

示例13: add_service

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import Context [as 别名]
def add_service(request, username, id_string):
    data = {}
    form = RestServiceForm()
    xform = get_object_or_404(
        XForm, user__username__iexact=username, id_string__exact=id_string)
    if request.method == 'POST':
        form = RestServiceForm(request.POST)
        restservice = None
        if form.is_valid():
            service_name = form.cleaned_data['service_name']
            service_url = form.cleaned_data['service_url']
            try:
                rs = RestService(service_url=service_url,
                                 name=service_name, xform=xform)
                rs.save()
            except IntegrityError:
                message = _(u"Service already defined.")
                status = 'fail'
            else:
                status = 'success'
                message = (_(u"Successfully added service %(name)s.")
                           % {'name': service_name})
                service_tpl = render_to_string("service.html", {
                    "sv": rs, "username": xform.user.username,
                    "id_string": xform.id_string})
                restservice = service_tpl
        else:
            status = 'fail'
            message = _(u"Please fill in all required fields")

            if form.errors:
                for field in form:
                    message += Template(u"{{ field.errors }}")\
                        .render(Context({'field': field}))
        if request.is_ajax():
            response = {'status': status, 'message': message}
            if restservice:
                response["restservice"] = u"%s" % restservice

            return HttpResponse(json.dumps(response))

        data['status'] = status
        data['message'] = message

    data['list_services'] = RestService.objects.filter(xform=xform)
    data['form'] = form
    data['username'] = username
    data['id_string'] = id_string

    return render(request, "add-service.html", data) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:52,代码来源:views.py


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