Commit 33ec296f authored by Борис Ким's avatar Борис Ким

Сделал ссылки удобней, добавил вью для создания нового урока или недели в курсе

parent bfb154c2
...@@ -14,14 +14,10 @@ Including another URLconf ...@@ -14,14 +14,10 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path, include
from webapp.views import courses_views as webapp_views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', webapp_views.CoursesListView.as_view(), name='courses_list'), path('', include('webapp.urls')),
path('course/<int:course_pk>/', webapp_views.CourseDetailView.as_view(), name='course_detail'),
path('course/<int:pk>/delete/', webapp_views.CourseDeleteView.as_view(), name='course_delete'),
path('course/new/', webapp_views.CourseCreateView.as_view(), name='course_create'),
path('course/<int:pk>/edit/', webapp_views.CourseEditView.as_view(), name='course_edit')
] ]
from django import forms from django import forms
from .models import Course from .models import Course, Class
class CourseForm(forms.ModelForm): class CourseForm(forms.ModelForm):
class Meta: class Meta:
model = Course model = Course
fields = ['title', 'description', 'group', 'teacher', 'start_date'] fields = ['title', 'description', 'group', 'teacher', 'start_date']
\ No newline at end of file
class ClassForm(forms.ModelForm):
class Meta:
model = Class
fields = ['title', 'description', 'file']
\ No newline at end of file
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a> <a class="navbar-brand" href="{% url 'webapp:courses_list' %}">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</nav> </nav>
<div class="row d-flex"> <div class="row d-flex">
<div class="sidebar col-2"> <div class="sidebar col-2">
<a href="{% url 'course_create' %}">Create new Course </a> <a href="{% url 'webapp:course_create' %}">Create new Course </a>
<a href="#services">Button 1</a> <a href="#services">Button 1</a>
<a href="#clients">Button 2</a> <a href="#clients">Button 2</a>
<a href="#contact">Button 3</a> <a href="#contact">Button 3</a>
......
{% extends "base.html" %}
{% block title %} Create new Class {% endblock %}
{% block content %}
<a href="{% url "courses_list" %}">Return to the main page..</a>
<hr>
<h1>Create new Class</h1>
<div class='column-center'>
<form action="{% url "class_create" %}" method="POST">
{% include "partial/create_form.html" with button_text="Create new class" %}
</form>
</div>
<hr>
<a href="{% url "courses_list" %}">Return to the main page..</a>
{% endblock %}
\ No newline at end of file
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
<p class="card-text"> {{course.description}} </p> <p class="card-text"> {{course.description}} </p>
</div> </div>
<div class="card-buttons" style="text-align: center;"> <div class="card-buttons" style="text-align: center;">
<a class="btn btn-primary" href="{% url 'course_detail' course.id %}"> See more </a> <a class="btn btn-primary" href="{% url 'webapp:course_detail' course.id %}"> See more </a>
<a class="btn btn-info" href="{% url 'course_edit' course.id %}"> Edit </a> <a class="btn btn-info" href="{% url 'webapp:course_edit' course.id %}"> Edit </a>
<a class="btn btn-danger" href="{% url 'course_delete' course.id %}"> Delete </a> <a class="btn btn-danger" href="{% url 'webapp:course_delete' course.id %}"> Delete </a>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
{% block title %} Create new Course {% endblock %} {% block title %} Create new Course {% endblock %}
{% block content %} {% block content %}
<a href="{% url "courses_list" %}">Return to the main page..</a> <a href="{% url "webapp:courses_list" %}">Return to the main page..</a>
<hr> <hr>
<h1>Create new Course</h1> <h1>Create new Course</h1>
<div class='column-center'> <div class='column-center'>
<form action="{% url "course_create" %}" method="POST"> <form action="{% url "webapp:course_create" %}" method="POST">
{% include "partial/create_form.html" with button_text="Create new course" %} {% include "partial/create_form.html" with button_text="Create new course" %}
</form> </form>
</div> </div>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block content %} {% block content %}
<h2>Are you sure you want to delete course - {{ course.title}} ?</h2> <h2>Are you sure you want to delete course - {{ course.title}} ?</h2>
<a href="{% url "courses_list" %}">Cancel</a> <a href="{% url "webapp:courses_list" %}">Cancel</a>
<form action='' method="post"> <form action='' method="post">
{% csrf_token %} {% csrf_token %}
<button>Yes</button> <button>Yes</button>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block title %} {{course.title}} {% endblock %} {% block title %} {{course.title}} {% endblock %}
{% block content %} {% block content %}
<a href="{% url "courses_list" %}"> << Return to the main page..</a> <a href="{% url "webapp:courses_list" %}"> << Return to the main page..</a>
<hr> <hr>
<div class='course-block-detail'> <div class='course-block-detail'>
<div class="card" style="width: 100%; height: 400px;"> <div class="card" style="width: 100%; height: 400px;">
...@@ -18,20 +18,25 @@ ...@@ -18,20 +18,25 @@
<footer class="blockquote-footer"> Pr. {{course.teacher}} </footer> <footer class="blockquote-footer"> Pr. {{course.teacher}} </footer>
</blockquote> </blockquote>
</div> </div>
<div style="width: 100px; height: 50px;">
<a href="{% url "webapp:class_create" %}"> Create new week </a>
</div>
</div> </div>
</div> </div>
{% for class in course.courses.all %} {% for class in course.courses.all %}
<div class="card border-dark mb-3" style="max-width: 100%; height: 200px; margin: 15px auto;"> <div class="card border-dark mb-3" style="max-width: 100%; height: 240px; margin: 15px auto;">
<div class="card-header"> <div class="card-header">
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p> <h6 style="color: #3A63A7;"> Week #{{forloop.counter}} </h6>
</div> </div>
<div class="card-body text-dark"> <div class="card-body text-dark">
<h5 class="card-title">Topic: {{ class.title }} </h5> <h5 class="card-title">Topic: {{ class.title }} </h5>
<p class="card-text"> Description: {{ class.description|truncatewords:5 }} </p> <p class="card-text"> Description: {{ class.description|truncatewords:30 }} </p>
{{ class.file }} {{ class.file }}
<hr>
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
<hr> <hr>
<a href="{% url "courses_list" %}"> << Return to the main page..</a> <a href="{% url "webapp:courses_list" %}"> << Return to the main page..</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block title %} Edit Course {% endblock %} {% block title %} Edit Course {% endblock %}
{% block content %} {% block content %}
<a href="{% url "courses_list" %}">Return to the main page..</a> <a href="{% url "webapp:courses_list" %}">Return to the main page..</a>
<hr> <hr>
<h1>Edit course "{{ course.title }}"</h1> <h1>Edit course "{{ course.title }}"</h1>
<div class='column-center'> <div class='column-center'>
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
</form> </form>
</div> </div>
<hr> <hr>
<a href="{% url "courses_list" %}">Return to the main page..</a> <a href="{% url "webapp:courses_list" %}">Return to the main page..</a>
{% endblock %} {% endblock %}
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
<p>{{ form|crispy }}</p> <p>{{ form|crispy }}</p>
<button>{{ button_text }}</button> <button class="btn btn-primary">{{ button_text }}</button>
from django.urls import path
from webapp import views as webapp_views
app_name = "webapp"
urlpatterns = [
path('', webapp_views.CoursesListView.as_view(), name='courses_list'),
path('course/<int:course_pk>/', webapp_views.CourseDetailView.as_view(), name='course_detail'),
path('course/<int:pk>/delete/', webapp_views.CourseDeleteView.as_view(), name='course_delete'),
path('course/new/', webapp_views.CourseCreateView.as_view(), name='course_create'),
path('course/<int:pk>/edit/', webapp_views.CourseEditView.as_view(), name='course_edit'),
path('courses/class/new', webapp_views.CreateClassView.as_view(), name='class_create')
]
\ No newline at end of file
from .classes_views import *
from .courses_views import *
\ No newline at end of file
from django.shortcuts import get_object_or_404, redirect
from django.urls.base import reverse, reverse_lazy
from django.views.generic import CreateView, DetailView, DeleteView
from django.views.generic import UpdateView
from webapp.models import Class, Course
from webapp.forms import ClassForm
class CreateClassView(CreateView):
model = Class
fields = ['title', 'description', 'file']
template_name = 'courses/create.html'
def form_valid(self, form):
course_pk = self.kwargs.get('pk')
course = get_object_or_404(Course, pk=course_pk)
classweek = form.save(commit=False)
classweek.course = classweek
classweek.save()
return redirect("webapp:course_detail", course_pk=course.pk)
def get_success_url(self):
return reverse("webapp:project_detail", kwargs = {'project_pk': self.object.course.pk})
class EditClassView(UpdateView):
pass
class DeleteClassView(DeleteView):
pass
\ No newline at end of file
...@@ -35,7 +35,7 @@ class CourseDetailView(DetailView): ...@@ -35,7 +35,7 @@ class CourseDetailView(DetailView):
class CourseDeleteView(DeleteView): class CourseDeleteView(DeleteView):
model = Course model = Course
template_name = 'courses/delete.html' template_name = 'courses/delete.html'
success_url = reverse_lazy('courses_list') success_url = reverse_lazy('webapp:courses_list')
class CourseEditView(UpdateView): class CourseEditView(UpdateView):
......
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