Skip to content

Commit

Permalink
Agregados campos phone y bio a "Usuario"
Browse files Browse the repository at this point in the history
  • Loading branch information
Scot3004 committed Aug 12, 2023
1 parent 4ccd229 commit 805ad4e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
12 changes: 9 additions & 3 deletions temii/templates/users/user_detail.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load static %}
{% load static i18n %}

{% block title %}User: {{ object.username }}{% endblock %}

Expand All @@ -13,6 +13,12 @@ <h2>{{ object.username }}</h2>
{% if object.name %}
<p>{{ object.name }}</p>
{% endif %}
{% if object.bio %}
<p>{% translate "Bio" %}: {{ object.bio }}</p>
{% endif %}
{% if object.phone %}
<p>{% translate "Phone" %}: {{ object.phone }}</p>
{% endif %}
</div>
</div>

Expand All @@ -21,8 +27,8 @@ <h2>{{ object.username }}</h2>
<div class="row">

<div class="col-sm-12">
<a class="btn btn-primary" href="{% url 'users:update' %}" role="button">My Info</a>
<a class="btn btn-primary" href="{% url 'account_email' %}" role="button">E-Mail</a>
<a class="btn btn-primary" href="{% url 'users:update' %}" role="button">{% translate "Update" %}</a>
<a class="btn btn-primary" href="{% url 'account_email' %}" role="button">{% translate "E-Mail" %}</a>
<!-- Your Stuff: Custom user template urls -->
</div>

Expand Down
4 changes: 2 additions & 2 deletions temii/templates/users/user_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% load crispy_forms_tags i18n %}

{% block title %}{{ user.username }}{% endblock %}

Expand All @@ -10,7 +10,7 @@ <h1>{{ user.username }}</h1>
{{ form|crispy }}
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Update</button>
<button type="submit" class="btn btn-primary">{% translate "Save" %}</button>
</div>
</div>
</form>
Expand Down
11 changes: 10 additions & 1 deletion temii/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.contrib.auth import forms as admin_forms
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _
from django import forms


User = get_user_model()

Expand Down Expand Up @@ -31,7 +33,14 @@ class UserSignupForm(SignupForm):
Default fields will be added automatically.
Check UserSocialSignupForm for accounts created from social.
"""

phone = forms.CharField(max_length=20, label=_("Phone"), required=False)
bio = forms.CharField(max_length=255, label=_("Bio"), required=False)
def save(self, request):
user = super(UserSignupForm, self).save(request)
user.phone = self.cleaned_data['phone']
user.bio = self.cleaned_data['bio']
user.save()
return user

class UserSocialSignupForm(SocialSignupForm):
"""
Expand Down
22 changes: 22 additions & 0 deletions temii/users/migrations/0002_user_bio_user_phone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.1.8 on 2023-08-12 01:57

from django.db import migrations, models


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

operations = [
migrations.AddField(
model_name="user",
name="phone",
field=models.CharField(blank=True, max_length=20, verbose_name="Phone"),
),
migrations.AddField(
model_name="user",
name="bio",
field=models.CharField(blank=True, max_length=255, verbose_name="Bio"),
),
]
2 changes: 2 additions & 0 deletions temii/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class User(AbstractUser):
name = CharField(_("Name of User"), blank=True, max_length=255)
first_name = None # type: ignore
last_name = None # type: ignore
phone = CharField(_("Phone"), blank=True, max_length=20)
bio = CharField(_("Bio"), blank=True, max_length=255)

def get_absolute_url(self) -> str:
"""Get URL for user's detail view.
Expand Down
2 changes: 1 addition & 1 deletion temii/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UserDetailView(LoginRequiredMixin, DetailView):

class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
model = User
fields = ["name"]
fields = ["name", "phone", "bio"]
success_message = _("Information successfully updated")

def get_success_url(self):
Expand Down

0 comments on commit 805ad4e

Please sign in to comment.