Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
DocuSign_test_project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Volkov Gherman
DocuSign_test_project
Commits
7dd7acf9
Commit
7dd7acf9
authored
Jun 01, 2023
by
Volkov Gherman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add api views in api app
parent
836b1c2a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
8 deletions
+45
-8
serializers.py
api/serializers.py
+1
-1
index.html
api/templates/index.html
+1
-1
views.py
api/views.py
+38
-2
urls.py
core/urls.py
+5
-4
No files found.
api/serializers.py
View file @
7dd7acf9
...
@@ -3,7 +3,7 @@ from rest_framework import serializers
...
@@ -3,7 +3,7 @@ from rest_framework import serializers
from
api.models
import
SignerInfo
from
api.models
import
SignerInfo
class
DocumentNDA
Serializer
(
serializers
.
ModelSerializer
):
class
SignerInfo
Serializer
(
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
model
=
SignerInfo
model
=
SignerInfo
...
...
api/templates/index.html
View file @
7dd7acf9
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
<script>
<script>
const
sendForm
=
(
e
)
=>
{
const
sendForm
=
(
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
fetch
(
`
${
window
.
location
.
protocol
+
'//'
+
window
.
location
.
host
}
/
api/v1
/`
,
{
fetch
(
`
${
window
.
location
.
protocol
+
'//'
+
window
.
location
.
host
}
/
send_email
/`
,
{
method
:
'POST'
,
method
:
'POST'
,
body
:
new
FormData
(
form
)
body
:
new
FormData
(
form
)
})
})
...
...
api/views.py
View file @
7dd7acf9
...
@@ -6,7 +6,7 @@ from rest_framework.response import Response
...
@@ -6,7 +6,7 @@ from rest_framework.response import Response
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
api.models
import
StatusChoices
,
SignerInfo
from
api.models
import
StatusChoices
,
SignerInfo
from
api.serializers
import
DocumentNDA
Serializer
from
api.serializers
import
SignerInfo
Serializer
from
api.services
import
send_docusign_email
from
api.services
import
send_docusign_email
...
@@ -22,7 +22,7 @@ class SendDocumentView(APIView):
...
@@ -22,7 +22,7 @@ class SendDocumentView(APIView):
return
Response
(
template_name
=
self
.
template_name
,
status
=
200
)
return
Response
(
template_name
=
self
.
template_name
,
status
=
200
)
def
post
(
self
,
request
):
def
post
(
self
,
request
):
serializer
=
DocumentNDA
Serializer
(
data
=
request
.
data
)
serializer
=
SignerInfo
Serializer
(
data
=
request
.
data
)
if
serializer
.
is_valid
():
if
serializer
.
is_valid
():
signer
=
serializer
.
save
()
signer
=
serializer
.
save
()
try
:
try
:
...
@@ -46,3 +46,39 @@ def view_status(request):
...
@@ -46,3 +46,39 @@ def view_status(request):
else
:
else
:
data
=
{
'signer'
:
signer
,
'status'
:
'default'
}
data
=
{
'signer'
:
signer
,
'status'
:
'default'
}
return
render
(
request
,
'status.html'
,
context
=
{
'data'
:
data
},
status
=
200
)
return
render
(
request
,
'status.html'
,
context
=
{
'data'
:
data
},
status
=
200
)
class
SignApiView
(
APIView
):
def
get
(
self
,
request
):
data
=
{
'message'
:
'Заполните три поля, '
'Для отправки письма на подпись: "signer_name" - Ваше имя, '
'"signer_surmane" - Ваша фамилия, '
'"signer_email" - Ваш email и нажмите кнопку отправить'
}
return
Response
(
data
=
data
,
status
=
200
)
def
post
(
self
,
request
):
print
(
request
.
data
,
'data'
)
serializer
=
SignerInfoSerializer
(
data
=
request
.
data
)
if
serializer
.
is_valid
():
signer
=
serializer
.
save
()
try
:
send_docusign_email
()
signer
.
status
=
StatusChoices
.
RESOLVE
signer
.
save
()
return
Response
(
status
=
200
,
data
=
serializer
.
data
)
except
HTTPException
as
e
:
signer
.
status
=
StatusChoices
.
REJECT
signer
.
save
()
return
Response
({
'error'
:
e
,
'signer'
:
signer
},
status
=
503
)
return
Response
({
'error'
:
'Bad Request'
,
'description'
:
'Введенные Вами данные не валидны'
},
status
=
400
)
class
SignApiDetailView
(
APIView
):
def
get
(
self
,
request
,
pk
):
try
:
signer
=
SignerInfo
.
objects
.
get
(
pk
=
pk
)
serializer
=
SignerInfoSerializer
(
signer
)
return
Response
(
serializer
.
data
,
status
=
200
)
except
SignerInfo
.
DoesNotExist
:
return
Response
({
'error'
:
'Объект не найден'
},
status
=
404
)
core/urls.py
View file @
7dd7acf9
...
@@ -17,12 +17,13 @@ Including another URLconf
...
@@ -17,12 +17,13 @@ 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
index_view
,
SendDocumentView
,
view_status
from
api.views
import
index_view
,
SendDocumentView
,
view_status
,
SignApiView
,
SignApiDetailView
urlpatterns
=
[
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
''
,
index_view
,
name
=
'index'
),
path
(
''
,
index_view
,
name
=
'index'
),
path
(
'api/v1/'
,
SendDocumentView
.
as_view
(),
name
=
'send_email'
),
path
(
'send_email/'
,
SendDocumentView
.
as_view
(),
name
=
'send_email'
),
path
(
'api/v1/status/'
,
view_status
,
name
=
'view_status'
),
path
(
'status/'
,
view_status
,
name
=
'view_status'
),
path
(
'api/v1/'
,
SignApiView
.
as_view
(),
name
=
'send_email'
),
path
(
'api/v1/<int:pk>/'
,
SignApiDetailView
.
as_view
(),
name
=
'sign_api_retrieve'
),
]
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment