From fa575c845a32973b7fe2895ae04b7557cfda8aaf Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 9 Dec 2022 23:24:19 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B0=20=D0=B4=D0=BE=D1=81=D1=82=D1=83?= =?UTF-8?q?=D0=BF=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=8C=D0=B8?= =?UTF-8?q?,=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=D0=B8=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D0=B2=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ cms/__init__.py | 0 cms/migrations/0001_initial.py | 22 ++++++++++++++++++++++ cms/migrations/__init__.py | 0 cms/models.py | 6 ++++++ cms/urls.py | 6 ++++++ cms/views.py | 18 ++++++++++++++++++ crossposting_backend/urls.py | 3 ++- 8 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 cms/__init__.py create mode 100644 cms/migrations/0001_initial.py create mode 100644 cms/migrations/__init__.py create mode 100644 cms/models.py create mode 100644 cms/urls.py create mode 100644 cms/views.py diff --git a/.gitignore b/.gitignore index 1d84f56..d6f97d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .idea/ .python-version db.sqlite3 +.env +__pycache__/ +identifier.sqlite \ No newline at end of file diff --git a/cms/__init__.py b/cms/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cms/migrations/0001_initial.py b/cms/migrations/0001_initial.py new file mode 100644 index 0000000..3e35365 --- /dev/null +++ b/cms/migrations/0001_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.4 on 2022-12-09 17:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Article', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('body', models.TextField()), + ], + ), + ] diff --git a/cms/migrations/__init__.py b/cms/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cms/models.py b/cms/models.py new file mode 100644 index 0000000..00b9e62 --- /dev/null +++ b/cms/models.py @@ -0,0 +1,6 @@ +from django.db import models + + +class Article(models.Model): + title = models.CharField(max_length=100) + body = models.TextField() \ No newline at end of file diff --git a/cms/urls.py b/cms/urls.py new file mode 100644 index 0000000..290752a --- /dev/null +++ b/cms/urls.py @@ -0,0 +1,6 @@ +from .views import ArticleView +from django.urls import path + +urlpatterns = [ + path('articles/', ArticleView.as_view()) +] diff --git a/cms/views.py b/cms/views.py new file mode 100644 index 0000000..dc03680 --- /dev/null +++ b/cms/views.py @@ -0,0 +1,18 @@ +from json import JSONDecoder +import requests +import os +from django.http import JsonResponse +from django.views import View +from django.utils.decorators import method_decorator +from django.views.decorators.csrf import csrf_exempt + +from cms.models import Article + + +@method_decorator(csrf_exempt, name='dispatch') +class ArticleView(View): + def post(self, request): + article_data = JSONDecoder().decode(request.body.decode()) + article = Article.objects.create(**article_data) + response = {'ok': True} + return JsonResponse(response) \ No newline at end of file diff --git a/crossposting_backend/urls.py b/crossposting_backend/urls.py index 4a330b6..9dd2af0 100644 --- a/crossposting_backend/urls.py +++ b/crossposting_backend/urls.py @@ -14,8 +14,9 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('cms/', include('cms.urls')), ]