def index(): api = system_util.pillar_api() # Get all projects, except the home project. projects_user = Project.all({ 'where': {'user': current_user.objectid, 'category': {'$ne': 'home'}}, 'sort': '-_created' }, api=api) projects_shared = Project.all({ 'where': {'user': {'$ne': current_user.objectid}, 'permissions.groups.group': {'$in': current_user.groups}, 'is_private': True}, 'sort': '-_created', 'embedded': {'user': 1}, }, api=api) # Attach project images for project in projects_user['_items']: utils.attach_project_pictures(project, api) for project in projects_shared['_items']: utils.attach_project_pictures(project, api) return render_template( 'projects/index_dashboard.html', gravatar=utils.gravatar(current_user.email, size=128), projects_user=projects_user['_items'], projects_shared=projects_shared['_items'], api=api)
def index(): api = system_util.pillar_api() projects_user = Project.all({ 'where': {'user': current_user.objectid}, 'sort': '-_created' }, api=api) projects_shared = Project.all({ 'where': {'user': {'$ne': current_user.objectid}, 'permissions.groups.group': {'$in': current_user.groups}, 'is_private': True}, 'sort': '-_created', 'embedded': {'user': 1}, }, api=api) # Attach project images for project in projects_user['_items']: attach_project_pictures(project, api) for project in projects_shared['_items']: attach_project_pictures(project, api) return render_template( 'projects/index_dashboard.html', gravatar=gravatar(current_user.email, size=128), title='dashboard', projects_user=projects_user['_items'], projects_shared=projects_shared['_items'], api=system_util.pillar_api())
def linked_projects(self, *, page=1, max_results=250, api) -> Resource: """Returns the projects linked to this Manager.""" if not self.projects: return Resource({ '_items': [], '_meta': { 'total': 0, 'page': 1, 'max_results': 250, } }) fetched = Project.all( { 'where': { '_id': { '$in': self.projects } }, 'projection': { '_id': 1, 'name': 1, 'url': 1, }, 'page': page, 'max_results': max_results, }, api=api) return fetched
def linked_projects(self, *, page=1, max_results=250, api) -> Resource: """Returns the projects linked to this Manager.""" if not self.projects: return Resource({ '_items': [], '_meta': { 'total': 0, 'page': 1, 'max_results': 250, } }) fetched = Project.all( { 'where': { '_id': {'$in': self.projects} }, 'projection': { '_id': 1, 'name': 1, 'url': 1, }, 'page': page, 'max_results': max_results, }, api=api) return fetched
def render_page(): api = system_util.pillar_api() projects = Project.all( { 'where': { 'category': 'film', 'is_private': False }, 'sort': '-_created', }, api=api) for project in projects._items: # Attach poster file (ensure the extension_props.cloud.poster # attributes exists) try: # If the attribute exists, but is None, continue if not project['extension_props'][EXTENSION_NAME]['poster']: continue # Fetch the file and embed it in the document project.extension_props.cloud.poster = get_file( project.extension_props.cloud.poster, api=api) # Add convenience attribute that specifies the presence of the # poster file project.has_poster = True # If there was a key error because one of the nested attributes is # missing, except KeyError: continue return render_template('films.html', title='films', projects=projects._items, api=system_util.pillar_api())
def index(): api = system_util.pillar_api() # Get all projects, except the home project. projects_user = Project.all({ 'where': {'user': current_user.objectid, 'category': {'$ne': 'home'}}, 'sort': '-_created' }, api=api) show_deleted_projects = request.args.get('deleted') is not None if show_deleted_projects: timeframe = utcnow() - datetime.timedelta(days=31) projects_deleted = Project.all({ 'where': {'user': current_user.objectid, 'category': {'$ne': 'home'}, '_deleted': True, '_updated': {'$gt': timeframe}}, 'sort': '-_created' }, api=api) else: projects_deleted = {'_items': []} projects_shared = Project.all({ 'where': {'user': {'$ne': current_user.objectid}, 'permissions.groups.group': {'$in': current_user.groups}, 'is_private': True}, 'sort': '-_created', 'embedded': {'user': 1}, }, api=api) # Attach project images for project_list in (projects_user, projects_deleted, projects_shared): utils.mass_attach_project_pictures(project_list['_items'], api=api, header=False) return render_template( 'projects/index_dashboard.html', gravatar=utils.gravatar(current_user.email, size=128), projects_user=projects_user['_items'], projects_deleted=projects_deleted['_items'], projects_shared=projects_shared['_items'], show_deleted_projects=show_deleted_projects, api=api)
def get_projects(category): """Utility to get projects based on category. Should be moved on the API and improved with more extensive filtering capabilities. """ api = system_util.pillar_api() projects = Project.all({ 'where': { 'category': category, 'is_private': False}, 'sort': '-_created', }, api=api) for project in projects._items: attach_project_pictures(project, api) return projects
def get_projects(category): """Utility to get projects based on category. Should be moved on the API and improved with more extensive filtering capabilities. """ api = system_util.pillar_api() projects = Project.all( { 'where': { 'category': category, 'is_private': False }, 'sort': '-_created', }, api=api) for project in projects._items: attach_project_pictures(project, api) return projects