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


Python models.Post类代码示例

本文整理汇总了Python中redwind.models.Post的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: share_on_facebook

def share_on_facebook():
    from .twitter import collect_images

    if request.method == "GET":
        post = Post.load_by_id(request.args.get("id"))

        message, link, name, picture = guess_content(post)
        imgs = [urljoin(get_settings().site_url, img) for img in collect_images(post)]

        albums = []
        if imgs:
            current_app.logger.debug("fetching user albums")
            resp = requests.get(
                "https://graph.facebook.com/v2.2/me/albums",
                params={"access_token": get_settings().facebook_access_token},
            )
            resp.raise_for_status()
            current_app.logger.debug("user albums response %s: %s", resp, resp.text)
            albums = resp.json().get("data", [])

        return render_template(
            "admin/share_on_facebook.jinja2",
            post=post,
            preview=message,
            link=link,
            name=name,
            picture=picture,
            imgs=imgs,
            albums=albums,
        )

    try:
        post_id = request.form.get("post_id")
        preview = request.form.get("preview")
        img_url = request.form.get("img")
        is_photo = request.form.get("post_type") == "photo"
        album_id = request.form.get("album")
        link = request.form.get("link")

        if album_id == "new":
            album_id = create_album(request.form.get("new_album_name"), request.form.get("new_album_message"))

        post = Post.load_by_id(post_id)
        facebook_url = handle_new_or_edit(
            post, message=preview, link=link, name=None, picture=img_url, is_photo=is_photo, album_id=album_id
        )

        db.session.commit()
        if has_request_context():
            flash(
                'Shared on Facebook: <a href="{}">Original</a>, '
                '<a href="{}">On Facebook</a><br/>'.format(post.permalink, facebook_url)
            )
            return redirect(post.permalink)

    except Exception as e:
        if has_request_context():
            current_app.logger.exception("posting to facebook")
            flash("Share on Facebook Failed! Exception: {}".format(e))
        return redirect(url_for("views.index"))
开发者ID:kylewm,项目名称:redwind,代码行数:60,代码来源:facebook.py

示例2: test_send_wms

def test_send_wms(client, mocker):
    getter = mocker.patch('requests.get')
    poster = mocker.patch('requests.post')
    urlopen = mocker.patch('urllib.request.urlopen')

    post = Post('note')
    post.content = 'This note links to [wikipedia](https://en.wikipedia.org/wiki/Webmention)'
    post.content_html = 'This note links to <a href="https://en.wikipedia.org/wiki/Webmention">wikipedia</a>'
    post.path = '2014/11/wm-sender-test'
    db.session.add(post)
    db.session.commit()

    urlopen.return_value = FakeUrlOpen(
        info=FakeUrlMetadata(content_type='text/html', content_length=256))

    getter.return_value = FakeResponse(text="""<!DOCTYPE html>
    <html>
      <link rel="webmention" href="https://en.wikipedia.org/endpoint">
    </html>""")

    wm_sender.do_send_webmentions(post.id)

    getter.assert_called_with('https://en.wikipedia.org/wiki/Webmention')
    poster.assert_called_with('https://en.wikipedia.org/endpoint', data={
        'source': post.permalink,
        'target': 'https://en.wikipedia.org/wiki/Webmention',
    }, headers={
        'content-type': 'application/x-www-form-urlencoded',
        'accept': 'application/json',
    })
开发者ID:thedod,项目名称:redwind,代码行数:30,代码来源:wm_sender_test.py

示例3: source_post

def source_post(app, db):
    post = Post('note')
    post.content = 'This note links to [wikipedia](https://en.wikipedia.org/wiki/Webmention)'
    post.content_html = 'This note links to <a href="https://en.wikipedia.org/wiki/Webmention">wikipedia</a>'
    post.path = '2014/11/wm-sender-test'
    db.session.add(post)
    db.session.commit()
    return post
开发者ID:Lancey6,项目名称:redwind,代码行数:8,代码来源:wm_sender_test.py

示例4: share_on_facebook

def share_on_facebook():
    from .twitter import collect_images

    if request.method == 'GET':
        post = Post.load_by_id(request.args.get('id'))

        message, link, name, picture = guess_content(post)
        imgs = [urllib.parse.urljoin(get_settings().site_url, img)
                for img in collect_images(post)]

        albums = []
        if imgs:
            current_app.logger.debug('fetching user albums')
            resp = requests.get(
                'https://graph.facebook.com/v2.2/me/albums',
                params={'access_token': get_settings().facebook_access_token})
            resp.raise_for_status()
            current_app.logger.debug(
                'user albums response %s: %s', resp, resp.text)
            albums = resp.json().get('data', [])

        return render_template('admin/share_on_facebook.jinja2', post=post,
                               preview=message, link=link, name=name,
                               picture=picture, imgs=imgs, albums=albums)

    try:
        post_id = request.form.get('post_id')
        preview = request.form.get('preview')
        img_url = request.form.get('img')
        is_photo = request.form.get('post_type') == 'photo'
        album_id = request.form.get('album')
        link = request.form.get('link')

        if album_id == 'new':
            album_id = create_album(
                request.form.get('new_album_name'),
                request.form.get('new_album_message'))

        post = Post.load_by_id(post_id)
        facebook_url = handle_new_or_edit(
            post, message=preview, link=link, name=None, picture=img_url,
            is_photo=is_photo, album_id=album_id)

        db.session.commit()
        if has_request_context():
            flash('Shared on Facebook: <a href="{}">Original</a>, '
                  '<a href="{}">On Facebook</a><br/>'
                  .format(post.permalink, facebook_url))
            return redirect(post.permalink)

    except Exception as e:
        if has_request_context():
            current_app.logger.exception('posting to facebook')
            flash('Share on Facebook Failed! Exception: {}'.format(e))
        return redirect(url_for('views.index'))
开发者ID:mongolsamurai,项目名称:redwind,代码行数:55,代码来源:facebook.py

示例5: edit_by_id

def edit_by_id():
    id = request.args.get('id')
    if not id:
        abort(404)
    post = Post.load_by_id(id)
    if not post:
        abort(404)
    type = 'post'
    if not request.args.get('advanced') and post.post_type:
        type = post.post_type

    if post.draft:
        button_text = {
            'publish': 'Publish Draft',
            'publish_quietly': 'Publish Draft Quietly',
            'publish+tweet': 'Publish Draft & Tweet',
            'save_draft': 'Resave Draft',
        }
    else:
        button_text = {
            'publish': 'Republish',
            'publish_quietly': 'Republish Quietly',
            'publish+tweet': 'Republish & Tweet',
            'save_draft': 'Unpublish, Save as Draft',
        }

    template = 'admin/edit_' + type + '.jinja2'
    if request.args.get('full'):
        template = 'admin/edit_post_all.jinja2'

    venues = Venue.query.order_by(Venue.name).all()
    return render_template(template, edit_type='edit', post=post,
                           tags=get_tags(), top_tags=get_top_tags(20),
                           people=get_contact_nicks(),
                           button_text=button_text, venues=venues)
开发者ID:kylewm,项目名称:redwind,代码行数:35,代码来源:admin.py

示例6: do_send_to_twitter

def do_send_to_twitter(post_id, app_config):
    with async_app_context(app_config):
        current_app.logger.debug('auto-posting to twitter for %s', post_id)
        post = Post.load_by_id(post_id)

        in_reply_to, repost_of, like_of = util.posse_post_discovery(
            post, PERMALINK_RE)

        # cowardly refuse to auto-POSSE a reply/repost/like when the
        # target tweet is not found.
        if post.in_reply_to and not in_reply_to:
            current_app.logger.warn(
                'could not find tweet to reply to for %s', post.in_reply_to)
            return None
        elif post.repost_of and not repost_of:
            current_app.logger.warn(
                'could not find tweet to repost for %s', post.repost_of)
            preview, img_url = guess_raw_share_tweet_content(post)
        elif post.like_of and not like_of:
            current_app.logger.warn(
                'could not find tweet to like for %s', post.like_of)
            return None
        else:
            preview, img_url = guess_tweet_content(post, in_reply_to)

        response = do_tweet(post_id, preview, img_url, in_reply_to, repost_of,
                            like_of)
        return str(response)
开发者ID:kylewm,项目名称:redwind,代码行数:28,代码来源:twitter.py

示例7: post_associated_file_by_historic_path

def post_associated_file_by_historic_path(post_type, year, month, day,
                                          index, filename):
    post = Post.load_by_historic_path('{}/{}/{:02d}/{:02d}/{}'.format(
        post_type, year, month, day, index))
    if not post:
        abort(404)
    return redirect('/{}/files/{}'.format(post.path, filename))
开发者ID:mongolsamurai,项目名称:redwind,代码行数:7,代码来源:views.py

示例8: do_send_to_wordpress

def do_send_to_wordpress(post_id, app_config):
    with async_app_context(app_config):
        post = Post.load_by_id(post_id)

        if post.like_of:
            for url in post.like_of:
                try_post_like(url, post)

        elif post.in_reply_to:
            for url in post.in_reply_to:
                try_post_reply(url, post)
开发者ID:kylewm,项目名称:redwind,代码行数:11,代码来源:wordpress.py

示例9: do_reverse_geocode_post

def do_reverse_geocode_post(postid, app_config):
    with async_app_context(app_config):
        post = Post.load_by_id(postid)
        if post.location and 'latitude' in post.location \
           and 'longitude' in post.location:
            adr = do_reverse_geocode(post.location['latitude'],
                                     post.location['longitude'])
            # copy the dict so that the ORM recognizes
            # that it changed
            post.location = dict(post.location)
            post.location.update(adr)
            db.session.commit()
开发者ID:Lancey6,项目名称:redwind,代码行数:12,代码来源:locations.py

示例10: delete_by_id

def delete_by_id():
    id = request.args.get('id')
    post = Post.load_by_id(id)
    if not post:
        abort(404)
    post.deleted = True
    db.session.commit()

    hooks.fire('post-deleted', post, request.args)
    redirect_url = request.args.get('redirect') or url_for('views.index')
    current_app.logger.debug('redirecting to {}'.format(redirect_url))
    return redirect(redirect_url)
开发者ID:Lancey6,项目名称:redwind,代码行数:12,代码来源:admin.py

示例11: do_send_to_facebook

def do_send_to_facebook(post_id, app_config):
    with async_app_context(app_config):
        current_app.logger.debug("auto-posting to facebook for %s", post_id)
        post = Post.load_by_id(post_id)

        message, link, name, picture = guess_content(post)
        facebook_url = handle_new_or_edit(post, message, link, name, picture, post.post_type == "photo", album_id=None)
        db.session.commit()
        if has_request_context():
            flash(
                'Shared on Facebook: <a href="{}">Original</a>, '
                '<a href="{}">On Facebook</a><br/>'.format(post.permalink, facebook_url)
            )
            return redirect(post.permalink)
开发者ID:kylewm,项目名称:redwind,代码行数:14,代码来源:facebook.py

示例12: new_post

def new_post(type):
    post = Post(type)
    post.published = post.updated = datetime.datetime.utcnow()
    post.content = ''

    if type == 'reply':
        in_reply_to = request.args.get('url')
        if in_reply_to:
            post.in_reply_to = [in_reply_to]
            # post.reply_contexts = [contexts.create_context(in_reply_to)]

    elif type == 'share':
        repost_of = request.args.get('url')
        if repost_of:
            post.repost_of = [repost_of]
            # post.repost_contexts = [contexts.create_context(repost_of)]

    elif type == 'like':
        like_of = request.args.get('url')
        if like_of:
            post.like_of = [like_of]
            # post.like_contexts = [contexts.create_context(like_of)]

    elif type == 'bookmark':
        bookmark_of = request.args.get('url')
        if bookmark_of:
            post.bookmark_of = [bookmark_of]
            # post.bookmark_contexts = [contexts.create_context(bookmark_of)]

    post.content = request.args.get('content')
    button_text = {
        'publish': 'Publish',
        'publish_quietly': 'Publish Quietly',
        'publish+tweet': 'Publish & Tweet',
        'save_draft': 'Save as Draft',
    }

    if type == 'event':
        venues = Venue.query.order_by(Venue.name).all()
    else:
        venues = []

    return render_template('admin/edit_' + type + '.jinja2',
                           edit_type='new', post=post,
                           tags=get_tags(), top_tags=get_top_tags(20),
                           button_text=button_text, venues=venues)
开发者ID:Lancey6,项目名称:redwind,代码行数:46,代码来源:admin.py

示例13: do_tweet

def do_tweet(post_id, preview, img_url, in_reply_to,
             repost_of, like_of):
    try:
        post = Post.load_by_id(post_id)
        twitter_url = handle_new_or_edit(
            post, preview, img_url, in_reply_to, repost_of, like_of)
        db.session.commit()

        if has_request_context():
            flash('Shared on Twitter: <a href="{}">Original</a>, '
                  '<a href="{}">On Twitter</a>'
                  .format(post.permalink, twitter_url))
            return redirect(post.permalink)

    except Exception as e:
        current_app.logger.exception('posting to twitter')
        if has_request_context():
            flash('Share on Twitter Failed!. Exception: {}'.format(e))
            return redirect(url_for('views.index'))
开发者ID:kylewm,项目名称:redwind,代码行数:19,代码来源:twitter.py

示例14: share_on_twitter

def share_on_twitter():
    if request.method == 'GET':
        id = request.args.get('id')
        if not id:
            abort(404)

        post = Post.load_by_id(id)
        if not post:
            abort(404)

        current_app.logger.debug('sharing on twitter. post: %s', post)

        in_reply_to, repost_of, like_of \
            = util.posse_post_discovery(post, PERMALINK_RE)

        current_app.logger.debug(
            'discovered in-reply-to: %s, repost-of: %s, like-of: %s',
            in_reply_to, repost_of, like_of)

        if post.repost_of and not repost_of:
            preview, _ = guess_raw_share_tweet_content(post)
            imgs = list(collect_images(post.repost_contexts[0]))
        else:
            preview, _ = guess_tweet_content(post, in_reply_to)
            imgs = list(collect_images(post))

        current_app.logger.debug('twitter post has images: %s', imgs)

        return render_template('admin/share_on_twitter.jinja2',
                               preview=preview,
                               post=post, in_reply_to=in_reply_to,
                               repost_of=repost_of, like_of=like_of, imgs=imgs)

    post_id = request.form.get('post_id')
    preview = request.form.get('preview')
    img_url = request.form.get('img')
    in_reply_to = request.form.get('in_reply_to')
    repost_of = request.form.get('repost_of')
    like_of = request.form.get('like_of')

    return do_tweet(post_id, preview, img_url, in_reply_to, repost_of,
                    like_of)
开发者ID:kylewm,项目名称:redwind,代码行数:42,代码来源:twitter.py

示例15: new_post

def new_post(type):
    if type not in util.POST_TYPES:
        abort(404)

    post = Post(type)
    post.published = post.updated = datetime.datetime.utcnow()
    post.content = ''

    if type == 'reply':
        in_reply_to = request.args.get('url')
        if in_reply_to:
            post.in_reply_to = [in_reply_to]

    elif type == 'share':
        repost_of = request.args.get('url')
        if repost_of:
            post.repost_of = [repost_of]

    elif type == 'like':
        like_of = request.args.get('url')
        if like_of:
            post.like_of = [like_of]

    elif type == 'bookmark':
        bookmark_of = request.args.get('url')
        if bookmark_of:
            post.bookmark_of = [bookmark_of]

    post.content = request.args.get('content')
    button_text = {
        'publish': 'Publish',
        'publish_quietly': 'Publish Quietly',
        'publish+tweet': 'Publish & Tweet',
        'save_draft': 'Save as Draft',
    }

    venues = Venue.query.order_by(Venue.name).all()
    return render_template('admin/edit_' + type + '.jinja2',
                           edit_type='new', post=post,
                           tags=get_tags(), top_tags=get_top_tags(20),
                           people=get_contact_nicks(),
                           button_text=button_text, venues=venues)
开发者ID:kylewm,项目名称:redwind,代码行数:42,代码来源:admin.py


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