Commit 7a0e6b0e authored by Борис Ким's avatar Борис Ким

Убрал ошибку с нахождением pk в форме создания урока. Доработал работу с файлом

parent 2dbf564e
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('webapp.urls')),
path('accounts/', include('accounts.urls'))
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file
......@@ -38,6 +38,9 @@ class Class(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("webapp:course_detail", args=[str(self.id)])
class Meta:
verbose_name = "Class"
verbose_name_plural = "Classes"
......
......@@ -7,7 +7,7 @@
<hr>
<h1>Create new Class</h1>
<div class='column-center'>
<form action="{% url "webapp:class_create" %}" method="POST">
<form action="{% url "webapp:class_create" course_pk %}" method="POST" enctype="multipart/form-data">
{% include "partial/create_form.html" with button_text="Create new class" %}
</form>
</div>
......
......@@ -13,8 +13,9 @@
<a class="p-2" href="{% url 'webapp:course_delete' course.id %}"> <i class="fas fa-trash-alt"></i> </a>
</div>
<div class="card-body" style="height: 200px;">
<div class='topic-name' style="height: 50px;">
<a class="card-title" href="{% url 'webapp:course_detail' course.id %}"> <h5>{{course.title}}</h5> </a>
<p class="card-text"> {{ course.description|truncatewords:30 }} </p>
</div>
<p class="card-text"> <b>Teacher:</b> {{course.teacher}} </p>
<p class="card-text"> <b>Groups(s):</b>
{% for group in course.group.all %} {{group}} {% endfor %}
......
......@@ -6,6 +6,7 @@
<a href="{% url "webapp:courses_list" %}">Return to the main page..</a>
<hr>
<h1>Create new Course</h1>
{{course}}
<div class='column-center'>
<form action="{% url "webapp:course_create" %}" method="POST">
{% include "partial/create_form.html" with button_text="Create new course" %}
......
......@@ -19,19 +19,19 @@
</blockquote>
</div>
<div style="width: 150px; height: 70px; margin: 20px;">
<a class='btn btn-primary' href="{% url "webapp:class_create" %}"> Create new week </a>
<a class='btn btn-primary' href="{% url "webapp:class_create" course.id %}"> 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: 240px; margin: 15px auto;">
<div class="card border-dark mb-3" style="max-width: 100%; height: 260px; margin: 15px auto;">
<div class="card-header">
<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 }} </p>
{{ class.file }}
<a href="{{ class.file.url }}"> See the lecture </a>
<hr>
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p>
</div>
......
......@@ -10,5 +10,5 @@ urlpatterns = [
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')
path('course/<int:course_pk>/class/new', webapp_views.CreateClassView.as_view(), name='class_create')
]
\ No newline at end of file
......@@ -13,17 +13,17 @@ class CreateClassView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
template_name = 'classes/create.html'
permission_required = 'webapp.add_class'
def get_context_data(self,**kwargs):
kwargs['course_pk']=self.kwargs.get('course_pk')
return super().get_context_data(**kwargs)
def form_valid(self, form):
course_pk = self.kwargs.get('pk')
course_pk = self.kwargs.get('course_pk')
course = get_object_or_404(Course, pk=course_pk)
classweek = form.save(commit=False)
classweek.course = classweek
classweek.save()
classweek = form.save()
course.courses.add(classweek)
return redirect("webapp:course_detail", course_pk=course.pk)
def get_success_url(self):
return reverse("webapp:course_detail", kwargs = {'project_pk': self.object.course.pk})
class EditClassView(UpdateView):
pass
......
......@@ -13,7 +13,7 @@ class CourseCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
template_name = 'courses/create.html'
form_class = CourseForm
model = Course
pk_url_kwarg = 'project_pk'
pk_url_kwarg = 'course_pk'
permission_required = 'webapp.add_course'
def get_form(self, form_class=None):
......
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