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