def get_collection_collectiongroup_engine(collection_id, group_slug): """Return collection and collection group by collection_id and group_slug.""" collection = Collection.objects.filter(id=collection_id).first() if not collection: log.exception( "Collection with provided ID does not exist. Check configured launch url." ) raise Http404('Bad launch_url collection ID.') collection_group = CollectionGroup.objects.filter(slug=group_slug).first() if collection_group is None: raise Http404( 'The launch URL is not correctly configured. The group with the slug `{}` cannot be found.' .format(group_slug)) if collection not in collection_group.collections.all(): raise Http404( 'The launch URL is not correctly configured. Collection with the ID `{}` is not in group with slug `{}`' .format(collection_id, group_slug)) if collection_group: engine = collection_group.engine or Engine.get_default() else: engine = Engine.get_default() return collection, collection_group, engine
def test_engine_get_default_engine(self): """Test get_default_engine method.""" engine_default_set = Engine.objects.filter(is_default=True) self.assertFalse(engine_default_set) default_engine = Engine.get_default() engine_default_new_set = Engine.objects.filter(is_default=True) self.assertEqual(engine_default_new_set.count(), 1) self.assertEqual(engine_default_set.first(), default_engine)
def get_form(self): form = super().get_form() collections = Collection.objects.filter( owner=self.request.user ) form.fields['engine'].initial = Engine.get_default() form.fields['course'].queryset = Course.objects.filter(owner=self.request.user) form.fields['collections'].queryset = collections if self.kwargs.get('group_slug'): group = get_object_or_404(CollectionGroup, slug=self.kwargs['group_slug']) if group.grading_policy: form.fields['grading_policy_name'].initial = group.grading_policy.name return form
def get_engine_and_collection_order(collection_order_slug): """ Return engine and CollectionOrder by CollectionOrder slug. """ # NOTE(AnadreyLikhoman): Using CollectionOrder to find engine collection_order = CollectionOrder.objects.filter( slug=collection_order_slug).first() if not collection_order: log.error( f"Collection_Order with the slug: {collection_order_slug} does not exist. Please check lti launch url." ) raise Http404( f'Bad slug of the collection_order in the lti launch url: ({collection_order_slug})' ) return collection_order.engine or Engine.get_default(), collection_order
def get_form(self): form = super().get_form() collections = Collection.objects.filter( Q(owner=self.request.user) | Q(collection_groups__contributors=self.request.user, collection_groups=form.group) | Q(collection_groups__owner=self.request.user) ) form.fields['engine'].initial = Engine.get_default() form.fields['collection'].queryset = collections.distinct() form.fields['collection'].required = False if self.kwargs.get('collection_order_slug'): collection_order = get_object_or_404( CollectionOrder, slug=self.kwargs['collection_order_slug'], ) if collection_order.grading_policy: form.initial['grading_policy_name'] = collection_order.grading_policy.name return form