Python django.shortcuts.render_to_response() Examples

The following are 30 code examples of django.shortcuts.render_to_response(). 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.shortcuts , or try the search function .
Example #1
Source File: references.py    From qmpy with MIT License 6 votes vote down vote up
def journal_view(request, journal_id):
    journal = Journal.objects.get(id=journal_id)
    dates = journal.references.values_list('year', flat=True)
    plt.hist(dates)
    plt.xlabel('Year')
    plt.ylabel('# of publications with new materials')
    img = StringIO.StringIO()
    plt.savefig(img, dpi=75, bbox_inches='tight')
    data_uri = 'data:image/jpg;base64,'
    data_uri += img.getvalue().encode('base64').replace('\n', '')
    plt.close()

    some_entries = Entry.objects.filter(reference__journal=journal)[:20]
    data = get_globals()
    data.update({'journal':journal, 
        'hist':data_uri,
        'entries':some_entries})
    return render_to_response('data/reference/journal.html', 
            data,
            RequestContext(request)) 
Example #2
Source File: composition.py    From qmpy with MIT License 6 votes vote down vote up
def generic_composition_view(request, search=None):
    data = {'search':search}
    composition = ''
    space = []
    if request.method == 'POST':
        p = request.POST
        search = p.get('search', '')
        data.update(p)
    if not search:
        return render_to_response('materials/generic_composition.html',
                data,
                RequestContext(request))
        
    gc = GenericComposition(search)
    data['gc'] = gc
    return render_to_response('materials/generic_composition.html', 
            data,
            RequestContext(request)) 
Example #3
Source File: views.py    From mendelmd with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #4
Source File: views.py    From mendelmd with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #5
Source File: admin.py    From django-usersettings2 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def render_select_site_form(self, request, context, form_url=''):
        """
        Render the site choice form.
        """
        app_label = self.opts.app_label
        context.update({
            'has_change_permission': self.has_change_permission(request),
            'form_url': mark_safe(form_url),
            'opts': self.opts,
            'add': True,
            'save_on_top': self.save_on_top,
        })

        return render_to_response(self.select_site_form_template or [
            'admin/%s/%s/select_site_form.html' % (app_label, self.opts.object_name.lower()),
            'admin/%s/select_site_form.html' % app_label,
            'admin/usersettings/select_site_form.html',  # added default here
            'admin/select_site_form.html'
        ], context) 
Example #6
Source File: options.py    From lykops with Apache License 2.0 6 votes vote down vote up
def detail(self, request):
        
        '''
        查看用户的ansible的option数据
        '''
        
        result = self._is_login(request)
        if result[0] :
            username = result[1]
        else :
            return HttpResponseRedirect(reverse('login'))
    
        vault_password = request.session['vault_password']
        result = self.ansible_option_api.detail(username, vault_password)
        if result[0] :
            data = result[1]
            error_message = ''
            self.logger.info(self.username + ' 查看用户' + username + '的ansible配置成功')
        else :
            data = {}
            error_message = self.username + ' 查看用户' + username + '的ansible配置失败,查询时发生错误,原因:' + result[1]
            self.logger.error(error_message) 
            error_message = result[1]
            
        return render_to_response('option_detail.html', {'data':data, 'login_user':username, 'error_message':error_message, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) 
Example #7
Source File: views.py    From mendelmd with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #8
Source File: views.py    From crowdata with MIT License 6 votes vote down vote up
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 #9
Source File: views.py    From crowdata with MIT License 6 votes vote down vote up
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 #10
Source File: references.py    From qmpy with MIT License 6 votes vote down vote up
def author_view(request, author_id):
    author = Author.objects.get(id=author_id)
    materials = Entry.objects.filter(reference__author_set=author)
    coauths = {}
    for co in Author.objects.filter(references__author_set=author):
        papers = Reference.objects.filter(author_set=author)
        papers = papers.filter(author_set=co)
        mats = Entry.objects.filter(reference__in=papers)
        data = {'papers': papers.distinct().count(),
                'materials': mats.distinct().count()}
        coauths[co] = data

    data = get_globals()
    data.update({'author':author,
        'materials':materials,
        'coauthors':coauths})
    return render_to_response('data/reference/author.html', 
            data,
            RequestContext(request)) 
Example #11
Source File: views.py    From aumfor with GNU General Public License v3.0 6 votes vote down vote up
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 #12
Source File: views.py    From aumfor with GNU General Public License v3.0 6 votes vote down vote up
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 #13
Source File: error.py    From DCRM with GNU Affero General Public License v3.0 5 votes vote down vote up
def bad_request(request):
    return render_to_response('error/400.html', status=400) 
Example #14
Source File: download.py    From qmpy with MIT License 5 votes vote down vote up
def download_home(request):
    data = get_globals()
    data['updated_on'] = DatabaseUpdate.value()
    return render_to_response('download.html', data) 
Example #15
Source File: documentation.py    From qmpy with MIT License 5 votes vote down vote up
def docs_view(request):
    return render_to_response('documentation/index.html', {}) 
Example #16
Source File: documentation.py    From qmpy with MIT License 5 votes vote down vote up
def vasp_docs(request):
    return render_to_response('documentation/vasp.html', {}) 
Example #17
Source File: report.py    From lykops with Apache License 2.0 5 votes vote down vote up
def summary(self,request):
        result = self._is_login(request)
        if result[0] :
            username = result[1]
        else :
            return HttpResponseRedirect(reverse('login'))
        
        http_referer = self.uri_api.get_httpreferer(username, no=-1)
        force = request.GET.get('force', False) 
        result = self.ansible_report_api.get_date_list(username, force=force)
        if not result[0] :
            return render_to_response('report_list.html', {'login_user':username, 'error_message':result[1], 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html})
        else :
            date_list = result[1]
        
        create_date = request.GET.get('create_date', None)
        if create_date == 'None' :
            create_date = None
        mode = request.GET.get('mode', 'all') 
        result = self.ansible_report_api.summary(username, dt=create_date, mode=mode)
        if not result[0] :
            error_message = self.username + ' 查看用户' + username + '的ansible任务执行报告列表失败,提交保存时发生错误,原因:' + result[1]
            self.logger.error(error_message) 
            return render_to_response('report_list.html', {'login_user':username, 'error_message':error_message, 'http_referer':http_referer, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html})
        else :
            work_list = result[1]
        
        self.logger.info(self.username + ' 查看用户' + username + '的ansible任务执行报告列表成功')
        return render_to_response('report_list.html', {'login_user':username, 'error_message':{}, 'http_referer':http_referer, 'date_list':date_list, 'work_list':work_list, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html}) 
Example #18
Source File: views.py    From PeachOrchard with MIT License 5 votes vote down vote up
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 #19
Source File: references.py    From qmpy with MIT License 5 votes vote down vote up
def reference_view(request, reference_id):
    ref = Reference.objects.get(id=reference_id)
    data = get_globals()
    data['reference'] = ref
    return render_to_response('data/reference/paper.html', 
            data,
            RequestContext(request)) 
Example #20
Source File: views.py    From PeachOrchard with MIT License 5 votes vote down vote up
def home(request):
    """ Load home template
    """

    nodes = Node.objects.all()
    return render_to_response("home.html",
                              {"nodes": nodes},
                              context_instance=RequestContext(request)) 
Example #21
Source File: error.py    From DCRM with GNU Affero General Public License v3.0 5 votes vote down vote up
def server_error(request):
    return render_to_response('error/500.html', status=500) 
Example #22
Source File: error.py    From DCRM with GNU Affero General Public License v3.0 5 votes vote down vote up
def page_not_found(request):
    return render_to_response('error/404.html', status=404) 
Example #23
Source File: views.py    From Cypher with GNU General Public License v3.0 5 votes vote down vote up
def main(request):
	return render_to_response('main.html', (request)) 
Example #24
Source File: export_tools.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def generate_kml_export(
        export_type, extension, username, id_string, export_id=None,
        filter_query=None):
    user = User.objects.get(username=username)
    xform = XForm.objects.get(user__username=username, id_string=id_string)
    response = render_to_response(
        'survey.kml', {'data': kml_export_data(id_string, user)})

    basename = "%s_%s" % (id_string,
                          datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
    filename = basename + "." + extension
    file_path = os.path.join(
        username,
        'exports',
        id_string,
        export_type,
        filename)

    storage = get_storage_class()()
    temp_file = NamedTemporaryFile(suffix=extension)
    temp_file.write(response.content)
    temp_file.seek(0)
    export_filename = storage.save(
        file_path,
        File(temp_file, file_path))
    temp_file.close()

    dir_name, basename = os.path.split(export_filename)

    # get or create export object
    if(export_id):
        export = Export.objects.get(id=export_id)
    else:
        export = Export.objects.create(xform=xform, export_type=export_type)

    export.filedir = dir_name
    export.filename = basename
    export.internal_status = Export.SUCCESSFUL
    export.save()

    return export 
Example #25
Source File: view.py    From dingtalk-django-example with GNU General Public License v3.0 5 votes vote down vote up
def format_res_data(self, context, timestamp=False):
        from django.shortcuts import render_to_response
        if isinstance(context, dict):
            return render_to_response("error.html", context)
        return Response(context) 
Example #26
Source File: views.py    From aumfor with GNU General Public License v3.0 5 votes vote down vote up
def handler500(request):
    responce = render_to_response('500.html', context_instance=RequestContext(request))
    responce.status_code = 500
    return responce 
Example #27
Source File: views.py    From aumfor with GNU General Public License v3.0 5 votes vote down vote up
def email(request):
    try:
        if request.POST.get("firstname") or request.POST.get("lastname") or request.POST.get("email"):

            name = str(request.POST.get("firstname") + ' ' + request.POST.get("lastname"))
            from_email = str(request.POST.get("email"))
            subject = str('Aumfor New' + ' ' + str(request.POST.get("subject")))

            # body = 'message from ' + name + "\n\n" + "\t\t" + str(request.POST.get("msg"))
            msg = str(request.POST.get("msg"))

            body = '''
				Hello Admin, <br>
				you have received new <b>%s</b> From AUMFOR and here is the detials ,<br>
				<b>From</b>    : %s <br>
				<b>Email</b>   : %s <br>
				<b>Subject</b> : %s <br>
				<b>Message</b> : <br>
				<span style="margin-left:5em;"><span> % s''' % (
            str(request.POST.get("subject")), name, from_email, subject, msg)

            email = EmailMessage(str(subject), str(body), str(from_email), to=['info@virtualrealitysystems.net'])

            for file in request.FILES.getlist("pic"):
                email.attach(filename=file.name, content=file.read(), mimetype=file.content_type)
            email.content_subtype = "html"
            email.send()
            return render_to_response('contactus.html', {"msg": "Your Response Submitted Successfully"},
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('contactus.html', {"msg": "Values are not set"},
                                      context_instance=RequestContext(request))


    except Exception as ex:
        print(ex)
        return render_to_response('contactus.html', {"msg": ex}, context_instance=RequestContext(request))


# --------------------------- 404 Page Error ---------------------- # 
Example #28
Source File: views.py    From aumfor with GNU General Public License v3.0 5 votes vote down vote up
def process_data(request):
    return render_to_response("processdetail.html", {}, context_instance=RequestContext(request)) 
Example #29
Source File: views.py    From aumfor with GNU General Public License v3.0 5 votes vote down vote up
def register(request):
    return render_to_response("register.html", {}, context_instance=RequestContext(request)) 
Example #30
Source File: views.py    From django-angularjs-blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def know(req, kid=None):
    return render_to_response("new_know.html")