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

Bootstrap Upgrade #72

Merged
merged 13 commits into from
Jun 20, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ external-repos/
.env
volumes
.ruff_cache
.idea/
20 changes: 11 additions & 9 deletions ctfpad/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,17 @@ def ctftime_get_ctf_logo_url(ctftime_id: int) -> str:
str: [description]
"""
default_logo = f"{STATIC_URL}images/{CTFPAD_DEFAULT_CTF_LOGO}"
try:
ctf_info = ctftime_get_ctf_info(ctftime_id)
logo = ctf_info.setdefault("logo", default_logo)
_, ext = os.path.splitext(logo)
if ext.lower() not in CTFPAD_ACCEPTED_IMAGE_EXTENSIONS:
return default_logo
except ValueError:
logo = default_logo
return logo
if ctftime_id != 0:
try:
ctf_info = ctftime_get_ctf_info(ctftime_id)
logo = ctf_info.setdefault("logo", default_logo)
_, ext = os.path.splitext(logo)
if ext.lower() not in CTFPAD_ACCEPTED_IMAGE_EXTENSIONS:
return default_logo
except ValueError:
logo = default_logo
return logo
return default_logo


def send_mail(recipients: list, subject: str, body: str) -> bool:
Expand Down
324 changes: 155 additions & 169 deletions ctfpad/templates/ctfpad/challenges/create.html

Large diffs are not rendered by default.

393 changes: 208 additions & 185 deletions ctfpad/templates/ctfpad/challenges/detail.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ctfpad/templates/ctfpad/challenges/files/create.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ form.errors }}
{% include 'snippets/formerror.html' %}
54 changes: 12 additions & 42 deletions ctfpad/templates/ctfpad/challenges/import.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'ctfpad/main.html' %}
{% load static %}

{% block content %}
<br/>
Expand Down Expand Up @@ -40,65 +41,34 @@ <h5 class="card-title">

<label for="{{ form.data.id_for_label }}" class="label"><strong>Data</strong></label>
<div class="input-group mb-3">
<div class="input-group-append">
<span class="input-group-text">
<i class="fas fa-file-import"></i>
</span>
</div>
<textarea id="{{ form.data.id_for_label }}"
name="{{ form.data.html_name }}"
placeholder="Data"
class="form-control"
required>{% if form.data.value %}
{{ form.data.value }}{% endif %}</textarea>
required>{% if form.data.value %}{{ form.data.value }}{% endif %}</textarea>
</div>
</div>

<div class="card-footer text-muted">
<div class="control card-footer-item">
<button type="button" class="btn-primary btn-sm btn-block"
onclick="this.form.submit();">Import Challenges
</button>
<button type="button" class="btn btn-secondary btn-sm btn-block"
onclick="window.history.back();">Cancel
</button>
<div class="d-grid gap-2">
<button type="button" class="btn btn-primary btn-sm"
onclick="this.form.submit();">Import Challenges
</button>
<button type="button" class="btn btn-secondary btn-sm"
onclick="window.history.back();">Cancel
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
var formatSelect = document.getElementById('{{ form.format.id_for_label }}');
var dataTextArea = document.getElementById('{{ form.data.id_for_label }}');

formatSelect.addEventListener('change', function () {
var selectedFormat = this.value;
var placeholderText;

switch (selectedFormat) {
case 'RAW':
placeholderText = 'name | category';
break;
case 'CTFd':
placeholderText = 'paste CTFd JSON /api/v1/challenges';
break;
case 'rCTF':
placeholderText = 'paste rCTF JSON /api/v1/challs';
break;
default:
placeholderText = '';
}

dataTextArea.setAttribute('placeholder', placeholderText);
});

// Trigger the change event on page load to set initial placeholder
formatSelect.dispatchEvent(new Event('change'));
});
</script>


<script src="{% static '/js/challenge.js' %}"></script>
{% endblock %}
Loading