From c4a41df849f0d965bee6f1fccccdefd722dcb756 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Mon, 19 Dec 2022 10:47:31 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=8C=D0=B8=20#13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cms/forms.py | 5 +++++ cms/templates/articles/new.html | 13 +++++++++++++ cms/urls.py | 5 +++-- cms/views.py | 19 +++++++++++++++---- 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 cms/forms.py create mode 100644 cms/templates/articles/new.html diff --git a/cms/forms.py b/cms/forms.py new file mode 100644 index 0000000..fdefe50 --- /dev/null +++ b/cms/forms.py @@ -0,0 +1,5 @@ +from django.forms import ModelForm + + +class ArticleForm(ModelForm): + pass diff --git a/cms/templates/articles/new.html b/cms/templates/articles/new.html new file mode 100644 index 0000000..d125fec --- /dev/null +++ b/cms/templates/articles/new.html @@ -0,0 +1,13 @@ +

Заполните данные статьи для продвижения в соц. сетях

+
+ {% csrf_token %} + + + + + +
\ No newline at end of file diff --git a/cms/urls.py b/cms/urls.py index b1c5b39..0f5fd29 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from .views import ArticleView +from .views import ArticleView, new_article urlpatterns = [ - path('articles/', ArticleView.as_view()) + path('articles/', ArticleView.as_view(), name='create-article'), + path('articles/new/', new_article, name='new-article'), ] diff --git a/cms/views.py b/cms/views.py index b71ab91..b59142c 100644 --- a/cms/views.py +++ b/cms/views.py @@ -2,9 +2,11 @@ import os from json import JSONDecoder, JSONEncoder import requests -from django.http import JsonResponse +from django.http import JsonResponse, HttpRequest +from django.shortcuts import render from django.utils.decorators import method_decorator from django.views import View +from django.urls import reverse from django.views.decorators.csrf import csrf_exempt from cms.models import Article @@ -69,11 +71,20 @@ class ArticleView(View): gid='70000001426867', attachment=encoded_attachments) - def post(self, request): - article_data = JSONDecoder().decode(request.body.decode()) - article = Article.objects.create(**article_data) + def post(self, request: HttpRequest): + post_data = request.POST + article = Article.objects.create(body=post_data['body'], + link=post_data['link']) self._promote_to_telegram(article) self._promote_to_ok(article) self._promote_to_vk(article) response = {'ok': True} return JsonResponse(response) + + +def new_article(request): + return render(request, + template_name='articles/new.html',) + + +