diff --git "a/Media/user_upload/pfp/\340\255\250\340\255\247_.png" "b/Media/user_upload/pfp/\340\255\250\340\255\247_.png" new file mode 100644 index 0000000..6f3afed Binary files /dev/null and "b/Media/user_upload/pfp/\340\255\250\340\255\247_.png" differ diff --git "a/Media/user_upload/pfp/\340\255\250\340\255\247__9LD43Ye.png" "b/Media/user_upload/pfp/\340\255\250\340\255\247__9LD43Ye.png" new file mode 100644 index 0000000..6f3afed Binary files /dev/null and "b/Media/user_upload/pfp/\340\255\250\340\255\247__9LD43Ye.png" differ diff --git a/db.sqlite3 b/db.sqlite3 index 6e8b871..fcfd79f 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/home/migrations/0008_userprofile_profile_pic.py b/home/migrations/0008_userprofile_profile_pic.py new file mode 100644 index 0000000..6cafe82 --- /dev/null +++ b/home/migrations/0008_userprofile_profile_pic.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.3 on 2024-03-21 02:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0007_userprofile_bio_userprofile_email_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='userprofile', + name='profile_pic', + field=models.ImageField(blank=True, null=True, upload_to='user_upload/pfp/'), + ), + ] diff --git a/home/models.py b/home/models.py index ea34da3..9dec9a2 100644 --- a/home/models.py +++ b/home/models.py @@ -62,6 +62,7 @@ class UserProfile(models.Model): email = models.CharField(max_length=255, null=True) display_name = models.CharField(max_length=255) bio = models.TextField(blank=True, null=True) + profile_pic = models.ImageField(upload_to='user_upload/pfp/', blank=True, null=True) def __str__(self): return 'User: '+str(self.user) diff --git a/portfolio_site_IMD2900/urls.py b/portfolio_site_IMD2900/urls.py index ad7c96f..858dca5 100644 --- a/portfolio_site_IMD2900/urls.py +++ b/portfolio_site_IMD2900/urls.py @@ -8,7 +8,7 @@ urlpatterns = [ path('admin/', admin.site.urls), path('', include("home.urls")), - path('register/', regv.register, name="register"), + path('register/', regv.CreateUserView.as_view(), name="register"), path('edit_profile/', regv.ProfileEditView.as_view(), name="edit_profile"), path('logout/', regv.logout_view, name="logout"), path('', include("django.contrib.auth.urls")), diff --git a/register/forms.py b/register/forms.py index fac06a0..9080d74 100644 --- a/register/forms.py +++ b/register/forms.py @@ -3,18 +3,25 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.contrib.auth.models import User +from home.models import UserProfile + class RegisterForm(UserCreationForm): email = forms.EmailField() + username = forms.CharField(max_length=150, required=True) class Meta: model = User fields = ["username", "email", "password1", "password2"] -class UpdateUserForm(UserChangeForm): - email = forms.EmailField() +class UpdateProfileForm(UserChangeForm): + email = forms.EmailField(required=False) + username = forms.CharField(max_length=150, required=False) + display_name = forms.CharField(max_length=255, required=False) + password = forms.CharField(widget=forms.PasswordInput, max_length=250, required=False) + profile_pic = forms.ImageField(required=False) class Meta: - model = User - fields = ["username", "email"] + model = UserProfile + fields = ["username", "email", "display_name", "password", "profile_pic"] diff --git a/register/views.py b/register/views.py index 998517a..ce0143b 100644 --- a/register/views.py +++ b/register/views.py @@ -2,32 +2,27 @@ from django.shortcuts import render, redirect from django.urls import reverse_lazy -from .forms import RegisterForm, UpdateUserForm +from .forms import RegisterForm, UpdateProfileForm from django.contrib.auth import login, logout -from django.views.generic import UpdateView +from django.views.generic import UpdateView, CreateView, ListView # Create your views here. -def register(response): - if response.method == "POST": - form = RegisterForm(response.POST) - if form.is_valid(): - form.save() - return redirect("/") - else: - form = RegisterForm() - return render(response, "registration/register.html", {"form": form}) - - def logout_view(request): logout(request) return render(request, "home.html") +class CreateUserView(CreateView): + template_name = "registration/register.html" + form_class = RegisterForm + success_url = reverse_lazy('home') + + class ProfileEditView(UpdateView): template_name = "edit_profile.html" - form_class = UserChangeForm + form_class = UpdateProfileForm success_url = reverse_lazy('home') def get_object(self, queryset=None): diff --git a/templates/edit_profile.html b/templates/edit_profile.html index 700a187..0162df0 100644 --- a/templates/edit_profile.html +++ b/templates/edit_profile.html @@ -2,7 +2,7 @@ {% block title %}Edit Profile - Portfol.io{% endblock %} {% block content %} -