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
246d01dc
Commit
246d01dc
authored
Oct 20, 2021
by
Владислав Андреев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adsfasdf
parent
7f956a25
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
126 additions
and
12 deletions
+126
-12
0004_auto_20210812_1418.py
articles/migrations/0004_auto_20210812_1418.py
+2
-2
0005_alter_article_tags.py
articles/migrations/0005_alter_article_tags.py
+1
-1
0006_auto_20210812_1509.py
articles/migrations/0006_auto_20210812_1509.py
+1
-1
0007_auto_20210812_1511.py
articles/migrations/0007_auto_20210812_1511.py
+1
-1
base.html
articles/templates/base.html
+6
-1
messages.html
articles/templates/partial/messages.html
+21
-0
pagination.html
articles/templates/partial/pagination.html
+1
-1
__init__.py
articles/templatetags/__init__.py
+0
-0
any_tag.py
articles/templatetags/any_tag.py
+10
-0
urls.py
articles/urls.py
+8
-1
article_views.py
articles/views/article_views.py
+11
-3
author_views.py
articles/views/author_views.py
+50
-1
script.js
static/js/script.js
+14
-0
No files found.
articles/migrations/0004_auto_20210812_1418.py
View file @
246d01dc
...
@@ -34,7 +34,7 @@ class Migration(migrations.Migration):
...
@@ -34,7 +34,7 @@ class Migration(migrations.Migration):
),
),
migrations
.
AddField
(
migrations
.
AddField
(
model_name
=
'article'
,
model_name
=
'article'
,
name
=
'tags'
,
name
=
't
emplatet
ags'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
'tags'
,
through
=
'articles.ArticleTag'
,
to
=
'articles.Tag'
),
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
't
emplatet
ags'
,
through
=
'articles.ArticleTag'
,
to
=
'articles.Tag'
),
),
),
]
]
articles/migrations/0005_alter_article_tags.py
View file @
246d01dc
...
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
...
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations
=
[
operations
=
[
migrations
.
AlterField
(
migrations
.
AlterField
(
model_name
=
'article'
,
model_name
=
'article'
,
name
=
'tags'
,
name
=
't
emplatet
ags'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
'articles'
,
through
=
'articles.ArticleTag'
,
to
=
'articles.Tag'
),
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
'articles'
,
through
=
'articles.ArticleTag'
,
to
=
'articles.Tag'
),
),
),
]
]
articles/migrations/0006_auto_20210812_1509.py
View file @
246d01dc
...
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
...
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations
=
[
operations
=
[
migrations
.
RemoveField
(
migrations
.
RemoveField
(
model_name
=
'article'
,
model_name
=
'article'
,
name
=
'tags'
,
name
=
't
emplatet
ags'
,
),
),
migrations
.
AddField
(
migrations
.
AddField
(
model_name
=
'article'
,
model_name
=
'article'
,
...
...
articles/migrations/0007_auto_20210812_1511.py
View file @
246d01dc
...
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
...
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations
=
[
operations
=
[
migrations
.
AddField
(
migrations
.
AddField
(
model_name
=
'article'
,
model_name
=
'article'
,
name
=
'tags'
,
name
=
't
emplatet
ags'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
'articles'
,
to
=
'articles.Tag'
),
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
'articles'
,
to
=
'articles.Tag'
),
),
),
migrations
.
AlterField
(
migrations
.
AlterField
(
...
...
articles/templates/base.html
View file @
246d01dc
{% load static %}
{% load static %}
{% load any_tag %}
<!doctype html>
<!doctype html>
<html
lang=
"en"
>
<html
lang=
"en"
>
<head>
<head>
...
@@ -12,9 +13,11 @@
...
@@ -12,9 +13,11 @@
</head>
</head>
<body>
<body>
{% include 'partial/navbar.html' %}
{% include 'partial/navbar.html' %}
{% any_function %}
{% some_function %}
<div
class=
"container"
>
<div
class=
"container"
>
{% block title %}{% endblock %}
{% block title %}{% endblock %}
{% include 'partial/messages.html' %}
<ul>
<ul>
{% block menu_links %}
{% block menu_links %}
...
@@ -24,5 +27,7 @@
...
@@ -24,5 +27,7 @@
{% block content %}
{% block content %}
{% endblock %}
{% endblock %}
<script
src=
"https://code.jquery.com/jquery-3.6.0.min.js"
></script>
<script
src=
"{% static 'js/script.js' %}"
></script>
</body>
</body>
</html>
</html>
\ No newline at end of file
articles/templates/partial/messages.html
0 → 100644
View file @
246d01dc
{% if messages %}
{% for message in messages %}
<div
class=
"alert alert-dismissible fade show {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
alert-danger
{% elif message.level == DEFAULT_MESSAGE_LEVELS.WARNING %}
alert-warning
{% elif message.level == DEFAULT_MESSAGE_LEVELS.SUCCESS %}
alert-success
{% elif message.level == DEFAULT_MESSAGE_LEVELS.INFO %}
alert-primary
{% else %}
alert-secondary
{% endif %}"
role=
"alert"
>
{{ message }}
<button
type=
"button"
class=
"close"
data-dismiss=
"alert"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
</div>
{% endfor %}
{% endif %}
\ No newline at end of file
articles/templates/partial/pagination.html
View file @
246d01dc
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
{% if page_obj.has_previous %}
{% if page_obj.has_previous %}
<a
href=
"?page={{ page_obj.previous_page_number }}"
>
Назад
</a>
<a
href=
"?page={{ page_obj.previous_page_number }}"
>
Назад
</a>
{% else %}
{% else %}
<span
class=
"page-disabled"
>
Назад
</span>
<span
class=
"page-disabled"
id=
"test"
>
Назад
</span>
{% endif %}
{% endif %}
<form
class=
"current-page"
method=
"get"
>
<form
class=
"current-page"
method=
"get"
>
...
...
articles/templatetags/__init__.py
0 → 100644
View file @
246d01dc
articles/templatetags/any_tag.py
0 → 100644
View file @
246d01dc
from
django
import
template
register
=
template
.
Library
()
@
register
.
simple_tag
def
any_function
():
return
"My Tag text"
@
register
.
simple_tag
def
some_function
():
return
"My Tag Some text"
\ No newline at end of file
articles/urls.py
View file @
246d01dc
...
@@ -16,7 +16,7 @@ from .views.author_views import (
...
@@ -16,7 +16,7 @@ from .views.author_views import (
AuthorUpdateView
,
AuthorUpdateView
,
AuthorListView
,
AuthorListView
,
AuthorDeleteView
,
AuthorDeleteView
,
AuthorCreateView
AuthorCreateView
,
json_echo_view
,
get_token_view
,
article_api_list_view
,
article_api_create_view
)
)
...
@@ -86,6 +86,13 @@ author_routes = [
...
@@ -86,6 +86,13 @@ author_routes = [
)
)
]
]
api
=
[
path
(
'echo/'
,
json_echo_view
),
path
(
'get_csrf/'
,
get_token_view
),
path
(
'api/articles/list'
,
article_api_list_view
),
path
(
'api/articles/create'
,
article_api_create_view
)
]
urlpatterns
=
comments_routes
urlpatterns
=
comments_routes
urlpatterns
+=
author_routes
urlpatterns
+=
author_routes
urlpatterns
+=
articles_routes
urlpatterns
+=
articles_routes
urlpatterns
+=
api
articles/views/article_views.py
View file @
246d01dc
import
json
from
datetime
import
datetime
from
urllib.parse
import
urlencode
from
urllib.parse
import
urlencode
from
django.contrib
import
messages
from
django.contrib.auth.mixins
import
LoginRequiredMixin
,
PermissionRequiredMixin
from
django.contrib.auth.mixins
import
LoginRequiredMixin
,
PermissionRequiredMixin
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.core.serializers
import
serialize
,
deserialize
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.http
import
HttpResponse
,
HttpResponseNotAllowed
,
JsonResponse
from
django.shortcuts
import
get_object_or_404
,
render
,
redirect
from
django.shortcuts
import
get_object_or_404
,
render
,
redirect
from
django.urls
import
reverse
,
reverse_lazy
from
django.urls
import
reverse
,
reverse_lazy
from
django.views.decorators.csrf
import
csrf_protect
from
django.views.decorators.csrf
import
csrf_protect
,
ensure_csrf_cookie
from
django.views.generic
import
FormView
,
DeleteView
from
django.views.generic
import
FormView
,
DeleteView
from
articles.forms
import
SearchForm
,
ArticleForm
,
CommentForm
from
articles.forms
import
SearchForm
,
ArticleForm
,
CommentForm
...
@@ -25,6 +29,8 @@ class ArticleListView(ListView):
...
@@ -25,6 +29,8 @@ class ArticleListView(ListView):
paginate_orphans
=
1
paginate_orphans
=
1
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
request
.
session
[
'key'
]
=
reverse
(
"author_list"
)
print
(
request
.
session
.
items
())
self
.
form
=
self
.
get_search_form
()
self
.
form
=
self
.
get_search_form
()
self
.
search_value
=
self
.
get_search_value
()
self
.
search_value
=
self
.
get_search_value
()
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
...
@@ -62,6 +68,7 @@ class ArticleCreateView(LoginRequiredMixin, CreateView):
...
@@ -62,6 +68,7 @@ class ArticleCreateView(LoginRequiredMixin, CreateView):
def
get_redirect_url
(
self
):
def
get_redirect_url
(
self
):
return
reverse
(
'article_detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
return
reverse
(
'article_detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
class
ArticleUpdateView
(
PermissionRequiredMixin
,
LoginRequiredMixin
,
UpdateView
):
class
ArticleUpdateView
(
PermissionRequiredMixin
,
LoginRequiredMixin
,
UpdateView
):
model
=
Article
model
=
Article
template_name
=
"articles/update.html"
template_name
=
"articles/update.html"
...
@@ -99,4 +106,5 @@ class ArticleDeleteView(DeleteView):
...
@@ -99,4 +106,5 @@ class ArticleDeleteView(DeleteView):
return
super
()
.
dispatch
(
request
,
*
args
,
**
kwargs
)
return
super
()
.
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
delete
(
request
,
*
args
,
**
kwargs
)
messages
.
add_message
(
self
.
request
,
messages
.
SUCCESS
,
f
"Запись {kwargs.get('pk')} удалена!"
)
return
self
.
delete
(
request
,
*
args
,
**
kwargs
)
\ No newline at end of file
articles/views/author_views.py
View file @
246d01dc
import
json
from
datetime
import
datetime
from
django.core.serializers
import
serialize
,
deserialize
from
django.http
import
HttpResponse
,
HttpResponseNotAllowed
,
JsonResponse
from
django.urls
import
reverse
,
reverse_lazy
from
django.urls
import
reverse
,
reverse_lazy
from
django.views.decorators.csrf
import
ensure_csrf_cookie
from
articles.forms
import
AuthorForm
from
articles.forms
import
AuthorForm
from
articles.helpers.views
import
ListView
,
CreateView
,
UpdateView
,
DeleteView
from
articles.helpers.views
import
ListView
,
CreateView
,
UpdateView
,
DeleteView
from
articles.models
import
Author
from
articles.models
import
Author
,
Article
class
AuthorListView
(
ListView
):
class
AuthorListView
(
ListView
):
...
@@ -32,3 +38,46 @@ class AuthorDeleteView(DeleteView):
...
@@ -32,3 +38,46 @@ class AuthorDeleteView(DeleteView):
confirm_deletion
=
False
confirm_deletion
=
False
redirect_url
=
reverse_lazy
(
'author_list'
)
redirect_url
=
reverse_lazy
(
'author_list'
)
@
ensure_csrf_cookie
def
get_token_view
(
request
,
*
args
,
**
kwargs
):
if
request
.
method
==
'GET'
:
return
HttpResponse
()
return
HttpResponseNotAllowed
(
'Разрешен только GET метод'
)
def
json_echo_view
(
request
,
*
args
,
**
kwargs
):
answer
=
{
'time'
:
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
),
'method'
:
request
.
method
}
if
request
.
body
:
answer
[
'content'
]
=
json
.
loads
(
request
.
body
)
answer_to_json
=
json
.
dumps
(
answer
)
response
=
HttpResponse
(
answer_to_json
)
response
[
'Content-Type'
]
=
'application/json'
return
response
def
article_api_list_view
(
request
,
*
args
,
**
kwargs
):
if
request
.
method
==
'GET'
:
articles
=
Article
.
objects
.
all
()
articles_data
=
serialize
(
'json'
,
articles
)
print
(
articles_data
)
return
HttpResponse
(
articles_data
)
def
article_api_create_view
(
request
,
*
args
,
**
kwargs
):
if
request
.
method
==
'POST'
:
if
request
.
body
:
article_data
=
deserialize
(
'json'
,
request
.
body
)
for
item
in
article_data
:
item
.
save
()
return
JsonResponse
({
'id'
:
item
.
object
.
id
})
response
=
JsonResponse
({
'error'
:
'No data provided!'
})
response
.
status_code
=
400
return
response
static/js/script.js
0 → 100644
View file @
246d01dc
$
(
document
).
ready
(
function
()
{
$
(
"body"
).
css
(
'background'
,
'white'
);
let
paginator
=
$
(
'.pagination'
);
let
children
=
paginator
.
children
().
children
(
'a, span'
)
children
.
css
(
'background'
,
'red'
)
let
elem
=
$
(
'#test'
);
elem
.
on
(
'click'
,
function
(
e
)
{
$
(
this
).
parents
(
'.container'
).
find
(
'thead'
).
css
(
'color'
,
'red'
);
$
(
this
).
parents
(
'step-links'
).
html
(
"<button>ТЕкст</button>"
);
$
(
this
).
parent
().
append
(
"<button>Текст</button>"
)
});
});
\ No newline at end of file
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