Commit 39348b27 authored by Volkov Gherman's avatar Volkov Gherman

Create base test logic api app

parent 90754e40
SECRET_KEY='django secret key'
DATABASE_NAME='your database name'
DATABASE_USER='your database owner'
DATABASE_PASSWORD='your database password'
DATABASE_HOST='your database host'
DATABASE_PORT='your database port'
\ No newline at end of file
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
max-line-length = 100 max-line-length = 100
import-order-style = google import-order-style = google
application-import-names = core application-import-names = core
exclude = venv exclude = venv, docusign_test_app-python
\ No newline at end of file \ No newline at end of file
...@@ -149,4 +149,6 @@ cython_debug/ ...@@ -149,4 +149,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/ .idea/
\ No newline at end of file .DS_Store
docusign_test_app-python/
# Generated by Django 4.2.1 on 2023-05-24 09:44
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='DocumentNDA',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('owner_name', models.CharField(max_length=20, verbose_name='Имя')),
('owner_surname', models.CharField(max_length=20, verbose_name='Фамилия')),
('owner_email', models.EmailField(max_length=254, verbose_name='Почта')),
('source', models.FileField(blank=True, null=True, upload_to='demo', verbose_name='Исходник')),
('status', models.CharField(choices=[('Документ в обработке', 'Pending'), ('Документ успешно подписан', 'Resolve'), ('Не удалось подписать документ', 'Reject'), ('Документ ожидает подтверждения отправки на подпись', 'Default')], default='Документ ожидает подтверждения отправки на подпись', max_length=50, verbose_name='Статус заявки')),
],
),
]
from django.core.files.storage import FileSystemStorage
from django.db import models from django.db import models
# Create your models here. from core import settings
class StatusChoices(models.TextChoices):
PENDING = 'Документ в обработке'
RESOLVE = 'Документ успешно подписан'
REJECT = 'Не удалось подписать документ'
DEFAULT = 'Документ ожидает подтверждения отправки на подпись'
class DocumentNDA(models.Model):
owner_name = models.CharField(
max_length=20,
null=False,
blank=False,
verbose_name='Имя',
)
owner_surname = models.CharField(
max_length=20,
null=False,
blank=False,
verbose_name='Фамилия',
)
owner_email = models.EmailField(
max_length=254,
verbose_name='Почта',
)
source = models.FileField(
storage=FileSystemStorage(
location=settings.MEDIA_ROOT,
),
default='settings.MEDIA_ROOT/document.docx',
upload_to='demo',
blank=True,
null=True,
verbose_name='Исходник',
)
status = models.CharField(
max_length=50,
null=False,
blank=False,
choices=StatusChoices.choices,
default=StatusChoices.DEFAULT,
verbose_name='Статус заявки',
)
def __str__(self):
return f'{self.owner_name} {self.owner_email}'
from rest_framework import serializers
from api.models import DocumentNDA
class DocumentNDASerializer(serializers.ModelSerializer):
class Meta:
model = DocumentNDA
fields = ('id', 'owner_name', 'owner_surname', 'owner_email', 'status')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DocuSign test page</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</head>
<body>
<form id='form' method="POST">
<div class="form-group">
<label for="formGroupExampleInput">Введите свое имя</label>
<input name="owner_name" type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" required>
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Введите свою фамилию</label>
<input name="owner_surname" type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" required>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Введите свой Email</label>
<input name="owner_email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp"
placeholder="Enter email" required>
</div>
<button type="submit" class="btn btn-primary">Подтвердить и подписать документ</button>
</form>
</body>
<script>
const sendForm = (e) => {
e.preventDefault();
fetch('http://localhost:8000/api/v1/', {
method: 'POST',
body: new FormData(form)
}).then(form.reset())
}
const form = document.querySelector('#form');
form.addEventListener('submit', sendForm);
</script>
</html>
\ No newline at end of file
from django.shortcuts import render from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
# Create your views here. from api.serializers import DocumentNDASerializer
class IndexView(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'index.html'
def get(self, request):
return Response(template_name=self.template_name)
def post(self, request):
serializer = DocumentNDASerializer(data=request.data)
if serializer.is_valid():
serializer.save()
# отправка в докусайн
return Response(status=200, data=serializer.data)
return Response({'error': 'Bad Request'}, status=400)
...@@ -46,6 +46,7 @@ INSTALLED_APPS = [ ...@@ -46,6 +46,7 @@ INSTALLED_APPS = [
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
...@@ -53,6 +54,7 @@ MIDDLEWARE = [ ...@@ -53,6 +54,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.common.CommonMiddleware',
] ]
ROOT_URLCONF = 'core.urls' ROOT_URLCONF = 'core.urls'
...@@ -73,6 +75,12 @@ TEMPLATES = [ ...@@ -73,6 +75,12 @@ TEMPLATES = [
}, },
] ]
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
]
}
WSGI_APPLICATION = 'core.wsgi.application' WSGI_APPLICATION = 'core.wsgi.application'
...@@ -109,6 +117,12 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -109,6 +117,12 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = [
'http://loaclhost:8000/api/v1/',
'http://127.0.0.1:8000/api/v1/'
]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/ # https://docs.djangoproject.com/en/4.2/topics/i18n/
...@@ -127,6 +141,9 @@ USE_TZ = True ...@@ -127,6 +141,9 @@ USE_TZ = True
STATIC_URL = 'static/' STATIC_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'demo')
MEDIA_URL = '/demo/'
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
......
...@@ -17,6 +17,10 @@ Including another URLconf ...@@ -17,6 +17,10 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from api.views import IndexView
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/v1/', IndexView.as_view()),
] ]
django==4.2.* django==4.2.*
django-rest-framework==0.1.* djangorestframework==3.14.*
psycopg2-binary==2.9.* psycopg2-binary==2.9.*
python-dotenv==1.0.* python-dotenv==1.0.*
docusign-esign==3.22.*
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