Browse Source

Реализована форма продвижения статьи #13

pull/32/head
Artur Galyamov 2 years ago
parent
commit
c4a41df849
  1. 5
      cms/forms.py
  2. 13
      cms/templates/articles/new.html
  3. 5
      cms/urls.py
  4. 19
      cms/views.py

5
cms/forms.py

@ -0,0 +1,5 @@
from django.forms import ModelForm
class ArticleForm(ModelForm):
pass

13
cms/templates/articles/new.html

@ -0,0 +1,13 @@
<h1>Заполните данные статьи для продвижения в соц. сетях</h1>
<form
method="post"
enctype="application/x-www-form-urlencoded"
action="{% url 'create-article' %}"
>
{% csrf_token %}
<label for="body">Краткий текст статьи</label>
<textarea id="body" name="body"></textarea>
<label for="link">Ссылка</label>
<input type="text" name="link" id="link">
<input type="submit" value="Продвинуть">
</form>

5
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'),
]

19
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',)

Loading…
Cancel
Save