本文整理汇总了Python中tendenci.core.theme.shortcuts.render_to_response函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_response函数的具体用法?Python render_to_response怎么用?Python render_to_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: locations_import_preview
def locations_import_preview(request, id, template_name='locations/import-map-fields.html'):
"""
This will generate a form based on the uploaded CSV for field mapping.
A preview will be generated based on the mapping given.
"""
locport = get_object_or_404(LocationImport, pk=id)
if request.method == 'POST':
form = ImportMapForm(request.POST, locport=locport)
if form.is_valid():
# Show the user a preview based on the mapping
cleaned_data = form.cleaned_data
#file_path = os.path.join(settings.MEDIA_ROOT, locport.get_file().file.name)
file_path = locport.get_file().file.name
locations, stats = parse_locs_from_csv(file_path, cleaned_data)
# return the form to use it for the confirm view
template_name = 'locations/import-preview.html'
return render_to_response(template_name, {
'locations': locations,
'stats': stats,
'locport': locport,
'form': form,
'now': datetime.now(),
}, context_instance=RequestContext(request))
else:
form = ImportMapForm(locport=locport)
return render_to_response(template_name, {
'form': form,
'locport': locport,
'now': datetime.now(),
}, context_instance=RequestContext(request))
示例2: bulk_add
def bulk_add(request, template_name="files/bulk-add.html"):
if not has_perm(request.user, "files.add_file"):
raise Http403
FileFormSet = modelformset_factory(
File,
form=FileForm,
can_delete=True,
fields=("name", "allow_anonymous_view", "user_perms", "member_perms", "group_perms", "status"),
extra=0,
)
if request.method == "POST":
# Setup formset html for json response
file_list = []
file_formset = FileFormSet(request.POST)
if file_formset.is_valid():
file_formset.save()
else:
# Handle formset errors
return render_to_response(
template_name, {"file_formset": file_formset}, context_instance=RequestContext(request)
)
formset_edit = True
# Handle existing files. Instance returned by file_formset.save() is not enough
for num in xrange(file_formset.total_form_count()):
key = "form-" + str(num) + "-id"
if request.POST.get(key):
file_list.append(request.POST.get(key))
# Handle new file uploads
for file in request.FILES.getlist("files"):
newFile = File(file=file)
# set up the user information
newFile.creator = request.user
newFile.creator_username = request.user.username
newFile.owner = request.user
newFile.owner_username = request.user.username
newFile.save()
file_list.append(newFile.id)
formset_edit = False
# Redirect if form_set is edited i.e. not a file select or drag event
if formset_edit:
return HttpResponseRedirect(reverse("file.search"))
# Handle json response
file_qs = File.objects.filter(id__in=file_list)
file_formset = FileFormSet(queryset=file_qs)
html = render_to_response(
"files/file-formset.html", {"file_formset": file_formset}, context_instance=RequestContext(request)
).content
data = {"form_set": html}
response = JSONResponse(data, {}, "application/json")
response["Content-Disposition"] = "inline; filename=files.json"
return response
else:
file_formset = FileFormSet({"form-TOTAL_FORMS": u"0", "form-INITIAL_FORMS": u"0", "form-MAX_NUM_FORMS": u""})
return render_to_response(template_name, {"file_formset": file_formset}, context_instance=RequestContext(request))
示例3: edit
def edit(request, id, form_class=DirectoryForm, template_name="directories/edit.html"):
directory = get_object_or_404(Directory, pk=id)
if not has_perm(request.user,'directories.change_directory', directory):
raise Http403
form = form_class(request.POST or None, request.FILES or None,
instance=directory,
user=request.user)
del form.fields['payment_method']
if not request.user.profile.is_superuser:
del form.fields['pricing']
del form.fields['list_type']
if request.method == "POST":
if form.is_valid():
directory = form.save(commit=False)
if directory.logo:
try:
directory.logo.file.seek(0)
except IOError:
directory.logo = None
# update all permissions and save the model
directory = update_perms_and_save(request, form, directory)
# resize the image that has been uploaded
if directory.logo:
if settings.USE_S3_STORAGE:
resize_s3_image(directory.logo.name)
else:
try:
logo = Image.open(directory.logo.path)
logo.thumbnail((200,200),Image.ANTIALIAS)
logo.save(directory.logo.path)
except:
pass
messages.add_message(request, messages.SUCCESS, 'Successfully updated %s' % directory)
return HttpResponseRedirect(reverse('directory', args=[directory.slug]))
else:
form = form_class(instance=directory, user=request.user)
return render_to_response(template_name, {'directory': directory, 'form':form},
context_instance=RequestContext(request))
return render_to_response(template_name, {'directory': directory, 'form':form},
context_instance=RequestContext(request))
示例4: photoset_details
def photoset_details(request, id, template_name="photos/photo-set/details.html"):
""" View photos in photo set """
photo_set = get_object_or_404(PhotoSet, id=id)
if not has_view_perm(request.user, 'photos.view_photoset', photo_set):
raise Http403
order = get_setting('module', 'photos', 'photoordering')
#if order == 'descending':
# photos = photo_set.get_images(user=request.user).order_by('-pk')
#else:
# photos = photo_set.get_images(user=request.user).order_by('pk')
photos = photo_set.get_images(user=request.user).order_by("position")
EventLog.objects.log(**{
'event_id': 991500,
'event_data': '%s (%d) viewed by %s' % (photo_set._meta.object_name, photo_set.pk, request.user),
'description': '%s viewed' % photo_set._meta.object_name,
'user': request.user,
'request': request,
'instance': photo_set,
})
return render_to_response(template_name, {
"photos": photos,
"photo_set": photo_set,
}, context_instance=RequestContext(request))
示例5: photoset_add
def photoset_add(request, form_class=PhotoSetAddForm, template_name="photos/photo-set/add.html"):
""" Add a photo set """
# if no permission; permission exception
if not has_perm(request.user,'photos.add_photoset'):
raise Http403
if request.method == "POST":
if request.POST["action"] == "add":
form = form_class(request.POST, user=request.user)
if form.is_valid():
photo_set = form.save(commit=False)
photo_set.author = request.user
# update all permissions and save the model
photo_set = update_perms_and_save(request, form, photo_set)
messages.add_message(request, messages.SUCCESS, 'Successfully added photo set!')
return HttpResponseRedirect(reverse('photos_batch_add', kwargs={'photoset_id':photo_set.id}))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {
"photoset_form": form,
}, context_instance=RequestContext(request))
示例6: edit
def edit(request, id=None, form_class=HelpFileForm, template_name="help_files/edit.html"):
help_file = get_object_or_404(HelpFile, pk=id)
if has_perm(request.user,'help_files.change_helpfile', help_file):
if request.method == "POST":
form = form_class(request.POST, instance=help_file, user=request.user)
if form.is_valid():
help_file = form.save(commit=False)
# add all permissions and save the model
help_file = update_perms_and_save(request, form, help_file)
form.save_m2m()
messages.add_message(request, messages.SUCCESS, 'Successfully edited %s' % help_file)
# send notification to administrator(s) and module recipient(s)
recipients = get_notice_recipients('module', 'help_files', 'helpfilerecipients')
# if recipients and notification:
# notification.send_emails(recipients,'help_file_added', {
# 'object': help_file,
# 'request': request,
# })
return HttpResponseRedirect(reverse('help_file.details', args=[help_file.slug]))
else:
form = form_class(instance=help_file, user=request.user)
return render_to_response(template_name, {'help_file': help_file, 'form':form},
context_instance=RequestContext(request))
else:
raise Http403
示例7: delete
def delete(request, id, template_name="articles/delete.html"):
article = get_object_or_404(Article, pk=id)
if has_perm(request.user, 'articles.delete_article'):
if request.method == "POST":
messages.add_message(request, messages.SUCCESS, 'Successfully deleted %s' % article)
# send notification to administrators
recipients = get_notice_recipients('module', 'articles', 'articlerecipients')
if recipients:
if notification:
extra_context = {
'object': article,
'request': request,
}
notification.send_emails(recipients, 'article_deleted', extra_context)
article.delete()
return HttpResponseRedirect(reverse('article.search'))
return render_to_response(template_name, {'article': article},
context_instance=RequestContext(request))
else:
raise Http403
示例8: export
def export(request, template_name="help_files/export.html"):
"""Export Help Files"""
if not request.user.is_superuser:
raise Http403
if request.method == 'POST':
# initilize initial values
file_name = "help_files.csv"
fields = [
'slug',
'topics',
'question',
'answer',
'level',
'is_faq',
'is_featured',
'is_video',
'syndicate',
'view_totals',
]
export_id = run_export_task('help_files', 'helpfile', fields)
EventLog.objects.log()
return redirect('export.status', export_id)
return render_to_response(template_name, {
}, context_instance=RequestContext(request))
示例9: locations_import_upload
def locations_import_upload(request, template_name='locations/import-upload-file.html'):
"""
This is the upload view for the location imports.
This will upload the location import file and then redirect the user
to the import mapping/preview page of the import file
"""
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
cleaned_data = form.cleaned_data
locport = LocationImport.objects.create(creator=request.user)
csv = File.objects.save_files_for_instance(request, locport)[0]
#file_path = os.path.join(settings.MEDIA_ROOT, csv.file.name)
file_path = str(csv.file.name)
import_valid, import_errs = is_import_valid(file_path)
if not import_valid:
for err in import_errs:
messages.add_message(request, messages.ERROR, err)
locport.delete()
return redirect('locations_import_upload_file')
EventLog.objects.log()
# reset the password_promt session
request.session['password_promt'] = False
return redirect('locations_import_preview', locport.id)
else:
form = UploadForm()
return render_to_response(template_name, {
'form': form,
'now': datetime.now(),
}, context_instance=RequestContext(request))
示例10: export
def export(request, template_name="locations/export.html"):
"""Export Locations"""
if not request.user.is_superuser:
raise Http403
if request.method == 'POST':
# initilize initial values
fields = [
'guid',
'location_name',
'description',
'contact',
'address',
'address2',
'city',
'state',
'zipcode',
'country',
'phone',
'fax',
'email',
'website',
'latitude',
'longitude',
'hq',
'entity',
]
export_id = run_export_task('locations', 'location', fields)
EventLog.objects.log()
return redirect('export.status', export_id)
return render_to_response(template_name, {
}, context_instance=RequestContext(request))
示例11: approve
def approve(request, id, template_name="resumes/approve.html"):
if not request.user.profile.is_superuser:
raise Http403
resume = get_object_or_404(Resume, pk=id)
if request.method == "POST":
resume.activation_dt = datetime.now()
resume.allow_anonymous_view = True
resume.status = True
resume.status_detail = 'active'
if not resume.creator:
resume.creator = request.user
resume.creator_username = request.user.username
if not resume.owner:
resume.owner = request.user
resume.owner_username = request.user.username
resume.save()
messages.add_message(request, messages.SUCCESS, 'Successfully approved %s' % resume)
return HttpResponseRedirect(reverse('resume', args=[resume.slug]))
return render_to_response(template_name, {'resume': resume},
context_instance=RequestContext(request))
示例12: search
def search(request, template_name="resumes/search.html"):
"""
This page lists out all resumes from newest to oldest.
If a search index is available, this page will also
have the option to search through resumes.
"""
has_index = get_setting('site', 'global', 'searchindex')
query = request.GET.get('q', None)
if has_index and query:
resumes = Resume.objects.search(query, user=request.user)
else:
filters = get_query_filters(request.user, 'resumes.view_resume')
resumes = Resume.objects.filter(filters).distinct()
if request.user.is_authenticated():
resumes = resumes.select_related()
resumes = resumes.order_by('-create_dt')
EventLog.objects.log(**{
'event_id' : 354000,
'event_data': '%s searched by %s' % ('Resume', request.user),
'description': '%s searched' % 'Resume',
'user': request.user,
'request': request,
'source': 'resumes'
})
return render_to_response(template_name, {'resumes':resumes},
context_instance=RequestContext(request))
示例13: export
def export(request, template_name="pages/export.html"):
"""Export Pages"""
if not request.user.is_superuser:
raise Http403
if request.method == 'POST':
fields = [
'guid',
'title',
'slug',
'header_image',
'content',
'view_contact_form',
'design_notes',
'syndicate',
'template',
'tags',
'entity',
'meta',
'categories',
]
export_id = run_export_task('pages', 'page', fields)
return redirect('export.status', export_id)
return render_to_response(template_name, {
}, context_instance=RequestContext(request))
示例14: delete
def delete(request, id, template_name="pages/delete.html"):
page = get_object_or_404(Page, pk=id)
if not has_perm(request.user, 'pages.delete_page'):
raise Http403
if request.method == "POST":
EventLog.objects.log(instance=page)
messages.add_message(request, messages.SUCCESS,
_('Successfully deleted %(p)s' % { 'p': unicode(page)}))
# send notification to administrators
recipients = get_notice_recipients('module', 'pages', 'pagerecipients')
if recipients:
if notification:
extra_context = {
'object': page,
'request': request,
}
notification.send_emails(recipients, 'page_deleted', extra_context)
# Soft delete
page.status = False
page.status_detail = 'inactive'
page.save()
return HttpResponseRedirect(reverse('page.search'))
return render_to_response(template_name, {'page': page},
context_instance=RequestContext(request))
示例15: edit_meta
def edit_meta(request, id, form_class=MetaForm, template_name="pages/edit-meta.html"):
"""
Return page that allows you to edit meta-html information.
"""
# check permission
page = get_object_or_404(Page, pk=id)
if not has_perm(request.user, 'pages.change_page', page):
raise Http403
defaults = {
'title': page.get_title(),
'description': page.get_description(),
'keywords': page.get_keywords(),
'canonical_url': page.get_canonical_url(),
}
page.meta = MetaTags(**defaults)
if request.method == "POST":
form = form_class(request.POST, instance=page.meta)
if form.is_valid():
page.meta = form.save() # save meta
page.save() # save relationship
messages.add_message(request, messages.SUCCESS,
_('Successfully updated meta for %(p)s' % {'p': unicode(page)}))
return HttpResponseRedirect(reverse('page', args=[page.slug]))
else:
form = form_class(instance=page.meta)
return render_to_response(template_name, {'page': page, 'form': form},
context_instance=RequestContext(request))