Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #206 solve: Autocomplete search fields #217

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
28 changes: 0 additions & 28 deletions .gitignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this file from PR

This file was deleted.

12 changes: 2 additions & 10 deletions oioioi/contests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.contrib.admin.utils import quote, unquote
from django.db.models import Case, F, OuterRef, Q, Subquery, Value, When
from django.db.models.functions import Coalesce
from django.forms import ModelForm
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
Expand All @@ -29,6 +28,7 @@
ProblemInstanceForm,
SimpleContestForm,
TestsSelectionForm,
ContestPermissionAdminForm,
)
from oioioi.contests.menu import (
contest_admin_menu_registry,
Expand Down Expand Up @@ -1016,19 +1016,11 @@ def get_custom_list_select_related(self):
order=50,
)


class ContestPermissionAdminForm(ModelForm):
user = UserSelectionField(label=_("Username"))

class Meta(object):
model = ContestPermission
fields = ('user', 'contest', 'permission')


class ContestPermissionAdmin(admin.ModelAdmin):
list_display = ['permission', 'user', 'user_full_name']
list_display_links = ['user']
ordering = ['permission', 'user']

form = ContestPermissionAdminForm

def user_full_name(self, instance):
Expand Down
14 changes: 13 additions & 1 deletion oioioi/contests/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from django import forms
from django.forms import ModelForm
from django.contrib.admin import widgets
from django.contrib.auth.models import User
from django.forms import ValidationError
Expand All @@ -11,11 +12,22 @@

from oioioi.base.utils.inputs import narrow_input_field, narrow_input_fields
from oioioi.base.utils.user_selection import UserSelectionField
from oioioi.contests.models import Contest, ProblemInstance, Round
from oioioi.contests.models import Contest, ProblemInstance, Round, ContestPermission
from oioioi.contests.utils import is_contest_basicadmin, submittable_problem_instances
from oioioi.programs.models import Test


class ContestPermissionAdminForm(ModelForm):
user = UserSelectionField(label=_("Username"))

def __init__(self, *args, **kwargs):
super(ContestPermissionAdminForm, self).__init__(*args, **kwargs)
self.fields['user'].hints_url = reverse('teacher_search')

class Meta(object):
model = ContestPermission
fields = ('user', 'contest', 'permission')

class SimpleContestForm(forms.ModelForm):
class Meta(object):
model = Contest
Expand Down
1 change: 1 addition & 0 deletions oioioi/contests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def glob_namespaced_patterns(namespace):
name='user_info_redirect',
),
re_path(r'^admin/', admin.contest_site.urls),
re_path(r'^teacher-search/$', views.get_teacher_names, name='teacher_search'),
]

nonc_patterns = [
Expand Down
4 changes: 4 additions & 0 deletions oioioi/contests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,7 @@ def reattach_problem_confirm_view(request, problem_instance_id, contest_id):
'contests/reattach_problem_confirm.html',
{'problem_instance': problem_instance, 'destination_contest': contest},
)

def get_teacher_names(request):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this view needs to be protected (i.e. only for admins)

queryset = User.objects.filter(teacher__isnull=False)
return get_user_hints_view(request, 'substr', queryset)