class RoundAdmin(admin.ModelAdmin): form = select2_modelform(Round) list_select_related = True list_display = ( "short_str", "get_semester_number", "get_semester_name", "get_year", "get_competition", "can_submit", "start_time", "end_time", "results_final", "visible", "tasks_pdf", "solutions_visible", "solutions_pdf", ) list_filter = ("semester__competition", "semester__year") actions = [make_results_final] get_semester_number = get_related(attribute_chain=("semester", "number"), description="časť", order="semester__number") get_semester_name = get_related(attribute_chain=("semester", "name"), description="názov časti", order="semester__name") get_year = get_related(attribute_chain=("semester", "year"), description="ročník", order="semester__year") get_competition = get_related( attribute_chain=("semester", "competition"), description="súťaž", order="semester__competition", ) tasks_pdf = attribute_format(attribute="tasks_pdf_exists", description="zadania v pdf", boolean=True) solutions_pdf = attribute_format(attribute="solutions_pdf_exists", description="vzoráky v pdf", boolean=True) can_submit = attribute_format(attribute="can_submit", description="prebieha", boolean=True) def get_queryset(self, request): user_groups = request.user.groups.all() competition_lst = Competition.objects.filter( organizers_group__in=user_groups) semester_lst = Semester.objects.filter(competition__in=competition_lst) return super( RoundAdmin, self).get_queryset(request).filter(semester__in=semester_lst)
class RoundAdmin(admin.ModelAdmin): form = select2_modelform(Round) list_select_related = True list_display = ('short_str', 'get_semester_number', 'get_semester_name', 'get_year', 'get_competition', 'can_submit', 'start_time', 'end_time', 'results_final', 'visible', 'tasks_pdf', 'solutions_visible', 'solutions_pdf') list_filter = ('semester__competition', 'semester__year') actions = [make_results_final] get_semester_number = get_related(attribute_chain=('semester', 'number'), description='časť', order='semester__number') get_semester_name = get_related(attribute_chain=('semester', 'name'), description='názov časti', order='semester__name') get_year = get_related(attribute_chain=('semester', 'year'), description='ročník', order='semester__year') get_competition = get_related(attribute_chain=('semester', 'competition'), description='súťaž', order='semester__competition') tasks_pdf = attribute_format(attribute='tasks_pdf_exists', description='zadania v pdf', boolean=True) solutions_pdf = attribute_format(attribute='solutions_pdf_exists', description='vzoráky v pdf', boolean=True) can_submit = attribute_format(attribute='can_submit', description='prebieha', boolean=True) def get_queryset(self, request): user_groups = request.user.groups.all() competition_lst = Competition.objects.filter( organizers_group__in=user_groups) semester_lst = Semester.objects.filter(competition__in=competition_lst) return super(RoundAdmin, self).get_queryset(request).filter( semester__in=semester_lst )
class SubmitAdmin(admin.ModelAdmin): change_form_template = "admin/submit_form.html" form = select2_modelform(Submit, form_class=SubmitAdminForm) list_select_related = True list_display = ( "get_task_name", "get_task_number", "get_round", "get_semester", "get_year", "get_competition", "get_categories", "user", "time", "get_points", "submit_type", "testing_status", "filepath", ) list_filter = ("task__round__semester__competition", "testing_status", "submit_type") search_fields = ( "user__username", "user__first_name", "user__last_name", "task__name", "protocol_id", ) get_points = attribute_format(attribute="user_points", description="body") get_task_name = get_related( attribute_chain=("task", "name"), description="úloha", order="task__name" ) get_task_number = get_related( attribute_chain=("task", "number"), description="č.ú.", order="task__number" ) get_round = get_related( attribute_chain=("task", "round", "short_str"), description="kolo", order="task__round__number", ) get_semester = get_related( attribute_chain=("task", "round", "semester", "short_str"), description="časť", order="task__round__semester__number", ) get_year = get_related( attribute_chain=("task", "round", "semester", "year"), description="ročník", order="task__round__semester__year", ) get_competition = get_related( attribute_chain=("task", "round", "semester", "competition"), description="súťaž", order="task__round__semester__competition", ) def get_urls(self): return submit_urls + super(SubmitAdmin, self).get_urls() def get_categories(self, obj): return ", ".join(force_text(x.name) for x in obj.task.categories.all()) get_categories.short_description = "kategória" get_categories.admin_order_field = "task__categories" def get_queryset(self, request): user_groups = request.user.groups.all() round_lst = Round.objects.filter(semester__competition__organizers_group__in=user_groups) task_lst = Task.objects.filter(round__in=round_lst) return ( super(SubmitAdmin, self) .get_queryset(request) .filter(task__in=task_lst) .prefetch_related("task__categories") )
class TaskAdmin(admin.ModelAdmin): change_form_template = "admin/task_review.html" form = select2_modelform(Task, form_class=TaskValidationForm) list_select_related = True list_display = ( "name", "number", "get_round", "get_semester", "get_year", "get_competition", "get_categories", "submit_type", "integer_source_points", "tasks_pdf", "solutions_pdf", ) list_filter = ("round__semester__competition", TaskByYearSubFilter, TaskByRoundSubFilter) search_fields = ("name",) inlines = [TaskPeopleInline] get_round = get_related( attribute_chain=("round", "short_str"), description="kolo", order="round__number" ) get_semester = get_related( attribute_chain=("round", "semester", "short_str"), description="časť", order="round__semester__number", ) get_year = get_related( attribute_chain=("round", "semester", "year"), description="ročník", order="round__semester__year", ) get_competition = get_related( attribute_chain=("round", "semester", "competition"), description="súťaž", order="round__semester__competition", ) def formfield_for_foreignkey(self, db_field, request, **kwargs): user_groups = request.user.groups.all() if db_field.name == "round": kwargs["queryset"] = Round.objects.filter( semester__competition__organizers_group__in=user_groups ).order_by("-end_time") return super(TaskAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) def get_urls(self): return task_review_urls + super(TaskAdmin, self).get_urls() def get_categories(self, obj): return ", ".join(force_text(x.name) for x in obj.categories.all()) get_categories.short_description = "kategória" get_categories.admin_order_field = "categories" def submit_type(self, obj): res = "" if obj.has_description: res += "popis:%i " % obj.description_points if obj.has_source: res += "kód:%i " % obj.source_points if obj.has_testablezip: res += "zip " if bool(obj.external_submit_link): res += "link: %s" % obj.external_submit_link return res submit_type.short_description = "odovzdávanie a bodovanie" tasks_pdf = attribute_format(attribute="task_file_exists", description="zadanie", boolean=True) solutions_pdf = attribute_format( attribute="solution_file_exists", description="vzorák", boolean=True ) def get_queryset(self, request): user_groups = request.user.groups.all() round_lst = Round.objects.filter(semester__competition__organizers_group__in=user_groups) return ( super(TaskAdmin, self) .get_queryset(request) .filter(round__in=round_lst) .distinct() .prefetch_related("categories") .select_related("round__semester__competition") )
class SubmitAdmin(admin.ModelAdmin): change_form_template = 'admin/submit_form.html' form = select2_modelform(Submit, form_class=SubmitAdminForm) list_select_related = True list_display = ( 'get_task_name', 'get_task_number', 'get_round', 'get_semester', 'get_year', 'get_competition', 'get_categories', 'user', 'time', 'get_points', 'submit_type', 'testing_status', 'filepath', ) list_filter = ('task__round__semester__competition', 'testing_status', 'submit_type') search_fields = ( 'user__username', 'task__name', ) get_points = attribute_format( attribute='user_points', description='body', ) get_task_name = get_related(attribute_chain=('task', 'name'), description='úloha', order='task__name') get_task_number = get_related(attribute_chain=('task', 'number'), description='č.ú.', order='task__number') get_round = get_related(attribute_chain=('task', 'round', 'short_str'), description='kolo', order='task__round__number') get_semester = get_related(attribute_chain=('task', 'round', 'semester', 'short_str'), description='časť', order='task__round__semester__number') get_year = get_related(attribute_chain=('task', 'round', 'semester', 'year'), description='ročník', order='task__round__semester__year') get_competition = get_related(attribute_chain=('task', 'round', 'semester', 'competition'), description='súťaž', order='task__round__semester__competition') def get_urls(self): return submit_urls + super(SubmitAdmin, self).get_urls() def get_categories(self, obj): return ', '.join(force_text(x.name) for x in obj.task.categories.all()) get_categories.short_description = 'kategória' get_categories.admin_order_field = 'task__categories' def get_queryset(self, request): user_groups = request.user.groups.all() round_lst = Round.objects.filter( semester__competition__organizers_group__in=user_groups) task_lst = Task.objects.filter(round__in=round_lst) return super(SubmitAdmin, self).get_queryset(request).filter( task__in=task_lst).prefetch_related('task__categories')
class TaskAdmin(admin.ModelAdmin): change_form_template = 'admin/task_review.html' form = select2_modelform(Task, form_class=TaskValidationForm) list_select_related = True list_display = ('name', 'number', 'get_round', 'get_semester', 'get_year', 'get_competition', 'get_categories', 'submit_type', 'integer_source_points', 'tasks_pdf', 'solutions_pdf') list_filter = ('round__semester__competition', TaskByYearSubFilter, TaskByRoundSubFilter) search_fields = ('name',) inlines = [ TaskPeopleInline, ] get_round = get_related(attribute_chain=('round', 'short_str'), description='kolo', order='round__number') get_semester = get_related(attribute_chain=('round', 'semester', 'short_str'), description='časť', order='round__semester__number') get_year = get_related(attribute_chain=('round', 'semester', 'year'), description='ročník', order='round__semester__year') get_competition = get_related(attribute_chain=('round', 'semester', 'competition'), description='súťaž', order='round__semester__competition') def formfield_for_foreignkey(self, db_field, request, **kwargs): user_groups = request.user.groups.all() if db_field.name == 'round': kwargs['queryset'] = Round.objects.filter( semester__competition__organizers_group__in=user_groups ).order_by('-end_time') return super(TaskAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) def get_urls(self): return task_review_urls + super(TaskAdmin, self).get_urls() def get_categories(self, obj): return ', '.join(force_text(x.name) for x in obj.categories.all()) get_categories.short_description = 'kategória' get_categories.admin_order_field = 'categories' def submit_type(self, obj): res = '' if obj.has_description: res += 'popis:%i ' % obj.description_points if obj.has_source: res += 'kód:%i ' % obj.source_points if obj.has_testablezip: res += 'zip ' if bool(obj.external_submit_link): res += 'link: %s' % obj.external_submit_link return res submit_type.short_description = 'odovzdávanie a bodovanie' tasks_pdf = attribute_format(attribute='task_file_exists', description='zadanie', boolean=True) solutions_pdf = attribute_format(attribute='solution_file_exists', description='vzorák', boolean=True) def get_queryset(self, request): user_groups = request.user.groups.all() round_lst = Round.objects.filter( semester__competition__organizers_group__in=user_groups) return super(TaskAdmin, self).get_queryset(request).filter( round__in=round_lst ).distinct().prefetch_related('categories').select_related( 'round__semester__competition' )