def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) reusable_resources = Resource.objects.exclude(activities=self.object).exclude( reuse=ResourceReuse.NON_REUSABLE.name).exclude( Q(reuse=ResourceReuse.ONLY_AUTHOR.name) & ~Q(author=self.request.user) # Resources that can be reused by their author ) # Suggestion for new activities context.update(PaginatorFactory.get_paginator_as_context( reusable_resources.all(), self.request.GET, prefix="suggested", nb_per_page=9) ) # User may query some words using the search filter form = BasicSearchForm(data=self.request.GET) if form.is_valid() and form.cleaned_data.get('query', str()): query = form.cleaned_data.get('query', str()) context.update(PaginatorFactory.get_paginator_as_context( reusable_resources.filter(Q(name__icontains=query) | Q(description__icontains=query)).all(), self.request.GET, prefix="search") ) # Add the query form to the view context['form'] = form return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # Add the paginator on courses where user is author context.update( PaginatorFactory.get_paginator_as_context( Course.objects.written_by(self.request.user), self.request.GET, prefix="author", nb_per_page=6)) # Add the paginator on courses where user is a collaborator context.update( PaginatorFactory.get_paginator_as_context( CourseCollaborator.objects.filter( collaborator=self.request.user), self.request.GET, prefix="contributor", nb_per_page=6)) # Execute the user query and add the paginator on query form = BasicSearchForm(data=self.request.GET) if form.is_valid() and form.cleaned_data.get('query', str()): context.update( PaginatorFactory.get_paginator_as_context( Course.objects.taught_by(self.request.user, query=form.cleaned_data.get( 'query', str())).all(), self.request.GET, prefix="search")) # Add the query form in the view context['form'] = form return context
def search_query_as_context(cls, obj_class: Type[BasicModelMixin], query_dict: dict) -> dict: """ Get all the objects of a specific object type given the query :param obj_class: the object class type for which to query objects :type obj_class: Type[BasicModelMixin] :param query_dict: the query dict that contains a “query” key. This can be POST or GET for instance. :type query_dict: dict :return: a dictionary containing the results of this search after a call to PaginatorFactor with the search prefix. :rtype: dict """ context = dict() form = BasicSearchForm(data=query_dict) if form.is_valid() and form.cleaned_data.get("query", str()): query = form.cleaned_data.get("query", str()) queryset = obj_class.objects.filter( Q(name__icontains=query) | Q(description__icontains=query)).all() context.update( PaginatorFactory.get_paginator_as_context(queryset, query_dict, prefix="search")) context["form"] = form return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # All available activities for new activities context.update( PaginatorFactory.get_paginator_as_context( Activity.objects.reusable(self.object, self.request.user), self.request.GET, prefix="reusable", nb_per_page=6)) # User may query some words using the search filter form = BasicSearchForm(data=self.request.GET) if form.is_valid() and form.cleaned_data.get("query", str()): query = form.cleaned_data.get("query", str()) context.update( PaginatorFactory.get_paginator_as_context( Activity.objects.reusable(self.object, self.request.user, query=query), self.request.GET, prefix="search", nb_per_page=6)) # Add the query form in the view context["form"] = form return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # Add the paginator on favourite courses of the user where he is student. # Prefix is “favourite”: so object are “favourite_has_obj…” context.update( PaginatorFactory.get_paginator_as_context( Course.objects.student_favourites_for(self.request.user), self.request.GET, prefix="favourite", nb_per_page=6)) # Add the paginator on courses where user is student. Prefix is “follow”: so object are “follow_has_obj…” context.update( PaginatorFactory.get_paginator_as_context( Course.objects.followed_by_without_favorites( self.request.user), self.request.GET, prefix="follow", nb_per_page=6)) # Execute the user query and add the paginator on query form = BasicSearchForm(data=self.request.GET) if form.is_valid() and form.cleaned_data.get("query", str()): context.update( PaginatorFactory.get_paginator_as_context( Course.objects.followed_by(self.request.user, query=form.cleaned_data.get( "query", str())).all(), self.request.GET, prefix="search")) # Add the query form in the view context["form"] = form return context
def search_query_as_context(cls, obj_class, query_dict): context = dict() form = BasicSearchForm(data=query_dict) if form.is_valid() and form.cleaned_data.get('query', str()): query = form.cleaned_data.get('query', str()) queryset = obj_class.objects.filter( Q(name__icontains=query) | Q(description__icontains=query)).all() context.update( PaginatorFactory.get_paginator_as_context(queryset, query_dict, prefix="search")) context['form'] = form return context
def get_context_data(self, **kwargs): context = super().get_context_data() # Add the paginator on favourite resources of the user. # Prefix is “favourite”: so object are “favourite_has_obj…” context.update( PaginatorFactory.get_paginator_as_context( Resource.objects.teacher_favourites_for(self.request.user), self.request.GET, prefix="favourite", nb_per_page=6)) # Add the paginator on resources where user is author context.update( PaginatorFactory.get_paginator_as_context( Resource.objects.written_by(self.request.user), self.request.GET, prefix="author", nb_per_page=6)) # Add the paginator on resources where user is a collaborator # FIXME: this should exclude favourite courses where the user contribute context.update( PaginatorFactory.get_paginator_as_context( ResourceCollaborator.objects.filter( collaborator=self.request.user), self.request.GET, prefix="contributor", nb_per_page=6)) # Execute the user query and add the paginator on query form = BasicSearchForm(data=self.request.GET) if form.is_valid() and form.cleaned_data.get("query", str()): context.update( PaginatorFactory.get_paginator_as_context( Resource.objects.taught_by(self.request.user, query=form.cleaned_data.get( "query", str())), self.request.GET, prefix="search")) # Add the query form in the view context["form"] = form return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) basic_queryset = Activity.objects.exclude( # activities already linked with the course course_activities__course=self.object ).exclude( # activities that are not reusable reuse=ActivityReuse.NON_REUSABLE.name, ).exclude( # activities that can only be reused by their respective authors Q(reuse=ActivityReuse.ONLY_AUTHOR.name) & ~Q(author=self.object.author)) # Suggestion for new activities context.update( PaginatorFactory.get_paginator_as_context(basic_queryset.all(), self.request.GET, prefix="suggested", nb_per_page=6)) # User may query some words using the search filter form = BasicSearchForm(data=self.request.GET) if form.is_valid() and form.cleaned_data.get('query', str()): query = form.cleaned_data.get('query', str()) context.update( PaginatorFactory.get_paginator_as_context( basic_queryset.filter( Q(name__icontains=query) | Q(description__icontains=query)).all(), self.request.GET, prefix="search", nb_per_page=6)) # Add the query form in the view context['form'] = form return context