def collaborator_add_notification(sender, **kwargs): collection = kwargs.get('collection', None) user = kwargs.get('user', None) request = kwargs.get('request', None) notification = Notification() notification.user = user # Get root host of the collection. import oer.CollectionUtilities as cu (collection_root_type, collection_root) = cu.get_collection_root(collection) if collection_root_type.name == 'project': notification.url = reverse( 'projects:list_collection', kwargs={ 'project_slug': collection_root.slug, 'collection_slug': collection.slug } ) notification.description = 'You have been added as a collaborator on the collection "%s"' % ( collection.title) notification.save() # Send an email about this notification. nu.notify_by_email(notification, request.get_host())
def get_resource_root(resource): from django.core.exceptions import MultipleObjectsReturned try: collection = Collection.objects.get(resources__id=resource.id) except MultipleObjectsReturned: collection = Collection.objects.filter( resources__id=resource.id)[0] try: import oer.CollectionUtilities as cu return cu.get_collection_root(collection) except: return None
def project_home(request, project_slug): try: project = Project.objects.get(slug=project_slug) # TODO(Varun): Check if this is a private project, and if it is, check # if the requestee of the page is a member of the project. If not, # have a flag that blocks the page contents from being listed, or has # an alternative view. if project.visibility == 'private': if request.user not in project.confirmed_members: return redirect('projects:project_about', project_slug=project.slug) # Get activity feed related to this project. from django.contrib.contenttypes.models import ContentType project_ct = ContentType.objects.get_for_model(Project) posts = Comment.objects.filter( parent_id=project.id, parent_type=project_ct).order_by('-created') # For each of the comments, get its child comments recursively comments_ct = ContentType.objects.get_for_model(Comment) build_posts_social(posts, request.user) categories = GroupCategory.objects.filter(parent=project) import oer.CollectionUtilities as cu # Setup attachments on posts. for post in posts: if post.attachment: if post.attachment_type.name == 'collection': (root_host_type, root_host) = cu.get_collection_root( post.attachment) post.attachment.host_type = root_host_type post.attachment.host = root_host context = { 'title': project.title + ' ‹ OpenCurriculum', 'project': project, 'posts': posts, 'categories': categories, 'host_content_type': comments_ct, 'comments_content_type': comments_ct, } return render(request, 'project/project.html', context) except: raise Http404