当前位置: 首页>>代码示例>>Python>>正文


Python Record.owner方法代码示例

本文整理汇总了Python中models.Record.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Record.owner方法的具体用法?Python Record.owner怎么用?Python Record.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Record的用法示例。


在下文中一共展示了Record.owner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: record

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import owner [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:
#.........这里部分代码省略.........
开发者ID:hanleybrand,项目名称:rooibos,代码行数:103,代码来源:views.py


注:本文中的models.Record.owner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。