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
Project 'vladislav_andreev/article_proj' was moved to 'v/article_proj'. Please update any links and bookmarks that may still have the old path.
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.views
import
View
from
django.views.generic
import
TemplateView
from
django.views.generic
import
TemplateView
,
ListView
class
CustomFormView
(
View
):
...
...
@@ -36,9 +37,29 @@ class CustomFormView(View):
class
ListView
(
TemplateView
):
model
=
None
context_key
=
'objects'
context_object_name
=
'objects'
paginate_by
=
5
paginate_orphans
=
0
ordering
=
[]
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
self
.
context_key
]
=
self
.
model
.
objects
.
all
()
return
context
\ No newline at end of file
objects
=
self
.
get_queryset
()
.
order_by
(
*
self
.
ordering
)
paginator
=
Paginator
(
object_list
=
objects
,
per_page
=
self
.
paginate_by
,
orphans
=
self
.
paginate_orphans
)
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 @@
<div
class=
"container"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"submit"
value=
"create"
>
</div>
</form>
...
...
articles/templates/authors/list.html
View file @
4cda59c6
...
...
@@ -26,7 +26,10 @@
{% endfor %}
</tbody>
</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>
{% include 'partial/pagination.html' %}
...
...
articles/views.py
View file @
4cda59c6
...
...
@@ -3,9 +3,9 @@ from django.shortcuts import render, redirect, get_object_or_404
from
django.template.defaultfilters
import
urlencode
from
django.urls
import
reverse
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
.forms
import
AuthorForm
,
CommentForm
,
ArticleForm
,
SearchForm
...
...
@@ -13,7 +13,6 @@ from .forms import AuthorForm, CommentForm, ArticleForm, SearchForm
class
ArticleListView
(
ListView
):
form
=
SearchForm
search_fields
=
(
'title'
,
'name'
)
template_name
=
'articles/list.html'
model
=
Article
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