當前位置: 首頁>>代碼示例>>Python>>正文


Python shortcuts.HttpResponse方法代碼示例

本文整理匯總了Python中django.shortcuts.HttpResponse方法的典型用法代碼示例。如果您正苦於以下問題:Python shortcuts.HttpResponse方法的具體用法?Python shortcuts.HttpResponse怎麽用?Python shortcuts.HttpResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.shortcuts的用法示例。


在下文中一共展示了shortcuts.HttpResponse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: download_current_events_csv

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def download_current_events_csv(request, past=None):
    unit_ids = [unit.id for unit in request.units]
    units = Unit.objects.filter(id__in=unit_ids)
    if not past:
        events = OutreachEvent.objects.current(units)
        filestring = "current"
    else:
        events = OutreachEvent.objects.past(units)
        filestring = "past"
    response = HttpResponse(content_type='text/csv')

    response['Content-Disposition'] = 'inline; filename="outreach_events-%s-%s.csv"' % \
                                      (datetime.now().strftime('%Y%m%d'), filestring)
    writer = csv.writer(response)
    if events:
        writer.writerow(['Title', 'Start Date', 'End Date', 'Description', 'Location', 'Unit', 'Resources',
                         'Cost', 'Notes', 'Email', 'Attendance', 'Private Notes', 'Registration Link'])
        for e in events:
            writer.writerow([e.title, e.start_date, e.end_date, e.description, e.location, e.unit, e.resources, e.cost,
                             e.notes, e.email, e.registration_count(), e.private_notes,
                             request.build_absolute_uri(reverse('outreach:register', kwargs={'event_slug': e.slug}))])
    return response 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:24,代碼來源:views.py

示例2: download_visas_csv

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def download_visas_csv(request):
    visas = Visa.objects.visible_by_unit(Unit.sub_units(request.units))
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'inline; filename="visas-%s.csv"' % datetime.now().strftime('%Y%m%d')
    writer = csv.writer(response)
    writer.writerow(['Person', 'Email', 'Unit', 'Start Date', 'End Date', 'Type', 'Validity'])
    for v in visas:
        person = v.person
        email = v.person.email()
        unit = v.unit.name
        start_date = v.start_date
        end_date = v.end_date
        visa_type = v.status
        validity = v.get_validity()
        writer.writerow([person, email, unit, start_date, end_date, visa_type, validity])

    return response 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:19,代碼來源:views.py

示例3: inventory_download

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def inventory_download(request):
    unit_ids = [unit.id for unit in request.units]
    units = Unit.objects.filter(id__in=unit_ids)
    assets = Asset.objects.visible(units)
    response = HttpResponse(content_type='text/csv')

    response['Content-Disposition'] = 'inline; filename="inventory-%s.csv"' % datetime.datetime.now().strftime('%Y%m%d')
    writer = csv.writer(response)
    if assets:
        writer.writerow(['Name', 'Unit', 'Brand', 'Description', 'Serial', 'Service/Asset Tag', 'Express Service Code',
                         'Quantity', 'Minimum Re-Order Quantity', 'Quantity Ordered', 'Minimum Vendor Quantity',
                         'Price', 'Category', 'Location', 'PR/PO No.', 'Account No.', 'Supplier/Vendor',
                         'Calibration/Service Date', 'End of Life Date', 'Notes', 'Service Records',
                         'Attachments', 'Change Records', 'User', 'Date Shipped/Received', 'Currently in Use', 'URL'])
        for a in assets:
            url = request.build_absolute_uri(reverse('inventory:view_asset', kwargs={'asset_slug': a.slug}))
            writer.writerow([a.name, a.unit, a.brand, a.description, a.serial, a.tag, a.express_service_code,
                             a.quantity, a.min_qty, a.qty_ordered, a.min_vendor_qty, a.price, a.get_category_display(),
                             a.location, a.po, a.account, a.vendor, a.calibration_date, a.eol_date, a.notes,
                             a.service_records, a.has_attachments(), a.has_records(), a.user, a.date_shipped, a.in_use,
                             url])
    return response 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:24,代碼來源:views.py

示例4: download_promises

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def download_promises(request, semester_name=None):
    if semester_name is None:
        semester = Semester.next_starting()
    else:
        semester = get_object_or_404(Semester, name=semester_name)
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'inline; filename="promises-%s-%s.csv"' % (semester.name,
                                                                                 datetime.now().strftime('%Y%m%d'))
    writer = csv.writer(response)
    writer.writerow(['Student', 'Program', 'Start Semester', 'Status', 'Promised', 'Received', 'Difference'])
    promises = Promise.objects.filter(end_semester=semester,
                                      student__program__unit__in=request.units)
    for p in promises:
        student = p.student.person.sortname()
        program = p.student.program.label
        start = p.student.start_semester.label()
        status = p.student.get_current_status_display()
        promised = p.amount
        received = p.received()
        difference = p.difference()
        writer.writerow([student, program, start, status, promised, received, difference])

    return response 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:25,代碼來源:all_promises.py

示例5: upload_ssh_key

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def upload_ssh_key(request):
    if request.method == 'POST':
        pkey = request.FILES.get('pkey')
        ssh_key = pkey.read().decode('utf-8')

        while True:
            filename = unique()
            ssh_key_path = os.path.join(TMP_DIR, filename)
            if not os.path.isfile(ssh_key_path):
                with open(ssh_key_path, 'w') as f:
                    f.write(ssh_key)
                break
            else:
                continue

        return HttpResponse(filename) 
開發者ID:huyuan1999,項目名稱:django-webssh,代碼行數:18,代碼來源:views.py

示例6: post

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def post(request):
        ret = {'status': True, 'error': None, }
        try:
            if request.POST.get('nid'):
                ids = request.POST.get('nid', None)
                Tools.objects.get(id=ids).delete()
            else:
                ids = request.POST.getlist('id', None)
                idstring = ','.join(ids)
                Tools.objects.extra(
                    where=['id IN (' + idstring + ')']).delete()
        except Exception as e:
            ret['status'] = False
            ret['error'] = '刪除請求錯誤,沒有權限{}'.format(e)
        finally:
            return HttpResponse(json.dumps(ret)) 
開發者ID:hequan2017,項目名稱:chain,代碼行數:18,代碼來源:views.py

示例7: get_context_data

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def get_context_data(self, **kwargs):
        pk = self.kwargs.get(self.pk_url_kwarg, None)
        name = Names.objects.get(username=self.request.user)
        task = ToolsResults.objects.get(id=pk)
        if name.is_superuser != 1:
            if task.add_user != name:
                return HttpResponse(status=500)
        try:
            results = TaskResult.objects.get(task_id=task.task_id)
        except Exception as e:
            logger.error(e)
            results = {'result': "還未完成,請稍後再查看!!"}

        context = {
            "tasks_active": "active",
            "tools_results_active": "active",
            "task": task,
            "results": results,
        }
        kwargs.update(context)
        return super().get_context_data(**kwargs) 
開發者ID:hequan2017,項目名稱:chain,代碼行數:23,代碼來源:views.py

示例8: post

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def post(request):
        ret = {'status': True, 'error': None, }
        try:
            if request.POST.get('nid'):
                ids = request.POST.get('nid', None)
                Names.objects.get(id=ids).delete()
            else:
                ids = request.POST.getlist('id', None)
                idstring = ','.join(ids)
                Names.objects.extra(
                    where=['id IN (' + idstring + ')']).delete()
        except Exception as e:
            ret['status'] = False
            ret['error'] = '刪除請求錯誤,沒有權限{}'.format(e)
        finally:
            return HttpResponse(json.dumps(ret)) 
開發者ID:hequan2017,項目名稱:chain,代碼行數:18,代碼來源:views.py

示例9: preprints_home

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def preprints_home(request):
    """
    Displays the preprints home page with search box and 6 latest preprints publications
    :param request: HttpRequest object
    :return: HttpResponse
    """
    preprints = submission_models.Article.preprints.filter(
        date_published__lte=timezone.now()).order_by('-date_published')[:3]

    subjects = models.Subject.objects.all().prefetch_related('preprints')

    template = 'preprints/home.html'
    context = {
        'preprints': preprints,
        'subjects': subjects,
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:20,代碼來源:views.py

示例10: preprints_dashboard

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def preprints_dashboard(request):
    """
    Displays a list of an author's preprints.
    :param request: HttpRequest object
    :return: HttpResponse
    """
    preprints = submission_models.Article.preprints.filter(Q(authors=request.user) | Q(owner=request.user),
                                                           date_submitted__isnull=False).distinct()

    incomplete_preprints = submission_models.Article.preprints.filter(Q(authors=request.user) | Q(owner=request.user),
                                                                      date_submitted__isnull=True)

    template = 'admin/preprints/dashboard.html'
    context = {
        'preprints': preprints,
        'incomplete_preprints': incomplete_preprints,
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:21,代碼來源:views.py

示例11: preprints_submit

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def preprints_submit(request, article_id=None):
    """
    Handles initial steps of generating a preprints submission.
    :param request: HttpRequest
    :return: HttpResponse or HttpRedirect
    """
    article = preprint_logic.get_preprint_article_if_id(request, article_id)
    additional_fields = submission_models.Field.objects.filter(press=request.press)
    form = forms.PreprintInfo(instance=article, additional_fields=additional_fields)

    if request.POST:
        form = forms.PreprintInfo(request.POST, instance=article, additional_fields=additional_fields)

        if form.is_valid():
            article = preprint_logic.save_preprint_submit_form(request, form, article, additional_fields)
            return redirect(reverse('preprints_authors', kwargs={'article_id': article.pk}))

    template = 'preprints/submit_start.html'
    context = {
        'form': form,
        'article': article,
        'additional_fields': additional_fields,
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:27,代碼來源:views.py

示例12: preprints_comments

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def preprints_comments(request, article_id):
    """
    Presents an interface for authors and editors to mark comments as publicly readable.
    :param request: HttpRequest object
    :param article_id: PK of an Article object
    :return: HttpRedirect if POST, HttpResponse otherwise
    """
    preprint = get_object_or_404(submission_models.Article.preprints, pk=article_id)

    if request.POST:
        preprint_logic.comment_manager_post(request, preprint)
        return redirect(reverse('preprints_comments', kwargs={'article_id': preprint.pk}))

    template = 'admin/preprints/comments.html'
    context = {
        'preprint': preprint,
        'new_comments': preprint.comment_set.filter(is_reviewed=False),
        'old_comments': preprint.comment_set.filter(is_reviewed=True)
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:23,代碼來源:views.py

示例13: preprints_settings

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def preprints_settings(request):
    """
    Displays and allows editing of various prepprint settings
    :param request: HttpRequest
    :return: HttpRedirect if POST else HttpResponse
    """
    form = forms.SettingsForm(instance=request.press)

    if request.POST:
        form = forms.SettingsForm(request.POST, instance=request.press)

        if form.is_valid():
            form.save()
            return redirect(reverse('preprints_settings'))

    template = 'admin/preprints/settings.html'
    context = {
        'form': form,
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:23,代碼來源:views.py

示例14: version_queue

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def version_queue(request):
    """
    Displays a list of version update requests.
    :param request: HttpRequest
    :return: HttpResponse or HttpRedirect
    """
    version_queue = models.VersionQueue.objects.filter(date_decision__isnull=True)
    duplicates = preprint_logic.check_duplicates(version_queue)

    if request.POST:
        if 'approve' in request.POST:
            return preprint_logic.approve_pending_update(request)
        elif 'deny' in request.POST:
            return preprint_logic.deny_pending_update(request)

    template = 'admin/preprints/version_queue.html'
    context = {
        'version_queue': version_queue,
        'duplicates': duplicates,
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:24,代碼來源:views.py

示例15: template_target_export

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponse [as 別名]
def template_target_export(request, id):
    rx_ids = template_target(request, id, return_refs_only=True)
    
    txt = '{"fileName":"reaxys_query.json", "version":"1.0","content": {"id":"root","facts": ['
    for i, rx_id in enumerate(rx_ids):
        if i != 0:
            txt += ','
        txt += '{"id":"Reaxys487",'
        if i != 0:
            txt += '"logicOperator":"OR",'
        txt += '"fields": [{"value":"%i","boundOperator":"op_num_equal","id":"RX.ID","displayName":"Reaction ID"}],' % (rx_id)
        txt += '"fieldsLogicOperator":"AND","exist":false,"bio":false}'

    txt += '], "exist":false,"bio":false } }'

    response = HttpResponse(txt, content_type='text/csv')
    response['Content-Disposition'] = 'attachment;filename=reaxys_query.json'
    return response

#@login_required 
開發者ID:connorcoley,項目名稱:ASKCOS,代碼行數:22,代碼來源:info.py


注:本文中的django.shortcuts.HttpResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。