Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
article_proj
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
Владислав Андреев
article_proj
Commits
4cda59c6
Commit
4cda59c6
authored
Aug 26, 2021
by
Владислав Андреев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asdf
parent
a57a45d5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
8 deletions
+38
-8
filters.py
articles/helpers/filters.py
+6
-0
views.py
articles/helpers/views.py
+25
-4
create.html
articles/templates/articles/create.html
+1
-0
list.html
articles/templates/authors/list.html
+4
-1
views.py
articles/views.py
+2
-3
No files found.
articles/helpers/filters.py
View file @
4cda59c6
from
django.template.defaultfilters
import
register
@
register
.
filter
def
capitalize
(
value
):
return
value
.
capitalize
()
\ No newline at end of file
articles/helpers/views.py
View file @
4cda59c6
from
django.core.paginator
import
Paginator
,
PageNotAnInteger
,
EmptyPage
from
django.shortcuts
import
render
,
redirect
from
django.shortcuts
import
render
,
redirect
from
django.views
import
View
from
django.views
import
View
from
django.views.generic
import
TemplateView
from
django.views.generic
import
TemplateView
,
ListView
class
CustomFormView
(
View
):
class
CustomFormView
(
View
):
...
@@ -36,9 +37,29 @@ class CustomFormView(View):
...
@@ -36,9 +37,29 @@ class CustomFormView(View):
class
ListView
(
TemplateView
):
class
ListView
(
TemplateView
):
model
=
None
model
=
None
context_key
=
'objects'
context_object_name
=
'objects'
paginate_by
=
5
paginate_orphans
=
0
ordering
=
[]
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
self
.
context_key
]
=
self
.
model
.
objects
.
all
()
objects
=
self
.
get_queryset
()
.
order_by
(
*
self
.
ordering
)
return
context
paginator
=
Paginator
(
object_list
=
objects
,
per_page
=
self
.
paginate_by
,
orphans
=
self
.
paginate_orphans
)
\ No newline at end of file
page
=
self
.
request
.
GET
.
get
(
'page'
)
try
:
objects_list
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
objects_list
=
paginator
.
page
(
1
)
except
EmptyPage
:
objects_list
=
paginator
.
page
(
paginator
.
num_pages
)
context
[
'page_obj'
]
=
objects_list
context
[
self
.
context_object_name
]
=
objects_list
.
object_list
return
context
def
get_queryset
(
self
):
return
self
.
model
.
objects
.
all
()
articles/templates/articles/create.html
View file @
4cda59c6
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
<div
class=
"container"
>
<div
class=
"container"
>
{% csrf_token %}
{% csrf_token %}
{{ form.as_p }}
{{ form.as_p }}
<input
type=
"submit"
value=
"create"
>
<input
type=
"submit"
value=
"create"
>
</div>
</div>
</form>
</form>
...
...
articles/templates/authors/list.html
View file @
4cda59c6
...
@@ -26,7 +26,10 @@
...
@@ -26,7 +26,10 @@
{% endfor %}
{% endfor %}
</tbody>
</tbody>
</table>
</table>
This text will be HTML-escaped, and will appear in all lowercase.
<br>
{% filter force_escape|upper %}
This text will be HTML-escaped, and will appear in all lowercase.
{% endfilter %}
<a
href=
"{% url 'author_create' %}"
>
Создать автора
</a>
<a
href=
"{% url 'author_create' %}"
>
Создать автора
</a>
{% include 'partial/pagination.html' %}
{% include 'partial/pagination.html' %}
...
...
articles/views.py
View file @
4cda59c6
...
@@ -3,9 +3,9 @@ from django.shortcuts import render, redirect, get_object_or_404
...
@@ -3,9 +3,9 @@ from django.shortcuts import render, redirect, get_object_or_404
from
django.template.defaultfilters
import
urlencode
from
django.template.defaultfilters
import
urlencode
from
django.urls
import
reverse
from
django.urls
import
reverse
from
django.views
import
View
from
django.views
import
View
from
django.views.generic
import
FormView
,
ListView
from
django.views.generic
import
FormView
from
.helpers.views
import
CustomFormView
from
.helpers.views
import
CustomFormView
,
ListView
from
articles.models
import
Article
,
Author
from
articles.models
import
Article
,
Author
from
.forms
import
AuthorForm
,
CommentForm
,
ArticleForm
,
SearchForm
from
.forms
import
AuthorForm
,
CommentForm
,
ArticleForm
,
SearchForm
...
@@ -13,7 +13,6 @@ from .forms import AuthorForm, CommentForm, ArticleForm, SearchForm
...
@@ -13,7 +13,6 @@ from .forms import AuthorForm, CommentForm, ArticleForm, SearchForm
class
ArticleListView
(
ListView
):
class
ArticleListView
(
ListView
):
form
=
SearchForm
form
=
SearchForm
search_fields
=
(
'title'
,
'name'
)
search_fields
=
(
'title'
,
'name'
)
template_name
=
'articles/list.html'
template_name
=
'articles/list.html'
model
=
Article
model
=
Article
context_object_name
=
'articles'
context_object_name
=
'articles'
...
...
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