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


Python template.RequestContext方法代码示例

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


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

示例1: form_detail

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def form_detail(request, slug, template="forms/form_detail.html"):
    form = get_object_or_404(models.DocumentSetForm, slug=slug)
    request_context = RequestContext(request)
    args = (form, request_context, request.POST or None)

    form_for_form = forms.DocumentSetFormForForm(*args)

    if request.method == 'POST':
        if not form_for_form.is_valid():
            form_invalid.send(sender=request, form=form_for_form)
            return HttpResponseBadRequest(json.dumps(form_for_form.errors), content_type='application/json')
        else:
            entry = form_for_form.save()
            form_valid.send(sender=request, form=form_for_form, entry=entry, document_id=request.session['document_id_for_entry'])
            return HttpResponse('')
    return render_to_response(template, { 'form': form }, request_context) 
开发者ID:crowdata,项目名称:crowdata,代码行数:18,代码来源:views.py

示例2: choose_current_organization

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def choose_current_organization(request):
    """ Show which Organizations can be selected """
    organizations = request.user.organization_set.all()
    
    current_organization = None
    
    try:
        user_profile = request.user.get_profile()      
    except models.UserProfile.DoesNotExist:
        user_profile = models.UserProfile(user=request.user, name=request.user.get_full_name())
        user_profile.save()
        
    if user_profile:
        current_organization = user_profile.current_organization

    template = 'choose_current_organization.html' if organizations.count() > 0 else 'without_organization.html'
    return render_to_response(template, {
                                'organizations': organizations, 
                                'current_organization': current_organization,
                                'organization_signup_link': settings.ORGANIZATION_SIGNUP_LINK
                               },
                               context_instance = RequestContext(request)) 
开发者ID:crowdata,项目名称:crowdata,代码行数:24,代码来源:views.py

示例3: view_capabilities

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def view_capabilities(request):
    instructors = Person.objects.filter(role__role__in=["FAC", "SESS", "COOP"],
                                        role__unit__in=request.units)
    capabilities = []
    for i in instructors:
        capabilities.append(TeachingCapability.objects.filter(instructor=i))
    capabilities_list = list(zip(instructors, capabilities))

    courses = PlanningCourse.objects.filter(owner__in=request.units)
    capabilities = []
    for c in courses:
        capabilities.append(TeachingCapability.objects.filter(course=c))
    course_capabilities_list = list(zip(courses, capabilities))

    return render(request, "planning/view_capabilities.html",
                              {'capabilities_list': capabilities_list,
                               'course_capabilities_list': course_capabilities_list},
                              context_instance=RequestContext(request)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:view_capabilities.py

示例4: wizard

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def wizard(request):
    form = FilterWizard([FilterWiZardForm1, FilterWiZardForm2, FilterWiZardForm3])
    if request.method == 'GET':
        print('CHECK HERE')
        query_string = request.META['QUERY_STRING']
        if query_string != '':
            print("LIMPANDO")
            new_query_string = []
            query_string = query_string.split('&')
            for item in query_string:
                if not (item.startswith('csrfmiddlewaretoken') or item.startswith('hash') or item.startswith('wizard')):
                    #get here only the ones need to be cleaned Ex. 1-chr
                    item = "-".join(item.split('-', 2)[1:])
                    new_query_string.append(item)

            #create new query
            filterstring = "&".join(new_query_string)
            # return HttpResponseRedirect('/filter_analysis/?%s' % (filterstring))
            return redirect(reverse('filter_analysis')+'?'+filterstring)
                    
                    
                     
                
                
    return form(context=RequestContext(request), request=request) 
开发者ID:raonyguimaraes,项目名称:mendelmd,代码行数:27,代码来源:views.py

示例5: index

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def index(request):
    if request.method == 'POST':
        form = PathAnalysisForm(request.POST)
        if  form.is_valid():
            query = form.cleaned_data['search']
            print(query)
            #here is where the magic happens!
            #search in kegg
#            data = kegg_rest_request('list/pathway/hsa')
#            pathways = kegg_rest_request('find/pathway/%s' % (query))
            pathways = Pathway.objects.filter(Q(name__icontains=query))
            # print pathways
            
    else:
        form = PathAnalysisForm()
#        pathways = kegg_rest_request('list/pathway/hsa')
        pathways = Pathway.objects.all()    
    
    
    return render_to_response('pathway_analysis/index.html', {'form': form, 'pathways': pathways}, context_instance=RequestContext(request)) 
开发者ID:raonyguimaraes,项目名称:mendelmd,代码行数:22,代码来源:views.py

示例6: _resolve_context

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def _resolve_context(self, context):
        # This wrapper deprecates returning a Context or a RequestContext in
        # subclasses that override resolve_context. It can be removed in
        # Django 1.10. If returning a Context or a RequestContext works by
        # accident, it won't be an issue per se, but it won't be officially
        # supported either.
        new_context = self.resolve_context(context)
        if isinstance(new_context, RequestContext) and self._request is None:
            self._request = new_context.request
        if isinstance(new_context, Context):
            warnings.warn(
                "{}.resolve_context() must return a dict, not a {}.".format(
                    self.__class__.__name__, new_context.__class__.__name__),
                RemovedInDjango110Warning, stacklevel=2)
            # It would be tempting to do new_context = new_context.flatten()
            # here but that would cause template context processors to run for
            # TemplateResponse(request, template, Context({})), which would be
            # backwards-incompatible. As a consequence another deprecation
            # warning will be raised when rendering the template. There isn't
            # much we can do about that.
        return new_context 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:23,代码来源:response.py

示例7: index

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def index(request):
    offline_register(request)

    if request.user.is_authenticated():
        request.session['username'] = request.user.username
        request.session['uid'] = request.user.pk
    else:
        request.session['uid'] = -1

    print(">>>>>>>", request.session.get('newdump'));
    # if request.session.get('newdump'):
    #      dumpid = request.session.get('newdump')
    #  return render(request,'index.html',context={"dump":dumpid})
    return render_to_response("index.html", locals(), context_instance=RequestContext(request))
    # contex = {
    #     "request":RequestContext(request),
    #     "dump":dumpid
    # }
    # return render(request,'index.html',contex) 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:21,代码来源:views.py

示例8: process_detail

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def process_detail(request):
    context = {}
    try:
        if request.POST.get("setPid") and request.POST.get("setDumpid"):

            context = {
                "pid": request.POST.get("setPid"),
                "dumpid": request.POST.get("setDumpid"),
                "dumpname": request.POST.get("dumpName")
            }
        else:
            raise Exception("No Process Id or Dump Id Specified")

    except Exception as ex:
        raise Exception(ex)
    return render_to_response("singleprocess.html", context, context_instance=RequestContext(request)) 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:18,代码来源:views.py

示例9: test_preferences_cp

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def test_preferences_cp(self):
        request = RequestFactory().get('/')
        context = context_processors.preferences_cp(request)

        # context should have preferences.
        my_preferences = context['preferences']

        # preferences should have test MyPreferences object member.
        my_preferences = my_preferences.MyPreferences
        self.failUnless(isinstance(my_preferences, MyPreferences),
                        "%s should be instance of MyPreferences." % my_preferences)

        # With preferences_cp is loaded as a TEMPLATE_CONTEXT_PROCESSORS
        # templates should have access to preferences object.
        context_instance = RequestContext(request)
        t = Template("{% if preferences %}{{ preferences }}{% endif %}")
        self.failUnless(t.render(context_instance), "preferences should be \
available in template context.")

        t = Template("{% if preferences.MyPreferences %}{{ \
preferences.MyPreferences }}{% endif %}")
        self.failUnless(t.render(context_instance), "MyPreferences should be \
available as part of preferences var in template context.") 
开发者ID:82Flex,项目名称:DCRM,代码行数:25,代码来源:test_all.py

示例10: calculation_view

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def calculation_view(request, calculation_id):
    calculation = Calculation.objects.get(pk=calculation_id)
    data = get_globals()
    data['calculation'] = calculation
    data['stdout'] = ''
    data['stderr'] = ''

    if os.path.exists(os.path.join(calculation.path, 'stdout.txt')):
        with open(os.path.join(calculation.path, 'stdout.txt')) as fr:
            data['stdout'] = fr.read()
    if os.path.exists(os.path.join(calculation.path, 'stderr.txt')):
        with open(os.path.join(calculation.path, 'stderr.txt')) as fr:
            data['stderr'] = fr.read()
    try:
        data['incar'] = ''.join(calculation.read_incar())
    except VaspError:
        data['incar'] = 'Could not read INCAR'

    if not calculation.dos is None:
        script, div = components(calculation.dos.bokeh_plot)
        data['dos'] = script
        data['dosdiv'] = div

    return render_to_response('analysis/calculation.html',
            data, RequestContext(request)) 
开发者ID:wolverton-research-group,项目名称:qmpy,代码行数:27,代码来源:calculation.py

示例11: create_admin

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def create_admin(request):
    """
    网站刚开始运行时,没有管理员,需要创建一个
    :param request:
    :return:
    """
    if SiteUser.has_admin():
        return error_404(request)
    else:
        request.page_title = '创建管理员'
        return render_to_response('accounts/create_admin.html', {'request': request})
        # 使用 context_instance=RequestContext(request) 会出现问题
        # Model class django.contrib.auth.models. Permission doesn't declare an explicit app_label and either
        # isn't in an application in INSTALLED_APPS or else was imported before its application was loaded.
        # return render_to_response('accounts/create_admin.html', {'request': request},
        #                            context_instance=RequestContext(request))
        # 解决csrf_protect不能工作,在前端不能显示csrf_token
        # 加上context_instance=RequestContext(request) 
开发者ID:restran,项目名称:fomalhaut-panel,代码行数:20,代码来源:views.py

示例12: project_edit

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def project_edit(request, project_id):

    proj = Project.objects.get(pk=project_id)

    if request.method == 'POST':

        title = request.POST.get('title', False)
        text = request.POST.get('text', False)
        project_priority = int(request.POST.get('project_priority', False))
        project_duedate = datetime.datetime.fromtimestamp(
            int(request.POST.get('project_duedate', False)))

        proj.title = title
        proj.text = text
        proj.priority = project_priority
        proj.due_date = project_duedate
        proj.save()

        return redirect('/taskManager/' + project_id + '/')
    else:
        return render_to_response(
            'taskManager/project_edit.html', {'proj': proj}, RequestContext(request))

# A4: Insecure Direct Object Reference (IDOR) 
开发者ID:python-security,项目名称:pyt,代码行数:26,代码来源:views.py

示例13: note_create

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def note_create(request, project_id, task_id):
    if request.method == 'POST':

        parent_task = Task.objects.get(pk=task_id)

        note_title = request.POST.get('note_title', False)
        text = request.POST.get('text', False)

        note = Notes(
            title=note_title,
            text=text,
            user=request.user,
            task=parent_task)

        note.save()
        return redirect('/taskManager/' + project_id + '/' +
                        task_id, {'new_note_added': True})
    else:
        return render_to_response(
            'taskManager/note_create.html', {'task_id': task_id}, RequestContext(request))

# A4: Insecure Direct Object Reference (IDOR) 
开发者ID:python-security,项目名称:pyt,代码行数:24,代码来源:views.py

示例14: test_i18n_switcher

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def test_i18n_switcher(rf):
    """ The language switcher is rendered correctly. """

    # create a fake template with a name
    template = "{% load core_tags %}{% i18n_switcher %}"

    # set a language
    translation.activate(settings.LANGUAGES[0][0])

    # render the link
    request = rf.get(reverse('home'))
    context = RequestContext(request, {})
    rendered_template = Template(template).render(context)
    for language in settings.LANGUAGES:
        if language == settings.LANGUAGES[0]:
            assert '<a href="/i18n/%s/"><u>%s</u></a>' % language in rendered_template
        else:
            assert'<a href="/i18n/%s/">%s</a>' % language in rendered_template 
开发者ID:rdmorganiser,项目名称:rdmo,代码行数:20,代码来源:test_tags.py

示例15: get_context

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import RequestContext [as 别名]
def get_context(request):
    ctx = RequestContext(request)
    ctx["API_CNAME"] = os.environ["API_CNAME"]
    ctx["API_PORT"] = os.environ["API_PORT"]
    ctx["TRADEMARK"] = os.environ.get("TRADEMARK", "")
    return ctx 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:8,代码来源:views.py


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