Skip to content

Commit

Permalink
Uhhh tried some stuff, unclear if it worked
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayliable committed Mar 21, 2024
1 parent 15e9aef commit b0d5347
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 20 deletions.
Binary file added Media/user_upload/pfp/୨୧_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/user_upload/pfp/୨୧__9LD43Ye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified db.sqlite3
Binary file not shown.
18 changes: 18 additions & 0 deletions home/migrations/0008_userprofile_profile_pic.py
Original file line number Diff line number Diff line change
@@ -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/'),
),
]
1 change: 1 addition & 0 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion portfolio_site_IMD2900/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
15 changes: 11 additions & 4 deletions register/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
23 changes: 9 additions & 14 deletions register/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion templates/edit_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block title %}Edit Profile - Portfol.io{% endblock %}

{% block content %}
<h1>Edit Profile:</h1>
<h1>Edit Profile: </h1>
<br><br>
<form method="POST" class="form-group">
{% csrf_token %}
Expand Down

0 comments on commit b0d5347

Please sign in to comment.