Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
coursework
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Борис Ким
coursework
Commits
635a5cd4
Commit
635a5cd4
authored
Nov 04, 2021
by
Борис Ким
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил миксин PermissionRequired для вьюх
parent
c97964de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
14 deletions
+17
-14
courses_list.html
source/webapp/templates/courses/courses_list.html
+4
-6
detail.html
source/webapp/templates/courses/detail.html
+1
-1
classes_views.py
source/webapp/views/classes_views.py
+3
-2
courses_views.py
source/webapp/views/courses_views.py
+9
-5
No files found.
source/webapp/templates/courses/courses_list.html
View file @
635a5cd4
...
@@ -12,12 +12,10 @@
...
@@ -12,12 +12,10 @@
<a
class=
"p-2"
href=
"{% url 'webapp:course_edit' course.id %}"
>
<i
class=
"fas fa-edit"
></i>
</a>
<a
class=
"p-2"
href=
"{% url 'webapp:course_edit' course.id %}"
>
<i
class=
"fas fa-edit"
></i>
</a>
<a
class=
"p-2"
href=
"{% url 'webapp:course_delete' course.id %}"
>
<i
class=
"fas fa-trash-alt"
></i>
</a>
<a
class=
"p-2"
href=
"{% url 'webapp:course_delete' course.id %}"
>
<i
class=
"fas fa-trash-alt"
></i>
</a>
</div>
</div>
<div
class=
"card-body"
style=
"height: 150px;"
>
<div
class=
"card-body"
style=
"height: 200px;"
>
<h5
class=
"card-title"
>
{{course.title}}
</h5>
<a
class=
"card-title"
href=
"{% url 'webapp:course_detail' course.id %}"
>
<h5>
{{course.title}}
</h5>
</a>
<p
class=
"card-text"
>
{{course.description}}
</p>
<p
class=
"card-text"
>
{{ course.description|truncatewords:30 }}
</p>
</div>
<p
class=
"card-text"
>
<b>
Teacher:
</b>
{{course.teacher}}
</p>
<div
class=
"card-buttons"
style=
"text-align: center;"
>
<a
class=
"btn btn-primary p-2"
href=
"{% url 'webapp:course_detail' course.id %}"
>
See more
<i
class=
"fas fa-eye"
></i>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
source/webapp/templates/courses/detail.html
View file @
635a5cd4
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
</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:30
}}
</p>
<p
class=
"card-text"
>
Description: {{ class.description }}
</p>
{{ class.file }}
{{ class.file }}
<hr>
<hr>
<p>
<b>
Created at:
</b>
{{ class.created_at }} -
<b>
by:
</b>
{{ course.teacher }}
</p>
<p>
<b>
Created at:
</b>
{{ class.created_at }} -
<b>
by:
</b>
{{ course.teacher }}
</p>
...
...
source/webapp/views/classes_views.py
View file @
635a5cd4
from
django.shortcuts
import
get_object_or_404
,
redirect
from
django.shortcuts
import
get_object_or_404
,
redirect
from
django.urls.base
import
reverse
,
reverse_lazy
from
django.urls.base
import
reverse
,
reverse_lazy
from
django.views.generic
import
CreateView
,
DeleteView
,
UpdateView
from
django.views.generic
import
CreateView
,
DeleteView
,
UpdateView
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.contrib.auth.mixins
import
LoginRequiredMixin
,
PermissionRequiredMixin
from
webapp.models
import
Class
,
Course
from
webapp.models
import
Class
,
Course
from
webapp.forms
import
ClassForm
from
webapp.forms
import
ClassForm
class
CreateClassView
(
LoginRequiredMixin
,
CreateView
):
class
CreateClassView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
CreateView
):
model
=
Class
model
=
Class
fields
=
[
'title'
,
'description'
,
'file'
]
fields
=
[
'title'
,
'description'
,
'file'
]
template_name
=
'courses/create.html'
template_name
=
'courses/create.html'
permission_required
=
'webapp.add_class'
def
form_valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
course_pk
=
self
.
kwargs
.
get
(
'pk'
)
course_pk
=
self
.
kwargs
.
get
(
'pk'
)
...
...
source/webapp/views/courses_views.py
View file @
635a5cd4
...
@@ -3,17 +3,18 @@ from django.shortcuts import redirect
...
@@ -3,17 +3,18 @@ from django.shortcuts import redirect
from
django.urls.base
import
reverse_lazy
from
django.urls.base
import
reverse_lazy
from
django.views.generic
import
ListView
,
CreateView
,
DetailView
,
DeleteView
from
django.views.generic
import
ListView
,
CreateView
,
DetailView
,
DeleteView
from
django.views.generic
import
UpdateView
from
django.views.generic
import
UpdateView
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.contrib.auth.mixins
import
LoginRequiredMixin
,
PermissionRequiredMixin
from
webapp.models
import
Course
from
webapp.models
import
Course
from
webapp.forms
import
CourseForm
from
webapp.forms
import
CourseForm
class
CourseCreateView
(
LoginRequiredMixin
,
CreateView
):
class
CourseCreateView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
CreateView
):
template_name
=
'courses/create.html'
template_name
=
'courses/create.html'
form_class
=
CourseForm
form_class
=
CourseForm
model
=
Course
model
=
Course
pk_url_kwarg
=
'project_pk'
pk_url_kwarg
=
'project_pk'
permission_required
=
'webapp.add_course'
def
get_form
(
self
,
form_class
=
None
):
def
get_form
(
self
,
form_class
=
None
):
form
=
super
()
.
get_form
()
form
=
super
()
.
get_form
()
...
@@ -27,20 +28,23 @@ class CoursesListView(ListView):
...
@@ -27,20 +28,23 @@ class CoursesListView(ListView):
paginate_by
=
6
paginate_by
=
6
class
CourseDetailView
(
LoginRequiredMixin
,
DetailView
):
class
CourseDetailView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
DetailView
):
model
=
Course
model
=
Course
template_name
=
'courses/detail.html'
template_name
=
'courses/detail.html'
pk_url_kwarg
=
'course_pk'
pk_url_kwarg
=
'course_pk'
permission_required
=
'webapp.view_course'
class
CourseDeleteView
(
LoginRequiredMixin
,
DeleteView
):
class
CourseDeleteView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
DeleteView
):
model
=
Course
model
=
Course
template_name
=
'courses/delete.html'
template_name
=
'courses/delete.html'
success_url
=
reverse_lazy
(
'webapp:courses_list'
)
success_url
=
reverse_lazy
(
'webapp:courses_list'
)
permission_required
=
'webapp.delete_course'
class
CourseEditView
(
LoginRequiredMixin
,
UpdateView
):
class
CourseEditView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
UpdateView
):
model
=
Course
model
=
Course
fields
=
[
'title'
,
'description'
,
'start_date'
]
fields
=
[
'title'
,
'description'
,
'start_date'
]
template_name
=
'courses/edit.html'
template_name
=
'courses/edit.html'
permission_required
=
'webapp.change_course'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment