示例#1
0
def execute(ctx, source_party, target_party, snippet_name):
    snippet_version = snippet_service \
        .find_current_version_of_snippet_with_name(
            source_party.id, snippet_name)

    if snippet_version is None:
        raise click.BadParameter('Unknown snippet name "{}" for party "{}".'
            .format(snippet_name, source_party.id))

    snippet = snippet_version.snippet

    if snippet.type_ == SnippetType.document:
        snippet_service.create_document(
            target_party.id,
            snippet.name,
            snippet_version.creator_id,
            snippet_version.title,
            snippet_version.body,
            head=snippet_version.head,
            image_url_path=snippet_version.image_url_path
        )
    elif snippet.type_ == SnippetType.fragment:
        snippet_service.create_fragment(
            target_party.id,
            snippet.name,
            snippet_version.creator_id,
            snippet_version.body
        )
    else:
        ctx.fail("Unknown snippet type '{}'.".format(snippet.type_))

    click.secho('Done.', fg='green')
示例#2
0
文件: base.py 项目: leathe/byceps
    def create_shop_fragment(self, shop_id, name, body):
        scope = Scope('shop', shop_id)

        try:
            self.admin
        except AttributeError:
            self.admin = create_user('Admin')

        snippet_service.create_fragment(scope, name, self.admin.id, body)
示例#3
0
    def setup_terms(self):
        scope = Scope.for_brand(self.brand_id)

        snippet, _ = snippet_service.create_fragment(
            scope,
            'terms_of_service',
            self.admin.id,
            'Don\'t do anything stupid!',
        )

        consent_subject = consent_subject_service.create_subject(
            f'{self.brand_id}_terms-of-service_v1',
            f'Terms of service for {self.brand.title} / v1',
            'terms_of_service',
        )

        terms_document_id = self.brand_id
        terms_document = terms_document_service.create_document(
            terms_document_id, terms_document_id)

        terms_version = terms_version_service.create_version(
            terms_document.id, '01-Jan-2016', snippet.id, consent_subject.id)

        terms_document_service.set_current_version(terms_document_id,
                                                   terms_version.id)

        brand_settings_service.create_setting(self.brand.id,
                                              'terms_document_id',
                                              str(terms_document.id))

        self.terms_version_id = terms_version.id
        self.terms_consent_subject_id = terms_version.consent_subject_id
示例#4
0
def execute(ctx, source_site, target_site, snippet_name):
    source_scope = Scope.for_site(source_site.id)
    target_scope = Scope.for_site(target_site.id)

    snippet_version = snippet_service.find_current_version_of_snippet_with_name(
        source_scope, snippet_name
    )

    if snippet_version is None:
        raise click.BadParameter(
            f'Unknown snippet name "{snippet_name}" '
            f'for site "{source_site.id}".'
        )

    snippet = snippet_version.snippet

    if snippet.type_ == SnippetType.document:
        snippet_service.create_document(
            target_scope,
            snippet.name,
            snippet_version.creator_id,
            snippet_version.title,
            snippet_version.body,
            head=snippet_version.head,
            image_url_path=snippet_version.image_url_path,
        )
    elif snippet.type_ == SnippetType.fragment:
        snippet_service.create_fragment(
            target_scope,
            snippet.name,
            snippet_version.creator_id,
            snippet_version.body,
        )
    else:
        ctx.fail(f"Unknown snippet type '{snippet.type_}'.")

    click.secho('Done.', fg='green')