Commit d983635d authored by nikkastra's avatar nikkastra

home and profile done

parent 7ecf0a1c
......@@ -5,10 +5,12 @@ class FirstName(forms.Form):
name = forms.CharField(label="Hello! What is your name? ", max_length=100)
class NicknameAndBio(forms.ModelForm):
class Meta:
model = Name
fields = ['nickname', 'bio']
class Nickname(forms.Form):
nickname = forms.CharField(label="", max_length=100, required=False)
class Bio(forms.Form):
bio = forms.CharField(label='', max_length=100, required=False)
class Picture(forms.ModelForm):
......
......@@ -50,19 +50,40 @@ def profile(request):
nickname = info.nickname
bio = info.bio
if request.method == "POST":
form = Picture(request.POST, request.FILES)
if form.is_valid():
form.save()
test = Name.objects.get(name="test")
info.image = test.image
picture = info.image
info.save()
test.delete()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form':form}
return render(request, 'profile.html', info_dict)
form1 = Picture(request.POST, request.FILES)
form2 = Nickname(request.POST)
form3 = Bio(request.POST)
if form1.is_valid() or form2.is_valid() or form3.is_valid():
if len(request.FILES) == 1:
form1.save()
test = Name.objects.get(name="test")
info.image = test.image
picture = info.image
info.save()
test.delete()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form1':form1, 'form2': form2, 'form3':form3}
return render(request, 'profile.html', info_dict)
elif len(request.POST) == 2:
x = ''
for y in request.POST:
x = y
if x == 'nickname':
info.nickname = request.POST['nickname']
nickname = info.nickname
info.save()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form1':form1, 'form2': form2, 'form3':form3}
return render(request, 'profile.html', info_dict)
else:
info.bio = request.POST['bio']
bio = info.bio
info.save()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form1':form1, 'form2': form2, 'form3':form3}
return render(request, 'profile.html', info_dict)
else:
form = Picture()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form':form}
form1 = Picture()
form2 = Nickname(use_required_attribute=False)
form3 = Bio(use_required_attribute=False)
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form1':form1, 'form2': form2, 'form3':form3}
return render(request, 'profile.html', info_dict)
......
......@@ -62,6 +62,7 @@ TEMPLATES = [
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.media',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
......
......@@ -11,12 +11,26 @@
<img src="{{picture}}" alt="hindi ako lilitaw" />
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
{{ form1.as_p }}
<button type='submit'>Change</button>
</form>
<ul>
<li> {{name}} </li>
<li> {{nickname}} </li>
<li> {{bio}} </li>
<li>
{{nickname}}
<form action="/profile" method="POST" id='nickname'>
{% csrf_token %}
{{ form2 }}
<input type='Submit' value='Edit' id='nickname'>
</form>
</li>
<li>
{{bio}}
<form action="/profile" method="POST" id='bio'>
{% csrf_token %}
{{ form3 }}
<input type='Submit' value='Edit' id='bio'>
</form>
</li>
</ul>
{% endblock %}
\ No newline at end of file
......@@ -23,6 +23,4 @@ from django.conf.urls.static import static
urlpatterns = [
path('', include('bulletjournal.urls')),
path('admin/', admin.site.urls),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file
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