Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/git_toolbox_prj.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/todo-list-test-task.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_list.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
django==4.0.2
django-debug-toolbar==3.2.4
django-crispy-forms==1.14.0
24 changes: 24 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
body {
margin-top: 20px;
}

.btn-blurred {
background-color: grey;
color: white;
}

.done {
color: green;
}

.not-done {
color: red;
}

.text-tag {
color: grey;
}

.text-deadline {
color: #de5416;
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add blank line to all files where is missing

41 changes: 41 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">

<head>
{% block title %}<title>Todo list</title>{% endblock %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>

<body>

<div class="container-fluid">
<div class="row">
<div class="col-sm-2">

{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}

</div>
<div class="col-sm-10 ">

{% block content %}{% endblock %}

{% block pagination %}
{% include "includes/pagination.html" %}
{% endblock %}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be consistent with identation

</div>
</div>
</div>
</body>

</html>
17 changes: 17 additions & 0 deletions templates/includes/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% if is_paginated %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item">
<a href="?page= {{ page_obj.previous_page_number }}" class="page-link">prev</a>
</li>
{% endif %}
<li class="page-item active">
<span class="page-link">{{ page_obj.number }} of {{ paginator.num_pages }}</span>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a href="?page= {{ page_obj.next_page_number }}" class="page-link">next</a>
</li>
{% endif %}
</ul>
{% endif %}
4 changes: 4 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ul class="sidebar-nav list-group">
<li class="list-group-item"><a href="{% url 'todo:task-list' %}">Home</a></li>
<li class="list-group-item"><a href="{% url 'todo:tag-list' %}">Tags</a></li>
</ul>
14 changes: 14 additions & 0 deletions templates/todo/tag_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "base.html" %}

{% block content %}

<h1>Delete tag</h1>

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To many blank lines


<p>Are you sure you want to delete the tag {{ tag }}</p>

<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, delete" class="btn btn-danger">
</form>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/todo/tag_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h1>{{ object|yesno:"Update,Create" }} Tag</h1>

<form action="" method="post">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="submit">
</form>
{% endblock %}
40 changes: 40 additions & 0 deletions templates/todo/tag_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "base.html" %}

{% block content %}
<h1>Tags</h1>
<button style="float: right; margin-right: 25px; bottom: 50px; position:relative;" class="btn btn-primary">
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended to have styles in a css file

<a role="button" style="color: white"
href="{% url 'todo:tag-create'%}">Add</a>
</button>

{% if tag_list %}
<table class="table">
<tr>
<th>Name</th>
<th>Update</th>
<th>Delete</th>
</tr>
{% for tag in tag_list %}
<tr>
<td>{{ tag.name }}</td>
<td>
<button style="background: gray" class="btn"><a role="button" style="color: white"
href="{% url 'todo:task_change_status' pk=tag.id %}">Update</a>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect url. Must be 'todo:tag-update'

</button>
</td>
<td>
<button style="background: gray" class="btn"><a role="button" style="color: white"
href="{% url 'todo:task_change_status' pk=tag.id %}">Delete</a>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect url. Must be 'todo:tag-delete'

</button>
</td>

</tr>
{% endfor %}

</table>

{% else %}
<p>There are no todos</p>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to 'tags'

{% endif %}

{% endblock %}
13 changes: 13 additions & 0 deletions templates/todo/task_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}

{% block content %}

<h1>Delete task</h1>

<p>Are you sure you want to delete the task {{ task }}</p>

<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, delete" class="btn btn-danger">
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended to add a cancel button.

</form>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/todo/task_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h1>{{ object|yesno:"Update,Create" }} Task</h1>

<form action="" method="post">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="submit">
</form>
{% endblock %}
68 changes: 68 additions & 0 deletions templates/todo/task_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{% extends "base.html" %}

{% block content %}
<h1>TODO list</h1>
<button style="float: right; bottom: 50px; position: relative" class="btn btn-primary"
type="submit"
value="submit">
<a role="button" style="color: white"
href="{% url 'todo:task-create' %}">Add task</a>
</button>
<br>

{% if task_list %}
{% for task in task_list %}
<br>
<div class="form-group">
<b>{{ task.content }}</b>


{% if task.is_done %}
<b><span class="done">Done</span></b>
<form method="post" action="{% url 'todo:task_change_status' pk=task.id %}">
{% csrf_token %}

<button style="float: right" type="submit" class="btn btn-blurred">
Undo
</button>

</form>

{% else %}
<b><span class="not-done">Not done</span></b>

<form method="post" action="{% url 'todo:task_change_status' pk=task.id %}">
{% csrf_token %}
<button style="float: right" type="submit" class="btn btn-success">
Complete
</button>
</form>

{% endif %}

</div>
<div class="form-group">
Created: {{ task.created_at }} {% if task.deadline %}
<span class="text-deadline">Deadline: {{ task.deadline }}</span>
{% endif %}
</div>
<div class="form-group">
<b><span class="text-tag"> Tags:
{% for tag in task.tags.all %}
{{ tag.name }}
{% endfor %}
</span></b>


<a href="{% url 'todo:task-update' pk=task.id %}">Update</a>
<a href="{% url 'todo:task-delete' pk=task.id %}">Delete</a>
</div>
{% endfor %}

{% else %}
<p>There are no todos</p>
{% endif %}



{% endblock %}
Empty file added todo/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions todo/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.contrib import admin

from todo.models import Tag, Task


@admin.register(Task)
class TaskAdmin(admin.ModelAdmin):
pass
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no special modifications to the logic, this can be simplified to regular model registration.



@admin.register(Tag)
class AdminTag(admin.ModelAdmin):
pass
6 changes: 6 additions & 0 deletions todo/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TodoConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "todo"
22 changes: 22 additions & 0 deletions todo/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django import forms
from django.core.exceptions import ValidationError
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import


from todo.models import Tag, Task


class TagForm(forms.ModelForm):
class Meta:
model = Tag
fields = "__all__"


class TaskForm(forms.ModelForm):
tags = forms.ModelMultipleChoiceField(
queryset=Tag.objects.all(),
widget=forms.CheckboxSelectMultiple,
required=False
)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also would be great to define 'SelectDateWidget' for deadline field

class Meta:
model = Task
fields = "__all__"
Empty file added todo/migrations/__init__.py
Empty file.
Loading