Fix broken installation

This commit is contained in:
cuom1999 2021-07-08 16:03:51 -05:00
parent 0161a98d32
commit 7db78177c1
5 changed files with 13 additions and 4 deletions

View file

@ -30,7 +30,7 @@ class JudgeAppConfig(AppConfig):
from django.contrib.auth.models import User from django.contrib.auth.models import User
try: try:
lang = Language.get_python3() lang = Language.get_default_language()
for user in User.objects.filter(profile=None): for user in User.objects.filter(profile=None):
# These poor profileless users # These poor profileless users
profile = Profile(user=user, language=lang) profile = Profile(user=user, language=lang)

View file

@ -6,6 +6,11 @@ from django.db import migrations, models
import judge.models.runtime import judge.models.runtime
def create_python3(apps, schema_editor):
Language = apps.get_model('judge', 'Language')
Language.objects.get_or_create(key='PY3', defaults={'name': 'Python 3'})[0]
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@ -13,6 +18,7 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(create_python3, reverse_code=migrations.RunPython.noop),
migrations.AlterField( migrations.AlterField(
model_name='profile', model_name='profile',
name='language', name='language',

View file

@ -97,7 +97,10 @@ class Language(models.Model):
@classmethod @classmethod
def get_default_language(cls): def get_default_language(cls):
return Language.objects.get(key=settings.DEFAULT_USER_LANGUAGE) try:
return Language.objects.get(key=settings.DEFAULT_USER_LANGUAGE)
except Language.DoesNotExist:
return cls.get_python3()
@classmethod @classmethod
def get_default_language_pk(cls): def get_default_language_pk(cls):

View file

@ -83,7 +83,7 @@ def make_profile(backend, user, response, is_new=False, *args, **kwargs):
if is_new: if is_new:
if not hasattr(user, 'profile'): if not hasattr(user, 'profile'):
profile = Profile(user=user) profile = Profile(user=user)
profile.language = Language.get_python3() profile.language = Language.get_default_language()
logger.info('Info from %s: %s', backend.name, response) logger.info('Info from %s: %s', backend.name, response)
profile.save() profile.save()
form = ProfileForm(instance=profile, user=user) form = ProfileForm(instance=profile, user=user)

View file

@ -81,7 +81,7 @@ class RegistrationView(OldRegistrationView):
def register(self, form): def register(self, form):
user = super(RegistrationView, self).register(form) user = super(RegistrationView, self).register(form)
profile, _ = Profile.objects.get_or_create(user=user, defaults={ profile, _ = Profile.objects.get_or_create(user=user, defaults={
'language': Language.get_python3(), 'language': Language.get_default_language(),
}) })
cleaned_data = form.cleaned_data cleaned_data = form.cleaned_data