Commit b4a59bb1 authored by James Esguerra's avatar James Esguerra

Changed ShowProfile function to render default nickname and bio

parent 42ca8ac5
from django import forms from django import forms
from .models import Key, ItemsThisWeek, ItemsToday from .models import User, Key, ItemsThisWeek, ItemsToday
class HomeForm(forms.Form): class HomeForm(forms.Form):
......
# Generated by Django 3.1.7 on 2021-04-07 07:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0003_auto_20210406_2221'),
]
operations = [
migrations.RenameField(
model_name='user',
old_name='profile',
new_name='profile_photo',
),
migrations.AlterField(
model_name='user',
name='bio',
field=models.TextField(default='A short description about yourself.'),
),
migrations.AlterField(
model_name='user',
name='nickname',
field=models.CharField(default='Your Nickname', max_length=50),
),
]
# Generated by Django 3.1.7 on 2021-04-07 07:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0004_auto_20210407_1544'),
]
operations = [
migrations.AlterField(
model_name='user',
name='bio',
field=models.TextField(default='A short description about yourself.', max_length=100),
),
]
# Generated by Django 3.1.7 on 2021-04-07 07:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0005_auto_20210407_1545'),
]
operations = [
migrations.AlterField(
model_name='user',
name='bio',
field=models.TextField(max_length=100),
),
migrations.AlterField(
model_name='user',
name='nickname',
field=models.CharField(max_length=50),
),
]
# Generated by Django 3.1.7 on 2021-04-07 08:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0006_auto_20210407_1548'),
]
operations = [
migrations.AlterField(
model_name='user',
name='nickname',
field=models.CharField(max_length=50, null=True),
),
]
# Generated by Django 3.1.7 on 2021-04-07 08:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0007_auto_20210407_1607'),
]
operations = [
migrations.AlterField(
model_name='user',
name='nickname',
field=models.CharField(blank=True, default='Your nickname', max_length=50),
),
]
# Generated by Django 3.1.7 on 2021-04-07 08:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0008_auto_20210407_1610'),
]
operations = [
migrations.AlterField(
model_name='user',
name='nickname',
field=models.CharField(default='Your nickname', max_length=50),
),
]
# Generated by Django 3.1.7 on 2021-04-07 09:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0009_auto_20210407_1617'),
]
operations = [
migrations.AlterField(
model_name='user',
name='bio',
field=models.TextField(default='A short description about yourself.', max_length=100),
),
]
...@@ -2,8 +2,10 @@ from django.db import models ...@@ -2,8 +2,10 @@ from django.db import models
class User(models.Model): class User(models.Model):
nickname = models.CharField(max_length=50) nickname = models.CharField(max_length=50, default='Your nickname')
bio = models.TextField(max_length=100) bio = models.TextField(
max_length=100,
default='A short description about yourself.')
profile_photo = models.ImageField() profile_photo = models.ImageField()
def __str__(self): def __str__(self):
......
import datetime import datetime
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from .forms import HomeForm, KeyForm, ItemsThisWeekForm, ItemsTodayForm from .forms import (
from .models import Key, ItemsThisWeek, ItemsToday HomeForm,
KeyForm,
ItemsThisWeekForm,
ItemsTodayForm,
)
from .models import User, Key, ItemsThisWeek, ItemsToday
def ShowHome(request): def ShowHome(request):
if request.method == 'POST': if request.method == 'POST':
form = HomeForm(request.POST) form = HomeForm(request.POST)
if form.is_valid(): if form.is_valid():
global name
name = form.cleaned_data['name'] name = form.cleaned_data['name']
#renders another HTML with the user's name and without the form #renders another HTML with the user's name and without the form
return render(request, 'home2.html', {'name': name}) return render(request, 'home2.html', {'name': name})
...@@ -19,7 +23,18 @@ def ShowHome(request): ...@@ -19,7 +23,18 @@ def ShowHome(request):
def ShowProfile(request): def ShowProfile(request):
return render(request, 'profile.html', {'name': name}) if User.objects.count() == 0:
user = User(
nickname='Your nickname',
bio='A short description about yourself.'
)
user.save()
else:
user = User.objects.get(pk=1)
context = {
'user': user,
}
return render(request, 'profile.html', context)
def ShowKey(request): def ShowKey(request):
......
...@@ -9,15 +9,12 @@ ...@@ -9,15 +9,12 @@
<div id='profile'> <div id='profile'>
<div> <div>
<h2> {{ name }} </h2> <p><b>Nickname:</b> {{ user.nickname }} </p>
<br> <br>
<p> My name is {{ name }}, I am 25 years old, and I graduated from Ateneo <p><b>Bio:</b> {{ user.bio }}</p>
de Manila University. My hobbies are singing, painting, and collecting
Pokemon cards!</p>
</div> </div>
<div> <div>
<img src='https://www.worldfuturecouncil.org/wp-content/uploads/2020/02/dummy-profile-pic-300x300-1.png' alt='Picture'>
</div> </div>
</div> </div>
......
...@@ -124,4 +124,4 @@ USE_TZ = True ...@@ -124,4 +124,4 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.1/howto/static-files/ # https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment