Upgrade to Django 3.2
This commit is contained in:
parent
c1f710c9ac
commit
409d2e3115
23 changed files with 1469 additions and 151 deletions
|
@ -6,13 +6,13 @@ from django.db import migrations
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('judge', '0135_auto_20221028_0300'),
|
||||
('chat_box', '0009_auto_20220618_1452'),
|
||||
("judge", "0135_auto_20221028_0300"),
|
||||
("chat_box", "0009_auto_20220618_1452"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='userroom',
|
||||
unique_together={('user', 'room')},
|
||||
name="userroom",
|
||||
unique_together={("user", "room")},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -42,7 +42,6 @@ class Message(models.Model):
|
|||
super(Message, self).save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
app_label = "chat_box"
|
||||
verbose_name = "message"
|
||||
verbose_name_plural = "messages"
|
||||
ordering = ("-time",)
|
||||
|
|
|
@ -483,3 +483,5 @@ try:
|
|||
exec(f.read(), globals())
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import pymysql
|
||||
|
||||
pymysql.install_as_MySQLdb()
|
||||
pymysql.version_info = (1, 3, 13, "final", 0)
|
||||
pymysql.version_info = (1, 4, 0, "final", 0)
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.conf import settings
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import Count
|
||||
from django.db.models import Count, FilteredRelation, Q
|
||||
from django.db.models.expressions import F, Value
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.forms import ModelForm
|
||||
|
@ -22,8 +22,7 @@ from reversion import revisions
|
|||
from reversion.models import Revision, Version
|
||||
|
||||
from judge.dblock import LockModel
|
||||
from judge.models import Comment, CommentLock, CommentVote, Notification
|
||||
from judge.utils.raw_sql import RawSQLColumn, unique_together_left_join
|
||||
from judge.models import Comment, CommentLock, Notification
|
||||
from judge.widgets import HeavyPreviewPageDownWidget
|
||||
from judge.jinja2.reference import get_user_from_text
|
||||
|
||||
|
@ -178,13 +177,12 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
)
|
||||
|
||||
if self.request.user.is_authenticated:
|
||||
queryset = queryset.annotate(
|
||||
vote_score=Coalesce(RawSQLColumn(CommentVote, "score"), Value(0))
|
||||
)
|
||||
profile = self.request.profile
|
||||
unique_together_left_join(
|
||||
queryset, CommentVote, "comment", "voter", profile.id
|
||||
)
|
||||
queryset = queryset.annotate(
|
||||
my_vote=FilteredRelation(
|
||||
"votes", condition=Q(votes__voter_id=profile.id)
|
||||
),
|
||||
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
|
||||
context["is_new_user"] = (
|
||||
not self.request.user.is_staff
|
||||
and not profile.submission_set.filter(
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
from abc import ABCMeta, abstractmethod, abstractproperty
|
||||
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class abstractclassmethod(classmethod):
|
||||
__isabstractmethod__ = True
|
||||
|
@ -11,7 +9,7 @@ class abstractclassmethod(classmethod):
|
|||
super(abstractclassmethod, self).__init__(callable)
|
||||
|
||||
|
||||
class BaseContestFormat(six.with_metaclass(ABCMeta)):
|
||||
class BaseContestFormat(metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def __init__(self, contest, config):
|
||||
self.config = config
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from django.utils import six
|
||||
|
||||
formats = {}
|
||||
|
||||
|
||||
|
@ -13,4 +11,4 @@ def register_contest_format(name):
|
|||
|
||||
|
||||
def choices():
|
||||
return [(key, value.name) for key, value in sorted(six.iteritems(formats))]
|
||||
return [(key, value.name) for key, value in sorted(formats.items())]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from django.utils import six
|
||||
|
||||
from judge.ratings import rating_class, rating_name, rating_progress
|
||||
from . import registry
|
||||
|
||||
|
@ -8,7 +6,7 @@ def _get_rating_value(func, obj):
|
|||
if obj is None:
|
||||
return None
|
||||
|
||||
if isinstance(obj, six.integer_types):
|
||||
if isinstance(obj, int):
|
||||
return func(obj)
|
||||
else:
|
||||
return func(obj.rating)
|
||||
|
|
File diff suppressed because one or more lines are too long
677
judge/migrations/0136_alter_profile_timezone.py
Normal file
677
judge/migrations/0136_alter_profile_timezone.py
Normal file
|
@ -0,0 +1,677 @@
|
|||
# Generated by Django 3.2.16 on 2022-11-01 01:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("judge", "0135_auto_20221028_0300"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="profile",
|
||||
name="timezone",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
(
|
||||
"Africa",
|
||||
[
|
||||
("Africa/Abidjan", "Abidjan"),
|
||||
("Africa/Accra", "Accra"),
|
||||
("Africa/Addis_Ababa", "Addis_Ababa"),
|
||||
("Africa/Algiers", "Algiers"),
|
||||
("Africa/Asmara", "Asmara"),
|
||||
("Africa/Asmera", "Asmera"),
|
||||
("Africa/Bamako", "Bamako"),
|
||||
("Africa/Bangui", "Bangui"),
|
||||
("Africa/Banjul", "Banjul"),
|
||||
("Africa/Bissau", "Bissau"),
|
||||
("Africa/Blantyre", "Blantyre"),
|
||||
("Africa/Brazzaville", "Brazzaville"),
|
||||
("Africa/Bujumbura", "Bujumbura"),
|
||||
("Africa/Cairo", "Cairo"),
|
||||
("Africa/Casablanca", "Casablanca"),
|
||||
("Africa/Ceuta", "Ceuta"),
|
||||
("Africa/Conakry", "Conakry"),
|
||||
("Africa/Dakar", "Dakar"),
|
||||
("Africa/Dar_es_Salaam", "Dar_es_Salaam"),
|
||||
("Africa/Djibouti", "Djibouti"),
|
||||
("Africa/Douala", "Douala"),
|
||||
("Africa/El_Aaiun", "El_Aaiun"),
|
||||
("Africa/Freetown", "Freetown"),
|
||||
("Africa/Gaborone", "Gaborone"),
|
||||
("Africa/Harare", "Harare"),
|
||||
("Africa/Johannesburg", "Johannesburg"),
|
||||
("Africa/Juba", "Juba"),
|
||||
("Africa/Kampala", "Kampala"),
|
||||
("Africa/Khartoum", "Khartoum"),
|
||||
("Africa/Kigali", "Kigali"),
|
||||
("Africa/Kinshasa", "Kinshasa"),
|
||||
("Africa/Lagos", "Lagos"),
|
||||
("Africa/Libreville", "Libreville"),
|
||||
("Africa/Lome", "Lome"),
|
||||
("Africa/Luanda", "Luanda"),
|
||||
("Africa/Lubumbashi", "Lubumbashi"),
|
||||
("Africa/Lusaka", "Lusaka"),
|
||||
("Africa/Malabo", "Malabo"),
|
||||
("Africa/Maputo", "Maputo"),
|
||||
("Africa/Maseru", "Maseru"),
|
||||
("Africa/Mbabane", "Mbabane"),
|
||||
("Africa/Mogadishu", "Mogadishu"),
|
||||
("Africa/Monrovia", "Monrovia"),
|
||||
("Africa/Nairobi", "Nairobi"),
|
||||
("Africa/Ndjamena", "Ndjamena"),
|
||||
("Africa/Niamey", "Niamey"),
|
||||
("Africa/Nouakchott", "Nouakchott"),
|
||||
("Africa/Ouagadougou", "Ouagadougou"),
|
||||
("Africa/Porto-Novo", "Porto-Novo"),
|
||||
("Africa/Sao_Tome", "Sao_Tome"),
|
||||
("Africa/Timbuktu", "Timbuktu"),
|
||||
("Africa/Tripoli", "Tripoli"),
|
||||
("Africa/Tunis", "Tunis"),
|
||||
("Africa/Windhoek", "Windhoek"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"America",
|
||||
[
|
||||
("America/Adak", "Adak"),
|
||||
("America/Anchorage", "Anchorage"),
|
||||
("America/Anguilla", "Anguilla"),
|
||||
("America/Antigua", "Antigua"),
|
||||
("America/Araguaina", "Araguaina"),
|
||||
(
|
||||
"America/Argentina/Buenos_Aires",
|
||||
"Argentina/Buenos_Aires",
|
||||
),
|
||||
("America/Argentina/Catamarca", "Argentina/Catamarca"),
|
||||
(
|
||||
"America/Argentina/ComodRivadavia",
|
||||
"Argentina/ComodRivadavia",
|
||||
),
|
||||
("America/Argentina/Cordoba", "Argentina/Cordoba"),
|
||||
("America/Argentina/Jujuy", "Argentina/Jujuy"),
|
||||
("America/Argentina/La_Rioja", "Argentina/La_Rioja"),
|
||||
("America/Argentina/Mendoza", "Argentina/Mendoza"),
|
||||
(
|
||||
"America/Argentina/Rio_Gallegos",
|
||||
"Argentina/Rio_Gallegos",
|
||||
),
|
||||
("America/Argentina/Salta", "Argentina/Salta"),
|
||||
("America/Argentina/San_Juan", "Argentina/San_Juan"),
|
||||
("America/Argentina/San_Luis", "Argentina/San_Luis"),
|
||||
("America/Argentina/Tucuman", "Argentina/Tucuman"),
|
||||
("America/Argentina/Ushuaia", "Argentina/Ushuaia"),
|
||||
("America/Aruba", "Aruba"),
|
||||
("America/Asuncion", "Asuncion"),
|
||||
("America/Atikokan", "Atikokan"),
|
||||
("America/Atka", "Atka"),
|
||||
("America/Bahia", "Bahia"),
|
||||
("America/Bahia_Banderas", "Bahia_Banderas"),
|
||||
("America/Barbados", "Barbados"),
|
||||
("America/Belem", "Belem"),
|
||||
("America/Belize", "Belize"),
|
||||
("America/Blanc-Sablon", "Blanc-Sablon"),
|
||||
("America/Boa_Vista", "Boa_Vista"),
|
||||
("America/Bogota", "Bogota"),
|
||||
("America/Boise", "Boise"),
|
||||
("America/Buenos_Aires", "Buenos_Aires"),
|
||||
("America/Cambridge_Bay", "Cambridge_Bay"),
|
||||
("America/Campo_Grande", "Campo_Grande"),
|
||||
("America/Cancun", "Cancun"),
|
||||
("America/Caracas", "Caracas"),
|
||||
("America/Catamarca", "Catamarca"),
|
||||
("America/Cayenne", "Cayenne"),
|
||||
("America/Cayman", "Cayman"),
|
||||
("America/Chicago", "Chicago"),
|
||||
("America/Chihuahua", "Chihuahua"),
|
||||
("America/Coral_Harbour", "Coral_Harbour"),
|
||||
("America/Cordoba", "Cordoba"),
|
||||
("America/Costa_Rica", "Costa_Rica"),
|
||||
("America/Creston", "Creston"),
|
||||
("America/Cuiaba", "Cuiaba"),
|
||||
("America/Curacao", "Curacao"),
|
||||
("America/Danmarkshavn", "Danmarkshavn"),
|
||||
("America/Dawson", "Dawson"),
|
||||
("America/Dawson_Creek", "Dawson_Creek"),
|
||||
("America/Denver", "Denver"),
|
||||
("America/Detroit", "Detroit"),
|
||||
("America/Dominica", "Dominica"),
|
||||
("America/Edmonton", "Edmonton"),
|
||||
("America/Eirunepe", "Eirunepe"),
|
||||
("America/El_Salvador", "El_Salvador"),
|
||||
("America/Ensenada", "Ensenada"),
|
||||
("America/Fort_Nelson", "Fort_Nelson"),
|
||||
("America/Fort_Wayne", "Fort_Wayne"),
|
||||
("America/Fortaleza", "Fortaleza"),
|
||||
("America/Glace_Bay", "Glace_Bay"),
|
||||
("America/Godthab", "Godthab"),
|
||||
("America/Goose_Bay", "Goose_Bay"),
|
||||
("America/Grand_Turk", "Grand_Turk"),
|
||||
("America/Grenada", "Grenada"),
|
||||
("America/Guadeloupe", "Guadeloupe"),
|
||||
("America/Guatemala", "Guatemala"),
|
||||
("America/Guayaquil", "Guayaquil"),
|
||||
("America/Guyana", "Guyana"),
|
||||
("America/Halifax", "Halifax"),
|
||||
("America/Havana", "Havana"),
|
||||
("America/Hermosillo", "Hermosillo"),
|
||||
("America/Indiana/Indianapolis", "Indiana/Indianapolis"),
|
||||
("America/Indiana/Knox", "Indiana/Knox"),
|
||||
("America/Indiana/Marengo", "Indiana/Marengo"),
|
||||
("America/Indiana/Petersburg", "Indiana/Petersburg"),
|
||||
("America/Indiana/Tell_City", "Indiana/Tell_City"),
|
||||
("America/Indiana/Vevay", "Indiana/Vevay"),
|
||||
("America/Indiana/Vincennes", "Indiana/Vincennes"),
|
||||
("America/Indiana/Winamac", "Indiana/Winamac"),
|
||||
("America/Indianapolis", "Indianapolis"),
|
||||
("America/Inuvik", "Inuvik"),
|
||||
("America/Iqaluit", "Iqaluit"),
|
||||
("America/Jamaica", "Jamaica"),
|
||||
("America/Jujuy", "Jujuy"),
|
||||
("America/Juneau", "Juneau"),
|
||||
("America/Kentucky/Louisville", "Kentucky/Louisville"),
|
||||
("America/Kentucky/Monticello", "Kentucky/Monticello"),
|
||||
("America/Knox_IN", "Knox_IN"),
|
||||
("America/Kralendijk", "Kralendijk"),
|
||||
("America/La_Paz", "La_Paz"),
|
||||
("America/Lima", "Lima"),
|
||||
("America/Los_Angeles", "Los_Angeles"),
|
||||
("America/Louisville", "Louisville"),
|
||||
("America/Lower_Princes", "Lower_Princes"),
|
||||
("America/Maceio", "Maceio"),
|
||||
("America/Managua", "Managua"),
|
||||
("America/Manaus", "Manaus"),
|
||||
("America/Marigot", "Marigot"),
|
||||
("America/Martinique", "Martinique"),
|
||||
("America/Matamoros", "Matamoros"),
|
||||
("America/Mazatlan", "Mazatlan"),
|
||||
("America/Mendoza", "Mendoza"),
|
||||
("America/Menominee", "Menominee"),
|
||||
("America/Merida", "Merida"),
|
||||
("America/Metlakatla", "Metlakatla"),
|
||||
("America/Mexico_City", "Mexico_City"),
|
||||
("America/Miquelon", "Miquelon"),
|
||||
("America/Moncton", "Moncton"),
|
||||
("America/Monterrey", "Monterrey"),
|
||||
("America/Montevideo", "Montevideo"),
|
||||
("America/Montreal", "Montreal"),
|
||||
("America/Montserrat", "Montserrat"),
|
||||
("America/Nassau", "Nassau"),
|
||||
("America/New_York", "New_York"),
|
||||
("America/Nipigon", "Nipigon"),
|
||||
("America/Nome", "Nome"),
|
||||
("America/Noronha", "Noronha"),
|
||||
("America/North_Dakota/Beulah", "North_Dakota/Beulah"),
|
||||
("America/North_Dakota/Center", "North_Dakota/Center"),
|
||||
(
|
||||
"America/North_Dakota/New_Salem",
|
||||
"North_Dakota/New_Salem",
|
||||
),
|
||||
("America/Nuuk", "Nuuk"),
|
||||
("America/Ojinaga", "Ojinaga"),
|
||||
("America/Panama", "Panama"),
|
||||
("America/Pangnirtung", "Pangnirtung"),
|
||||
("America/Paramaribo", "Paramaribo"),
|
||||
("America/Phoenix", "Phoenix"),
|
||||
("America/Port-au-Prince", "Port-au-Prince"),
|
||||
("America/Port_of_Spain", "Port_of_Spain"),
|
||||
("America/Porto_Acre", "Porto_Acre"),
|
||||
("America/Porto_Velho", "Porto_Velho"),
|
||||
("America/Puerto_Rico", "Puerto_Rico"),
|
||||
("America/Punta_Arenas", "Punta_Arenas"),
|
||||
("America/Rainy_River", "Rainy_River"),
|
||||
("America/Rankin_Inlet", "Rankin_Inlet"),
|
||||
("America/Recife", "Recife"),
|
||||
("America/Regina", "Regina"),
|
||||
("America/Resolute", "Resolute"),
|
||||
("America/Rio_Branco", "Rio_Branco"),
|
||||
("America/Rosario", "Rosario"),
|
||||
("America/Santa_Isabel", "Santa_Isabel"),
|
||||
("America/Santarem", "Santarem"),
|
||||
("America/Santiago", "Santiago"),
|
||||
("America/Santo_Domingo", "Santo_Domingo"),
|
||||
("America/Sao_Paulo", "Sao_Paulo"),
|
||||
("America/Scoresbysund", "Scoresbysund"),
|
||||
("America/Shiprock", "Shiprock"),
|
||||
("America/Sitka", "Sitka"),
|
||||
("America/St_Barthelemy", "St_Barthelemy"),
|
||||
("America/St_Johns", "St_Johns"),
|
||||
("America/St_Kitts", "St_Kitts"),
|
||||
("America/St_Lucia", "St_Lucia"),
|
||||
("America/St_Thomas", "St_Thomas"),
|
||||
("America/St_Vincent", "St_Vincent"),
|
||||
("America/Swift_Current", "Swift_Current"),
|
||||
("America/Tegucigalpa", "Tegucigalpa"),
|
||||
("America/Thule", "Thule"),
|
||||
("America/Thunder_Bay", "Thunder_Bay"),
|
||||
("America/Tijuana", "Tijuana"),
|
||||
("America/Toronto", "Toronto"),
|
||||
("America/Tortola", "Tortola"),
|
||||
("America/Vancouver", "Vancouver"),
|
||||
("America/Virgin", "Virgin"),
|
||||
("America/Whitehorse", "Whitehorse"),
|
||||
("America/Winnipeg", "Winnipeg"),
|
||||
("America/Yakutat", "Yakutat"),
|
||||
("America/Yellowknife", "Yellowknife"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Antarctica",
|
||||
[
|
||||
("Antarctica/Casey", "Casey"),
|
||||
("Antarctica/Davis", "Davis"),
|
||||
("Antarctica/DumontDUrville", "DumontDUrville"),
|
||||
("Antarctica/Macquarie", "Macquarie"),
|
||||
("Antarctica/Mawson", "Mawson"),
|
||||
("Antarctica/McMurdo", "McMurdo"),
|
||||
("Antarctica/Palmer", "Palmer"),
|
||||
("Antarctica/Rothera", "Rothera"),
|
||||
("Antarctica/South_Pole", "South_Pole"),
|
||||
("Antarctica/Syowa", "Syowa"),
|
||||
("Antarctica/Troll", "Troll"),
|
||||
("Antarctica/Vostok", "Vostok"),
|
||||
],
|
||||
),
|
||||
("Arctic", [("Arctic/Longyearbyen", "Longyearbyen")]),
|
||||
(
|
||||
"Asia",
|
||||
[
|
||||
("Asia/Aden", "Aden"),
|
||||
("Asia/Almaty", "Almaty"),
|
||||
("Asia/Amman", "Amman"),
|
||||
("Asia/Anadyr", "Anadyr"),
|
||||
("Asia/Aqtau", "Aqtau"),
|
||||
("Asia/Aqtobe", "Aqtobe"),
|
||||
("Asia/Ashgabat", "Ashgabat"),
|
||||
("Asia/Ashkhabad", "Ashkhabad"),
|
||||
("Asia/Atyrau", "Atyrau"),
|
||||
("Asia/Baghdad", "Baghdad"),
|
||||
("Asia/Bahrain", "Bahrain"),
|
||||
("Asia/Baku", "Baku"),
|
||||
("Asia/Bangkok", "Bangkok"),
|
||||
("Asia/Barnaul", "Barnaul"),
|
||||
("Asia/Beirut", "Beirut"),
|
||||
("Asia/Bishkek", "Bishkek"),
|
||||
("Asia/Brunei", "Brunei"),
|
||||
("Asia/Calcutta", "Calcutta"),
|
||||
("Asia/Chita", "Chita"),
|
||||
("Asia/Choibalsan", "Choibalsan"),
|
||||
("Asia/Chongqing", "Chongqing"),
|
||||
("Asia/Chungking", "Chungking"),
|
||||
("Asia/Colombo", "Colombo"),
|
||||
("Asia/Dacca", "Dacca"),
|
||||
("Asia/Damascus", "Damascus"),
|
||||
("Asia/Dhaka", "Dhaka"),
|
||||
("Asia/Dili", "Dili"),
|
||||
("Asia/Dubai", "Dubai"),
|
||||
("Asia/Dushanbe", "Dushanbe"),
|
||||
("Asia/Famagusta", "Famagusta"),
|
||||
("Asia/Gaza", "Gaza"),
|
||||
("Asia/Harbin", "Harbin"),
|
||||
("Asia/Hebron", "Hebron"),
|
||||
("Asia/Ho_Chi_Minh", "Ho_Chi_Minh"),
|
||||
("Asia/Hong_Kong", "Hong_Kong"),
|
||||
("Asia/Hovd", "Hovd"),
|
||||
("Asia/Irkutsk", "Irkutsk"),
|
||||
("Asia/Istanbul", "Istanbul"),
|
||||
("Asia/Jakarta", "Jakarta"),
|
||||
("Asia/Jayapura", "Jayapura"),
|
||||
("Asia/Jerusalem", "Jerusalem"),
|
||||
("Asia/Kabul", "Kabul"),
|
||||
("Asia/Kamchatka", "Kamchatka"),
|
||||
("Asia/Karachi", "Karachi"),
|
||||
("Asia/Kashgar", "Kashgar"),
|
||||
("Asia/Kathmandu", "Kathmandu"),
|
||||
("Asia/Katmandu", "Katmandu"),
|
||||
("Asia/Khandyga", "Khandyga"),
|
||||
("Asia/Kolkata", "Kolkata"),
|
||||
("Asia/Krasnoyarsk", "Krasnoyarsk"),
|
||||
("Asia/Kuala_Lumpur", "Kuala_Lumpur"),
|
||||
("Asia/Kuching", "Kuching"),
|
||||
("Asia/Kuwait", "Kuwait"),
|
||||
("Asia/Macao", "Macao"),
|
||||
("Asia/Macau", "Macau"),
|
||||
("Asia/Magadan", "Magadan"),
|
||||
("Asia/Makassar", "Makassar"),
|
||||
("Asia/Manila", "Manila"),
|
||||
("Asia/Muscat", "Muscat"),
|
||||
("Asia/Nicosia", "Nicosia"),
|
||||
("Asia/Novokuznetsk", "Novokuznetsk"),
|
||||
("Asia/Novosibirsk", "Novosibirsk"),
|
||||
("Asia/Omsk", "Omsk"),
|
||||
("Asia/Oral", "Oral"),
|
||||
("Asia/Phnom_Penh", "Phnom_Penh"),
|
||||
("Asia/Pontianak", "Pontianak"),
|
||||
("Asia/Pyongyang", "Pyongyang"),
|
||||
("Asia/Qatar", "Qatar"),
|
||||
("Asia/Qostanay", "Qostanay"),
|
||||
("Asia/Qyzylorda", "Qyzylorda"),
|
||||
("Asia/Rangoon", "Rangoon"),
|
||||
("Asia/Riyadh", "Riyadh"),
|
||||
("Asia/Saigon", "Saigon"),
|
||||
("Asia/Sakhalin", "Sakhalin"),
|
||||
("Asia/Samarkand", "Samarkand"),
|
||||
("Asia/Seoul", "Seoul"),
|
||||
("Asia/Shanghai", "Shanghai"),
|
||||
("Asia/Singapore", "Singapore"),
|
||||
("Asia/Srednekolymsk", "Srednekolymsk"),
|
||||
("Asia/Taipei", "Taipei"),
|
||||
("Asia/Tashkent", "Tashkent"),
|
||||
("Asia/Tbilisi", "Tbilisi"),
|
||||
("Asia/Tehran", "Tehran"),
|
||||
("Asia/Tel_Aviv", "Tel_Aviv"),
|
||||
("Asia/Thimbu", "Thimbu"),
|
||||
("Asia/Thimphu", "Thimphu"),
|
||||
("Asia/Tokyo", "Tokyo"),
|
||||
("Asia/Tomsk", "Tomsk"),
|
||||
("Asia/Ujung_Pandang", "Ujung_Pandang"),
|
||||
("Asia/Ulaanbaatar", "Ulaanbaatar"),
|
||||
("Asia/Ulan_Bator", "Ulan_Bator"),
|
||||
("Asia/Urumqi", "Urumqi"),
|
||||
("Asia/Ust-Nera", "Ust-Nera"),
|
||||
("Asia/Vientiane", "Vientiane"),
|
||||
("Asia/Vladivostok", "Vladivostok"),
|
||||
("Asia/Yakutsk", "Yakutsk"),
|
||||
("Asia/Yangon", "Yangon"),
|
||||
("Asia/Yekaterinburg", "Yekaterinburg"),
|
||||
("Asia/Yerevan", "Yerevan"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Atlantic",
|
||||
[
|
||||
("Atlantic/Azores", "Azores"),
|
||||
("Atlantic/Bermuda", "Bermuda"),
|
||||
("Atlantic/Canary", "Canary"),
|
||||
("Atlantic/Cape_Verde", "Cape_Verde"),
|
||||
("Atlantic/Faeroe", "Faeroe"),
|
||||
("Atlantic/Faroe", "Faroe"),
|
||||
("Atlantic/Jan_Mayen", "Jan_Mayen"),
|
||||
("Atlantic/Madeira", "Madeira"),
|
||||
("Atlantic/Reykjavik", "Reykjavik"),
|
||||
("Atlantic/South_Georgia", "South_Georgia"),
|
||||
("Atlantic/St_Helena", "St_Helena"),
|
||||
("Atlantic/Stanley", "Stanley"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Australia",
|
||||
[
|
||||
("Australia/ACT", "ACT"),
|
||||
("Australia/Adelaide", "Adelaide"),
|
||||
("Australia/Brisbane", "Brisbane"),
|
||||
("Australia/Broken_Hill", "Broken_Hill"),
|
||||
("Australia/Canberra", "Canberra"),
|
||||
("Australia/Currie", "Currie"),
|
||||
("Australia/Darwin", "Darwin"),
|
||||
("Australia/Eucla", "Eucla"),
|
||||
("Australia/Hobart", "Hobart"),
|
||||
("Australia/LHI", "LHI"),
|
||||
("Australia/Lindeman", "Lindeman"),
|
||||
("Australia/Lord_Howe", "Lord_Howe"),
|
||||
("Australia/Melbourne", "Melbourne"),
|
||||
("Australia/NSW", "NSW"),
|
||||
("Australia/North", "North"),
|
||||
("Australia/Perth", "Perth"),
|
||||
("Australia/Queensland", "Queensland"),
|
||||
("Australia/South", "South"),
|
||||
("Australia/Sydney", "Sydney"),
|
||||
("Australia/Tasmania", "Tasmania"),
|
||||
("Australia/Victoria", "Victoria"),
|
||||
("Australia/West", "West"),
|
||||
("Australia/Yancowinna", "Yancowinna"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Brazil",
|
||||
[
|
||||
("Brazil/Acre", "Acre"),
|
||||
("Brazil/DeNoronha", "DeNoronha"),
|
||||
("Brazil/East", "East"),
|
||||
("Brazil/West", "West"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Canada",
|
||||
[
|
||||
("Canada/Atlantic", "Atlantic"),
|
||||
("Canada/Central", "Central"),
|
||||
("Canada/Eastern", "Eastern"),
|
||||
("Canada/Mountain", "Mountain"),
|
||||
("Canada/Newfoundland", "Newfoundland"),
|
||||
("Canada/Pacific", "Pacific"),
|
||||
("Canada/Saskatchewan", "Saskatchewan"),
|
||||
("Canada/Yukon", "Yukon"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Chile",
|
||||
[
|
||||
("Chile/Continental", "Continental"),
|
||||
("Chile/EasterIsland", "EasterIsland"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Etc",
|
||||
[
|
||||
("Etc/Greenwich", "Greenwich"),
|
||||
("Etc/UCT", "UCT"),
|
||||
("Etc/UTC", "UTC"),
|
||||
("Etc/Universal", "Universal"),
|
||||
("Etc/Zulu", "Zulu"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Europe",
|
||||
[
|
||||
("Europe/Amsterdam", "Amsterdam"),
|
||||
("Europe/Andorra", "Andorra"),
|
||||
("Europe/Astrakhan", "Astrakhan"),
|
||||
("Europe/Athens", "Athens"),
|
||||
("Europe/Belfast", "Belfast"),
|
||||
("Europe/Belgrade", "Belgrade"),
|
||||
("Europe/Berlin", "Berlin"),
|
||||
("Europe/Bratislava", "Bratislava"),
|
||||
("Europe/Brussels", "Brussels"),
|
||||
("Europe/Bucharest", "Bucharest"),
|
||||
("Europe/Budapest", "Budapest"),
|
||||
("Europe/Busingen", "Busingen"),
|
||||
("Europe/Chisinau", "Chisinau"),
|
||||
("Europe/Copenhagen", "Copenhagen"),
|
||||
("Europe/Dublin", "Dublin"),
|
||||
("Europe/Gibraltar", "Gibraltar"),
|
||||
("Europe/Guernsey", "Guernsey"),
|
||||
("Europe/Helsinki", "Helsinki"),
|
||||
("Europe/Isle_of_Man", "Isle_of_Man"),
|
||||
("Europe/Istanbul", "Istanbul"),
|
||||
("Europe/Jersey", "Jersey"),
|
||||
("Europe/Kaliningrad", "Kaliningrad"),
|
||||
("Europe/Kiev", "Kiev"),
|
||||
("Europe/Kirov", "Kirov"),
|
||||
("Europe/Kyiv", "Kyiv"),
|
||||
("Europe/Lisbon", "Lisbon"),
|
||||
("Europe/Ljubljana", "Ljubljana"),
|
||||
("Europe/London", "London"),
|
||||
("Europe/Luxembourg", "Luxembourg"),
|
||||
("Europe/Madrid", "Madrid"),
|
||||
("Europe/Malta", "Malta"),
|
||||
("Europe/Mariehamn", "Mariehamn"),
|
||||
("Europe/Minsk", "Minsk"),
|
||||
("Europe/Monaco", "Monaco"),
|
||||
("Europe/Moscow", "Moscow"),
|
||||
("Europe/Nicosia", "Nicosia"),
|
||||
("Europe/Oslo", "Oslo"),
|
||||
("Europe/Paris", "Paris"),
|
||||
("Europe/Podgorica", "Podgorica"),
|
||||
("Europe/Prague", "Prague"),
|
||||
("Europe/Riga", "Riga"),
|
||||
("Europe/Rome", "Rome"),
|
||||
("Europe/Samara", "Samara"),
|
||||
("Europe/San_Marino", "San_Marino"),
|
||||
("Europe/Sarajevo", "Sarajevo"),
|
||||
("Europe/Saratov", "Saratov"),
|
||||
("Europe/Simferopol", "Simferopol"),
|
||||
("Europe/Skopje", "Skopje"),
|
||||
("Europe/Sofia", "Sofia"),
|
||||
("Europe/Stockholm", "Stockholm"),
|
||||
("Europe/Tallinn", "Tallinn"),
|
||||
("Europe/Tirane", "Tirane"),
|
||||
("Europe/Tiraspol", "Tiraspol"),
|
||||
("Europe/Ulyanovsk", "Ulyanovsk"),
|
||||
("Europe/Uzhgorod", "Uzhgorod"),
|
||||
("Europe/Vaduz", "Vaduz"),
|
||||
("Europe/Vatican", "Vatican"),
|
||||
("Europe/Vienna", "Vienna"),
|
||||
("Europe/Vilnius", "Vilnius"),
|
||||
("Europe/Volgograd", "Volgograd"),
|
||||
("Europe/Warsaw", "Warsaw"),
|
||||
("Europe/Zagreb", "Zagreb"),
|
||||
("Europe/Zaporozhye", "Zaporozhye"),
|
||||
("Europe/Zurich", "Zurich"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Indian",
|
||||
[
|
||||
("Indian/Antananarivo", "Antananarivo"),
|
||||
("Indian/Chagos", "Chagos"),
|
||||
("Indian/Christmas", "Christmas"),
|
||||
("Indian/Cocos", "Cocos"),
|
||||
("Indian/Comoro", "Comoro"),
|
||||
("Indian/Kerguelen", "Kerguelen"),
|
||||
("Indian/Mahe", "Mahe"),
|
||||
("Indian/Maldives", "Maldives"),
|
||||
("Indian/Mauritius", "Mauritius"),
|
||||
("Indian/Mayotte", "Mayotte"),
|
||||
("Indian/Reunion", "Reunion"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Mexico",
|
||||
[
|
||||
("Mexico/BajaNorte", "BajaNorte"),
|
||||
("Mexico/BajaSur", "BajaSur"),
|
||||
("Mexico/General", "General"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Other",
|
||||
[
|
||||
("CET", "CET"),
|
||||
("CST6CDT", "CST6CDT"),
|
||||
("Cuba", "Cuba"),
|
||||
("EET", "EET"),
|
||||
("EST", "EST"),
|
||||
("EST5EDT", "EST5EDT"),
|
||||
("Egypt", "Egypt"),
|
||||
("Eire", "Eire"),
|
||||
("GB", "GB"),
|
||||
("GB-Eire", "GB-Eire"),
|
||||
("Greenwich", "Greenwich"),
|
||||
("HST", "HST"),
|
||||
("Hongkong", "Hongkong"),
|
||||
("Iceland", "Iceland"),
|
||||
("Iran", "Iran"),
|
||||
("Israel", "Israel"),
|
||||
("Jamaica", "Jamaica"),
|
||||
("Japan", "Japan"),
|
||||
("Kwajalein", "Kwajalein"),
|
||||
("Libya", "Libya"),
|
||||
("MET", "MET"),
|
||||
("MST", "MST"),
|
||||
("MST7MDT", "MST7MDT"),
|
||||
("NZ", "NZ"),
|
||||
("NZ-CHAT", "NZ-CHAT"),
|
||||
("Navajo", "Navajo"),
|
||||
("PRC", "PRC"),
|
||||
("PST8PDT", "PST8PDT"),
|
||||
("Poland", "Poland"),
|
||||
("Portugal", "Portugal"),
|
||||
("ROC", "ROC"),
|
||||
("ROK", "ROK"),
|
||||
("Singapore", "Singapore"),
|
||||
("Turkey", "Turkey"),
|
||||
("UCT", "UCT"),
|
||||
("UTC", "UTC"),
|
||||
("Universal", "Universal"),
|
||||
("W-SU", "W-SU"),
|
||||
("WET", "WET"),
|
||||
("Zulu", "Zulu"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"Pacific",
|
||||
[
|
||||
("Pacific/Apia", "Apia"),
|
||||
("Pacific/Auckland", "Auckland"),
|
||||
("Pacific/Bougainville", "Bougainville"),
|
||||
("Pacific/Chatham", "Chatham"),
|
||||
("Pacific/Chuuk", "Chuuk"),
|
||||
("Pacific/Easter", "Easter"),
|
||||
("Pacific/Efate", "Efate"),
|
||||
("Pacific/Enderbury", "Enderbury"),
|
||||
("Pacific/Fakaofo", "Fakaofo"),
|
||||
("Pacific/Fiji", "Fiji"),
|
||||
("Pacific/Funafuti", "Funafuti"),
|
||||
("Pacific/Galapagos", "Galapagos"),
|
||||
("Pacific/Gambier", "Gambier"),
|
||||
("Pacific/Guadalcanal", "Guadalcanal"),
|
||||
("Pacific/Guam", "Guam"),
|
||||
("Pacific/Honolulu", "Honolulu"),
|
||||
("Pacific/Johnston", "Johnston"),
|
||||
("Pacific/Kanton", "Kanton"),
|
||||
("Pacific/Kiritimati", "Kiritimati"),
|
||||
("Pacific/Kosrae", "Kosrae"),
|
||||
("Pacific/Kwajalein", "Kwajalein"),
|
||||
("Pacific/Majuro", "Majuro"),
|
||||
("Pacific/Marquesas", "Marquesas"),
|
||||
("Pacific/Midway", "Midway"),
|
||||
("Pacific/Nauru", "Nauru"),
|
||||
("Pacific/Niue", "Niue"),
|
||||
("Pacific/Norfolk", "Norfolk"),
|
||||
("Pacific/Noumea", "Noumea"),
|
||||
("Pacific/Pago_Pago", "Pago_Pago"),
|
||||
("Pacific/Palau", "Palau"),
|
||||
("Pacific/Pitcairn", "Pitcairn"),
|
||||
("Pacific/Pohnpei", "Pohnpei"),
|
||||
("Pacific/Ponape", "Ponape"),
|
||||
("Pacific/Port_Moresby", "Port_Moresby"),
|
||||
("Pacific/Rarotonga", "Rarotonga"),
|
||||
("Pacific/Saipan", "Saipan"),
|
||||
("Pacific/Samoa", "Samoa"),
|
||||
("Pacific/Tahiti", "Tahiti"),
|
||||
("Pacific/Tarawa", "Tarawa"),
|
||||
("Pacific/Tongatapu", "Tongatapu"),
|
||||
("Pacific/Truk", "Truk"),
|
||||
("Pacific/Wake", "Wake"),
|
||||
("Pacific/Wallis", "Wallis"),
|
||||
("Pacific/Yap", "Yap"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"US",
|
||||
[
|
||||
("US/Alaska", "Alaska"),
|
||||
("US/Aleutian", "Aleutian"),
|
||||
("US/Arizona", "Arizona"),
|
||||
("US/Central", "Central"),
|
||||
("US/East-Indiana", "East-Indiana"),
|
||||
("US/Eastern", "Eastern"),
|
||||
("US/Hawaii", "Hawaii"),
|
||||
("US/Indiana-Starke", "Indiana-Starke"),
|
||||
("US/Michigan", "Michigan"),
|
||||
("US/Mountain", "Mountain"),
|
||||
("US/Pacific", "Pacific"),
|
||||
("US/Samoa", "Samoa"),
|
||||
],
|
||||
),
|
||||
],
|
||||
default="Asia/Ho_Chi_Minh",
|
||||
max_length=50,
|
||||
verbose_name="location",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -28,7 +28,6 @@ from judge.models.problem import (
|
|||
ProblemTranslation,
|
||||
ProblemType,
|
||||
Solution,
|
||||
TranslatedProblemForeignKeyQuerySet,
|
||||
TranslatedProblemQuerySet,
|
||||
ProblemPointsVote,
|
||||
)
|
||||
|
|
|
@ -6,8 +6,7 @@ from django.contrib.contenttypes.fields import GenericRelation
|
|||
from django.core.cache import cache
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import CASCADE, F, Q, QuerySet, SET_NULL
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models import CASCADE, F, FilteredRelation, Q, SET_NULL
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.urls import reverse
|
||||
from django.utils.functional import cached_property
|
||||
|
@ -17,7 +16,6 @@ from judge.fulltext import SearchQuerySet
|
|||
from judge.models.profile import Organization, Profile
|
||||
from judge.models.runtime import Language
|
||||
from judge.user_translations import gettext as user_gettext
|
||||
from judge.utils.raw_sql import RawSQLColumn, unique_together_left_join
|
||||
from judge.models.problem_data import (
|
||||
problem_data_storage,
|
||||
problem_directory_file_helper,
|
||||
|
@ -31,7 +29,6 @@ __all__ = [
|
|||
"License",
|
||||
"Solution",
|
||||
"TranslatedProblemQuerySet",
|
||||
"TranslatedProblemForeignKeyQuerySet",
|
||||
]
|
||||
|
||||
|
||||
|
@ -112,43 +109,18 @@ class TranslatedProblemQuerySet(SearchQuerySet):
|
|||
)
|
||||
|
||||
def add_i18n_name(self, language):
|
||||
queryset = self._clone()
|
||||
alias = unique_together_left_join(
|
||||
queryset, ProblemTranslation, "problem", "language", language
|
||||
)
|
||||
return queryset.annotate(
|
||||
return self.annotate(
|
||||
i18n_translation=FilteredRelation(
|
||||
"translations",
|
||||
condition=Q(translations__language=language),
|
||||
)
|
||||
).annotate(
|
||||
i18n_name=Coalesce(
|
||||
RawSQL("%s.name" % alias, ()),
|
||||
F("name"),
|
||||
output_field=models.CharField(),
|
||||
F("i18n_translation__name"), F("name"), output_field=models.CharField()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TranslatedProblemForeignKeyQuerySet(QuerySet):
|
||||
def add_problem_i18n_name(self, key, language, name_field=None):
|
||||
queryset = (
|
||||
self._clone() if name_field is None else self.annotate(_name=F(name_field))
|
||||
)
|
||||
alias = unique_together_left_join(
|
||||
queryset,
|
||||
ProblemTranslation,
|
||||
"problem",
|
||||
"language",
|
||||
language,
|
||||
parent_model=Problem,
|
||||
)
|
||||
# You must specify name_field if Problem is not yet joined into the QuerySet.
|
||||
kwargs = {
|
||||
key: Coalesce(
|
||||
RawSQL("%s.name" % alias, ()),
|
||||
F(name_field) if name_field else RawSQLColumn(Problem, "name"),
|
||||
output_field=models.CharField(),
|
||||
)
|
||||
}
|
||||
return queryset.annotate(**kwargs)
|
||||
|
||||
|
||||
class Problem(models.Model):
|
||||
code = models.CharField(
|
||||
max_length=20,
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.utils.functional import cached_property
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from judge.judgeapi import abort_submission, judge_submission
|
||||
from judge.models.problem import Problem, TranslatedProblemForeignKeyQuerySet
|
||||
from judge.models.problem import Problem
|
||||
from judge.models.profile import Profile
|
||||
from judge.models.runtime import Language
|
||||
from judge.utils.unicode import utf8bytes
|
||||
|
@ -120,8 +120,6 @@ class Submission(models.Model):
|
|||
related_name="+",
|
||||
)
|
||||
|
||||
objects = TranslatedProblemForeignKeyQuerySet.as_manager()
|
||||
|
||||
@classmethod
|
||||
def result_class_from_code(cls, result, case_points, case_total):
|
||||
if result == "AC":
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from django.conf import settings
|
||||
from django.utils import six
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
|
||||
if settings.USE_I18N:
|
||||
|
@ -27,7 +26,7 @@ if settings.USE_I18N:
|
|||
else:
|
||||
translation_object = translation(get_language())
|
||||
result = getattr(translation_object, translation_function)(eol_message)
|
||||
if not isinstance(result, six.text_type):
|
||||
if not isinstance(result, str):
|
||||
result = result.decode("utf-8")
|
||||
|
||||
if isinstance(message, SafeData):
|
||||
|
|
|
@ -40,7 +40,6 @@ import requests
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.password_validation import CommonPasswordValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.six import string_types
|
||||
from django.utils.translation import gettext as _, ungettext
|
||||
|
||||
from judge.utils.unicode import utf8bytes
|
||||
|
@ -83,7 +82,7 @@ def pwned_password(password):
|
|||
"""
|
||||
Checks a password against the Pwned Passwords database.
|
||||
"""
|
||||
if not isinstance(password, string_types):
|
||||
if not isinstance(password, str):
|
||||
raise TypeError("Password values to check must be strings.")
|
||||
password_hash = hashlib.sha1(utf8bytes(password)).hexdigest().upper()
|
||||
prefix, suffix = password_hash[:5], password_hash[5:]
|
||||
|
@ -107,7 +106,7 @@ class PwnedPasswordsValidator(object):
|
|||
error_message = error_message or self.DEFAULT_PWNED_MESSAGE
|
||||
|
||||
# If there is no plural, use the same message for both forms.
|
||||
if isinstance(error_message, string_types):
|
||||
if isinstance(error_message, str):
|
||||
singular, plural = error_message, error_message
|
||||
else:
|
||||
singular, plural = error_message
|
||||
|
|
|
@ -1,40 +1,10 @@
|
|||
from copy import copy
|
||||
|
||||
from django.db import connections
|
||||
from django.db.models import Field
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models.sql.constants import INNER, LOUTER
|
||||
from django.db.models.sql.datastructures import Join
|
||||
from django.utils import six
|
||||
|
||||
from judge.utils.cachedict import CacheDict
|
||||
|
||||
|
||||
def unique_together_left_join(
|
||||
queryset, model, link_field_name, filter_field_name, filter_value, parent_model=None
|
||||
):
|
||||
link_field = copy(model._meta.get_field(link_field_name).remote_field)
|
||||
filter_field = model._meta.get_field(filter_field_name)
|
||||
|
||||
def restrictions(where_class, alias, related_alias):
|
||||
cond = where_class()
|
||||
cond.add(
|
||||
filter_field.get_lookup("exact")(filter_field.get_col(alias), filter_value),
|
||||
"AND",
|
||||
)
|
||||
return cond
|
||||
|
||||
link_field.get_extra_restriction = restrictions
|
||||
|
||||
if parent_model is not None:
|
||||
parent_alias = parent_model._meta.db_table
|
||||
else:
|
||||
parent_alias = queryset.query.get_initial_alias()
|
||||
return queryset.query.join(
|
||||
Join(model._meta.db_table, parent_alias, None, LOUTER, link_field, True)
|
||||
)
|
||||
|
||||
|
||||
class RawSQLJoin(Join):
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -65,8 +35,9 @@ class RawSQLJoin(Join):
|
|||
|
||||
|
||||
class FakeJoinField:
|
||||
def __init__(self, joining_columns):
|
||||
def __init__(self, joining_columns, related_model):
|
||||
self.joining_columns = joining_columns
|
||||
self.related_model = related_model
|
||||
|
||||
def get_joining_columns(self):
|
||||
return self.joining_columns
|
||||
|
@ -76,35 +47,36 @@ class FakeJoinField:
|
|||
|
||||
|
||||
def join_sql_subquery(
|
||||
queryset, subquery, params, join_fields, alias, join_type=INNER, parent_model=None
|
||||
queryset,
|
||||
subquery,
|
||||
params,
|
||||
join_fields,
|
||||
alias,
|
||||
related_model,
|
||||
join_type=INNER,
|
||||
parent_model=None,
|
||||
):
|
||||
if parent_model is not None:
|
||||
parent_alias = parent_model._meta.db_table
|
||||
else:
|
||||
parent_alias = queryset.query.get_initial_alias()
|
||||
queryset.query.external_aliases.add(alias)
|
||||
if isinstance(queryset.query.external_aliases, dict): # Django 3.x
|
||||
queryset.query.external_aliases[alias] = True
|
||||
else:
|
||||
queryset.query.external_aliases.add(alias)
|
||||
join = RawSQLJoin(
|
||||
subquery,
|
||||
params,
|
||||
parent_alias,
|
||||
alias,
|
||||
join_type,
|
||||
FakeJoinField(join_fields),
|
||||
FakeJoinField(join_fields, related_model),
|
||||
join_type == LOUTER,
|
||||
)
|
||||
queryset.query.join(join)
|
||||
join.table_alias = alias
|
||||
|
||||
|
||||
def RawSQLColumn(model, field=None):
|
||||
if isinstance(model, Field):
|
||||
field = model
|
||||
model = field.model
|
||||
if isinstance(field, six.string_types):
|
||||
field = model._meta.get_field(field)
|
||||
return RawSQL("%s.%s" % (model._meta.db_table, field.get_attname_column()[1]), ())
|
||||
|
||||
|
||||
def make_straight_join_query(QueryType):
|
||||
class Query(QueryType):
|
||||
def join(self, join, *args, **kwargs):
|
||||
|
|
|
@ -1,17 +1,37 @@
|
|||
from django.utils import six
|
||||
from typing import AnyStr, Optional, overload
|
||||
|
||||
|
||||
@overload
|
||||
def utf8bytes(maybe_text: AnyStr) -> bytes:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def utf8bytes(maybe_text: None) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def utf8bytes(maybe_text):
|
||||
if maybe_text is None:
|
||||
return
|
||||
if isinstance(maybe_text, six.binary_type):
|
||||
return None
|
||||
if isinstance(maybe_text, bytes):
|
||||
return maybe_text
|
||||
return maybe_text.encode("utf-8")
|
||||
|
||||
|
||||
def utf8text(maybe_bytes, errors="strict"):
|
||||
@overload
|
||||
def utf8text(maybe_bytes: AnyStr, errors="strict") -> str:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def utf8text(maybe_bytes: None, errors="strict") -> None:
|
||||
pass
|
||||
|
||||
|
||||
def utf8text(maybe_bytes, errors="strict") -> Optional[str]:
|
||||
if maybe_bytes is None:
|
||||
return
|
||||
if isinstance(maybe_bytes, six.text_type):
|
||||
return None
|
||||
if isinstance(maybe_bytes, str):
|
||||
return maybe_bytes
|
||||
return maybe_bytes.decode("utf-8", errors)
|
||||
|
|
|
@ -11,7 +11,19 @@ from django.contrib.auth.decorators import login_required
|
|||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.db.models import Count, F, Prefetch, Q, Sum, Case, When, IntegerField
|
||||
from django.db.models import (
|
||||
BooleanField,
|
||||
Case,
|
||||
CharField,
|
||||
Count,
|
||||
F,
|
||||
FilteredRelation,
|
||||
Prefetch,
|
||||
Q,
|
||||
When,
|
||||
IntegerField,
|
||||
)
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.db.utils import ProgrammingError
|
||||
from django.http import (
|
||||
Http404,
|
||||
|
@ -49,7 +61,6 @@ from judge.models import (
|
|||
Solution,
|
||||
Submission,
|
||||
SubmissionSource,
|
||||
TranslatedProblemForeignKeyQuerySet,
|
||||
Organization,
|
||||
VolunteerProblemVote,
|
||||
Profile,
|
||||
|
@ -498,11 +509,23 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
.defer("problem__description")
|
||||
.order_by("problem__code")
|
||||
.annotate(user_count=Count("submission__participation", distinct=True))
|
||||
.annotate(
|
||||
i18n_translation=FilteredRelation(
|
||||
"problem__translations",
|
||||
condition=Q(
|
||||
problem__translations__language=self.request.LANGUAGE_CODE
|
||||
),
|
||||
)
|
||||
)
|
||||
.annotate(
|
||||
i18n_name=Coalesce(
|
||||
F("i18n_translation__name"),
|
||||
F("problem__name"),
|
||||
output_field=CharField(),
|
||||
)
|
||||
)
|
||||
.order_by("order")
|
||||
)
|
||||
queryset = TranslatedProblemForeignKeyQuerySet.add_problem_i18n_name(
|
||||
queryset, "i18n_name", self.request.LANGUAGE_CODE, "problem__name"
|
||||
)
|
||||
return [
|
||||
{
|
||||
"id": p["problem_id"],
|
||||
|
@ -593,12 +616,14 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
if self.point_end is not None:
|
||||
queryset = queryset.filter(points__lte=self.point_end)
|
||||
queryset = queryset.annotate(
|
||||
has_public_editorial=Sum(
|
||||
Case(
|
||||
When(solution__is_public=True, then=1),
|
||||
default=0,
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
has_public_editorial=Case(
|
||||
When(
|
||||
solution__is_public=True,
|
||||
solution__publish_on__lte=timezone.now(),
|
||||
then=True,
|
||||
),
|
||||
default=False,
|
||||
output_field=BooleanField(),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class RankedSubmissions(ProblemSubmissions):
|
|||
constraint = ""
|
||||
queryset = (
|
||||
super(RankedSubmissions, self)
|
||||
.get_queryset()
|
||||
._get_queryset()
|
||||
.filter(user__is_unlisted=False)
|
||||
)
|
||||
join_sql_subquery(
|
||||
|
@ -57,6 +57,7 @@ class RankedSubmissions(ProblemSubmissions):
|
|||
else [self.problem.id] * 3,
|
||||
alias="best_subs",
|
||||
join_fields=[("id", "id")],
|
||||
related_model=Submission,
|
||||
)
|
||||
|
||||
if self.in_contest:
|
||||
|
@ -75,7 +76,9 @@ class RankedSubmissions(ProblemSubmissions):
|
|||
)
|
||||
|
||||
def _get_result_data(self):
|
||||
return get_result_data(super(RankedSubmissions, self).get_queryset().order_by())
|
||||
return get_result_data(
|
||||
super(RankedSubmissions, self)._get_queryset().order_by()
|
||||
)
|
||||
|
||||
|
||||
class ContestRankedSubmission(ForceContestMixin, RankedSubmissions):
|
||||
|
|
|
@ -2,7 +2,6 @@ from collections import defaultdict
|
|||
from functools import partial
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.utils import six
|
||||
from django.utils.translation import gettext as _
|
||||
from packaging import version
|
||||
|
||||
|
@ -74,12 +73,12 @@ def version_matrix(request):
|
|||
):
|
||||
matrix[runtime.judge_id][runtime.language_id].append(runtime)
|
||||
|
||||
for judge, data in six.iteritems(matrix):
|
||||
for judge, data in matrix.items():
|
||||
name_tuple = judges[judge].rpartition(".")
|
||||
groups[name_tuple[0] or name_tuple[-1]].append((judges[judge], data))
|
||||
|
||||
matrix = {}
|
||||
for group, data in six.iteritems(groups):
|
||||
for group, data in groups.items():
|
||||
if len(data) == 1:
|
||||
judge, data = data[0]
|
||||
matrix[judge] = data
|
||||
|
@ -102,14 +101,14 @@ def version_matrix(request):
|
|||
if ds[i] != rep:
|
||||
matrix[j] = x
|
||||
|
||||
for data in six.itervalues(matrix):
|
||||
for language, versions in six.iteritems(data):
|
||||
for data in matrix.values():
|
||||
for language, versions in data.items():
|
||||
versions.versions = [version.parse(runtime.version) for runtime in versions]
|
||||
if versions.versions > latest[language]:
|
||||
latest[language] = versions.versions
|
||||
|
||||
for data in six.itervalues(matrix):
|
||||
for language, versions in six.iteritems(data):
|
||||
for data in matrix.values():
|
||||
for language, versions in data.items():
|
||||
versions.is_latest = versions.versions == latest[language]
|
||||
|
||||
languages = sorted(languages, key=lambda lang: version.parse(lang.name))
|
||||
|
|
|
@ -391,6 +391,7 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
|
|||
params=[],
|
||||
join_fields=[("problem_id", "id")],
|
||||
alias="visible_problems",
|
||||
related_model=Problem,
|
||||
)
|
||||
return queryset
|
||||
|
||||
|
|
|
@ -232,7 +232,10 @@ class HeavySelect2Mixin(Select2Mixin):
|
|||
chosen.queryset = chosen.queryset.filter(
|
||||
pk__in=[int(i) for i in result if isinstance(i, int) or i.isdigit()]
|
||||
)
|
||||
self.choices = set(chosen)
|
||||
self.choices = {
|
||||
(value if isinstance(value, str) else value.value, label)
|
||||
for value, label in chosen
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
Django>=2.2,<3
|
||||
django_compressor
|
||||
django-mptt
|
||||
Django>=3.2,<4
|
||||
django_compressor>=3
|
||||
django-mptt>=0.13
|
||||
django-pagedown
|
||||
django-registration-redux
|
||||
django-reversion
|
||||
django-registration-redux>=2.10
|
||||
django-reversion>=3.0.5,<4
|
||||
django-reversion-compare
|
||||
django-social-share
|
||||
django-sortedm2m @ git+https://github.com/DMOJ/django-sortedm2m.git
|
||||
django-sortedm2m>=3.1.0
|
||||
django-impersonate
|
||||
dmoj-wpadmin @ git+https://github.com/LQDJudge/dmoj-wpadmin.git
|
||||
lxml
|
||||
|
@ -18,13 +18,13 @@ pika
|
|||
ua-parser
|
||||
pyyaml
|
||||
jinja2
|
||||
django_jinja
|
||||
django_jinja>=2.5.0
|
||||
llist
|
||||
requests
|
||||
django-fernet-fields
|
||||
pyotp
|
||||
qrcode[pil]
|
||||
jsonfield
|
||||
jsonfield @ git+https://github.com/DMOJ/jsonfield.git
|
||||
pymoss
|
||||
packaging
|
||||
celery
|
||||
|
|
Loading…
Reference in a new issue