Skip to content

Commit

Permalink
Merge pull request #11 from ProdByGodfather/main
Browse files Browse the repository at this point in the history
`v2.2.0` - Make profile form for update user data
  • Loading branch information
ProdByGodfather authored Jan 6, 2024
2 parents 7ad074f + 85d7112 commit f0072d9
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 13 deletions.
26 changes: 21 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions chat/migrations/0004_alter_message_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0 on 2024-01-05 21:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('chat', '0003_message_image'),
]

operations = [
migrations.AlterField(
model_name='message',
name='image',
field=models.CharField(blank=True, max_length=500, null=True),
),
]
Binary file modified db.sqlite3
Binary file not shown.
8 changes: 4 additions & 4 deletions templates/panel/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
<div class="wrapper">
<nav id="sidebar" class="active">
<div class="sidebar-header">
<img src="{% static 'assets/img/logo.jpg' %}" alt="Abarvision Logo" width="40px" class="app-logo">
<img src="{{ user.image.url }}" alt="Profile {{ user.username }}" width="40px" class="app-logo">
</div>
<ul class="list-unstyled components text-secondary">
<li>
<a href="{% url 'panel' %}"><i class="fas fa-home"></i> Dashboard</a>
</li>

{# <li>#}
{# <a href="icons.html"><i class="fas fa-icons"></i> Icons</a>#}
{# </li>#}
<li>
<a href="{% url 'profile' %}"><i class="fas fa-file-alt"></i>Profile</a>
</li>
{# <li>#}
{# <a href="#uielementsmenu" data-bs-toggle="collapse" aria-expanded="false" class="dropdown-toggle no-caret-down"><i class="fas fa-layer-group"></i> UI Elements</a>#}
{# <ul class="collapse list-unstyled" id="uielementsmenu">#}
Expand Down
25 changes: 25 additions & 0 deletions templates/panel/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'panel/base.html' %}
{% load static %}
{% block title %}
Register
{% endblock %}

{% block content %}
<div class="card">
<div class="card-header">Profile</div>
<div class="card-body">
<h5 class="card-title">You Can See Or Edit Your Profile</h5>
<form accept-charset="utf-8">
<div class="row g-2">
{% csrf_token %}
{{ form }}
</div>
<br>
<button type="submit" class="btn btn-success">Edit Profile</button>
</form>
</div>
</div>
</div>


{% endblock %}
39 changes: 38 additions & 1 deletion users/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from users.models import User
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.forms import UserCreationForm,UserChangeForm

class RegisterForm(UserCreationForm):
# fields we want to include and customize in our form
Expand Down Expand Up @@ -43,3 +43,40 @@ class Meta:
fields = ['first_name', 'last_name', 'username', 'email', 'password1', 'password2']



class ProfileForm(UserChangeForm):
# fields we want to include and customize in our form
first_name = forms.CharField(max_length=100,
required=True,
widget=forms.TextInput(attrs={'placeholder': 'First Name',
'class': 'form-control col-md-6',
}))
last_name = forms.CharField(max_length=100,
required=True,
widget=forms.TextInput(attrs={'placeholder': 'Last Name',
'class': 'form-control col-md-6',
}))
username = forms.CharField(max_length=100,
required=True,
widget=forms.TextInput(attrs={'placeholder': 'Username',
'class': 'form-control col-md-6',
}))
email = forms.EmailField(required=False,
widget=forms.EmailInput(attrs={'placeholder': 'Email',
'class': 'form-control col-md-6',
}))

bio = forms.CharField(max_length=255,
required=False,
widget=forms.Textarea(attrs={'placeholder': 'bio',
'class': 'form-control',
'data-toggle': 'bio',
'id': 'bio',
}))
password = None

class Meta:
model = User
fields = ['first_name', 'last_name', 'username', 'email', 'image', 'bio']


18 changes: 18 additions & 0 deletions users/migrations/0004_user_bio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0 on 2024-01-05 21:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0003_alter_user_image'),
]

operations = [
migrations.AddField(
model_name='user',
name='bio',
field=models.TextField(blank=True, max_length=255, null=True),
),
]
1 change: 1 addition & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# Create your models here.
class User(AbstractUser):
image = models.ImageField(upload_to='users/%Y/%m/', blank=True,null=True)
bio = models.TextField(max_length=255, blank=True,null=True)
3 changes: 2 additions & 1 deletion users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
# login auth user model
path("login/", auth_views.LoginView.as_view(template_name='chat/login.html'), name='login'),
# register have a view
path('register/', views.RegisterView.as_view(), name='register')
path('register/', views.RegisterView.as_view(), name='register'),
path("profile/",views.Profile.as_view(),name='profile')
]
16 changes: 14 additions & 2 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from django.views import View

from django.views.generic import UpdateView, DetailView
from users.forms import ProfileForm
from chat import models
from users.forms import RegisterForm
from users.models import User
Expand Down Expand Up @@ -78,4 +79,15 @@ def post(self, request, *args, **kwargs):

return redirect(to='/')

return render(request, self.template_name, {'form': form})
return render(request, self.template_name, {'form': form})



# Detail Profile
class Profile(UpdateView,DetailView):
model = User
template_name = 'panel/profile.html'
form_class = ProfileForm
success_url = reverse_lazy("profile")
def get_object(self):
return User.objects.get(pk = self.request.user.pk)

0 comments on commit f0072d9

Please sign in to comment.