Implement organization logo override; closes #803 (#1133)

This commit is contained in:
Evan Zhang 2019-10-26 12:34:53 -04:00 committed by Tudor Brindus
parent 3ed9ca9379
commit 3923b7580b
8 changed files with 37 additions and 4 deletions

View File

@ -21,7 +21,8 @@ class OrganizationForm(ModelForm):
class OrganizationAdmin(VersionAdmin):
readonly_fields = ('creation_date',)
fields = ('name', 'slug', 'short_name', 'is_open', 'about', 'slots', 'registrant', 'creation_date', 'admins')
fields = ('name', 'slug', 'short_name', 'is_open', 'about', 'logo_override_image', 'slots', 'registrant',
'creation_date', 'admins')
list_display = ('name', 'short_name', 'is_open', 'slots', 'registrant', 'show_public')
prepopulated_fields = {'slug': ('name',)}
actions_on_top = True

View File

@ -86,7 +86,7 @@ class ProblemSubmitForm(ModelForm):
class EditOrganizationForm(ModelForm):
class Meta:
model = Organization
fields = ['about', 'admins']
fields = ['about', 'logo_override_image', 'admins']
widgets = {'admins': Select2MultipleWidget()}
if HeavyPreviewPageDownWidget is not None:
widgets['about'] = HeavyPreviewPageDownWidget(preview=reverse_lazy('organization_preview'))

View File

@ -4,4 +4,6 @@ from . import registry
@registry.filter
def camo(url):
if camo_client is None:
return url
return camo_client.image_url(url)

View File

@ -0,0 +1,18 @@
# Generated by Django 2.1.12 on 2019-10-23 00:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('judge', '0094_submissiontestcase_unique_together'),
]
operations = [
migrations.AddField(
model_name='organization',
name='logo_override_image',
field=models.CharField(blank=True, default='', help_text='This image will replace the default site logo for users viewing the organization.', max_length=150, verbose_name='Logo override image'),
),
]

View File

@ -44,6 +44,10 @@ class Organization(models.Model):
'only applicable to private organizations'))
access_code = models.CharField(max_length=7, help_text=_('Student access code'),
verbose_name=_('access code'), null=True, blank=True)
logo_override_image = models.CharField(verbose_name=_('Logo override image'), default='', max_length=150,
blank=True,
help_text=_('This image will replace the default site logo for users '
'viewing the organization.'))
def __contains__(self, item):
if isinstance(item, int):

View File

@ -167,6 +167,9 @@ class ContestMixin(object):
context['meta_description'] = self.object.summary or metadata[0]
context['og_image'] = self.object.og_image or metadata[1]
context['has_moss_api_key'] = settings.MOSS_API_KEY is not None
context['logo_override_image'] = self.object.logo_override_image
if not context['logo_override_image'] and self.object.organizations.count() == 1:
context['logo_override_image'] = self.object.organizations.first().logo_override_image
return context

View File

@ -30,6 +30,11 @@ class OrganizationMixin(object):
context_object_name = 'organization'
model = Organization
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['logo_override_image'] = self.object.logo_override_image
return context
def dispatch(self, request, *args, **kwargs):
try:
return super(OrganizationMixin, self).dispatch(request, *args, **kwargs)

View File

@ -1,7 +1,7 @@
{% if request.in_contest and request.participation.contest.logo_override_image %}
<img src="{{ request.participation.contest.logo_override_image|camo }}" alt="{{ SITE_NAME }}" height="44" style="border: none">
{% elif contest is defined and contest.logo_override_image %}
<img src="{{ contest.logo_override_image|camo }}" alt="{{ SITE_NAME }}" height="44" style="border: none">
{% elif logo_override_image is defined and logo_override_image %}
<img src="{{ logo_override_image|camo }}" alt="{{ SITE_NAME }}" height="44" style="border: none">
{% else %}
<img src="{{ static('icons/logo.svg') }}" alt="{{ SITE_NAME }}" width="160" height="44"
onerror="this.src=&quot;{{ static('icons/logo.png') }}&quot;; this.onerror=null" style="border: none">