def user_news(context, num, more=0): if not 'instance' in context: raise TagUsageError() if not 'now' in context: context['now'] = timezone.now() if not 'course_news' in context: context['course_news'] = CachedNews(context['instance']) news = context['course_news'] if context['is_course_staff']: alerts, news = news.for_staff() else: user = context['request'].user alerts, news = news.for_user(not user.is_authenticated or user.userprofile.is_external) i = 0 for item in news: i += 1 item['collapsed'] = i > num if more > 0 and i == more: item['begin_more'] = True return { 'is_course_staff': context['is_course_staff'], 'now': context['now'], 'alerts': alerts, 'news': news, 'more': more, }
def _prepare_context(context, student=None): if not 'instance' in context: raise TagUsageError() instance = context['instance'] _prepare_now(context) if not 'content' in context: context['content'] = CachedContent(instance) def points(user, key): if not key in context: context[key] = CachedPoints(instance, user, context['content']) return context[key] if student: return points(student, 'studentpoints') return points(context['request'].user, 'points')
def exercise_text_stats(context, exercise): if not 'instance' in context: raise TagUsageError() instance = context['instance'] if not 'student_count' in context: context['student_count'] = instance.students.count() total = context['student_count'] if isinstance(exercise, int): num = instance.students.filter( submissions__exercise_id=exercise).distinct().count() else: num = exercise.number_of_submitters() if exercise else 0 return { "number": num, "percentage": int(100 * num / total) if total else 0, }
def _prepare_context(context: Context, student: Optional[User] = None) -> CachedPoints: if not 'instance' in context: raise TagUsageError() instance = context['instance'] _prepare_now(context) if not 'content' in context: context['content'] = CachedContent(instance) def points(user: User, key: str) -> CachedPoints: if not key in context: context[key] = CachedPoints(instance, user, context['content'], context['is_course_staff']) return context[key] if student: return points(student, 'studentpoints') return points(context['request'].user, 'points')
def user_news(context, num, more=0): if not 'instance' in context: raise TagUsageError() if not 'now' in context: context['now'] = timezone.now() if not 'course_news' in context: context['course_news'] = CachedNews(context['instance']) news = context['course_news'] if context['is_course_staff']: news = news.for_staff() else: user = context['request'].user news = news.for_user(not user.is_authenticated or user.userprofile.is_external) return { 'is_course_staff': context['is_course_staff'], 'now': context['now'], 'news': news, 'more': more, }
def prepare_course_menu(context): if not 'instance' in context: raise TagUsageError() if not 'course_menu' in context: context['course_menu'] = CachedCourseMenu(context['instance']) return ""