adsfasdf

parent 7f956a25
......@@ -34,7 +34,7 @@ class Migration(migrations.Migration):
),
migrations.AddField(
model_name='article',
name='tags',
field=models.ManyToManyField(blank=True, related_name='tags', through='articles.ArticleTag', to='articles.Tag'),
name='templatetags',
field=models.ManyToManyField(blank=True, related_name='templatetags', through='articles.ArticleTag', to='articles.Tag'),
),
]
......@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='article',
name='tags',
name='templatetags',
field=models.ManyToManyField(blank=True, related_name='articles', through='articles.ArticleTag', to='articles.Tag'),
),
]
......@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.RemoveField(
model_name='article',
name='tags',
name='templatetags',
),
migrations.AddField(
model_name='article',
......
......@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='article',
name='tags',
name='templatetags',
field=models.ManyToManyField(blank=True, related_name='articles', to='articles.Tag'),
),
migrations.AlterField(
......
{% load static %}
{% load any_tag %}
<!doctype html>
<html lang="en">
<head>
......@@ -12,9 +13,11 @@
</head>
<body>
{% include 'partial/navbar.html' %}
{% any_function %}
{% some_function %}
<div class="container">
{% block title %}{% endblock %}
{% include 'partial/messages.html' %}
<ul>
{% block menu_links %}
......@@ -24,5 +27,7 @@
{% block content %}
{% endblock %}
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="{% static 'js/script.js' %}"></script>
</body>
</html>
\ No newline at end of file
{% 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">&times;</span>
</button>
</div>
{% endfor %}
{% endif %}
\ No newline at end of file
......@@ -48,7 +48,7 @@
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}">Назад</a>
{% else %}
<span class="page-disabled">Назад</span>
<span class="page-disabled" id="test">Назад</span>
{% endif %}
<form class="current-page" method="get">
......
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
......@@ -16,7 +16,7 @@ from .views.author_views import (
AuthorUpdateView,
AuthorListView,
AuthorDeleteView,
AuthorCreateView
AuthorCreateView, json_echo_view, get_token_view, article_api_list_view, article_api_create_view
)
......@@ -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 += author_routes
urlpatterns += articles_routes
urlpatterns += api
import json
from datetime import datetime
from urllib.parse import urlencode
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.core.serializers import serialize, deserialize
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.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 articles.forms import SearchForm, ArticleForm, CommentForm
......@@ -25,6 +29,8 @@ class ArticleListView(ListView):
paginate_orphans = 1
def get(self, request, *args, **kwargs):
request.session['key'] = reverse("author_list")
print(request.session.items())
self.form = self.get_search_form()
self.search_value = self.get_search_value()
return super().get(request, *args, **kwargs)
......@@ -62,6 +68,7 @@ class ArticleCreateView(LoginRequiredMixin, CreateView):
def get_redirect_url(self):
return reverse('article_detail', kwargs={'pk': self.object.pk})
class ArticleUpdateView(PermissionRequiredMixin, LoginRequiredMixin, UpdateView):
model = Article
template_name = "articles/update.html"
......@@ -99,4 +106,5 @@ class ArticleDeleteView(DeleteView):
return super().dispatch(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
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.views.decorators.csrf import ensure_csrf_cookie
from articles.forms import AuthorForm
from articles.helpers.views import ListView, CreateView, UpdateView, DeleteView
from articles.models import Author
from articles.models import Author, Article
class AuthorListView(ListView):
......@@ -32,3 +38,46 @@ class AuthorDeleteView(DeleteView):
confirm_deletion = False
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
$(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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment