Пример #1
0
def create(community_url: str, post_type: str):
    api = system_util.pillar_api()

    project = Project.find_first({'where': {'url': community_url}}, api=api)
    if project is None:
        return abort(404)

    log.info('Creating post for user {}'.format(current_user.objectid))

    dillo_post_node_type = project.get_node_type('dillo_post')
    dillo_post_tags_default = dillo_post_node_type['dyn_schema']['tags']['schema']['default']

    post_props = dict(
        project=project['_id'],
        name='Awesome Post Title',
        user=current_user.objectid,
        node_type='dillo_post',
        properties=dict(
            tags=[dillo_post_tags_default, ],
            post_type=post_type)
    )

    post = Node(post_props)
    post.create(api=api)
    embed = request.args.get('embed')
    return redirect(url_for(
        'nodes.edit', node_id=post._id, embed=embed, _external=True,
        _scheme=current_app.config['SCHEME']))
Пример #2
0
def index(community_url):
    api = system_util.pillar_api()

    project = Project.find_first({'where': {'url': community_url}}, api=api)

    if project is None:
        return abort(404)

    attach_project_pictures(project, api)

    # Fetch all activities for the main project
    activities = Activity.all({
        'where': {
            'project': project['_id'],
        },
        'sort': [('_created', -1)],
        'max_results': 15,
    }, api=api)

    # Fetch more info for each activity.
    for act in activities['_items']:
        act.actor_user = subquery.get_user_info(act.actor_user)
        try:
            act.link = url_for_node(node_id=act.object)
        except ValueError:
            # If the node was delete, we get ValueError exception.
            # By setting act.link to '', it does not get displayed in the list.
            act.link = ''

    return render_template(
        'dillo/index.html',
        col_right={'activities': activities},
        project=project,
        submit_menu=project_submit_menu(project))
Пример #3
0
    def render_page():
        # Get latest posts
        api = system_util.pillar_api()
        project = Project.find_first({'where': {'url': community_url}}, api=api)
        if not project:
            abort(404)

        feed = AtomFeed(project.name + ' - ' + _('Latest updates'),
                        feed_url=request.url,
                        url=request.url_root)

        latest_posts = Node.all({
            'where': {'node_type': 'dillo_post', 'properties.status': 'published',
                      'project': project['_id']},
            'embedded': {'user': 1},
            'sort': '-_created',
            'max_results': '15'
            }, api=api)

        populate_feed(feed, latest_posts)
        return feed.get_response()