Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
ap-11_django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
Давид Ли
ap-11_django
Commits
2665861b
Commit
2665861b
authored
Aug 07, 2023
by
Давид Ли
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lesson 57
parent
7e1bde5a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
8 deletions
+15
-8
.DS_Store
.DS_Store
+0
-0
forms.py
web/forms.py
+1
-3
article_detail.html
web/templates/article/article_detail.html
+2
-2
pagination.html
web/templates/partial/pagination.html
+0
-2
article.py
web/views/article.py
+7
-1
comment.py
web/views/comment.py
+5
-0
No files found.
.DS_Store
View file @
2665861b
No preview for this file type
web/forms.py
View file @
2665861b
...
...
@@ -35,11 +35,9 @@ class ArticleModelForm(forms.ModelForm):
class
CommentModelForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Comment
fields
=
[
'
author'
,
'text'
,
'article
'
]
fields
=
[
'
text
'
]
widgets
=
{
'text'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control mb-3'
}),
'author'
:
forms
.
HiddenInput
(
attrs
=
{
'class'
:
'form-control mb-3'
}),
'article'
:
forms
.
HiddenInput
()
}
...
...
web/templates/article/article_detail.html
View file @
2665861b
...
...
@@ -40,8 +40,8 @@
<form
action=
"{% url 'comment_create' %}"
method=
"POST"
>
{% csrf_token %}
{% include 'partial/form.html' with button_text='add' %}
<input
type=
"hidden"
name=
"article"
value=
"{{ article.id }}"
>
<input
type=
"hidden"
name=
"author"
value=
"{{ request.user.id }}"
>
{#
<input
type=
"hidden"
name=
"article"
value=
"{{ article.id }}"
>
#}
{#
<input
type=
"hidden"
name=
"author"
value=
"{{ request.user.id }}"
>
#}
</form>
{% for comment in comments %}
...
...
web/templates/partial/pagination.html
View file @
2665861b
...
...
@@ -11,8 +11,6 @@
</li>
{% endif %}
{% for num in paginator.page_range %}
<li
class=
"
page-item
...
...
web/views/article.py
View file @
2665861b
...
...
@@ -25,6 +25,7 @@ class ArticleIndexView(ListView):
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
form
=
self
.
get_search_form
()
self
.
search_value
=
self
.
get_search_value
()
session
=
request
.
session
return
super
()
.
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
*
,
object_list
=
None
,
**
kwargs
):
...
...
@@ -63,7 +64,7 @@ class ArticleCreateView(CreateView):
return
reverse
(
'article_detail'
,
kwargs
=
{
'id'
:
self
.
object
.
id
})
class
ArticleDetailView
(
DetailView
):
class
ArticleDetailView
(
LoginRequiredMixin
,
DetailView
):
raise_exception
=
True
template_name
=
'article/article_detail.html'
model
=
Article
...
...
@@ -71,6 +72,11 @@ class ArticleDetailView(DetailView):
pk_url_kwarg
=
'id'
extra_context
=
{
'form'
:
CommentModelForm
}
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
request
.
session
[
'article_id'
]
=
kwargs
.
get
(
'id'
)
request
.
session
[
'author_id'
]
=
request
.
user
.
id
return
super
()
.
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
return
super
()
.
get_context_data
(
comments
=
self
.
object
.
comments
.
order_by
(
'-created_at'
),
...
...
web/views/comment.py
View file @
2665861b
...
...
@@ -14,6 +14,11 @@ class CommentCreateView(CreateView):
template_name
=
'comment/create_update.html'
form_class
=
CommentModelForm
def
form_valid
(
self
,
form
):
form
.
instance
.
author_id
=
self
.
request
.
session
.
get
(
'author_id'
)
form
.
instance
.
article_id
=
self
.
request
.
session
.
get
(
'article_id'
)
return
super
()
.
form_valid
(
form
)
def
get_success_url
(
self
):
return
reverse
(
'article_detail'
,
kwargs
=
{
'id'
:
self
.
object
.
article
.
id
})
...
...
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