示例#1
0
文件: admin.py 项目: dodo42/web
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)
示例#2
0
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
        )
示例#3
0
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")
        )
示例#4
0
文件: admin.py 项目: sobkulir/web
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")
        )
示例#5
0
class UserAdmin(ExportMixin, DefaultUserAdmin):
    change_form_template = 'admin/people/submitted_tasks_button.html'
    list_display = ('username', 'first_name', 'last_name', 'email',
                    'get_school', 'graduation', 'get_is_staff', 'get_groups',
                    'is_active', 'get_properties')
    list_filter = ('groups', StaffFilter, ActiveInCompetitionFilter,
                   ActiveInSemesterSubFilter)
    search_fields = ('username', 'first_name', 'last_name')

    add_form = AdminUserAddForm

    formfield_overrides = {models.ForeignKey: {'widget': Select2()}}

    add_fieldsets = ((None, {
        'fields': ('first_name', 'last_name', 'school', 'graduation')
    }), )

    fieldsets = (
        (None, {
            'fields': ('username', )
        }),
        (_('Personal info'), {
            'fields':
            ('first_name', 'last_name', 'email', 'gender', 'birth_date')
        }),
        (_('Address'), {
            'fields': ('home_address', 'mail_to_school', 'mailing_address')
        }),
        (_('School'), {
            'fields': ('school', 'graduation')
        }),
        (_('Password'), {
            'fields': ('password', )
        }),
    )
    superuser_fieldsets = fieldsets + (
        (_('Permissions'), {
            'fields': ('is_active', 'is_staff', 'is_superuser', 'groups',
                       'user_permissions')
        }),
        (_('Important dates'), {
            'fields': ('last_login', 'date_joined')
        }),
    )

    inlines = (UserPropertyInLine, )

    resource_class = UsersExport

    def get_queryset(self, request):
        qs = super(UserAdmin, self).get_queryset(request)
        return qs.select_related('school').prefetch_related(
            'groups', 'properties__key')

    def get_fieldsets(self, request, obj=None):
        if obj is None or not request.user.is_superuser:
            return super(UserAdmin, self).get_fieldsets(request, obj)
        else:
            return self.superuser_fieldsets

    def get_groups(self, obj):
        return ', '.join(force_text(x) for x in obj.groups.all())

    get_groups.short_description = 'skupiny'

    get_is_staff = attribute_format(attribute='is_staff',
                                    description='vedúci',
                                    boolean=True)

    def get_school(self, obj):
        if obj.school:
            if obj.school.has_abbreviation:
                show = obj.school.abbreviation
            else:
                show = obj.school.verbose_name
            return '<span title="%s">%s</span>' % (escape(
                force_text(obj.school)), escape(force_text(show)))

    get_school.short_description = 'škola'
    get_school.admin_order_field = 'school'
    get_school.allow_tags = True

    def get_properties(self, obj):
        return '<br />'.join(
            escape(force_text(x)) for x in obj.properties.all())

    get_properties.short_description = 'dodatočné vlastnosti'
    get_properties.allow_tags = True

    def get_urls(self):
        return submitted_tasks_urls + super(UserAdmin, self).get_urls()

    def user_change_password(self, request, id, form_url=''):
        if not request.user.is_superuser:
            raise PermissionDenied
        return super(UserAdmin,
                     self).user_change_password(request, id, form_url)
示例#6
0
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')
示例#7
0
文件: admin.py 项目: dodo42/web
class UserAdmin(ExportMixin, DefaultUserAdmin):
    change_form_template = "admin/people/submitted_tasks_button.html"
    list_display = (
        "username",
        "first_name",
        "last_name",
        "email",
        "get_school",
        "graduation",
        "get_is_staff",
        "get_groups",
        "is_active",
        "get_properties",
    )
    list_filter = ("groups", StaffFilter, ActiveInCompetitionFilter,
                   ActiveInSemesterSubFilter)
    search_fields = ("username", "first_name", "last_name")

    add_form = AdminUserAddForm

    formfield_overrides = {models.ForeignKey: {"widget": Select2()}}

    add_fieldsets = ((None, {
        "fields": ("first_name", "last_name", "school", "graduation")
    }), )

    fieldsets = (
        (None, {
            "fields": ("username", )
        }),
        (
            _("Personal info"),
            {
                "fields":
                ("first_name", "last_name", "email", "gender", "birth_date")
            },
        ),
        (_("Address"), {
            "fields": ("home_address", "mail_to_school", "mailing_address")
        }),
        (_("School"), {
            "fields": ("school", "graduation")
        }),
        (_("Password"), {
            "fields": ("password", )
        }),
    )
    superuser_fieldsets = fieldsets + (
        (
            _("Permissions"),
            {
                "fields": ("is_active", "is_staff", "is_superuser", "groups",
                           "user_permissions")
            },
        ),
        (_("Important dates"), {
            "fields": ("last_login", "date_joined")
        }),
    )

    inlines = (UserPropertyInLine, )

    resource_class = UsersExport

    def get_queryset(self, request):
        qs = super(UserAdmin, self).get_queryset(request)
        return qs.select_related("school").prefetch_related(
            "groups", "properties__key")

    def get_fieldsets(self, request, obj=None):
        if obj is None or not request.user.is_superuser:
            return super(UserAdmin, self).get_fieldsets(request, obj)
        else:
            return self.superuser_fieldsets

    def get_groups(self, obj):
        return ", ".join(force_text(x) for x in obj.groups.all())

    get_groups.short_description = "skupiny"

    get_is_staff = attribute_format(attribute="is_staff",
                                    description="vedúci",
                                    boolean=True)

    def get_school(self, obj):
        if obj.school:
            if obj.school.has_abbreviation:
                show = obj.school.abbreviation
            else:
                show = obj.school.verbose_name
            return format_html(
                '<span title="{}">{}</span>',
                escape(force_text(obj.school)),
                escape(force_text(show)),
            )

    get_school.short_description = "škola"
    get_school.admin_order_field = "school"
    get_school.allow_tags = True

    def get_properties(self, obj):
        return mark_safe("<br />".join(
            escape(force_text(x)) for x in obj.properties.all()))

    get_properties.short_description = "dodatočné vlastnosti"
    get_properties.allow_tags = True

    def get_urls(self):
        return submitted_tasks_urls + super(UserAdmin, self).get_urls()

    def user_change_password(self, request, id, form_url=""):
        if not request.user.is_superuser:
            raise PermissionDenied
        return super(UserAdmin,
                     self).user_change_password(request, id, form_url)
示例#8
0
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'
        )