BES-45 BES-50 BES-51 Added topics.html template, added method to use template notes.html to generate notes_by_topic_id, modified backend to work with the mentioned addtions.

This commit is contained in:
ksanu 2019-12-15 17:49:20 +01:00
parent 83a612f934
commit 6e010e9bcf
18 changed files with 64 additions and 11 deletions

View File

@ -2,16 +2,12 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b23c009e-2f8a-48f7-8b29-023f93596932" name="Default Changelist" comment=""> <list default="true" id="b23c009e-2f8a-48f7-8b29-023f93596932" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/bestnotes/static/note.css" afterDir="false" /> <change afterPath="$PROJECT_DIR$/bestnotes/static/topics.css" afterDir="false" />
<change afterPath="$PROJECT_DIR$/bestnotes/templates/note.html" afterDir="false" /> <change afterPath="$PROJECT_DIR$/bestnotes/templates/topics.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/bestnotes/templates/test.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/bestnotes/templates/testid.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bestnotes/admin.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/admin.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/bestnotes/templates/subjects.html" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/templates/subjects.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bestnotes/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/models.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bestnotes/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/urls.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/bestnotes/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/urls.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bestnotes/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/views.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/bestnotes/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/views.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/db.sqlite3" beforeDir="false" afterPath="$PROJECT_DIR$/db.sqlite3" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />

View File

@ -0,0 +1,4 @@
.subjectname{
text-decoration: none;
color:white;
}

View File

@ -26,17 +26,17 @@
<a class="row justify-content-center text-white">Liczba dostępnych przedmiotów: 3/5</a> <a class="row justify-content-center text-white">Liczba dostępnych przedmiotów: 3/5</a>
<ul class="list-group cProductsList mt-3"> <ul class="list-group cProductsList mt-3">
<li class="list-group-item d-sm-flex justify-content-between"><p class="p-0 m-0 flex-grow-1">Programowanie</p> <li class="list-group-item d-sm-flex justify-content-between"><p class="p-0 m-0 flex-grow-1">Programowanie</p>
<button class="btn-primary mr-1" ><a class="nolink" href="/bestnotes/notes/1">Zarządzaj</a></button> <button class="btn-primary mr-1" ><a class="nolink" href="/bestnotes/topics_by_subject_id/1">Zarządzaj</a></button>
<button class="btn-success mr-1">Edytuj</button> <button class="btn-success mr-1">Edytuj</button>
<button class="btn-danger">Usuń</button> <button class="btn-danger">Usuń</button>
</li> </li>
<li class="list-group-item d-sm-flex justify-content-between"><p class="p-0 m-0 flex-grow-1">Matematyka</p> <li class="list-group-item d-sm-flex justify-content-between"><p class="p-0 m-0 flex-grow-1">Matematyka</p>
<button class="btn-primary mr-1"><a class="nolink" href="/bestnotes/notes/2">Zarządzaj</a></button> <button class="btn-primary mr-1"><a class="nolink" href="/bestnotes/topics_by_subject_id/2">Zarządzaj</a></button>
<button class="btn-success mr-1">Edytuj</button> <button class="btn-success mr-1">Edytuj</button>
<button class="btn-danger">Usuń</button> <button class="btn-danger">Usuń</button>
</li> </li>
<li class="list-group-item d-sm-flex justify-content-between"><p class="p-0 m-0 flex-grow-1">Systemy informatyczne</p> <li class="list-group-item d-sm-flex justify-content-between"><p class="p-0 m-0 flex-grow-1">Systemy informatyczne</p>
<button class="btn-primary mr-1"><a class="nolink" href="/bestnotes/notes/3">Zarządzaj</a></button> <button class="btn-primary mr-1"><a class="nolink" href="/bestnotes/topics_by_subject_id/3">Zarządzaj</a></button>
<button class="btn-success mr-1">Edytuj</button> <button class="btn-success mr-1">Edytuj</button>
<button class="btn-danger">Usuń</button> <button class="btn-danger">Usuń</button>
</li> </li>

View File

@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% load static %}
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'topics.css' %}">
{% endblock %}
{% block content %}
{% include 'navbar.html' %}
<div class="container d-flex justify-content-center">
<div class="row mt-4"><h1 class="subjectname">{{subject_name}}</h1></div>
</div>
<div class="container d-flex justify-content-center">
<div class="row">
<div class="col-sm-12">
<h2 class="text-white text-center">Dostępne zagadnienia</h2>
<ul class="list-group cProductsList mt-4">
{% for topic in topics%}
<a href="/bestnotes/notes_by_topic/{{ topic.id }}" class="list-group-item list-group-item-action">{{ topic.name }}</a>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endblock %}

View File

@ -9,6 +9,8 @@ urlpatterns = [
path('subject/', views.subject, name="subject"), path('subject/', views.subject, name="subject"),
path('subject/<id>', views.subject_id, name="subjectid"), path('subject/<id>', views.subject_id, name="subjectid"),
path('note/<id>', views.note_id, name="note"), path('note/<id>', views.note_id, name="note"),
path('notes_by_topic/<topic_id>', views.notes_by_topic_id, name="notes"),
path('topics_by_subject_id/<subject_id>', views.topics_by_subject_id, name="topics"),
path('notes/', views.notes_all, name="notes"), path('notes/', views.notes_all, name="notes"),
path('notes/<subject_id>', views.notes_name, name="notes_id") path('notes/<subject_id>', views.notes_name, name="notes_id")

View File

@ -1,5 +1,5 @@
from django.shortcuts import render from django.shortcuts import render
from bestnotes.models import Note from bestnotes.models import Note, Topic, Subject
# Create your views here. # Create your views here.
from django.http import HttpResponse from django.http import HttpResponse
@ -38,6 +38,32 @@ def notes_name(request,subject_id):
#Change website here #Change website here
return render(request, "notes.html", context) return render(request, "notes.html", context)
def notes_by_topic_id(request,topic_id):
all_notes = Note.objects.all()
topic_notes = all_notes.filter(topic__id=topic_id) #Get all notes with given topic id
context = {
'notes' : topic_notes
}
#Change website here
return render(request, "notes.html", context)
def topics_by_subject_id(request,subject_id):
all_topics = Topic.objects.all()
topics_under_subject = all_topics.filter(subject__id=subject_id) #get topics under given subject
if len(topics_under_subject) > 0:
subject_name = all_topics[0].subject.name # Get note with given id
context = {
'subject_name': subject_name,
'topics': topics_under_subject
}
return render(request, "topics.html", context)
else:
return HttpResponse("Topics not found.")
def notes_all(request): def notes_all(request):
all_notes = Note.objects.all() all_notes = Note.objects.all()
context = { context = {