コード例 #1
0
ファイル: __init__.py プロジェクト: secretisdead/persephone
def manage_media(medium_id=None, rss=False):
    if not rss and not terms_agreed():
        return terms(agreement_form=True, medium_id=medium_id)
    return search_media(
        management_mode=True,
        omit_future=False,
        medium_id=medium_id,
        rss=rss,
        rss_endpoint='persephone.manage_media_rss',
        rss_media_endpoint='persephone.manage_media',
    )
コード例 #2
0
ファイル: __init__.py プロジェクト: secretisdead/persephone
def user_sticker_placements(user_identifier, sticker_id, medium_id=None):
    user = require_profile_user(user_identifier)
    require_self_or_manager(user)
    if (user.id != g.accounts.current_user.id and
            not g.accounts.current_user.has_permission(group_names='manager')):
        abort(403)

    sticker = g.stickers.get_sticker(sticker_id)
    if not sticker:
        abort(404)

    # get media ids this sticker was placed on
    # this isn't going to be particularly efficient
    # for users that have placed a lot of stickers
    # since it's sending a large list of medium ids
    # to the search_media filter
    # maybe at least check to see if both media and stickers are
    # configured to use the same db, and then write some special
    # cross-db methods just for this?
    sticker_placements = g.stickers.search_sticker_placements(filter={
        'user_ids':
        user.id_bytes,
        'sticker_ids':
        sticker.id,
    }, )
    medium_ids = []
    for sticker_placement in sticker_placements.values():
        if sticker_placement.subject_id_bytes not in medium_ids:
            medium_ids.append(sticker_placement.subject_id_bytes)

    override_filters, management_mode, omit_future = build_search_override()
    override_filters['ids'] = medium_ids

    return search_media(
        override_filters=override_filters,
        management_mode=management_mode,
        omit_future=omit_future,
        medium_id=medium_id,
        header=render_template(
            'user_sticker_placements_header.html',
            sticker=sticker,
        ),
        user_identifier=user_identifier,
        sticker_id=sticker.id,
    )
コード例 #3
0
ファイル: __init__.py プロジェクト: secretisdead/persephone
def search_public_media(medium_id=None, rss=False):
    if not rss and not terms_agreed():
        return terms(agreement_form=True, medium_id=medium_id)
    override_filters, management_mode, omit_future = build_search_override()
    return search_media(
        # put overrides here to create a limited main search
        override_filters=override_filters,
        override_tags={
            #'add_tags': ['-some tag to never return],
            #'remove_tags': ['some tag to never return'],
        },
        management_mode=management_mode,
        omit_future=omit_future,
        medium_id=medium_id,
        rss=rss,
        rss_endpoint='persephone.search_public_media_rss',
        rss_media_endpoint='persephone.search_public_media',
    )
コード例 #4
0
ファイル: __init__.py プロジェクト: secretisdead/persephone
def user_liked_media(user_identifier, medium_id=None):
    user = require_profile_user(user_identifier)
    require_self_or_manager(user)

    override_filters, management_mode, omit_future = build_search_override()
    override_filters['liked_by_user'] = user.id_bytes
    override_filters['default_sort'] = 'likes'
    override_tags = {}

    return search_media(
        override_filters=override_filters,
        override_tags=override_tags,
        management_mode=management_mode,
        omit_future=omit_future,
        medium_id=medium_id,
        header=render_template(
            'user_liked_media_header.html',
            user_identifier=user_identifier,
        ),
        user_identifier=user_identifier,
    )
コード例 #5
0
ファイル: __init__.py プロジェクト: secretisdead/persephone
def search_user_media(user_identifier, medium_id=None, rss=False):
    if not rss and not terms_agreed():
        return terms(agreement_form=True,
                     user_identifier=user_identifier,
                     medium_id=medium_id)
    user = require_profile_user(user_identifier)
    override_filters, management_mode, omit_future = build_search_override(
        user)
    if (not g.persephone_config['public_contributors']
            or user.id in g.persephone_config['public_contributors']):
        override_filters['owner_ids'] = user.id_bytes
    else:
        # force no results
        override_filters['smaller_than'] = 0
    return search_media(
        override_filters=override_filters,
        management_mode=management_mode,
        omit_future=omit_future,
        medium_id=medium_id,
        rss=rss,
        rss_endpoint='persephone.search_user_media_rss',
        rss_media_endpoint='persephone.search_user_media',
        user_identifier=user_identifier,
    )