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

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

parent bfb154c2
......@@ -14,14 +14,10 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from webapp.views import courses_views as webapp_views
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
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('', include('webapp.urls')),
]
from django import forms
from .models import Course
from .models import Course, Class
class CourseForm(forms.ModelForm):
class Meta:
model = Course
fields = ['title', 'description', 'group', 'teacher', 'start_date']
\ No newline at end of file
fields = ['title', 'description', 'group', 'teacher', 'start_date']
class ClassForm(forms.ModelForm):
class Meta:
model = Class
fields = ['title', 'description', 'file']
\ No newline at end of file
......@@ -13,7 +13,7 @@
</head>
<body>
<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">
<span class="navbar-toggler-icon"></span>
</button>
......@@ -36,7 +36,7 @@
</nav>
<div class="row d-flex">
<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="#clients">Button 2</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 @@
<p class="card-text"> {{course.description}} </p>
</div>
<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-info" href="{% url 'course_edit' course.id %}"> Edit </a>
<a class="btn btn-danger" href="{% url 'course_delete' course.id %}"> Delete </a>
<a class="btn btn-primary" href="{% url 'webapp:course_detail' course.id %}"> See more </a>
<a class="btn btn-info" href="{% url 'webapp:course_edit' course.id %}"> Edit </a>
<a class="btn btn-danger" href="{% url 'webapp:course_delete' course.id %}"> Delete </a>
</div>
</div>
</div>
......
......@@ -3,11 +3,11 @@
{% block title %} Create new Course {% endblock %}
{% 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>
<h1>Create new Course</h1>
<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" %}
</form>
</div>
......
......@@ -4,7 +4,7 @@
{% block content %}
<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">
{% csrf_token %}
<button>Yes</button>
......
......@@ -3,7 +3,7 @@
{% block title %} {{course.title}} {% endblock %}
{% 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>
<div class='course-block-detail'>
<div class="card" style="width: 100%; height: 400px;">
......@@ -18,20 +18,25 @@
<footer class="blockquote-footer"> Pr. {{course.teacher}} </footer>
</blockquote>
</div>
<div style="width: 100px; height: 50px;">
<a href="{% url "webapp:class_create" %}"> Create new week </a>
</div>
</div>
</div>
{% 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">
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p>
<h6 style="color: #3A63A7;"> Week #{{forloop.counter}} </h6>
</div>
<div class="card-body text-dark">
<h5 class="card-title">Topic: {{ class.title }} </h5>
<p class="card-text"> Description: {{ class.description|truncatewords:5 }} </p>
{{ class.file }}
<p class="card-text"> Description: {{ class.description|truncatewords:30 }} </p>
{{ class.file }}
<hr>
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p>
</div>
</div>
{% endfor %}
<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 %}
\ No newline at end of file
......@@ -4,7 +4,7 @@
{% block title %} Edit Course {% endblock %}
{% 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>
<h1>Edit course "{{ course.title }}"</h1>
<div class='column-center'>
......@@ -14,6 +14,6 @@
</form>
</div>
<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 %}
......@@ -12,4 +12,4 @@
{% endfor %}
{% endfor %}
<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):
class CourseDeleteView(DeleteView):
model = Course
template_name = 'courses/delete.html'
success_url = reverse_lazy('courses_list')
success_url = reverse_lazy('webapp:courses_list')
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