BES-32 Added single note view by id

This commit is contained in:
ksanu 2019-12-07 19:24:05 +01:00
parent 16f0e52ff9
commit cfb9840d1a
23 changed files with 123 additions and 8 deletions

View File

@ -2,10 +2,15 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="b23c009e-2f8a-48f7-8b29-023f93596932" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/bestnotes/dbAPI.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/bestnotes/static/note.css" afterDir="false" />
<change afterPath="$PROJECT_DIR$/bestnotes/templates/note.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$/bestnotes/admin.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/admin.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bestnotes/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/models.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bestnotes/tests.py" beforeDir="false" afterPath="$PROJECT_DIR$/bestnotes/tests.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$/db.sqlite3" beforeDir="false" afterPath="$PROJECT_DIR$/db.sqlite3" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -18,6 +23,7 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
<option value="HTML File" />
</list>
</option>
</component>
@ -32,6 +38,7 @@
<component name="ProjectId" id="1U5Jq3TEUnuX8tmyYK4OsXqAEBc" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="PropertiesComponent">
<property name="DefaultHtmlFileTemplate" value="HTML File" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="preferences.general" />
@ -49,7 +56,7 @@
</option>
</component>
<component name="RunManager">
<configuration name="Unittests in bestnotesunittests.py" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
<configuration name="Unittests in E:/MojeDane/StudiaWMI/Semestr_2_Zimowy_2019-20/Systemy_informatyczne/BES-32/BestNotes/bestnotes/bestnotesunittests.py" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
<module name="BestNotesProject" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@ -65,7 +72,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python tests.Unittests in bestnotesunittests.py" />
<item itemvalue="Python tests.Unittests in E:/MojeDane/StudiaWMI/Semestr_2_Zimowy_2019-20/Systemy_informatyczne/BES-32/BestNotes/bestnotes/bestnotesunittests.py" />
</list>
</recent_temporary>
</component>

View File

@ -2,8 +2,9 @@ from django.contrib import admin
# Register your models here.
from django.contrib import admin
from .models import StudentProfile, Subject, Topic
from .models import StudentProfile, Subject, Topic, Note
admin.site.register(StudentProfile)
admin.site.register(Subject)
admin.site.register(Topic)
admin.site.register(Note)

View File

@ -0,0 +1,25 @@
# Generated by Django 2.2.7 on 2019-12-07 17:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bestnotes', '0002_subject_topic'),
]
operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=30)),
('text', models.TextField()),
('add_date', models.DateField()),
('topic', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bestnotes.Topic')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bestnotes.StudentProfile')),
],
),
]

View File

@ -46,3 +46,9 @@ class Topic(models.Model):
add_date = models.DateField()
class Note(models.Model):
name = models.CharField(max_length=30)
text = models.TextField(blank=False)
topic = models.ForeignKey(Topic, on_delete=models.SET_NULL, null=True)
user = models.ForeignKey(StudentProfile, on_delete=models.CASCADE)
add_date = models.DateField()

View File

View File

@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% load static %}
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'note.css' %}">
{% endblock %}
{% block content %}
{% include 'navbar.html' %}
<div class="container d-flex justify-content-center">
<div class="row mt-4"><h1>Tytuł: {{ note.name }}</h1></div>
</div>
<div class="container">
<div class="d-flex justify-content-center mt-5">
<h3> {{ note.text }}</h3>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
{% for note in notes%}
{{ note.name }}
{% endfor %}
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
{% for note in notes%}
{{ note.name }}
{% endfor %}
{% endblock %}

View File

@ -8,4 +8,8 @@ urlpatterns = [
path('accounts/', include("django.contrib.auth.urls")),
path('subject/', views.subject, name="subject"),
path('subject/<id>', views.subject_id, name="subjectid"),
path('note/<id>', views.note_id, name="note"),
path('notes/', views.notes_all, name="notes"),
path('notes/<subject_name>', views.notes_name, name="notes_name")
]

View File

@ -1,5 +1,5 @@
from django.shortcuts import render
from bestnotes.models import Note
# Create your views here.
from django.http import HttpResponse
@ -14,3 +14,33 @@ def subject(request):
def subject_id(request,id):
return render(request, "subject.html", {'id': id})
def note_id(request,id):
all_notes = Note.objects.all()
notes = all_notes.filter(id=id)
if len(notes) > 0:
single_note = Note.objects.get(pk=id) # Get note with given id
context = {
'note': single_note
}
return render(request, "note.html", context)
else:
return HttpResponse("Note not found.")
#Give all notes connected with subject name and pass it to html
def notes_name(request,subject_name):
all_notes = Note.objects.all()
subject_notes = all_notes.filter(topic__subject__name=subject_name) #Get all notes with subject name
context = {
'notes' : subject_notes
}
#Change website here
return render(request, "test.html", context)
def notes_all(request):
all_notes = Note.objects.all()
context = {
'notes' : all_notes
}
return render(request, "test.html", context)

Binary file not shown.