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


Python LICENSES.keys方法代码示例

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


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

示例1: create_snapshot

# 需要导入模块: from corehq.apps.domain.models import LICENSES [as 别名]
# 或者: from corehq.apps.domain.models.LICENSES import keys [as 别名]
def create_snapshot(request, domain):
    domain = Domain.get_by_name(domain)
    #latest_applications = [app.get_latest_saved() or app for app in domain.applications()]
    if request.method == 'GET':
        form = SnapshotSettingsForm(initial={
                'default_timezone': domain.default_timezone,
                'case_sharing': json.dumps(domain.case_sharing),
                'city': domain.city,
                'country': domain.country,
                'region': domain.region,
                'project_type': domain.project_type,
                'share_multimedia': True,
                'license': domain.license
            })
        published_snapshot = domain.published_snapshot() or domain
        published_apps = {}
        if published_snapshot is not None:
            form = SnapshotSettingsForm(initial={
                'default_timezone': published_snapshot.default_timezone,
                'case_sharing': json.dumps(published_snapshot.case_sharing),
                'city': published_snapshot.city,
                'country': published_snapshot.country,
                'region': published_snapshot.region,
                'project_type': published_snapshot.project_type,
                'license': published_snapshot.license,
                'title': published_snapshot.title,
                'author': published_snapshot.author,
                'share_multimedia': True,
                'description': published_snapshot.description
            })
            for app in published_snapshot.full_applications():
                if domain == published_snapshot:
                    published_apps[app._id] = app
                else:
                    published_apps[app.original_doc] = app
        app_forms = []
        for app in domain.applications():
            app = app.get_latest_saved() or app
            if published_snapshot and app._id in published_apps:
                original = published_apps[app._id]
                app_forms.append((app, SnapshotApplicationForm(initial={
                    'publish': True,
                    'name': original.name,
                    'description': original.description,
                    'deployment_date': original.deployment_date,
                    'user_type': original.user_type,
                    'attribution_notes': original.attribution_notes,
                    'phone_model': original.phone_model,

                }, prefix=app.id)))
            else:
                app_forms.append((app, SnapshotApplicationForm(initial={'publish': (published_snapshot is None or published_snapshot == domain)}, prefix=app.id)))
        return render_to_response(request, 'domain/create_snapshot.html',
            {'domain': domain.name,
             'form': form,
             #'latest_applications': latest_applications,
             'app_forms': app_forms,
             'autocomplete_fields': ('project_type', 'phone_model', 'user_type', 'city', 'country', 'region')})
    elif request.method == 'POST':
        form = SnapshotSettingsForm(request.POST, request.FILES)
        app_forms = []
        publishing_apps = False
        for app in domain.applications():
            app = app.get_latest_saved() or app
            app_forms.append((app, SnapshotApplicationForm(request.POST, prefix=app.id)))
            publishing_apps = publishing_apps or request.POST.get("%s-publish" % app.id, False)
        if not publishing_apps:
            messages.error(request, "Cannot publish a project without applications to CommCare Exchange")
            return render_to_response(request, 'domain/create_snapshot.html',
                {'domain': domain.name,
                 'form': form,
                 'app_forms': app_forms,
                 'autocomplete_fields': ('project_type', 'phone_model', 'user_type', 'city', 'country', 'region')})
        
        if not form.is_valid():
            return render_to_response(request, 'domain/create_snapshot.html',
                    {'domain': domain.name,
                     'form': form,
                     #'latest_applications': latest_applications,
                     'app_forms': app_forms,
                     'autocomplete_fields': ('project_type', 'phone_model', 'user_type', 'city', 'country', 'region')})

        if request.POST.get('share_multimedia', False):
            media = domain.all_media()
            for m_file in media:
                if domain.name not in m_file.shared_by:
                    m_file.shared_by.append(domain.name)
                    m_file.licenses[domain.name] = domain.license
                    m_file.save()
        old = domain.published_snapshot()
        new_domain = domain.save_snapshot()
        if request.POST['license'] in LICENSES.keys():
            new_domain.license = request.POST['license']
        new_domain.description = request.POST['description']
        new_domain.project_type = request.POST['project_type']
        new_domain.region = request.POST['region']
        new_domain.city = request.POST['city']
        new_domain.country = request.POST['country']
        new_domain.title = request.POST['title']
        new_domain.author = request.POST['author']
#.........这里部分代码省略.........
开发者ID:mchampanis,项目名称:core-hq,代码行数:103,代码来源:views.py


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