final but hopefully with pep8

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