本文整理汇总了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
示例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
示例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
示例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
示例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)
示例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))
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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