Python django.template.RequestContext() Examples
The following are 30
code examples of django.template.RequestContext().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.template
, or try the search function
.
Example #1
Source File: views.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #2
Source File: views.py From fomalhaut-panel with MIT License | 6 votes |
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)
Example #3
Source File: family_analysis.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: views.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #5
Source File: views.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #6
Source File: family_analysis.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #7
Source File: response.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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
Example #8
Source File: family_analysis.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #9
Source File: view_capabilities.py From coursys with GNU General Public License v3.0 | 6 votes |
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))
Example #10
Source File: views.py From aumfor with GNU General Public License v3.0 | 6 votes |
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)
Example #11
Source File: views.py From crowdata with MIT License | 6 votes |
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))
Example #12
Source File: views.py From crowdata with MIT License | 6 votes |
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)
Example #13
Source File: calculation.py From qmpy with MIT License | 6 votes |
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))
Example #14
Source File: views.py From aumfor with GNU General Public License v3.0 | 6 votes |
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))
Example #15
Source File: views.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #16
Source File: test_all.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
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.")
Example #17
Source File: views.py From pyt with GNU General Public License v2.0 | 6 votes |
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)
Example #18
Source File: views.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #19
Source File: views.py From pyt with GNU General Public License v2.0 | 6 votes |
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)
Example #20
Source File: test_tags.py From rdmo with Apache License 2.0 | 6 votes |
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
Example #21
Source File: views.py From PeachOrchard with MIT License | 5 votes |
def home(request): """ Load home template """ nodes = Node.objects.all() return render_to_response("home.html", {"nodes": nodes}, context_instance=RequestContext(request))
Example #22
Source File: views.py From pyt with GNU General Public License v2.0 | 5 votes |
def manage_projects(request): user = request.user if user.is_authenticated(): logged_in = True if user.has_perm('can_change_group'): if request.method == 'POST': userid = request.POST.get("userid") projectid = request.POST.get("projectid") user = User.objects.get(pk=userid) project = Project.objects.get(pk=projectid) project.users_assigned.add(user) return redirect('/taskManager/') else: return render_to_response( 'taskManager/manage_projects.html', { 'projects': Project.objects.order_by('title'), 'users': User.objects.order_by('date_joined'), 'logged_in': logged_in}, RequestContext(request)) else: return redirect('/taskManager/', {'permission': False}) return redirect('/taskManager/', {'logged_in': False}) # A7 - Missing Function Level Access Control
Example #23
Source File: tests.py From django-seo with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_not_request_context(self): """ Tests the view metadata on a view that is not a request context. """ self.view_metadata._view = "userapp_my_other_view" self.view_metadata.save() try: response = self.client.get(reverse('userapp_my_other_view', args=["abc123"])) self.fail("No error raised when RequestContext not used.") except TemplateSyntaxError: pass
Example #24
Source File: views.py From PeachOrchard with MIT License | 5 votes |
def node(request, node_id=-1): """ Load a node and render pertinent info """ ret = render_to_response('node.html', {'node': False}, context_instance=RequestContext(request)) try: node = Node.objects.get(id=node_id) if 'crash' in request.GET: crash_id = int(request.GET.get('crash')) if vu._validate_crash(crash_id, node): ret = render_to_response('crash.html', {'node': node, 'crash_id': crash_id, 'crash': vu._get_crash_data(node.id, crash_id)}, context_instance=RequestContext(request)) else: ret = HttpResponse("Invalid crash") elif 'action' in request.GET: action = request.GET.get("action") if 'delete' in action: vu.delete_node(node_id) ret = HttpResponseRedirect("/") else: crashes = Crash.objects.filter(node_index=node) ret = render_to_response('node.html', {'node': node, 'crashes': crashes}, context_instance=RequestContext(request)) except Node.DoesNotExist: pass return ret
Example #25
Source File: test_templatetag.py From django-rangepaginator with MIT License | 5 votes |
def render_template(value, **context): template = Template(value) request = context.get('request') ctx = RequestContext(request, context) if request else Context(context) return template.render(ctx).strip()
Example #26
Source File: test_compat.py From django-compat with MIT License | 5 votes |
def test_request_context(self): self.assertEqual(render_to_string(self.template_name, context_instance=RequestContext(None, {'obj': 'test'})), 'obj:test')
Example #27
Source File: __init__.py From django-compat with MIT License | 5 votes |
def render_to_string(template_name, context=None, context_instance=_context_instance_undefined, dirs=_dirs_undefined, dictionary=_dictionary_undefined, request=None, using=None): if (context_instance is _context_instance_undefined and dirs is _dirs_undefined and dictionary is _dictionary_undefined): if django.VERSION >= (1, 8): # Call new render_to_string with new arguments return render_to_string_django(template_name, context, request, using) else: # Call legacy render_to_string with new arguments from django.template import RequestContext context_instance = RequestContext(request) if request else None return render_to_string_django(template_name, context, context_instance) else: if django.VERSION >= (1, 10): # Call new render_to_string with legacy arguments raise NotImplementedError('Django compat does not support calling post-1.8 render_to_string with pre-1.8 ' 'keyword arguments') else: # Call legacy render_to_string with legacy arguments if dictionary is _dictionary_undefined: dictionary = {} if context_instance is _context_instance_undefined: context_instance = None return render_to_string_django(template_name, dictionary, context_instance) ### Undocumented ###
Example #28
Source File: views.py From django-twitter-stream with MIT License | 5 votes |
def _render_to_string_request(request, template, dictionary): """ Wrapper around render_to_string that includes the request context This is necessary to get all of the TEMPLATE_CONTEXT_PROCESSORS activated in the template. """ context = RequestContext(request, dictionary) return render_to_string(template, context_instance=context)
Example #29
Source File: models.py From DCRM with GNU Affero General Public License v3.0 | 5 votes |
def on_comment_posted(sender, comment, request, **kwargs): """ Send email notification of a new comment to site staff when email notifications have been requested. """ # This code is copied from django_comments.moderation. # That code doesn't offer a RequestContext, which makes it really # hard to generate proper URL's with FQDN in the email # # Instead of implementing this feature in the moderator class, the signal is used instead # so the notification feature works regardless of a manual moderator.register() call in the project. if not appsettings.FLUENT_COMMENTS_USE_EMAIL_NOTIFICATION: return recipient_list = [manager_tuple[1] for manager_tuple in settings.MANAGERS] site = get_current_site(request) content_object = comment.content_object if comment.is_removed: subject = u'[{0}] Spam comment on "{1}"'.format(site.name, content_object) elif not comment.is_public: subject = u'[{0}] Moderated comment on "{1}"'.format(site.name, content_object) else: subject = u'[{0}] New comment posted on "{1}"'.format(site.name, content_object) context = { 'site': site, 'comment': comment, 'content_object': content_object } if django.VERSION >= (1, 8): message = render_to_string("comments/comment_notification_email.txt", context, request=request) else: message = render_to_string("comments/comment_notification_email.txt", context, context_instance=RequestContext(request)) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True)
Example #30
Source File: views.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def _submission_response(request, instance): data = {} data['message'] = _("Successful submission.") data['formid'] = instance.xform.id_string data['encrypted'] = instance.xform.encrypted data['instanceID'] = u'uuid:%s' % instance.uuid data['submissionDate'] = instance.date_created.isoformat() data['markedAsCompleteDate'] = instance.date_modified.isoformat() context = RequestContext(request, data) t = loader.get_template('submission.xml') return BaseOpenRosaResponse(t.render(context))