-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make site logo configurable in
misc_config
- Loading branch information
1 parent
261841b
commit 65e1cb4
Showing
9 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.23 on 2024-01-12 10:16 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('judge', '0202_import_polygon_package'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='miscconfig', | ||
name='key', | ||
field=models.CharField(max_length=30, unique=True, verbose_name='key'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django import forms | ||
from django.db import transaction | ||
from django.http import Http404 | ||
from django.urls import reverse | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.views.generic import FormView | ||
|
||
from judge.models import MiscConfig | ||
from judge.utils.views import TitleMixin | ||
from judge.views.widgets import static_uploader | ||
|
||
|
||
class MiscConfigForm(forms.Form): | ||
logo = forms.FileField(help_text='The site logo e.g. the image in the top left corner.') | ||
|
||
|
||
class MiscConfigEdit(TitleMixin, FormView): | ||
template_name = 'misc_config/edit.html' | ||
form_class = MiscConfigForm | ||
title = _('Site settings') | ||
|
||
def get_success_url(self): | ||
return reverse('home') | ||
|
||
def form_valid(self, form): | ||
with transaction.atomic(): | ||
logo = form.files.get('logo', default=None) | ||
if logo is not None: | ||
logo_url = static_uploader(logo) | ||
config, _ = MiscConfig.objects.update_or_create(key='site_logo', defaults={'value': logo_url}) | ||
config.save() | ||
return super().form_valid(form) | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
if not request.user.is_superuser: | ||
raise Http404 | ||
return super().dispatch(request, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block js_media %} | ||
{{ form.media.js }} | ||
{% endblock %} | ||
|
||
{% block media %} | ||
{{ form.media.css }} | ||
<link rel="stylesheet" type="text/css" href="{{ static('ui_form.css') }}"> | ||
<style> | ||
.hidden { | ||
display: none; | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
{% block body %} | ||
<div> | ||
{% if request.user.is_staff %} | ||
<div class="alert alert-warning alert-dismissable"> | ||
<a class="close">x</a> | ||
<a href="{{ url('admin:judge_miscconfig_changelist') }}">{{ _('Configure in admin panel for more options') }}</a> | ||
</div> | ||
{% endif %} | ||
<form action="" method="post" class="form-area" enctype="multipart/form-data" style="display: flex; justify-content: center; flex-direction: column;"> | ||
{% if form.errors %} | ||
<p class="errornote"> {{ _('Please correct the error below.') }}</p> | ||
{% endif %} | ||
{% csrf_token %} | ||
<table class="django-as-table">{{ form.as_table() }}</table> | ||
<table> | ||
<tr><td style="float: left;"> | ||
<td style="float: right;"><input type="submit" value="{{ _('Update') }}" class="button"></td></tr> | ||
</table> | ||
</form> | ||
</div> | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters