Skip to content

Commit

Permalink
add youtube link to search results
Browse files Browse the repository at this point in the history
  • Loading branch information
DasUnicorn committed Aug 31, 2023
1 parent dcb8dc0 commit 17e5e57
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
48 changes: 26 additions & 22 deletions templates/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@
<section class="fullSection">
<p class="padding">Die Buchstabenkombination <b>"{{query}}"</b> konnte {{results.count}} Mal gefunden werden.</p>
<form action="/search/" method="GET" class="gridCenter">
<div class="padding small">
<input name="q" type="text" placeholder="Suchwort" class="searchInput" id="floatingInput" />
<div class="input-group-append">
<button class="searching" type="submit">Suchen</button>
</div>
</div>
<div class="padding small">
<input name="q" type="text" placeholder="Suchwort" class="searchInput" id="floatingInput" />
<div class="input-group-append">
<button class="searching" type="submit">Suchen</button>
</div>
</div>
</form>

<table class="padding">
<thead>
<tr>
<th scope="col">Episode</th>
<th scope="col">Zeit</th>
<th scope="col">Sprecher:in</th>
<th scope="col">Text</th>
</tr>
</thead>
<tbody>
{% for result in results %}
<thead>
<tr>
<th scope="row">{{result.episode.number}}</th>
<td>{{result.start_time}}</td>
<td>{{result.speaker.name}}</td>
<td>{{result.text}}</td>
<th scope="col">Episode</th>
<th scope="col">Zeit</th>
<th scope="col">Sprecher:in</th>
<th scope="col">Text</th>
</tr>
</thead>
<tbody>
{% for result in results %}
<tr>
<th scope="row">{{result.episode.number}}</th>
{% if result.youtube_link %}
<td><a href="{{ result.youtube_link }}" target="_blank" rel="noopener noreferrer">{{result.start_time}}</a></td>
{% else %}
<td>{{result.start_time}}</td>
{% endif %}
<td>{{result.speaker.name}}</td>
<td>{{result.text}}</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</tbody>
</table>
</section>

Expand Down
18 changes: 18 additions & 0 deletions wordsearch/migrations/0017_episode_youtube_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.4 on 2023-08-31 15:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('wordsearch', '0016_line_words'),
]

operations = [
migrations.AddField(
model_name='episode',
name='youtube_id',
field=models.CharField(blank=True, max_length=20, null=True),
),
]
7 changes: 7 additions & 0 deletions wordsearch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Episode(models.Model):
duration = models.DurationField(default=timedelta)
spoken_time = models.DurationField(default=timedelta)
spoken_words = models.PositiveIntegerField(default=0)
youtube_id = models.CharField(null=True, blank=True, max_length=20)

def __str__(self):
return f'Episode {self.number}'
Expand All @@ -40,6 +41,12 @@ class Line(models.Model):
def duration(self):
return self.end_time - self.start_time

def youtube_link(self):
if not self.episode.youtube_id:
return None
time = int(self.start_time.total_seconds())
return f"https://www.youtube.com/watch?v={self.episode.youtube_id}&t={time}"

def __str__(self):
return self.text

Expand Down
4 changes: 1 addition & 3 deletions wordsearch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def index(request):
def search_results(request):
query = request.GET.get("q")
results = Line.objects.filter(text__icontains=query)

return render(request, 'search_results.html', {"results": results, "query": query})

def impressum(request):
Expand Down Expand Up @@ -67,7 +68,6 @@ def data(request):
min_time_esp_name = spoken_time_min.get('episode')
min_time_esp = spoken_time_min.get('time')


#Spoken time by gender
spoken_time_female = duration_per_line.filter(speaker__gender="female").aggregate(Sum('time'))
spoken_time_male = duration_per_line.filter(speaker__gender="male").aggregate(Sum('time'))
Expand All @@ -84,8 +84,6 @@ def data(request):
min_speaker_time = min_speaker.get('time')




return render(request, 'data.html', {
"speaker_number": speaker_number,
"episode_number": episode_number,
Expand Down

0 comments on commit 17e5e57

Please sign in to comment.