Python django.template.context.RequestContext() Examples
The following are 16
code examples of django.template.context.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.context
, or try the search function
.
Example #1
Source File: views.py From dirigible-spreadsheet with MIT License | 6 votes |
def export_csv(request, sheet, csv_format): if csv_format == 'unicode': encoding = 'utf-8' else: encoding = 'windows-1252' try: content = worksheet_to_csv( sheet.unjsonify_worksheet(), encoding=encoding ) except UnicodeEncodeError: return render( request, 'export_csv_error.html', {'sheet': sheet}, context_instance=RequestContext(request) ) response = HttpResponse(content, content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=%s.csv' % (sheet.name,) response['Content-Length'] = len(content) return response
Example #2
Source File: utils.py From StormOnline with Apache License 2.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #3
Source File: django.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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)
Example #4
Source File: utils.py From weibo-analysis-system with MIT License | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #5
Source File: utils.py From myblog with GNU Affero General Public License v3.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #6
Source File: utils.py From CTF_AWD_Platform with MIT License | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #7
Source File: views.py From dirigible-spreadsheet with MIT License | 5 votes |
def import_xls(request, username): if request.user.username != username: return HttpResponseForbidden(render_to_string("403.html")) handle, filename = mkstemp() try: os.write(handle, request.FILES['file'].read()) wb = xlrd.open_workbook(filename) for xl_sheet in wb.sheets(): if xl_sheet.nrows > 0 and xl_sheet.ncols > 0: name = '%s - %s' % ( splitext(request.FILES['file'].name)[0], xl_sheet.name ) sheet = Sheet(owner=request.user, name=name) sheet.jsonify_worksheet(worksheet_from_excel(xl_sheet)) sheet.save() try: calculate(request, sheet.owner.username, sheet.id) except: pass except Exception: return render( request, 'import_xls_error.html', {}, context_instance=RequestContext(request) ) finally: os.close(handle) os.unlink(filename) return HttpResponseRedirect('/')
Example #8
Source File: views.py From dirigible-spreadsheet with MIT License | 5 votes |
def import_csv(request, sheet): def error_response(): return render( request, 'import_csv_error.html', {'sheet': sheet}, context_instance=RequestContext(request) ) form = ImportCSVForm(request.POST, request.FILES) if not form.is_valid(): return error_response() worksheet = sheet.unjsonify_worksheet() csv_file = request.FILES['file'] column = form.cleaned_data['column'] row = form.cleaned_data['row'] excel_file_encoding = request.POST['csv_encoding']=='excel' try: worksheet = worksheet_from_csv( worksheet, csv_file, column, row, excel_file_encoding ) except DirigibleImportError: return error_response() sheet.jsonify_worksheet(worksheet) if update_sheet_with_version_check(sheet, contents_json=sheet.contents_json): calculate(request, sheet.owner.username, sheet.id) return HttpResponseRedirect(reverse('sheet_page',kwargs={ 'username' : request.user.username, 'sheet_id' : sheet.id, })) else: return HttpResponse('FAILED')
Example #9
Source File: utils.py From django_OA with GNU General Public License v3.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #10
Source File: django.py From openhgsenti with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: utils.py From Mxonline3 with Apache License 2.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #12
Source File: utils.py From imoocc with GNU General Public License v2.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #13
Source File: dashboard.py From devops with MIT License | 5 votes |
def widget(self): context = {'widget_id': self.id, 'widget_title': self.title, 'widget_icon': self.widget_icon, 'widget_type': self.widget_type, 'form': self, 'widget': self} self.context(context) return loader.render_to_string(self.template, context, context_instance=RequestContext(self.request))
Example #14
Source File: utils.py From online with GNU Affero General Public License v3.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #15
Source File: utils.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = context.flatten() else: ctx = context return ctx
Example #16
Source File: utils.py From ImitationTmall_Django with GNU General Public License v3.0 | 5 votes |
def get_context_dict(context): """ Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django, the function helps the transition by converting the [RequestContext] object to the dictionary when necessary. :param context: RequestContext :return: dict """ if isinstance(context, RequestContext): ctx = {} map(ctx.update, context.dicts) else: ctx = context return ctx