Skip to content

Commit

Permalink
Talk
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuspdf committed Jun 19, 2024
1 parent aa68cec commit addc504
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 11 deletions.
3 changes: 2 additions & 1 deletion eventex/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from eventex.core.models import Speaker, Contact
from eventex.core.models import Speaker, Contact, Talk
from django.contrib import admin
from django.utils.html import format_html

Expand All @@ -25,3 +25,4 @@ def photo_img(self, obj):


admin.site.register(Speaker, SpeakerModelAdmin)
admin.site.register(Talk)
31 changes: 31 additions & 0 deletions eventex/core/migrations/0005_talk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.0.3 on 2024-06-13 22:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0004_alter_contact_options_alter_contact_kind_and_more"),
]

operations = [
migrations.CreateModel(
name="Talk",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=200)),
("start", models.TimeField()),
("description", models.TextField()),
("speakers", models.ManyToManyField(to="core.speaker")),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.0.3 on 2024-06-13 22:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0005_talk"),
]

operations = [
migrations.AlterModelOptions(
name="talk",
options={"verbose_name": "palestra", "verbose_name_plural": "palestras"},
),
migrations.AlterField(
model_name="talk",
name="description",
field=models.TextField(blank=True, verbose_name="descrição"),
),
migrations.AlterField(
model_name="talk",
name="speakers",
field=models.ManyToManyField(
blank=True, to="core.speaker", verbose_name="palestrantes"
),
),
migrations.AlterField(
model_name="talk",
name="start",
field=models.TimeField(blank=True, null=True, verbose_name="início"),
),
migrations.AlterField(
model_name="talk",
name="title",
field=models.CharField(max_length=200, verbose_name="Título"),
),
]
14 changes: 14 additions & 0 deletions eventex/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ class Meta:

def __str__(self):
return self.value


class Talk(models.Model):
title = models.CharField('Título', max_length=200)
start = models.TimeField('início', blank=True, null=True)
description = models.TextField('descrição', blank=True)
speakers = models.ManyToManyField('Speaker', verbose_name='palestrantes', blank=True)

class Meta:
verbose_name_plural = 'palestras'
verbose_name = 'palestra'

def __str__(self):
return self.title
10 changes: 10 additions & 0 deletions eventex/core/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,15 @@ section header h2 {
padding-right: 40px;
}

.talks h3{
padding: 0;
min-height: 0;
}

.talks h4{
min-height: 1em;
font-size: 1em;
padding: 0;
margin: 0;
}
/* Fim Customização */
12 changes: 6 additions & 6 deletions eventex/core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<!-- CSS -->

<!-- <style>-->
<!-- @import url('{% static 'fonts/Tiny5-Regular.ttf' %}');-->
<!-- </style>-->
<style>
@import url('{% static 'fonts/Tiny5-Regular.ttf' %}');
</style>
<!-- <link href='https://fonts.googleapis.com/css?family=Economica:400,700' rel='stylesheet' type='text/css'>-->
<!-- <link rel="stylesheet" href="{% static 'css/font-awesome.min.css' %}">-->
<!-- <link rel="stylesheet" href="{% static 'css/basalstyle/style.min.css' %}">-->
<!-- <link rel="stylesheet" href="{% static 'css/main.css' %}">-->
<link rel="stylesheet" href="{% static 'css/font-awesome.min.css' %}">
<link rel="stylesheet" href="{% static 'css/basalstyle/style.min.css' %}">
<link rel="stylesheet" href="{% static 'css/main.css' %}">

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down
21 changes: 21 additions & 0 deletions eventex/core/templates/core/talk_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base.html' %}

{% block content %}
<section>
<div class="talks content row padding-bottom-3 desktop-12 container">
<h2>Manhã</h2>
{% for talk in morning_talks %}
{% include 'core/talk_list_snippet.html' with talk=talk only %}
{% empty %}
<p>Ainda não existem palestras de manhã.</p>
{% endfor %}

<h2>Tarde</h2>
{% for talk in afternoon_talks %}
{% include 'core/talk_list_snippet.html' with talk=talk only %}
{% empty %}
<p>Ainda não existem palestras de tarde.</p>
{% endfor %}
</div>
</section>
{% endblock content %}
7 changes: 7 additions & 0 deletions eventex/core/templates/core/talk_list_snippet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h3>{{ talk.start }} - {{ talk.title}}</h3>
<h4>Por
{% for speaker in talk.speakers.all %}
<a href="{{ speaker.get_absolute_url }}">{{ speaker.name }}</a>
{% endfor %}
</h4>
<p>{{ talk.description }}</p>
1 change: 1 addition & 0 deletions eventex/core/templates/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h1><a href="{% url 'home' %}" rel="home">Eventex</h1>
<a href="javascript:void(0);" class="nav-mobile"><i class="fa fa-bars"></i></a>
<ul>
<li><a data-scroll href="{% url 'home' %}#overview">Conferência</a></li>
<li><a data-scroll href="{% url 'talk_list' %}">Palestras</a></li>
<li><a data-scroll href="{% url 'home' %}#speakers">Palestrantes</a></li>
<li><a data-scroll href="{% url 'home' %}#sponsors">Patrocinadores</a></li>
<li><a data-scroll href="{% url 'home' %}#register">Inscrição</a></li>
Expand Down
40 changes: 40 additions & 0 deletions eventex/core/tests/test_model_talk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.test import TestCase
from eventex.core.models import Talk


class TalkModelTest(TestCase):
def setUp(self):
self.talk = Talk.objects.create(
title='Título da Palestra'
)

def test_create(self):
self.assertTrue(Talk.objects.exists())

def test_has_speakers(self):
"""Talk has many Speakers and vice-versa"""
self.talk.speakers.create(
name='Henrique Bastos',
slug='henrique-bastos',
website='http://henriquebastos.net'
)
self.assertEqual(1, self.talk.speakers.count())

def test_description_blank(self):
field = Talk._meta.get_field('description')
self.assertTrue(field.blank)

def test_speakers_blank(self):
field = Talk._meta.get_field('speakers')
self.assertTrue(field.blank)

def test_start_blank(self):
field = Talk._meta.get_field('start')
self.assertTrue(field.blank)

def test_start_null(self):
field = Talk._meta.get_field('start')
self.assertTrue(field.null)

def test_str(self):
self.assertEqual('Título da Palestra', str(self.talk))
4 changes: 4 additions & 0 deletions eventex/core/tests/test_view_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def test_speakers(self):
def test_speakers_link(self):
expected = 'href="{}#speakers"'.format(r('home'))
self.assertContains(self.response, expected)

def test_talks_link(self):
expected = 'href="{}"'.format(r('talk_list'))
self.assertContains(self.response, expected)
59 changes: 59 additions & 0 deletions eventex/core/tests/test_view_talk_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.test import TestCase
from django.shortcuts import resolve_url as r

from eventex.core.models import Talk, Speaker


class TalkListGet(TestCase):
def setUp(self):
t1 = Talk.objects.create(title='Título da Palestra', start='10:00', description='Descrição da palestra')
t2 = Talk.objects.create(title='Título da Palestra', start='13:00', description='Descrição da palestra')

speaker = Speaker.objects.create(
name='Henrique Bastos',
slug='henrique-bastos',
website='http://henriquebastos.net'
)

t1.speakers.add(speaker)
t2.speakers.add(speaker)

self.resp = self.client.get(r('talk_list'))

def test_get(self):
self.assertEqual(200, self.resp.status_code)

def test_template(self):
self.assertTemplateUsed(self.resp, 'core/talk_list.html')

def test_html(self):
contents = [
(2, 'Título da Palestra'),
(1, '10:00'),
(1, '13:00'),
(2, '/palestrantes/henrique-bastos/'),
(2, 'Henrique Bastos'),
(2, 'Descrição da palestra'),
]

for count, expected in contents:
with self.subTest():
self.assertContains(self.resp, expected, count)

def test_context(self):
variables = [
'morning_talks',
'afternoon_talks'
]

for key in variables:
with self.subTest():
self.assertIn(key, self.resp.context)


class TalkListGetEmpty(TestCase):
def test_get_empty(self):
response = self.client.get(r('talk_list'))

self.assertContains(response, 'Ainda não existem palestras de manhã.')
self.assertContains(response, 'Ainda não existem palestras de tarde.')
11 changes: 10 additions & 1 deletion eventex/core/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import render, get_object_or_404

from eventex.core.models import Speaker
from eventex.core.models import Speaker, Talk


def home(request):
Expand All @@ -11,3 +11,12 @@ def home(request):
def speaker_detail(request, slug):
speaker = get_object_or_404(Speaker, slug=slug)
return render(request, 'core/speaker_detail.html', {'speaker': speaker})


def talk_list(request):
context = {
'morning_talks': Talk.objects.filter(start__lt='12:00'),
'afternoon_talks': Talk.objects.filter(start__gte='12:00')
}

return render(request, 'core/talk_list.html', context)
2 changes: 1 addition & 1 deletion eventex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = "static/"
STATIC_URL = "/static/"
STATIC_ROOT = str(BASE_DIR / 'staticfiles')

# Default primary key field type
Expand Down
5 changes: 3 additions & 2 deletions eventex/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"""
from django.contrib import admin
from django.urls import path, include
from eventex.core.views import home, speaker_detail
from eventex.core.views import home, speaker_detail, talk_list


urlpatterns = [
path('', home, name='home'),
path('inscricao/', include('eventex.subscriptions.urls')),
path('inscricao/', include('eventex.subscriptions.urls', namespace='subscriptions')),
path('palestras/', talk_list, name='talk_list'),
path('palestrantes/<slug:slug>/', speaker_detail, name='speaker_detail'),
path('admin/', admin.site.urls),
]

0 comments on commit addc504

Please sign in to comment.