Commit d983635d authored by nikkastra's avatar nikkastra

home and profile done

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