Commit f4f758cf authored by Volkov Gherman's avatar Volkov Gherman

Refactor model

parent fe9c07b7
# Generated by Django 4.2.1 on 2023-05-24 09:44
# Generated by Django 4.2.1 on 2023-05-28 17:20
from django.db import migrations, models
......@@ -12,14 +12,13 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='DocumentNDA',
name='SignerInfo',
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='Статус заявки')),
('signer_name', models.CharField(max_length=20, verbose_name='Имя')),
('signer_surname', models.CharField(max_length=20, verbose_name='Фамилия')),
('signer_email', models.EmailField(max_length=254, verbose_name='Почта')),
('status', models.CharField(choices=[('Документ успешно подписан', 'Resolve'), ('Не удалось подписать документ', 'Reject'), ('Документ ожидает подтверждения отправки на подпись', 'Default')], default='Документ ожидает подтверждения отправки на подпись', max_length=50, verbose_name='Статус заявки')),
],
),
]
# Generated by Django 4.2.1 on 2023-05-28 17:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='signerinfo',
name='status',
field=models.CharField(choices=[('Документ отправлен на подпись, проверьте Вашу почту', 'Resolve'), ('Не удалось отправить документ на подпись', 'Reject'), ('Документ ожидает подтверждения отправки на подпись', 'Default')], default='Документ ожидает подтверждения отправки на подпись', max_length=100, verbose_name='Статус заявки'),
),
]
......@@ -5,41 +5,30 @@ from core import settings
class StatusChoices(models.TextChoices):
PENDING = 'Документ в обработке'
RESOLVE = 'Документ успешно подписан'
REJECT = 'Не удалось подписать документ'
RESOLVE = 'Документ отправлен на подпись, проверьте Вашу почту'
REJECT = 'Не удалось отправить документ на подпись'
DEFAULT = 'Документ ожидает подтверждения отправки на подпись'
class DocumentNDA(models.Model):
owner_name = models.CharField(
class SignerInfo(models.Model):
signer_name = models.CharField(
max_length=20,
null=False,
blank=False,
verbose_name='Имя',
)
owner_surname = models.CharField(
signer_surname = models.CharField(
max_length=20,
null=False,
blank=False,
verbose_name='Фамилия',
)
owner_email = models.EmailField(
signer_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,
max_length=100,
null=False,
blank=False,
choices=StatusChoices.choices,
......@@ -48,4 +37,4 @@ class DocumentNDA(models.Model):
)
def __str__(self):
return f'{self.owner_name} {self.owner_email}'
return f'{self.signer_name} {self.signer_email}'
from rest_framework import serializers
from api.models import DocumentNDA
from api.models import SignerInfo
class DocumentNDASerializer(serializers.ModelSerializer):
class Meta:
model = DocumentNDA
fields = ('id', 'owner_name', 'owner_surname', 'owner_email', 'status')
model = SignerInfo
fields = ('id', 'signer_name', 'signer_surname', 'signer_email', 'status')
......@@ -3,15 +3,15 @@ from docusign_esign import ApiClient, ApiException
from api.jwt_console import get_consent_url, get_token
from api.docusign_app.jwt_helpers import get_private_key
from api.models import DocumentNDA
from api.models import SignerInfo
from api.docusign_app.jwt_config import DS_JWT
from api.docusign_app.eSignature.examples.eg002_signing_via_email import Eg002SigningViaEmailController
def get_args(api_account_id, access_token, base_path):
document = DocumentNDA.objects.last()
signer_email = document.owner_email
signer_name = document.owner_name
document = SignerInfo.objects.last()
signer_email = document.signer_email
signer_name = document.signer_name
cc_email = 'example@mail.com'
cc_name = 'name'
......
......@@ -17,23 +17,24 @@
<form style="width: 70vh; margin: 10vh auto; padding: 20px 30px;" id='form' method="POST">
<div class="form-group">
<label for="formGroupExampleInput">Введите свое имя</label>
<input name="owner_name" type="text" class="form-control" id="formGroupExampleInput" placeholder="Вася"
<input name="signer_name" type="text" class="form-control" id="formGroupExampleInput" placeholder="Вася"
required>
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Введите свою фамилию</label>
<input name="owner_surname" type="text" class="form-control" id="formGroupExampleInput2"
<input name="signer_surname" type="text" class="form-control" id="formGroupExampleInput2"
placeholder="Пупкин" required>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Введите свой Email</label>
<input name="owner_email" type="email" class="form-control" id="exampleInputEmail1"
<input name="signer_email" type="email" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp"
placeholder="vasyaPupkin@.mail.com" required>
</div>
<button type="submit" class="btn btn-primary">Подтвердить и подписать документ
</button>
</form>
</main>
</body>
......
......@@ -5,6 +5,7 @@ from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
from api.models import StatusChoices
from api.serializers import DocumentNDASerializer
from api.services import send_docusign_email
......@@ -18,15 +19,20 @@ class SendDocumentView(APIView):
template_name = 'index.html'
def get(self, request):
return Response(template_name=self.template_name, status=200)
data = {'error': 'error'}
return Response(data, template_name=self.template_name, status=200)
def post(self, request):
serializer = DocumentNDASerializer(data=request.data)
if serializer.is_valid():
serializer.save()
signer = serializer.save()
try:
send_docusign_email()
signer.status = StatusChoices.RESOLVE
signer.save()
return Response(status=200, data=serializer.data)
except HTTPException as e:
return Response({'error': e}, status=503)
return Response({'error': 'Bad Request'}, status=400)
signer.status = StatusChoices.REJECT
signer.save()
return Response({'error': e, 'signer': signer}, status=503)
return Response({'error': 'Bad Request', 'description': 'Введенные Вами данные не валидны'}, status=400)
......@@ -76,6 +76,8 @@ TEMPLATES = [
},
]
APP_DIRS = True
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
......
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