コード例 #1
0
def shared_image_nodes(home_project_id, api):
    """Returns a list of pillarsdk.Node objects."""

    parent_group = Node.find_first({
        'where': {'project': home_project_id,
                  'node_type': 'group',
                  'parent': None,
                  'name': IMAGE_SHARING_GROUP_NODE_NAME},
        'projection': {'_id': 1}},
        api=api)

    if not parent_group:
        log.debug('No image sharing parent node found.')
        return []

    nodes = Node.all({
        'where': {'project': home_project_id,
                  'node_type': 'asset',
                  'properties.content_type': 'image',
                  'parent': parent_group['_id']},
        'sort': '-_created',
        'projection': {
            '_created': 1,
            'name': 1,
            'picture': 1,
            'short_code': 1,
        }},
        api=api)

    nodes = nodes._items or []
    for node in nodes:
        node.picture = utils.get_file(node.picture)

    return nodes
コード例 #2
0
def synced_blender_versions(home_project_id, api):
    """Returns a list of Blender versions with synced settings.

    Returns a list of {'version': '2.77', 'date': datetime.datetime()} dicts.
    Returns an empty list if no Blender versions were synced.
    """

    sync_group = Node.find_first({
        'where': {'project': home_project_id,
                  'node_type': 'group',
                  'parent': None,
                  'name': SYNC_GROUP_NODE_NAME},
        'projection': {'_id': 1}},
        api=api)

    if not sync_group:
        return []

    sync_nodes = Node.all({
        'where': {'project': home_project_id,
                  'node_type': 'group',
                  'parent': sync_group['_id']},
        'projection': {
            'name': 1,
            '_updated': 1,
        }},
        api=api)

    sync_nodes = sync_nodes._items
    if not sync_nodes:
        return []

    return [{'version': node.name, 'date': node._updated}
            for node in sync_nodes]
コード例 #3
0
ファイル: posts.py プロジェクト: BibleUs/pillar-web
def posts_create(project_id):
    api = SystemUtility.attract_api()
    node_type = NodeType.find_first(
        {
            'where': '{"name" : "blog"}',
            'projection': '{"name": 1}'
        }, api=api)
    blog = Node.find_first(
        {
            'where':
            '{"node_type" : "%s", \
            "parent": "%s"}' % (node_type._id, project_id),
        },
        api=api)
    node_type = NodeType.find_first({
        'where': '{"name" : "post"}',
    }, api=api)
    form = get_node_form(node_type)
    if form.validate_on_submit():
        user_id = current_user.objectid
        if process_node_form(form, node_type=node_type, user=user_id):
            return redirect(url_for('main_blog'))
    form.parent.data = blog._id
    return render_template('nodes/custom/post/create.html',
                           node_type=node_type,
                           form=form,
                           project_id=project_id)
コード例 #4
0
ファイル: model.py プロジェクト: aditiapratama/pillar-web
    def project(self, project_name):
        """Get single project for one user. The project is searched by looking
        up project directly associated with that user or organization."""
        # Find node_type project id (this could become static)
        node_type = NodeType.find_first({
            'where': '{"name" : "project"}',
            }, api=self.api)
        if not node_type: return abort(404)


        # Define key for querying for the project
        if self.is_organization:
            user_path = 'properties.organization'
        else:
            user_path = 'user'

        project_node = Node.find_first({
        'where': '{"node_type" : "%s", "properties.url" : "%s", "%s": "%s"}'\
            % (node_type._id, project_name, user_path, self._id),
        }, api=self.api)
        if not project_node: return abort(404)
        return project_node
コード例 #5
0
ファイル: posts.py プロジェクト: mcgrathd/pillar-web
def posts_create(project_id):
    api = SystemUtility.attract_api()
    node_type = NodeType.find_first({
        'where': '{"name" : "blog"}',
        'projection': '{"name": 1}'
        }, api=api)
    blog = Node.find_first({
        'where': '{"node_type" : "%s", \
            "parent": "%s"}' % (node_type._id, project_id),
        }, api=api)
    node_type = NodeType.find_first({'where': '{"name" : "post"}',}, api=api)
    form = get_node_form(node_type)
    if form.validate_on_submit():
        user_id = current_user.objectid
        if process_node_form(
                form, node_type=node_type, user=user_id):
            return redirect(url_for('main_blog'))
    form.parent.data = blog._id
    return render_template('nodes/custom/post/create.html',
        node_type=node_type,
        form=form,
        project_id=project_id)
コード例 #6
0
ファイル: model.py プロジェクト: BibleUs/pillar-web
    def project(self, project_name):
        """Get single project for one user. The project is searched by looking
        up project directly associated with that user or organization."""
        # Find node_type project id (this could become static)
        node_type = NodeType.find_first({
            'where': '{"name" : "project"}',
        },
                                        api=self.api)
        if not node_type: return abort(404)

        # Define key for querying for the project
        if self.is_organization:
            user_path = 'properties.organization'
        else:
            user_path = 'user'

        project_node = Node.find_first({
        'where': '{"node_type" : "%s", "properties.url" : "%s", "%s": "%s"}'\
            % (node_type._id, project_name, user_path, self._id),
        }, api=self.api)
        if not project_node: return abort(404)
        return project_node
コード例 #7
0
def project_navigation_links(project: typing.Type[Project], api) -> list:
    """Returns a list of nodes for the project, for top navigation display.

    Args:
        project: A Project object.
        api: the api client credential.

    Returns:
        A list of links for the Project.
        For example we display a link to the project blog if present, as well
        as pages. The list is structured as follows:

        [{'url': '/p/spring/about', 'label': 'About'},
        {'url': '/p/spring/blog', 'label': 'Blog'}]
    """

    links = []

    # Fetch the blog
    blog = Node.find_first(
        {
            'where': {
                'project': project._id,
                'node_type': 'blog',
                '_deleted': {
                    '$ne': True
                }
            },
            'projection': {
                'name': 1,
            }
        },
        api=api)

    if blog:
        links.append({
            'url': finders.find_url_for_node(blog),
            'label': blog.name,
            'slug': 'blog'
        })

    # Fetch pages
    pages = Node.all(
        {
            'where': {
                'project': project._id,
                'node_type': 'page',
                '_deleted': {
                    '$ne': True
                }
            },
            'projection': {
                'name': 1,
                'properties.url': 1
            }
        },
        api=api)

    # Process the results and append the links to the list
    for p in pages._items:
        links.append({
            'url': finders.find_url_for_node(p),
            'label': p.name,
            'slug': p.properties.url
        })

    return links