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

feat: Formulario y vista para proponer una nueva charla #217

Merged
merged 7 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ De esta forma podrás usar `import ipdb; ipdb.set_trace()` en tu código de Pyth

Para ejecutar los tests, verificar el coverage y generar un reporte de coverage en HTML:

coverage run -m pytest
coverage html
docker compose -f local.yml run --rm django coverage run -m pytest
docker compose -f local.yml run --rm django coverage html
open htmlcov/index.html

#### Ejecutar los test usando pytest
Expand Down
128 changes: 94 additions & 34 deletions locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-07 12:27-0500\n"
"POT-Creation-Date: 2023-10-27 18:39-0500\n"
"PO-Revision-Date: 2023-09-05 23:34-0500\n"
"Last-Translator: Sergio Orozco <[email protected]>\n"
"Language-Team: \n"
Expand All @@ -18,6 +18,32 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.0.1\n"

#: htmlcov/d_afce42a2cf3d92da_base_html.html:140 temii/templates/base.html:58
msgid "Admin"
msgstr "Administrador"

#: htmlcov/d_afce42a2cf3d92da_base_html.html:148 temii/templates/base.html:66
msgid "My Profile"
msgstr "Mi perfil"

#: htmlcov/d_afce42a2cf3d92da_base_html.html:155
#: temii/templates/account/logout.html:5 temii/templates/account/logout.html:8
#: temii/templates/account/logout.html:17 temii/templates/base.html:73
msgid "Sign Out"
msgstr "Salir"

#: htmlcov/d_afce42a2cf3d92da_base_html.html:161
#: temii/templates/account/signup.html:9 temii/templates/account/signup.html:19
#: temii/templates/base.html:79
msgid "Sign Up"
msgstr "Inscribirse"

#: htmlcov/d_afce42a2cf3d92da_base_html.html:166
#: temii/templates/account/login.html:7 temii/templates/account/login.html:11
#: temii/templates/account/login.html:56 temii/templates/base.html:84
msgid "Sign In"
msgstr "Iniciar sesión"

#: temii/talks/apps.py:7
msgid "Talks"
msgstr "Charlas"
Expand Down Expand Up @@ -66,23 +92,37 @@ msgstr "Nivel"
msgid "Language"
msgstr "Lenguaje"

#: temii/talks/models.py:26
#: temii/talks/models.py:27
msgid "Timezone"
msgstr "Zona horaria"

#: temii/talks/models.py:27
#: temii/talks/models.py:30
msgid ""
"Timezone of the place you are located. E.g., Colombia (UTC-5), Argentina or "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que seria bueno traducir este mensaje

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

"Chile (UTC-3), Mexico (UTC-6), etc."
msgstr "ona horaria del lugar donde se encuentra. Por ejemplo,"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msgstr "Zona horaria del lugar donde se encuentra. Por ejemplo,"
Falta una Z

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jeje ups. Ya lo corregí

"Colombia (UTC-5), Argentina o Chile (UTC-3), México (UTC-6), etc."

#: temii/talks/models.py:34
msgid "Comments"
msgstr "Comentarios"

#: temii/talks/models.py:28
#: temii/talks/models.py:35
msgid "Precense"
msgstr "Presencialidad"

#: temii/talks/models.py:29
#: temii/talks/models.py:37
msgid "Months"
msgstr "Meses"

#: temii/talks/models.py:32
#: temii/talks/models.py:41
msgid ""
"Please write your time availability in months.The more specific, the better. "
"E.g., October and November, any day after 6pm."
msgstr "Por favor escribe tu disponibilidad de tiempo en meses. Cuanto más específico, mejor."
"Por ejemplo, octubre y noviembre, cualquier día después de las 6 p.m."

#: temii/talks/models.py:47
msgid "Talk"
msgstr "Charla"

Expand Down Expand Up @@ -178,18 +218,13 @@ msgstr "Confirmar"
#: temii/templates/account/email_confirm.html:27
#, python-format
msgid ""
"This e-mail confirmation link expired or is invalid. Please <a "
"href=\"%(email_url)s\">issue a new e-mail confirmation request</a>."
"This e-mail confirmation link expired or is invalid. Please <a href="
"\"%(email_url)s\">issue a new e-mail confirmation request</a>."
msgstr ""
"Este enlace de confirmación de correo electrónico expiro o es invalido. Por "
"favor <a href=\"%(email_url)s\">solicite una nueva confirmación de correo "
"electrónico</a>."

#: temii/templates/account/login.html:7 temii/templates/account/login.html:11
#: temii/templates/account/login.html:56 temii/templates/base.html:76
msgid "Sign In"
msgstr "Iniciar sesión"

#: temii/templates/account/login.html:17
msgid "Please sign in with one of your existing third party accounts:"
msgstr ""
Expand All @@ -211,21 +246,16 @@ msgstr "o"
#: temii/templates/account/login.html:41
#, python-format
msgid ""
"If you have not created an account yet, then please <a "
"href=\"%(signup_url)s\">sign up</a> first."
"If you have not created an account yet, then please <a href=\"%(signup_url)s"
"\">sign up</a> first."
msgstr ""
"Si no has creado tu cuenta aún, por favor <a "
"href=\"%(signup_url)s\">registrate</a>."
"Si no has creado tu cuenta aún, por favor <a href=\"%(signup_url)s"
"\">registrate</a>."

#: temii/templates/account/login.html:55
msgid "Forgot Password?"
msgstr "Olvido su contraseña?"

#: temii/templates/account/logout.html:5 temii/templates/account/logout.html:8
#: temii/templates/account/logout.html:17 temii/templates/base.html:65
msgid "Sign Out"
msgstr "Salir"

#: temii/templates/account/logout.html:10
msgid "Are you sure you want to sign out?"
msgstr "¿Estás seguro que deseas salir?"
Expand Down Expand Up @@ -302,11 +332,6 @@ msgstr ""
msgid "Signup"
msgstr ""

#: temii/templates/account/signup.html:9 temii/templates/account/signup.html:19
#: temii/templates/base.html:71
msgid "Sign Up"
msgstr ""

#: temii/templates/account/signup.html:11
#, python-format
msgid ""
Expand Down Expand Up @@ -357,9 +382,48 @@ msgid ""
"mail address</a>."
msgstr ""

#: temii/templates/base.html:61
msgid "My Profile"
msgstr "Mi perfil"
#: temii/templates/base.html:62
msgid "About"
msgstr ""

#: temii/templates/base.html:69 temii/templates/talks/talk_form.html:8
msgid "Propose a talk"
msgstr "Proponer una charla"

#: temii/templates/talks/talk_form.html:4
msgid "Create Talk"
msgstr "Crear una charla"

#: temii/templates/talks/talk_form.html:10
msgid "Here you can propose a future talk"
msgstr "Aquí puedes proponer una futura charla"

#: temii/templates/talks/talk_form.html:11
msgid ""
"If you wish to make more than one proposal, you must fill out the form again"
msgstr "Si deseas hacer más de una propuesta debes diligenciar nuevamente el formulario"

#: temii/templates/talks/talk_form.html:18
#: temii/templates/users/user_form.html:13
msgid "Save"
msgstr "Guardar"

#: temii/templates/talks/talk_thanks.html:4
#: temii/templates/talks/talk_thanks.html:11
msgid "Thanks for your proposal"
msgstr "Gracias por tu propuesta"

#: temii/templates/talks/talk_thanks.html:13
msgid "Your contribution greatly contributes to the community"
msgstr "Tu aporte contribuye enormemente a la comunidad"

#: temii/templates/talks/talk_thanks.html:16
msgid "If you wish, you can"
msgstr "Si deseas, puedes"

#: temii/templates/talks/talk_thanks.html:17
msgid "propose another talk again"
msgstr "volver a proponer otra charla"

#: temii/templates/users/user_detail.html:19 temii/users/forms.py:37
#: temii/users/models.py:23
Expand All @@ -379,10 +443,6 @@ msgstr "Actualizar"
msgid "E-Mail"
msgstr "Coreo electrónico"

#: temii/templates/users/user_form.html:13
msgid "Save"
msgstr "Guardar"

#: temii/users/admin.py:17
msgid "Personal info"
msgstr "Información personal"
Expand Down
3 changes: 2 additions & 1 deletion temii/talks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

@admin.register(Talk)
class TalkAdmin(admin.ModelAdmin):
list_display = ["name"]
list_display = ["name", "user", "months"]
search_fields = ["name"]
list_filter = ["level", "precense", "language"]
18 changes: 18 additions & 0 deletions temii/talks/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import forms

from .models import Talk


class NewTalkForm(forms.ModelForm):
class Meta:
model = Talk
fields = [
"name",
"description",
"level",
"language",
"timezone",
"comments",
"precense",
"months",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.1 on 2023-10-31 01:59

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("talks", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="talk",
name="months",
field=models.CharField(
blank=True,
help_text="Please write your time availability in months.The more specific, the better. E.g., October and November, any day after 6pm.",
max_length=100,
verbose_name="Months",
),
),
migrations.AlterField(
model_name="talk",
name="timezone",
field=models.CharField(
help_text="Timezone of the place you are located. E.g., Colombia (UTC-5), Argentina or Chile (UTC-3), Mexico (UTC-6), etc.",
max_length=60,
verbose_name="Timezone",
),
),
]
19 changes: 17 additions & 2 deletions temii/talks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,25 @@ class InPerson(models.IntegerChoices):
description = models.CharField(_("Description"), max_length=300)
level = models.PositiveIntegerField(_("Level"), choices=Level.choices, default=Level.BEGINNER)
language = models.CharField(_("Language"), max_length=2, choices=Language.choices, default=Language.ES)
timezone = models.CharField(_("Timezone"), max_length=60)
timezone = models.CharField(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Al cambiar los modelos se requieren crear migraciones, por favor, crealas

_("Timezone"),
max_length=60,
help_text=_(
"Timezone of the place you are located. E.g., "
"Colombia (UTC-5), Argentina or Chile (UTC-3), Mexico (UTC-6), etc."
),
)
comments = models.CharField(_("Comments"), max_length=300)
precense = models.PositiveIntegerField(_("Precense"), choices=InPerson.choices, default=InPerson.ON_SITE)
months = models.CharField(_("Months"), max_length=100, blank=True)
months = models.CharField(
_("Months"),
max_length=100,
blank=True,
help_text=_(
"Please write your time availability in months."
"The more specific, the better. E.g., October and November, any day after 6pm."
),
)

class Meta:
verbose_name = _("Talk")
26 changes: 26 additions & 0 deletions temii/talks/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from django.test import RequestFactory

from temii.talks.forms import NewTalkForm
from temii.talks.tests.factories import TalkFactory
from temii.talks.views import TalkCreateView
from temii.users.models import User

pytestmark = pytest.mark.django_db


class TestTalkCreateView:
def test_form_valid(self, user: User, rf: RequestFactory):
view = TalkCreateView()
talk = TalkFactory()
request = rf.get("/fake-url/")
request.user = user

view.request = request

# Initialize the form
form = NewTalkForm(instance=talk)
form.cleaned_data = {}
view.form_valid(form)

assert form.instance.user == request.user
4 changes: 4 additions & 0 deletions temii/talks/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.urls import path
from django.views.generic import TemplateView

from .views import talk_create_view

app_name = "talks"
urlpatterns = [
path("", TemplateView.as_view(template_name="pages/about.html"), name="talks"),
path("~create/", view=talk_create_view, name="create"),
path("thanks/", TemplateView.as_view(template_name="talks/talk_thanks.html"), name="thanks"),
]
22 changes: 22 additions & 0 deletions temii/talks/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.views.generic.edit import CreateView

from .forms import NewTalkForm
from .models import Talk


class TalkCreateView(LoginRequiredMixin, CreateView):
"""Propose a new talk."""

model = Talk
form_class = NewTalkForm
success_url = reverse_lazy("talks:thanks")

def form_valid(self, form):
# Se agrega el usuario que hace la petición al formulario
form.instance.user = self.request.user
return super().form_valid(form)


talk_create_view = TalkCreateView.as_view()
10 changes: 9 additions & 1 deletion temii/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@
<li class="nav-item active">
<a class="nav-link" href="{% url 'home' %}">Home <span class="visually-hidden">(current)</span></a>
</li>
{% if request.user.is_staff %}
<li class="nav-item">
<a class="nav-link" href="{% url 'admin:index' %}">{% translate "Admin" %}</a>
</li>
{% endif %}
<li class="nav-item">
<a class="nav-link" href="{% url 'about' %}">About</a>
<a class="nav-link" href="{% url 'about' %}">{% translate "About" %}</a>
</li>
{% if request.user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'users:detail' request.user.username %}">{% translate "My Profile" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'talks:create' %}">{% translate "Propose a talk" %}</a>
</li>
<li class="nav-item">
{# URL provided by django-allauth/account/urls.py #}
<a class="nav-link" href="{% url 'account_logout' %}">{% translate "Sign Out" %}</a>
Expand Down
Loading