本文整理汇总了Python中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)
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: delete
def delete(request, id, template_name="news/delete.html"):
news = get_object_or_404(News, pk=id)
# check permission
if not has_perm(request.user, "news.delete_news"):
raise Http403
if request.method == "POST":
log_defaults = {
"event_id": 305300,
"event_data": "%s (%d) deleted by %s" % (news._meta.object_name, news.pk, request.user),
"description": "%s deleted" % news._meta.object_name,
"user": request.user,
"request": request,
"instance": news,
}
EventLog.objects.log(**log_defaults)
messages.add_message(request, messages.SUCCESS, "Successfully deleted %s" % news)
# send notification to administrators
recipients = get_notice_recipients("module", "news", "newsrecipients")
if recipients:
if notification:
extra_context = {"object": news, "request": request}
notification.send_emails(recipients, "news_deleted", extra_context)
news.delete()
return HttpResponseRedirect(reverse("news.search"))
return render_to_response(template_name, {"news": news}, context_instance=RequestContext(request))
示例3: approve
def approve(request, id, template_name="resumes/approve.html"):
if not is_admin(request.user):
raise Http403
resume = get_object_or_404(Resume, pk=id)
if request.method == "POST":
resume.activation_dt = now_localized()
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))
示例4: edit_meta
def edit_meta(request, id, form_class=MetaForm, template_name="resumes/edit-meta.html"):
# check permission
resume = get_object_or_404(Resume, pk=id)
if not has_perm(request.user,'resumes.change_resume',resume):
raise Http403
defaults = {
'title': resume.get_title(),
'description': resume.get_description(),
'keywords': resume.get_keywords(),
'canonical_url': resume.get_canonical_url(),
}
resume.meta = MetaTags(**defaults)
if request.method == "POST":
form = form_class(request.POST, instance=resume.meta)
if form.is_valid():
resume.meta = form.save() # save meta
resume.save() # save relationship
messages.add_message(request, messages.SUCCESS, 'Successfully updated meta for %s' % resume)
return HttpResponseRedirect(reverse('resume', args=[resume.slug]))
else:
form = form_class(instance=resume.meta)
return render_to_response(template_name, {'resume': resume, 'form':form},
context_instance=RequestContext(request))
示例5: search
def search(request, template_name="jobs/search.html"):
query = request.GET.get('q', None)
if get_setting('site', 'global', 'searchindex') and query:
jobs = Job.objects.search(query, user=request.user)
else:
filters = get_query_filters(request.user, 'jobs.view_job')
jobs = Job.objects.filter(filters).distinct()
if not request.user.is_anonymous():
jobs = jobs.select_related()
jobs = jobs.order_by('status_detail','list_type','-post_dt')
log_defaults = {
'event_id': 254000,
'event_data': '%s searched by %s' % ('Job', request.user),
'description': '%s searched' % 'Job',
'user': request.user,
'request': request,
'source': 'jobs'
}
EventLog.objects.log(**log_defaults)
return render_to_response(template_name, {'jobs': jobs},
context_instance=RequestContext(request))
示例6: pricing_delete
def pricing_delete(request, id, template_name="jobs/pricing-delete.html"):
job_pricing = get_object_or_404(JobPricing, pk=id)
if not has_perm(request.user, 'jobs.delete_jobpricing'):
raise Http403
if request.method == "POST":
log_defaults = {
'event_id': 265120,
'event_data': '%s (%d) deleted by %s' % (
job_pricing._meta.object_name,
job_pricing.pk,
request.user
),
'description': '%s deleted' % job_pricing._meta.object_name,
'user': request.user,
'request': request,
'instance': job_pricing,
}
EventLog.objects.log(**log_defaults)
messages.add_message(request, messages.SUCCESS, 'Successfully deleted %s' % job_pricing)
job_pricing.delete()
return HttpResponseRedirect(reverse('job_pricing.search'))
return render_to_response(template_name, {'job_pricing': job_pricing},
context_instance=RequestContext(request))
示例7: pricing_add
def pricing_add(request, form_class=JobPricingForm, template_name="jobs/pricing-add.html"):
if has_perm(request.user, 'jobs.add_jobpricing'):
if request.method == "POST":
form = form_class(request.POST)
if form.is_valid():
job_pricing = form.save(commit=False)
job_pricing.status = 1
job_pricing.save(request.user)
log_defaults = {
'event_id': 265100,
'event_data': '%s (%d) added by %s' % (
job_pricing._meta.object_name,
job_pricing.pk,
request.user
),
'description': '%s added' % job_pricing._meta.object_name,
'user': request.user,
'request': request,
'instance': job_pricing,
}
EventLog.objects.log(**log_defaults)
return HttpResponseRedirect(reverse('job_pricing.view', args=[job_pricing.id]))
else:
form = form_class()
return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))
else:
raise Http403
示例8: edit
def edit(request, id, form_class=FileForm, template_name="files/edit.html"):
file = get_object_or_404(File, pk=id)
# check permission
if not has_perm(request.user,'files.change_file',file):
raise Http403
if request.method == "POST":
form = form_class(request.POST, request.FILES, instance=file, user=request.user)
if form.is_valid():
file = form.save(commit=False)
file.name = file.file.path.split('/')[-1]
# update all permissions and save the model
file = update_perms_and_save(request, form, file)
log_defaults = {
'event_id' : 182000,
'event_data': '%s (%d) edited by %s' % (file._meta.object_name, file.pk, request.user),
'description': '%s edited' % file._meta.object_name,
'user': request.user,
'request': request,
'instance': file,
}
EventLog.objects.log(**log_defaults)
return HttpResponseRedirect(reverse('file.search'))
else:
form = form_class(instance=file, user=request.user)
return render_to_response(template_name, {'file': file, 'form':form},
context_instance=RequestContext(request))
示例9: photoset_view_latest
def photoset_view_latest(request, template_name="photos/photo-set/latest.html"):
""" View latest photo set """
query = request.GET.get('q', None)
if get_setting('site', 'global', 'searchindex') and query:
photo_sets = PhotoSet.objects.search(query, user=request.user)
else:
filters = get_query_filters(request.user, 'photos.view_photoset')
photo_sets = PhotoSet.objects.filter(filters).distinct()
if not request.user.is_anonymous():
photo_sets = photo_sets.select_related()
photo_sets = photo_sets.order_by('-create_dt')
log_defaults = {
'event_id' : 991400,
'event_data': '%s searched by %s' % ('PhotoSet', request.user),
'description': '%s searched' % 'PhotoSet',
'user': request.user,
'request': request,
'source': 'photos'
}
EventLog.objects.log(**log_defaults)
return render_to_response(template_name, {"photo_sets": photo_sets},
context_instance=RequestContext(request))
示例10: photoset_delete
def photoset_delete(request, id, template_name="photos/photo-set/delete.html"):
photo_set = get_object_or_404(PhotoSet, id=id)
# if no permission; permission exception
if not has_perm(request.user,'photos.delete_photoset',photo_set):
raise Http403
if request.method == "POST":
EventLog.objects.log(**{
'event_id' : 991300,
'event_data': '%s (%d) deleted by %s' % (photo_set._meta.object_name, photo_set.pk, request.user),
'description': '%s deleted' % photo_set._meta.object_name,
'user': request.user,
'request': request,
'instance': photo_set,
})
photo_set.delete()
# soft delete all images in photo set
Image.objects.filter(photoset=photo_set).delete()
messages.add_message(request, messages.INFO, 'Photo Set %s deleted' % photo_set)
if "delete" in request.META.get('HTTP_REFERER', None):
#if the referer is the get page redirect to the photo set search
return redirect('photoset_latest')
return HttpResponseRedirect(request.META.get('HTTP_REFERER', None))
return render_to_response(template_name, {
'photo_set': photo_set,
}, context_instance=RequestContext(request))
示例11: delete
def delete(request, id, set_id=0):
""" delete photo """
photo = get_object_or_404(Image, id=id)
# permissions
if not has_perm(request.user,'photologue.delete_photo',photo):
raise Http403
if request.method == "POST":
request.user.message_set.create(message=_("Successfully deleted photo '%s'") % photo.title)
log_defaults = {
'event_id' : 990300,
'event_data': '%s (%d) deleted by %s' % (photo._meta.object_name, photo.pk, request.user),
'description': '%s deleted' % photo._meta.object_name,
'user': request.user,
'request': request,
'instance': photo,
}
EventLog.objects.log(**log_defaults)
photo.delete()
messages.add_message(request, messages.INFO, 'Photo %s deleted' % id)
try:
photo_set = PhotoSet.objects.get(id=set_id)
return HttpResponseRedirect(reverse("photoset_details", args=[set_id]))
except PhotoSet.DoesNotExist:
return HttpResponseRedirect(reverse("photos_search"))
return render_to_response("photos/delete.html", {
"photo": photo,
}, context_instance=RequestContext(request))
示例12: memberphotos
def memberphotos(request, username, template_name="photos/memberphotos.html", group_slug=None, bridge=None):
""" Get the members photos and display them """
if bridge:
try:
group = bridge.get_group(group_slug)
except ObjectDoesNotExist:
raise Http404
else:
group = None
user = get_object_or_404(User, username=username)
photos = Image.objects.filter(
member__username = username,
is_public = True
)
if group:
photos = group.content_objects(photos, join="pool")
else:
photos = photos.filter(pool__object_id=None)
photos = photos.order_by("-date_added")
return render_to_response(template_name, {
"group": group,
"photos": photos,
}, context_instance=RequestContext(request))
示例13: photo
def photo(request, id, set_id=0, partial=False, template_name="photos/details.html"):
""" photo details """
photo = get_object_or_404(Image, id=id)
if not has_perm(request.user, 'photologue.view_photo', photo):
raise Http403
EventLog.objects.log(**{
'event_id' : 990500,
'event_data': '%s (%d) viewed by %s' % (photo._meta.object_name, photo.pk, request.user),
'description': '%s viewed' % photo._meta.object_name,
'user': request.user,
'request': request,
'instance': photo,
})
# default prev/next URL
photo_prev_url, photo_next_url = '', ''
if set_id:
photo_set = get_object_or_404(PhotoSet, id=set_id)
photo_prev = photo.get_prev(set=set_id)
photo_next = photo.get_next(set=set_id)
if photo_prev: photo_prev_url = reverse("photo", args= [photo_prev.id, set_id])
if photo_next: photo_next_url = reverse("photo", args= [photo_next.id, set_id])
photo_sets = list(photo.photoset.all())
if photo_set in photo_sets:
photo_sets.remove(photo_set)
photo_sets.insert(0, photo_set)
else:
set_id = 0
else:
photo_prev = photo.get_prev()
photo_next = photo.get_next()
if photo_prev: photo_prev_url = reverse("photo", args= [photo_prev.id])
if photo_next: photo_next_url = reverse("photo", args= [photo_next.id])
photo_sets = photo.photoset.all()
if photo_sets:
set_id = photo_sets[0].id
# "is me" variable
is_me = photo.member == request.user
if partial: # return partial html; for ajax end-user
template_name = "photos/partial-details.html"
return render_to_response(template_name, {
"photo_prev_url": photo_prev_url,
"photo_next_url": photo_next_url,
"photo": photo,
"photo_sets": photo_sets,
"photo_set_id": set_id,
"id": id,
"set_id": set_id,
"is_me": is_me,
}, context_instance=RequestContext(request))
示例14: edit
def edit(request, id, form_class=NewsForm, template_name="news/edit.html"):
news = get_object_or_404(News, pk=id)
# check permission
if not has_perm(request.user, "news.change_news", news):
raise Http403
form = form_class(instance=news, user=request.user)
if request.method == "POST":
form = form_class(request.POST, instance=news, user=request.user)
if form.is_valid():
news = form.save(commit=False)
# update all permissions and save the model
news = update_perms_and_save(request, form, news)
log_defaults = {
"event_id": 305200,
"event_data": "%s (%d) edited by %s" % (news._meta.object_name, news.pk, request.user),
"description": "%s edited" % news._meta.object_name,
"user": request.user,
"request": request,
"instance": news,
}
EventLog.objects.log(**log_defaults)
messages.add_message(request, messages.SUCCESS, "Successfully updated %s" % news)
return HttpResponseRedirect(reverse("news.view", args=[news.slug]))
return render_to_response(template_name, {"news": news, "form": form}, context_instance=RequestContext(request))
示例15: index
def index(request, slug=None, template_name="news/view.html"):
if not slug:
return HttpResponseRedirect(reverse("news.search"))
news = get_object_or_404(News, slug=slug)
# non-admin can not view the non-active content
# status=0 has been taken care of in the has_perm function
if (news.status_detail).lower() <> "active" and (not is_admin(request.user)):
raise Http403
# check permission
if not has_perm(request.user, "news.view_news", news):
raise Http403
log_defaults = {
"event_id": 305500,
"event_data": "%s (%d) viewed by %s" % (news._meta.object_name, news.pk, request.user),
"description": "%s viewed" % news._meta.object_name,
"user": request.user,
"request": request,
"instance": news,
}
EventLog.objects.log(**log_defaults)
return render_to_response(template_name, {"news": news}, context_instance=RequestContext(request))