예제 #1
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
예제 #2
0
def execute(ctx, search_term, site, verbose):
    scope = None
    if site is not None:
        scope = Scope.for_site(site.id)

    scope_label = get_scope_label(verbose, scope)

    matches = snippet_service.search_snippets(search_term, scope=scope)

    if not matches:
        if verbose:
            click.secho(
                f'No matching snippets for {scope_label} '
                f'and search term "{search_term}".',
                fg='yellow',
            )
        return

    for version in matches:
        snippet = version.snippet
        click.secho(f'{format_scope(snippet.scope)}\t{snippet.name}')

    if verbose:
        click.secho(
            f'\n{len(matches):d} matching snippet(s) '
            f'for {scope_label} and search term "{search_term}".',
            fg='green',
        )
예제 #3
0
def execute(ctx, search_term, site, verbose):
    scope = None
    if site is not None:
        scope = Scope.for_site(site.id)

    if verbose:
        if scope is not None:
            scope_label = 'scope "{}"'.format(format_scope(scope))
        else:
            scope_label = 'any scope'

    matches = snippet_service.search_snippets(search_term, scope=scope)

    if not matches:
        if verbose:
            click.secho(
                f'No matching snippets for {scope_label} '
                f'and search term "{search_term}".',
                fg='yellow')
        return

    for version in matches:
        snippet = version.snippet
        click.secho('{}\t{}'.format(format_scope(snippet.scope), snippet.name))

    if verbose:
        click.secho(
            '\n{:d} matching snippet(s) for {} and search term "{}".'
                .format(len(matches), scope_label, search_term),
            fg='green')
예제 #4
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)
예제 #5
0
def test_unknown_name(admin_app_with_db):
    brand = create_brand('lafiesta', 'La Fiesta')

    party = create_party(brand.id, 'lafiesta-2014', 'La Fiesta 2014')

    scope = Scope.for_site(party.id)

    actual = snippet_service.find_current_version_of_snippet_with_name(
        scope, 'totally-unknown-snippet-name')

    assert actual is None
예제 #6
0
def test_current_party_is_considered(admin_app_with_db, admin_user):
    brand = create_brand('lafiesta', 'La Fiesta')

    party2014 = create_party(brand.id, 'lafiesta-2014', 'La Fiesta 2014')
    party2015 = create_party(brand.id, 'lafiesta-2015', 'La Fiesta 2015')

    scope_site2014 = Scope.for_site(party2014.id)
    scope_site2015 = Scope.for_site(party2015.id)

    creator = admin_user

    fragment_info2014_version = create_fragment_with_version(
            scope_site2014, 'info', creator.id, '2014-10-23 14:55:00')
    fragment_info2015_version = create_fragment_with_version(
            scope_site2015, 'info', creator.id, '2014-10-23 18:21:00')

    actual = snippet_service.find_current_version_of_snippet_with_name(
        scope_site2014, 'info')

    assert actual == fragment_info2014_version
예제 #7
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')