本文整理汇总了Python中models.Record.get_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python Record.get_or_404方法的具体用法?Python Record.get_or_404怎么用?Python Record.get_or_404使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Record
的用法示例。
在下文中一共展示了Record.get_or_404方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: record_preview
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import get_or_404 [as 别名]
def record_preview(request, id):
record = Record.get_or_404(id, request.user)
return render_to_response(
'data_previewrecord.html',
{
'record': record,
'none': None,
},
context_instance=RequestContext(request)
)
示例2: record_delete
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import get_or_404 [as 别名]
def record_delete(request, id, name):
if request.method == 'POST':
record = Record.get_or_404(id, request.user)
if record.editable_by(request.user):
record.delete()
messages.add_message(
request,
messages.INFO,
message="Record deleted successfully."
)
from rooibos.middleware import HistoryMiddleware
return HttpResponseRedirect(HistoryMiddleware.go_back(
request,
to_before=reverse(
'data-record', kwargs=dict(id=id, name=name)),
default=reverse('solr-search')
))
return HttpResponseRedirect(
reverse('data-record', kwargs=dict(id=id, name=name)))
示例3: record
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import get_or_404 [as 别名]
def record(request, id, name, contexttype=None, contextid=None,
contextname=None, edit=False, customize=False, personal=False,
copy=False, copyid=None, copyname=None):
collections = apply_collection_visibility_preferences(
request.user, Collection.objects.all())
writable_collections = list(
filter_by_access(request.user, collections, write=True)
.values_list('id', flat=True)
)
readable_collections = list(
filter_by_access(request.user, collections)
.values_list('id', flat=True)
)
personal_collections = None
can_edit = request.user.is_authenticated()
can_manage = False
if id and name:
record = Record.get_or_404(id, request.user)
can_edit = can_edit and record.editable_by(request.user)
can_manage = record.manageable_by(request.user)
else:
if request.user.is_authenticated():
if personal:
personal_collections = \
get_allowed_collections_for_personal_records(
request.user, readable_collections)
if writable_collections or (personal and personal_collections):
record = Record()
if personal:
record.owner = request.user
else:
raise Http404()
else:
raise Http404()
if record.owner:
if personal_collections is None:
personal_collections = \
get_allowed_collections_for_personal_records(
request.user, readable_collections)
valid_collections = (
set(personal_collections) | set(writable_collections))
else:
valid_collections = writable_collections
context = None
if contexttype and contextid:
app_label, model = contexttype.split('.')
model_class = get_object_or_404(
ContentType, app_label=app_label, model=model).model_class()
context = get_object_or_404(
filter_by_access(request.user, model_class), id=contextid)
media = Media.objects.select_related().filter(
record=record,
storage__in=filter_by_access(request.user, Storage)
)
# Can any media be downloaded?
download_image = False
# Only list media that is downloadable or editable
for m in media:
# Calculate permissions and store with object for later use in template
m.downloadable_in_template = m.is_downloadable_by(request.user)
m.editable_in_template = m.editable_by(request.user)
download_image = download_image or \
m.is_downloadable_by(request.user, original=False)
media = filter(
lambda m: m.downloadable_in_template or m.editable_in_template, media)
edit = edit and request.user.is_authenticated()
copyrecord = Record.get_or_404(copyid, request.user) if copyid else None
class FieldSetForm(forms.Form):
fieldset = FieldSetChoiceField(
user=request.user, default_label='Default' if not edit else None)
fieldsetform = FieldSetForm(request.GET)
if fieldsetform.is_valid():
if fieldsetform.cleaned_data['fieldset']:
fieldset = FieldSet.for_user(request.user).get(
id=fieldsetform.cleaned_data['fieldset'])
else:
fieldset = None
elif edit:
default_fieldset_name = getattr(
settings, 'RECORD_DEFAULT_FIELDSET', 'dc')
# Creating new record, use DC fieldset by default
fieldset = FieldSet.objects.get(name=default_fieldset_name)
else:
fieldset = None
collection_items = collectionformset = None
if edit:
#.........这里部分代码省略.........