def resource_view(request, resource_slug): resource = get_object_or_404( Resource.objects.approved(user=request.user), slug=resource_slug) if resource.status == Resource.ARCHIVED: messages.error(request, _( "This resource has been archived by the COVID-19 Library Content" " Review Team, so is not available for users to view")) elif resource.status != Resource.APPROVED: messages.error(request, _( "This resource is not yet approved by the COVID-19 Library Content" " Review Team, so is not yet available for all users to view")) options_menu = [] if resource_can_edit(resource, request.user): om = {} om['title'] = _('Edit') om['url'] = reverse('orb_resource_edit', args=[resource.id]) options_menu.append(om) if request.user.is_staff and resource.status == Resource.PENDING: om = {} om['title'] = _('Reject') om['url'] = reverse('orb_resource_reject', args=[resource.id]) options_menu.append(om) om = {} om['title'] = _('Approve') om['url'] = reverse('orb_resource_approve', args=[resource.id]) options_menu.append(om) resource_viewed.send(sender=resource, resource=resource, request=request) user_rating = 0 if request.user.is_authenticated: try: user_rating = ResourceRating.objects.get( resource=resource, user=request.user).rating except ResourceRating.DoesNotExist: pass # get the collections for this resource collections = Collection.objects.filter( collectionresource__resource=resource, visibility=Collection.PUBLIC) # See if bookmarked bookmarks = Collection.objects.filter(collectionresource__resource=resource, visibility=Collection.PRIVATE, collectionuser__user__id=request.user.id).count() if bookmarks > 0: bookmarked = True else: bookmarked = False return render(request, 'orb/resource/view.html', { 'resource': resource, 'options_menu': options_menu, 'user_rating': user_rating, 'collections': collections, 'bookmarked': bookmarked, })
def authorized_read_detail(self, object_list, bundle): # add to ResourceTracker if bundle.obj.id: resource_viewed.send(sender=bundle.obj, resource=bundle.obj, request=bundle.request, type=ResourceTracker.VIEW_API)
def resource_view(request, resource_slug): resource = get_object_or_404( Resource.objects.approved(user=request.user), slug=resource_slug) if resource.status == Resource.ARCHIVED: messages.error(request, _( u"This resource has been archived by the ORB Content" u" Review Team, so is not available for users to view")) elif resource.status != Resource.APPROVED: messages.error(request, _( u"This resource is not yet approved by the ORB Content" u" Review Team, so is not yet available for all users to view")) options_menu = [] if resource_can_edit(resource, request.user): om = {} om['title'] = _(u'Edit') om['url'] = reverse('orb_resource_edit', args=[resource.id]) options_menu.append(om) if request.user.is_staff and resource.status == Resource.PENDING: om = {} om['title'] = _(u'Reject') om['url'] = reverse('orb_resource_reject', args=[resource.id]) options_menu.append(om) om = {} om['title'] = _(u'Approve') om['url'] = reverse('orb_resource_approve', args=[resource.id]) options_menu.append(om) resource_viewed.send(sender=resource, resource=resource, request=request) user_rating = 0 if request.user.is_authenticated(): try: user_rating = ResourceRating.objects.get( resource=resource, user=request.user).rating except ResourceRating.DoesNotExist: pass # get the collections for this resource collections = Collection.objects.filter( collectionresource__resource=resource, visibility=Collection.PUBLIC) # See if bookmarked bookmarks = Collection.objects.filter(collectionresource__resource=resource, visibility=Collection.PRIVATE, collectionuser__user__id=request.user.id).count() if bookmarks > 0: bookmarked = True else: bookmarked = False return render(request, 'orb/resource/view.html', { 'resource': resource, 'options_menu': options_menu, 'user_rating': user_rating, 'collections': collections, 'bookmarked': bookmarked, })