final but hopefully with pep8

parent cf6e3aa2
...@@ -4,8 +4,11 @@ from django.urls import reverse ...@@ -4,8 +4,11 @@ from django.urls import reverse
class Name(models.Model): class Name(models.Model):
name = models.CharField(max_length=100, unique=True, default="test") name = models.CharField(max_length=100, unique=True, default="test")
nickname = models.CharField(max_length=50, default='Your nickname') nickname = models.CharField(max_length=50, default='Your nickname')
bio = models.CharField(max_length=200, default='A short bio about yourself') bio = models.CharField(max_length=200, default='A short bio about you')
image = models.ImageField(upload_to='profilepictures', default='static/img/default.jpg') image = models.ImageField(
upload_to='profilepictures',
default='static/img/default.jpg'
)
def __str__(self): def __str__(self):
return '{} {} {}'.format(self.name, self.nickname, self.bio) return '{} {} {}'.format(self.name, self.nickname, self.bio)
......
...@@ -44,6 +44,7 @@ class HomePageView(View): ...@@ -44,6 +44,7 @@ class HomePageView(View):
return render(request, 'index.html', {'form': form}) return render(request, 'index.html', {'form': form})
def home(request): def home(request):
all_names = Name.objects.all()
if len(name_dict) == 1: if len(name_dict) == 1:
return render(request, 'index.html', name_dict) return render(request, 'index.html', name_dict)
elif request.method == 'POST': elif request.method == 'POST':
...@@ -51,7 +52,7 @@ def home(request): ...@@ -51,7 +52,7 @@ def home(request):
if form.is_valid(): if form.is_valid():
name_dict['name'] = form.cleaned_data['name'] name_dict['name'] = form.cleaned_data['name']
try: try:
if Name.objects.get(name=name_dict['name']) in Name.objects.all(): if Name.objects.get(name=name_dict['name']) in all_names:
return render(request,'index.html', name_dict) return render(request,'index.html', name_dict)
except: except:
person_info = Name(name=name_dict['name']) person_info = Name(name=name_dict['name'])
...@@ -80,7 +81,13 @@ def profile(request): ...@@ -80,7 +81,13 @@ def profile(request):
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, 'form1':form1, 'form2': form2, 'form3':form3} 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)
elif len(request.POST) == 2: elif len(request.POST) == 2:
x = '' x = ''
...@@ -90,19 +97,37 @@ def profile(request): ...@@ -90,19 +97,37 @@ def profile(request):
info.nickname = request.POST['nickname'] info.nickname = request.POST['nickname']
nickname = info.nickname nickname = info.nickname
info.save() info.save()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form1':form1, 'form2': form2, 'form3':form3} 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:
info.bio = request.POST['bio'] info.bio = request.POST['bio']
bio = info.bio bio = info.bio
info.save() info.save()
info_dict = {'name': name_dict['name'],'nickname': nickname, 'bio': bio, 'picture':picture, 'form1':form1, 'form2': form2, 'form3':form3} 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:
form1 = Picture() form1 = Picture()
form2 = Nickname(use_required_attribute=False) form2 = Nickname(use_required_attribute=False)
form3 = Bio(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} 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)
...@@ -111,7 +136,8 @@ def key(request): ...@@ -111,7 +136,8 @@ def key(request):
if request.method == 'POST': if request.method == 'POST':
form = Keys(request.POST) form = Keys(request.POST)
if form.is_valid(): if form.is_valid():
new_key = Key(key=form.cleaned_data['key'], description=form.cleaned_data['description']) new_key = Key(key=form.cleaned_data['key'],
description=form.cleaned_data['description'])
new_key.save() new_key.save()
key_dict = {'form': form} key_dict = {'form': form}
the_keys = [str(x) for x in Key.objects.all()] the_keys = [str(x) for x in Key.objects.all()]
...@@ -129,7 +155,9 @@ def thisweek(request): ...@@ -129,7 +155,9 @@ def thisweek(request):
if request.method == 'POST': if request.method == 'POST':
form = Task(request.POST) form = Task(request.POST)
if form.is_valid(): if form.is_valid():
new_task = Tasks(name=Name.objects.get(name=name_dict['name']), key=form.cleaned_data['key'], task=form.cleaned_data['task']) new_task = Tasks(name=Name.objects.get(name=name_dict['name']),
key=form.cleaned_data['key'],
task=form.cleaned_data['task'])
new_task.save() new_task.save()
return redirect('thisweek') return redirect('thisweek')
else: else:
...@@ -151,7 +179,9 @@ def today(request): ...@@ -151,7 +179,9 @@ def today(request):
if request.method == 'POST': if request.method == 'POST':
form = Today(request.POST) form = Today(request.POST)
if form.is_valid(): if form.is_valid():
new_task = Today(name=Name.objects.get(name=name_dict['name']), key=form.cleaned_data['key'], task=form.cleaned_data['task']) new_task = Today(name=Name.objects.get(name=name_dict['name']),
key=form.cleaned_data['key'],
task=form.cleaned_data['task'])
new_task.save() new_task.save()
return redirect('today') return redirect('today')
else: else:
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
{% load static %} {% load static %}
{% block title %} Your Bujo {% endblock %} {% block title %} Your Bujo {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}" type='text/css'>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
{% load static %} {% load static %}
{% block title %} Keys {% endblock %} {% block title %} Keys {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}" type='text/css'>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
...@@ -20,7 +19,10 @@ ...@@ -20,7 +19,10 @@
<p> No keys. </p> <p> No keys. </p>
{% endif %} {% endif %}
</ul> </ul>
<button type="button" onclick="document.getElementById('form').open='open'"> Add Key </button> <button type="button"
onclick="document.getElementById('form').open='open'">
Add Key
</button>
<dialog id="form"> <dialog id="form">
<form action="{% url 'key'%}" method="post"> <form action="{% url 'key'%}" method="post">
{% csrf_token %} {% csrf_token %}
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
{% load static %} {% load static %}
{% block title %} Profile {% endblock %} {% block title %} Profile {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}" type='text/css'>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
{% load static %} {% load static %}
{% block title %} This Week {% endblock %} {% block title %} This Week {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}" type='text/css'>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
...@@ -11,23 +10,50 @@ ...@@ -11,23 +10,50 @@
<p> 03.29.MON - 04.04.SUN </p> <p> 03.29.MON - 04.04.SUN </p>
<ul> <ul>
{% if object_list %} {% if object_list %}
{% for Tasks in object_list %} {% for Tasks in object_list %}
{% if Tasks.key.key == "Task" %} {% if Tasks.key.key == "Task" %}
<li> <li>
<span id="{{forloop.counter}}">{{Tasks.key.key}} : {{Tasks.task}} </span> <span id="{{forloop.counter}}">
<a href="{{Tasks.get_absolute_url}}"><button type='button'> Edit </button></a> {{Tasks.key.key}} : {{Tasks.task}}
<a href="{{Tasks.get_absolute_url}}"><button type='button'> Delete </button></a> </span>
<button type='button' onclick='document.getElementById("{{forloop.counter}}").innerHTML="Task Done"'> Mark as Done </button> <a href="{{Tasks.get_absolute_url}}">
</li> <button type='button'>
{% else %} Edit
<li> </button>
{{Tasks.key.key}} : {{Tasks.task}} </a>
<a href="{{Tasks.get_absolute_url}}"><button type='button'> Edit </button></a> <a href="{{Tasks.get_absolute_url}}">
<a href="{{Tasks.get_absolute_url}}"><button type='button'> Delete </button></a> <button type='button'>
</li> Delete
{% endif %} </button>
{% endfor %} </a>
<button type='button'
onclick='document.getElementById(
"{{forloop.counter}}"
).innerHTML="Task Done"'>
Mark as Done
</button>
</li>
{% else %}
<li>
{{Tasks.key.key}} : {{Tasks.task}}
<a href="{{Tasks.get_absolute_url}}">
<button type='button'>
Edit
</button>
</a>
<a href="{{Tasks.get_absolute_url}}">
<button type='button'>
Delete
</button>
</a>
</li>
{% endif %}
{% endfor %}
{% endif %} {% endif %}
</ul> </ul>
<a href ="{% url 'addtask' %}"><button type='button'>Add Item</button></a> <a href ="{% url 'addtask' %}">
<button type='button'>
Add Item
</button>
</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
{% load static %} {% load static %}
{% block title %} Today {% endblock %} {% block title %} Today {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}" type='text/css'>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
...@@ -11,23 +10,49 @@ ...@@ -11,23 +10,49 @@
<p> 04.10 SAT </p> <p> 04.10 SAT </p>
<ul> <ul>
{% if object_list %} {% if object_list %}
{% for Today in object_list %} {% for Today in object_list %}
{% if Today.key.key == "Task" %} {% if Today.key.key == "Task" %}
<li> <li>
<span id="{{forloop.counter}}">{{Today.key.key}} : {{Today.task}} </span> <span id="{{forloop.counter}}">
<a href="{{Today.get_absolute_url}}"><button type='button'> Edit </button></a> {{Today.key.key}} : {{Today.task}}
<a href="{{Today.get_absolute_url}}"><button type='button'> Delete </button></a> </span>
<button type='button' onclick='document.getElementById("{{forloop.counter}}").innerHTML="Task Done"'> Mark as Done </button> <a href="{{Today.get_absolute_url}}">
</li> <button type='button'>
{% else %} Edit
<li> </button>
{{Today.key.key}} : {{Today.task}} </a>
<a href="{{Today.get_absolute_url}}"><button type='button'> Edit </button></a> <a href="{{Today.get_absolute_url}}">
<a href="{{Today.get_absolute_url}}"><button type='button'> Delete </button></a> <button type='button'>
</li> Delete
{% endif %} </button>
{% endfor %} </a>
<button type='button' onclick='document.getElementById(
"{{forloop.counter}}"
).innerHTML="Task Done"'>
Mark as Done
</button>
</li>
{% else %}
<li>
{{Today.key.key}} : {{Today.task}}
<a href="{{Today.get_absolute_url}}">
<button type='button'>
Edit
</button>
</a>
<a href="{{Today.get_absolute_url}}">
<button type='button'>
Delete
</button>
</a>
</li>
{% endif %}
{% endfor %}
{% endif %} {% endif %}
</ul> </ul>
<a href ="{% url 'addtoday' %}"><button type='button'>Add Item</button></a> <a href ="{% url 'addtoday' %}">
<button type='button'>
Add Item
</button>
</a>
{% endblock %} {% endblock %}
\ 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