Commit a0d62440 authored by Volkov Gherman's avatar Volkov Gherman

Merge branch 'feature/base_application' into 'develop'

Merge base api logic into develop branch

See merge request !1
parents 963940e1 39348b27
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/
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
# 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 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.test import TestCase
# Create your tests here.
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
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)
...@@ -10,8 +10,12 @@ For the full list of settings and their values, see ...@@ -10,8 +10,12 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/ https://docs.djangoproject.com/en/4.2/ref/settings/
""" """
import os
from pathlib import Path from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
...@@ -20,7 +24,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent ...@@ -20,7 +24,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-hvwjn!iz%=4^9z*i-vb&%cm$m=8pf*6(qp(#7%r14ysc$0v3k2' SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
...@@ -37,9 +41,12 @@ INSTALLED_APPS = [ ...@@ -37,9 +41,12 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework',
'api',
] ]
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',
...@@ -47,6 +54,7 @@ MIDDLEWARE = [ ...@@ -47,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'
...@@ -67,6 +75,12 @@ TEMPLATES = [ ...@@ -67,6 +75,12 @@ TEMPLATES = [
}, },
] ]
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
]
}
WSGI_APPLICATION = 'core.wsgi.application' WSGI_APPLICATION = 'core.wsgi.application'
...@@ -75,9 +89,13 @@ WSGI_APPLICATION = 'core.wsgi.application' ...@@ -75,9 +89,13 @@ WSGI_APPLICATION = 'core.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': os.getenv('DATABASE_NAME'),
} 'USER': os.getenv('DATABASE_USER'),
'PASSWORD': os.getenv('DATABASE_PASSWORD'),
'HOST': os.getenv('DATABASE_HOST'),
'PORT': os.getenv('DATABASE_PORT'),
},
} }
...@@ -99,6 +117,12 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -99,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/
...@@ -117,6 +141,9 @@ USE_TZ = True ...@@ -117,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()),
] ]
...@@ -13,7 +13,7 @@ def main(): ...@@ -13,7 +13,7 @@ def main():
raise ImportError( raise ImportError(
"Couldn't import Django. Are you sure it's installed and " "Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you " "available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?" "forget to activate a virtual environment?",
) from exc ) from exc
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
......
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