Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.2.17 on 2026-11-30 15:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('office', '0012_contestoffice_office_explanation_we_vote_id_and_more'),
]

operations = [
migrations.AddField(
model_name='officeexplanation',
name='youtube_url_horizontal',
field=models.TextField(null=True),
),
migrations.AddField(
model_name='officeexplanation',
name='youtube_url_vertical',
field=models.TextField(null=True),
),
]
2 changes: 2 additions & 0 deletions office/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@
DoesNotExist = None
MultipleObjectsReturned = None
objects = None
we_vote_id = models.CharField(
verbose_name="we vote permanent id for this contest office", max_length=255, default=None, null=True,
blank=True, unique=True)

Check failure on line 141 in office/models.py

View workflow job for this annotation

GitHub Actions / Ruff

ruff (django-unordered-body-content-in-model)

office/models.py:139:5: django-unordered-body-content-in-model: Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before manager declaration
# The name of the office for this contest.
office_name = models.CharField(verbose_name="name of the office", max_length=255, null=False, blank=False)
date_last_updated = models.DateTimeField(null=True, auto_now=True)
Expand Down Expand Up @@ -297,23 +297,23 @@
return ""

# We override the save function, so we can auto-generate we_vote_id
def save(self, *args, **kwargs):
# Even if this data came from another source we still need a unique we_vote_id
if self.we_vote_id:
self.we_vote_id = self.we_vote_id.strip().lower()
if self.we_vote_id == "" or self.we_vote_id is None: # If there isn't a value...
# ...generate a new id
site_unique_id_prefix = fetch_site_unique_id_prefix()
next_local_integer = fetch_next_we_vote_id_contest_office_integer()
# "wv" = We Vote
# site_unique_id_prefix = a generated (or assigned) unique id for one server running We Vote
# "off" = tells us this is a unique id for a ContestOffice
# next_integer = a unique, sequential integer for this server - not necessarily tied to database id
self.we_vote_id = "wv{site_unique_id_prefix}off{next_integer}".format(
site_unique_id_prefix=site_unique_id_prefix,
next_integer=next_local_integer,
)
super(ContestOffice, self).save(*args, **kwargs)

Check failure on line 316 in office/models.py

View workflow job for this annotation

GitHub Actions / Ruff

ruff (django-unordered-body-content-in-model)

office/models.py:300:5: django-unordered-body-content-in-model: Order of model's inner classes, methods, and fields does not follow the Django Style Guide: `save` method should come before custom method


class ContestOfficeManager(models.Manager):
Expand Down Expand Up @@ -1946,8 +1946,8 @@
MultipleObjectsReturned = None
DoesNotExist = None
objects = None
contest_office1_we_vote_id = models.CharField(
verbose_name="first contest office we are tracking", max_length=255, null=True, unique=False, db_index=True)

Check failure on line 1950 in office/models.py

View workflow job for this annotation

GitHub Actions / Ruff

ruff (django-unordered-body-content-in-model)

office/models.py:1949:5: django-unordered-body-content-in-model: Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before manager declaration
contest_office2_we_vote_id = models.CharField(
verbose_name="second contest office we are tracking", max_length=255, null=True, unique=False, db_index=True)

Expand Down Expand Up @@ -2056,13 +2056,15 @@
MultipleObjectsReturned = None
objects = None

date_last_updated = models.DateTimeField(null=True, auto_now=True)

Check failure on line 2059 in office/models.py

View workflow job for this annotation

GitHub Actions / Ruff

ruff (django-unordered-body-content-in-model)

office/models.py:2059:5: django-unordered-body-content-in-model: Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before manager declaration
office_explanation = models.TextField(null=True)
office_explanation_name = models.CharField(max_length=255, null=False)
state_code = models.CharField(max_length=2, null=True)
video_url_horizontal = models.TextField(null=True)
video_url_square = models.TextField(null=True)
video_url_vertical = models.TextField(null=True)
youtube_url_horizontal = models.TextField(null=True)
youtube_url_vertical = models.TextField(null=True)
we_vote_id = models.CharField(max_length=255, default=None, null=True, unique=True)

class Meta:
Expand Down
6 changes: 6 additions & 0 deletions office/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,8 @@ def office_explanation_process_view(request):
office_video_url_horizontal = request.POST.get('video_url_horizontal', '')
office_video_url_square = request.POST.get('video_url_square', '')
office_video_url_vertical = request.POST.get('video_url_vertical', '')
office_youtube_url_horizontal = request.POST.get('youtube_url_horizontal', '')
office_youtube_url_vertical = request.POST.get('youtube_url_vertical', '')
contest_office_search = request.POST.get('contest_office_search', '')
office_held_search = request.POST.get('office_held_search', '')
we_vote_id = request.POST.get('we_vote_id', '')
Expand Down Expand Up @@ -2571,6 +2573,8 @@ def office_explanation_process_view(request):
video_url_horizontal=office_video_url_horizontal,
video_url_square=office_video_url_square,
video_url_vertical=office_video_url_vertical,
youtube_url_horizontal=office_youtube_url_horizontal,
youtube_url_vertical=office_youtube_url_vertical,
state_code=state_code,
we_vote_id=None,
)
Expand All @@ -2583,6 +2587,8 @@ def office_explanation_process_view(request):
office_explanation.video_url_horizontal = office_video_url_horizontal
office_explanation.video_url_square = office_video_url_square
office_explanation.video_url_vertical = office_video_url_vertical
office_explanation.youtube_url_horizontal = office_youtube_url_horizontal
office_explanation.youtube_url_vertical = office_youtube_url_vertical
office_explanation.state_code = state_code
office_explanation.save()
messages.add_message(request, messages.INFO, 'Office explanation updated.')
Expand Down
73 changes: 59 additions & 14 deletions templates/office/office_explanation_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
value="{% if office_explanation %}{{ office_explanation.video_url_horizontal|default_if_none:'' }}{% else %}{{ video_url_horizontal|default_if_none:'' }}{% endif %}" />
</div>
</div>

<div class="form-group">
<label for="youtube_url_horizontal_id" class="col-sm-3 control-label">YouTube Video URL (Horizontal)</label>
<div class="col-sm-8">
<input type="text"
name="youtube_url_horizontal"
id="youtube_url_horizontal_id"
class="form-control"
value="{% if office_explanation %}{{ office_explanation.youtube_url_horizontal|default_if_none:'' }}{% else %}{{ youtube_url_horizontal|default_if_none:'' }}{% endif %}" />
</div>
</div>

<div class="form-group">
<label for="video_url_square_id" class="col-sm-3 control-label">Video URL (Square)</label>
Expand All @@ -99,12 +110,23 @@
value="{% if office_explanation %}{{ office_explanation.video_url_vertical|default_if_none:'' }}{% else %}{{ video_url_vertical|default_if_none:'' }}{% endif %}" />
</div>
</div>

<div class="form-group">
<label for="youtube_url_vertical_id" class="col-sm-3 control-label">YouTube Video URL (Vertical)</label>
<div class="col-sm-8">
<input type="text"
name="youtube_url_vertical"
id="youtube_url_vertical_id"
class="form-control"
value="{% if office_explanation %}{{ office_explanation.youtube_url_vertical|default_if_none:'' }}{% else %}{{ youtube_url_vertical|default_if_none:'' }}{% endif %}" />
</div>
</div>

{# Optional: show date_last_updated read-only if desired #}
{% if office_explanation and office_explanation.date_last_updated %}
<div class="form-group">
<label class="col-sm-3 control-label">Last Updated</label>
<div class="col-sm-8" style="padding-top: 7px;">{{ office_explanation.date_last_updated }}</div>

Check warning on line 129 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
</div>
{% endif %}

Expand Down Expand Up @@ -144,8 +166,8 @@

{# Optional list table, following your Measure template pattern #}
{% if office_explanation_list %}
<br />
<br />

Check warning on line 170 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H036 Do not use br tags for spacing.
<h5>Existing Office Explanations</h5>
<table border="1" cellpadding="5" cellspacing="5">
<tr>
Expand All @@ -162,8 +184,8 @@
<td>{{ one.state_code }}</td>
<td>{{ one.we_vote_id }}</td>
<td>
<a href="{% url 'office:office_explanation_edit_process' one.we_vote_id %}"
style="font-size: .65em">edit</a>

Check warning on line 188 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
</td>
</tr>
{% endfor %}
Expand All @@ -175,8 +197,8 @@
<div class="form-group clearfix">
<label class="col-sm-3 control-label">Video Preview</label>
<div class="col-sm-8">
<div style="border:1px solid #ddd; padding:10px; border-radius:4px;">

Check warning on line 200 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
<div style="margin-bottom:8px; font-size:.9em;">

Check warning on line 201 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
Previewing:
<button type="button"
class="btn btn-default btn-xs"
Expand All @@ -185,17 +207,27 @@
<button type="button"
class="btn btn-default btn-xs"
id="preview_vertical_btn">Vertical</button>
{% if office_explanation.youtube_url_horizontal %}
<button type="button"
class="btn btn-default btn-xs"
id="preview_horizontal_youtube_btn">HorizontalYT</button>
{% endif %}
{% if office_explanation.youtube_url_vertical %}
<button type="button"
class="btn btn-default btn-xs"
id="preview_vertical_youtube_btn">VerticalYT</button>
{% endif %}
</div>

<div id="video_preview_wrapper" style="width:100%; max-width:720px;">

Check warning on line 222 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
<div id="video_preview_aspect"
style="position:relative;

Check warning on line 224 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
width:100%;
padding-top:56.25%">
<iframe id="video_preview_iframe"
src=""

Check warning on line 228 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H056 Src should not be empty.
referrerpolicy="origin-when-cross-origin"
style="position:absolute;

Check warning on line 230 in templates/office/office_explanation_edit.html

View workflow job for this annotation

GitHub Actions / djlint

H021 Inline styles should be avoided.
top:0;
left:0;
width:100%;
Expand All @@ -222,6 +254,8 @@
const horizontalInput = document.getElementById('video_url_horizontal_id');
const squareInput = document.getElementById('video_url_square_id');
const verticalInput = document.getElementById('video_url_vertical_id');
const horizontal_youtubeInput = document.getElementById('youtube_url_horizontal_id');
const vertical_youtubeInput = document.getElementById('youtube_url_vertical_id');

// Preview elements
const iframe = document.getElementById('video_preview_iframe');
Expand All @@ -232,25 +266,31 @@
const btnH = document.getElementById('preview_horizontal_btn');
const btnS = document.getElementById('preview_square_btn');
const btnV = document.getElementById('preview_vertical_btn');
const btnHYT = document.getElementById('preview_horizontal_youtube_btn');
const btnVYT = document.getElementById('preview_vertical_youtube_btn');

// Keep track of selected source (default horizontal)
let active = 'horizontal';
// Keep track of selected source (default horizontal_youtube if present, else horizontal)
let active = btnHYT ? 'horizontal_youtube' : 'horizontal';

function setActiveButton() {
// Simple visual cue without needing extra CSS
[btnH, btnS, btnV].forEach(b => b.classList.remove('btn-primary'));
[btnH, btnS, btnV].forEach(b => b.classList.add('btn-default'));

if (active === 'horizontal') btnH.classList.add('btn-primary');
if (active === 'square') btnS.classList.add('btn-primary');
if (active === 'vertical') btnV.classList.add('btn-primary');
[btnH, btnS, btnV, btnHYT, btnVYT].filter(Boolean).forEach(b => {
b.classList.remove('btn-primary');
b.classList.add('btn-default');
});

if (active === 'horizontal' && btnH) btnH.classList.add('btn-primary');
if (active === 'square' && btnS) btnS.classList.add('btn-primary');
if (active === 'vertical' && btnV) btnV.classList.add('btn-primary');
if (active === 'horizontal_youtube' && btnHYT) btnHYT.classList.add('btn-primary');
if (active === 'vertical_youtube' && btnVYT) btnVYT.classList.add('btn-primary');
}

function setAspectRatio(mode) {
// horizontal 16:9, square 1:1, vertical 9:16
let paddingTop = '56.25%'; // 16:9
if (mode === 'square') paddingTop = '100%';
if (mode === 'vertical') paddingTop = '177.78%'; // 16/9 * 100
if (mode === 'vertical' || mode === 'vertical_youtube') paddingTop = '177.78%'; // 16/9 * 100
aspectBox.style.paddingTop = paddingTop;
}

Expand All @@ -264,7 +304,8 @@
const ytMatch =
url.match(/youtu\.be\/([A-Za-z0-9_-]{6,})/) ||
url.match(/youtube\.com\/watch\?v=([A-Za-z0-9_-]{6,})/) ||
url.match(/youtube\.com\/embed\/([A-Za-z0-9_-]{6,})/);
url.match(/youtube\.com\/embed\/([A-Za-z0-9_-]{6,})/) ||
url.match(/youtube\.com\/shorts\/([A-Za-z0-9_-]{6,})/);

if (ytMatch && ytMatch[1]) {
return 'https://www.youtube.com/embed/' + ytMatch[1];
Expand All @@ -289,6 +330,8 @@
if (active === 'horizontal') return horizontalInput?.value || '';
if (active === 'square') return squareInput?.value || '';
if (active === 'vertical') return verticalInput?.value || '';
if (active === 'horizontal_youtube') return horizontal_youtubeInput?.value || '';
if (active === 'vertical_youtube') return vertical_youtubeInput?.value || '';
return '';
}

Expand All @@ -312,12 +355,14 @@
}

// Button handlers
btnH.addEventListener('click', function() { active = 'horizontal'; renderPreview(); });
btnS.addEventListener('click', function() { active = 'square'; renderPreview(); });
btnV.addEventListener('click', function() { active = 'vertical'; renderPreview(); });
if (btnH) btnH.addEventListener('click', function() { active = 'horizontal'; renderPreview(); });
if (btnS) btnS.addEventListener('click', function() { active = 'square'; renderPreview(); });
if (btnV) btnV.addEventListener('click', function() { active = 'vertical'; renderPreview(); });
if (btnHYT) btnHYT.addEventListener('click', function() { active = 'horizontal_youtube'; renderPreview(); });
if (btnVYT) btnVYT.addEventListener('click', function() { active = 'vertical_youtube'; renderPreview(); });

// Live update when URLs change
[horizontalInput, squareInput, verticalInput].forEach(function(input) {
[horizontalInput, squareInput, verticalInput, horizontal_youtubeInput, vertical_youtubeInput].forEach(function(input) {
if (!input) return;
input.addEventListener('input', renderPreview);
input.addEventListener('change', renderPreview);
Expand Down
19 changes: 15 additions & 4 deletions templates/office/office_explanations_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,21 @@ <h1>Office Explanations</h1>
</td>
<td>{{ office.state_code }}</td>
<td>{{ office.office_explanation|default:"(no explanation)"|truncatechars:120 }}</td>
<td class="u-wrap-links">
H: {% if office.video_url_horizontal %}<a href="{{ office.video_url_horizontal }}" target="_blank" class="u-wrap-links">{{ office.video_url_horizontal }}</a>{% else %}(no url){% endif %}<br>
S: {% if office.video_url_square %}<a href="{{ office.video_url_square }}" target="_blank" class="u-wrap-links">{{ office.video_url_square }}</a>{% else %}(no url){% endif %}<br>
V: {% if office.video_url_vertical %}<a href="{{ office.video_url_vertical }}" target="_blank" class="u-wrap-links">{{ office.video_url_vertical }}</a>{% else %}(no url){% endif %}
<td>
<div>
H: {% if office.video_url_horizontal %}<a href="{{ office.video_url_horizontal }}" target="_blank" rel="noopener noreferrer" title="{{ office.video_url_horizontal }}">Vimeo</a>{% endif %}
{% if office.video_url_horizontal and office.youtube_url_horizontal %} || {% endif %}
{% if office.youtube_url_horizontal %}<a href="{{ office.youtube_url_horizontal }}" target="_blank" rel="noopener noreferrer" title="{{ office.youtube_url_horizontal }}">YouTube</a>{% endif %}
{% if not office.video_url_horizontal and not office.youtube_url_horizontal %} (no url) {% endif %}
<br>
</div>
S: {% if office.video_url_square %}<a href="{{ office.video_url_square }}" target="_blank" rel="noopener noreferrer" title="{{ office.video_url_square }}">Vimeo</a>{% else %}(no url){% endif %}
<div>
V: {% if office.video_url_vertical %}<a href="{{ office.video_url_vertical }}" target="_blank" rel="noopener noreferrer" title="{{ office.video_url_vertical }}">Vimeo</a>{% endif %}
{% if office.video_url_vertical and office.youtube_url_vertical %} || {% endif %}
{% if office.youtube_url_vertical %}<a href="{{ office.youtube_url_vertical }}" target="_blank" rel="noopener noreferrer" title="{{ office.youtube_url_vertical }}">YouTube</a>{% endif %}
{% if not office.video_url_vertical and not office.youtube_url_vertical %} (no url) {% endif %}
</div>
</td>
<td>
<a href="{% url 'office:office_explanation_contest_office_link' office.we_vote_id %}">Contest Office(s) to Link</a> (Linked: {{office.contest_office_links}})
Expand Down
Loading