50 from pyams_skin.viewlet.menu import MenuItem |
50 from pyams_skin.viewlet.menu import MenuItem |
51 from pyams_template.template import template_config |
51 from pyams_template.template import template_config |
52 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
52 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
53 from pyams_utils.date import format_datetime, SH_DATETIME_FORMAT |
53 from pyams_utils.date import format_datetime, SH_DATETIME_FORMAT |
54 from pyams_utils.fanstatic import get_resource_path |
54 from pyams_utils.fanstatic import get_resource_path |
55 from pyams_utils.list import unique |
55 from pyams_utils.list import unique_iter |
56 from pyams_utils.property import cached_property |
56 from pyams_utils.property import cached_property |
57 from pyams_utils.registry import get_utility |
57 from pyams_utils.registry import get_utility |
58 from pyams_utils.timezone import tztime |
58 from pyams_utils.timezone import tztime |
59 from pyams_utils.traversing import get_parent |
59 from pyams_utils.traversing import get_parent |
60 from pyams_viewlet.manager import viewletmanager_config |
60 from pyams_viewlet.manager import viewletmanager_config |
340 catalog = get_utility(ICatalog) |
340 catalog = get_utility(ICatalog) |
341 workflow = get_utility(IWorkflow, name=self.context.shared_content_workflow) |
341 workflow = get_utility(IWorkflow, name=self.context.shared_content_workflow) |
342 params = Eq(catalog['parents'], intids.register(self.context)) & \ |
342 params = Eq(catalog['parents'], intids.register(self.context)) & \ |
343 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
343 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
344 Any(catalog['workflow_state'], workflow.waiting_states) |
344 Any(catalog['workflow_state'], workflow.waiting_states) |
345 return filter(self.check_access, |
345 yield from filter(self.check_access, |
346 unique(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), |
346 unique_iter(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), |
347 key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], |
347 key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], |
348 CatalogResultSet(CatalogQuery(catalog).query(params, |
348 CatalogResultSet(CatalogQuery(catalog).query(params, |
349 sort_index='modified_date'))))) |
349 sort_index='modified_date'))))) |
350 |
350 |
351 def check_access(self, content): |
351 def check_access(self, content): |
352 if self.request.has_permission(MANAGE_SITE_ROOT_PERMISSION, context=content): |
352 if self.request.has_permission(MANAGE_SITE_ROOT_PERMISSION, context=content): |
353 return True |
353 return True |
354 if self.request.principal.id in content.managers: |
354 if self.request.principal.id in content.managers: |
385 workflow = get_utility(IWorkflow, name=self.context.shared_content_workflow) |
385 workflow = get_utility(IWorkflow, name=self.context.shared_content_workflow) |
386 params = Eq(catalog['parents'], intids.register(self.context)) & \ |
386 params = Eq(catalog['parents'], intids.register(self.context)) & \ |
387 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
387 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
388 Any(catalog['workflow_state'], workflow.waiting_states) & \ |
388 Any(catalog['workflow_state'], workflow.waiting_states) & \ |
389 Eq(catalog['workflow_principal'], self.request.principal.id) |
389 Eq(catalog['workflow_principal'], self.request.principal.id) |
390 return unique(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), |
390 yield from unique_iter(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), |
391 key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], |
391 key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], |
392 CatalogResultSet(CatalogQuery(catalog).query(params, |
392 CatalogResultSet(CatalogQuery(catalog).query(params, |
393 sort_index='modified_date')))) |
393 sort_index='modified_date')))) |
394 |
394 |
395 |
395 |
396 # |
396 # |
397 # Last owned modified contents |
397 # Last owned modified contents |
398 # |
398 # |
421 catalog = get_utility(ICatalog) |
421 catalog = get_utility(ICatalog) |
422 params = And(Eq(catalog['parents'], intids.register(self.context)), |
422 params = And(Eq(catalog['parents'], intids.register(self.context)), |
423 Any(catalog['content_type'], CONTENT_TYPES.keys()), |
423 Any(catalog['content_type'], CONTENT_TYPES.keys()), |
424 Or(Eq(catalog['role:owner'], self.request.principal.id), |
424 Or(Eq(catalog['role:owner'], self.request.principal.id), |
425 Eq(catalog['role:contributor'], self.request.principal.id))) |
425 Eq(catalog['role:contributor'], self.request.principal.id))) |
426 return unique(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), |
426 yield from unique_iter(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), |
427 key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], |
427 key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], |
428 CatalogResultSet(CatalogQuery(catalog).query(params, |
428 CatalogResultSet(CatalogQuery(catalog).query(params, |
429 limit=50, |
429 limit=50, |
430 sort_index='modified_date', |
430 sort_index='modified_date', |
431 reverse=True)))) |
431 reverse=True)))) |
432 |
432 |
433 |
433 |
434 # |
434 # |
435 # All my contents menu |
435 # All my contents menu |
436 # |
436 # |
516 catalog = get_utility(ICatalog) |
516 catalog = get_utility(ICatalog) |
517 profile = IAdminProfile(self.request.principal) |
517 profile = IAdminProfile(self.request.principal) |
518 params = And(Eq(catalog['parents'], intids.register(self.context)), |
518 params = And(Eq(catalog['parents'], intids.register(self.context)), |
519 Any(catalog['content_type'], CONTENT_TYPES.keys()), |
519 Any(catalog['content_type'], CONTENT_TYPES.keys()), |
520 Any(catalog['oid'], profile.favorites or ())) |
520 Any(catalog['oid'], profile.favorites or ())) |
521 return unique(map(lambda x: IWorkflowVersions(x).get_last_versions()[0], |
521 yield from unique_iter(map(lambda x: IWorkflowVersions(x).get_last_versions()[0], |
522 CatalogResultSet(CatalogQuery(catalog).query(params, |
522 CatalogResultSet(CatalogQuery(catalog).query(params, |
523 sort_index='modified_date', |
523 sort_index='modified_date', |
524 reverse=True)))) |
524 reverse=True)))) |
525 |
525 |
526 |
526 |
527 @pagelet_config(name='my-favorites.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
527 @pagelet_config(name='my-favorites.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
528 class SharedToolFavoritesView(InnerAdminView, ContainerView): |
528 class SharedToolFavoritesView(InnerAdminView, ContainerView): |
529 """Shared tool favorites view""" |
529 """Shared tool favorites view""" |
580 params = And(Eq(catalog['parents'], intids.register(self.context)), |
580 params = And(Eq(catalog['parents'], intids.register(self.context)), |
581 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
581 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
582 Or(Eq(catalog['role:owner'], self.request.principal.id), |
582 Or(Eq(catalog['role:owner'], self.request.principal.id), |
583 Eq(catalog['role:contributor'], self.request.principal.id)), |
583 Eq(catalog['role:contributor'], self.request.principal.id)), |
584 Eq(catalog['workflow_state'], workflow.initial_state)) |
584 Eq(catalog['workflow_state'], workflow.initial_state)) |
585 return unique(CatalogResultSet(CatalogQuery(catalog).query(params, |
585 yield from unique_iter(CatalogResultSet(CatalogQuery(catalog).query(params, |
586 sort_index='modified_date', |
586 sort_index='modified_date', |
587 reverse=True))) |
587 reverse=True))) |
588 |
588 |
589 |
589 |
590 @pagelet_config(name='my-preparations.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
590 @pagelet_config(name='my-preparations.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
591 class SharedToolPreparationsView(InnerAdminView, ContainerView): |
591 class SharedToolPreparationsView(InnerAdminView, ContainerView): |
592 """Shared tool preparations view""" |
592 """Shared tool preparations view""" |
643 params = And(Eq(catalog['parents'], intids.register(self.context)), |
643 params = And(Eq(catalog['parents'], intids.register(self.context)), |
644 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
644 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
645 Or(Eq(catalog['role:owner'], self.request.principal.id), |
645 Or(Eq(catalog['role:owner'], self.request.principal.id), |
646 Eq(catalog['role:contributor'], self.request.principal.id)), |
646 Eq(catalog['role:contributor'], self.request.principal.id)), |
647 Any(catalog['workflow_state'], workflow.waiting_states)) |
647 Any(catalog['workflow_state'], workflow.waiting_states)) |
648 return unique(CatalogResultSet(CatalogQuery(catalog).query(params, |
648 yield from unique_iter(CatalogResultSet(CatalogQuery(catalog).query(params, |
649 sort_index='modified_date', |
649 sort_index='modified_date', |
650 reverse=True))) |
650 reverse=True))) |
651 |
651 |
652 |
652 |
653 @pagelet_config(name='my-submissions.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
653 @pagelet_config(name='my-submissions.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
654 class SharedToolSubmissionsView(InnerAdminView, ContainerView): |
654 class SharedToolSubmissionsView(InnerAdminView, ContainerView): |
655 """Shared tool submissions view""" |
655 """Shared tool submissions view""" |
706 params = And(Eq(catalog['parents'], intids.register(self.context)), |
706 params = And(Eq(catalog['parents'], intids.register(self.context)), |
707 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
707 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
708 Or(Eq(catalog['role:owner'], self.request.principal.id), |
708 Or(Eq(catalog['role:owner'], self.request.principal.id), |
709 Eq(catalog['role:contributor'], self.request.principal.id)), |
709 Eq(catalog['role:contributor'], self.request.principal.id)), |
710 Any(catalog['workflow_state'], workflow.published_states)) |
710 Any(catalog['workflow_state'], workflow.published_states)) |
711 return unique(CatalogResultSet(CatalogQuery(catalog).query(params, |
711 yield from unique_iter(CatalogResultSet(CatalogQuery(catalog).query(params, |
712 sort_index='modified_date', |
712 sort_index='modified_date', |
713 reverse=True))) |
713 reverse=True))) |
714 |
714 |
715 |
715 |
716 @pagelet_config(name='my-publications.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
716 @pagelet_config(name='my-publications.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
717 class SharedToolPublicationsView(InnerAdminView, ContainerView): |
717 class SharedToolPublicationsView(InnerAdminView, ContainerView): |
718 """Shared tool publications view""" |
718 """Shared tool publications view""" |
769 params = And(Eq(catalog['parents'], intids.register(self.context)), |
769 params = And(Eq(catalog['parents'], intids.register(self.context)), |
770 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
770 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
771 Or(Eq(catalog['role:owner'], self.request.principal.id), |
771 Or(Eq(catalog['role:owner'], self.request.principal.id), |
772 Eq(catalog['role:contributor'], self.request.principal.id)), |
772 Eq(catalog['role:contributor'], self.request.principal.id)), |
773 Any(catalog['workflow_state'], workflow.retired_states)) |
773 Any(catalog['workflow_state'], workflow.retired_states)) |
774 return unique(CatalogResultSet(CatalogQuery(catalog).query(params, |
774 yield from unique_iter(CatalogResultSet(CatalogQuery(catalog).query(params, |
775 sort_index='modified_date', |
775 sort_index='modified_date', |
776 reverse=True))) |
776 reverse=True))) |
777 |
777 |
778 |
778 |
779 @pagelet_config(name='my-retired-contents.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
779 @pagelet_config(name='my-retired-contents.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
780 permission=VIEW_SYSTEM_PERMISSION) |
780 permission=VIEW_SYSTEM_PERMISSION) |
781 class SharedToolRetiredContentsView(InnerAdminView, ContainerView): |
781 class SharedToolRetiredContentsView(InnerAdminView, ContainerView): |
834 params = And(Eq(catalog['parents'], intids.register(self.context)), |
834 params = And(Eq(catalog['parents'], intids.register(self.context)), |
835 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
835 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
836 Or(Eq(catalog['role:owner'], principal_id), |
836 Or(Eq(catalog['role:owner'], principal_id), |
837 Eq(catalog['role:contributor'], principal_id)), |
837 Eq(catalog['role:contributor'], principal_id)), |
838 Any(catalog['workflow_state'], workflow.archived_states)) |
838 Any(catalog['workflow_state'], workflow.archived_states)) |
839 return unique(map(lambda x: sorted((version for version in |
839 yield from unique_iter(map(lambda x: sorted((version for version in |
840 IWorkflowVersions(x).get_versions(workflow.archived_states) |
840 IWorkflowVersions(x).get_versions(workflow.archived_states) |
841 if principal_id in (version.owner | version.contributors)), |
841 if principal_id in (version.owner | version.contributors)), |
842 key=lambda x: IWorkflowState(x).version_id, |
842 key=lambda x: IWorkflowState(x).version_id, |
843 reverse=True)[0], |
843 reverse=True)[0], |
844 CatalogResultSet(CatalogQuery(catalog).query(params, |
844 CatalogResultSet(CatalogQuery(catalog).query(params, |
845 sort_index='modified_date', |
845 sort_index='modified_date', |
846 reverse=True)))) |
846 reverse=True)))) |
847 |
847 |
848 |
848 |
849 @pagelet_config(name='my-archived-contents.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
849 @pagelet_config(name='my-archived-contents.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
850 permission=VIEW_SYSTEM_PERMISSION) |
850 permission=VIEW_SYSTEM_PERMISSION) |
851 class SharedToolArchivedContentsView(InnerAdminView, ContainerView): |
851 class SharedToolArchivedContentsView(InnerAdminView, ContainerView): |
923 catalog = get_utility(ICatalog) |
923 catalog = get_utility(ICatalog) |
924 workflow = get_utility(IWorkflow, name=self.context.shared_content_workflow) |
924 workflow = get_utility(IWorkflow, name=self.context.shared_content_workflow) |
925 params = And(Eq(catalog['parents'], intids.register(self.context)), |
925 params = And(Eq(catalog['parents'], intids.register(self.context)), |
926 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
926 Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ |
927 Any(catalog['workflow_state'], workflow.published_states)) |
927 Any(catalog['workflow_state'], workflow.published_states)) |
928 return unique(CatalogResultSet(CatalogQuery(catalog).query(params, |
928 yield from unique_iter(CatalogResultSet(CatalogQuery(catalog).query(params, |
929 limit=50, |
929 limit=50, |
930 sort_index='modified_date', |
930 sort_index='modified_date', |
931 reverse=True))) |
931 reverse=True))) |
932 |
932 |
933 |
933 |
934 @pagelet_config(name='all-publications.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
934 @pagelet_config(name='all-publications.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
935 permission=VIEW_SYSTEM_PERMISSION) |
935 permission=VIEW_SYSTEM_PERMISSION) |
936 class SharedToolAllPublicationsView(InnerAdminView, ContainerView): |
936 class SharedToolAllPublicationsView(InnerAdminView, ContainerView): |
990 def values(self): |
990 def values(self): |
991 intids = get_utility(IIntIds) |
991 intids = get_utility(IIntIds) |
992 catalog = get_utility(ICatalog) |
992 catalog = get_utility(ICatalog) |
993 params = Eq(catalog['parents'], intids.register(self.context)) & \ |
993 params = Eq(catalog['parents'], intids.register(self.context)) & \ |
994 Any(catalog['content_type'], CONTENT_TYPES.keys()) |
994 Any(catalog['content_type'], CONTENT_TYPES.keys()) |
995 return unique(CatalogResultSet(CatalogQuery(catalog).query(params, |
995 yield from unique_iter(CatalogResultSet(CatalogQuery(catalog).query(params, |
996 limit=50, |
996 limit=50, |
997 sort_index='modified_date', |
997 sort_index='modified_date', |
998 reverse=True))) |
998 reverse=True))) |
999 |
999 |
1000 |
1000 |
1001 @pagelet_config(name='all-updates.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
1001 @pagelet_config(name='all-updates.html', context=IBaseSharedTool, layer=IPyAMSLayer, |
1002 permission=VIEW_SYSTEM_PERMISSION) |
1002 permission=VIEW_SYSTEM_PERMISSION) |
1003 class SharedToolAllUpdatesView(InnerAdminView, ContainerView): |
1003 class SharedToolAllUpdatesView(InnerAdminView, ContainerView): |